~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/sip/pres_sub_client.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2012, 2013 LOTES TM LLC
 
3
 *  Author : Andrey Loukhnov <aol.nnov@gmail.com>
 
4
 *  Author : Patrick Keroulas <patrick.keroulas@savoirfairelinux.com>
 
5
 *  This file is a part of pult5-voip
 
6
 *
 
7
 *  pult5-voip is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 3 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  pult5-voip is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this programm. If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 *  Additional permission under GNU GPL version 3 section 7:
 
21
 *
 
22
 *  If you modify pult5-voip, or any covered work, by linking or
 
23
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
24
 *  modified version of that library), containing parts covered by the
 
25
 *  terms of the OpenSSL or SSLeay licenses, LOTES-TM LLC
 
26
 *  Corresponding Source for a non-source form of such a combination
 
27
 *  shall include the source code for the parts of OpenSSL used as well
 
28
 *  as that of the covered work.
 
29
 */
 
30
 
 
31
#ifndef PRES_SUB_CLIENT_H
 
32
#define PRES_SUB_CLIENT_H
 
33
 
 
34
#include <pjsip-simple/presence.h>
 
35
#include <pj/timer.h>
 
36
#include <pj/pool.h>
 
37
#include <string>
 
38
 
 
39
#include <pjsip-simple/evsub.h>
 
40
#include <pjsip-simple/evsub_msg.h>
 
41
#include <pjsip/sip_endpoint.h>
 
42
#include <pjsip/sip_transport.h>
 
43
#include "noncopyable.h"
 
44
 
 
45
class SIPPresence;
 
46
 
 
47
class PresSubClient {
 
48
 
 
49
    public:
 
50
        /**
 
51
         * Constructor
 
52
         * @param uri   SIP uri of remote user that we want to subscribe,
 
53
         */
 
54
        PresSubClient(const std::string &uri, SIPPresence *pres);
 
55
        /**
 
56
         * Destructor.
 
57
         * Process the the unsubscription before the destruction.
 
58
         */
 
59
        ~PresSubClient();
 
60
        /**
 
61
         * Compare with another pres_client's uris.
 
62
         * @param b     Other pres_client pointer
 
63
         */
 
64
        bool match(PresSubClient *b);
 
65
        /**
 
66
         * Enable the monitoring and report signal to the client.
 
67
         * The PBX server must approve and maintain the subrciption before the pres_client is added in the pres_client list.
 
68
         * @param flag  State of subscription. True if active.
 
69
         */
 
70
        void enable(bool flag);
 
71
        /**
 
72
         * Get associated parent presence_module
 
73
         */
 
74
        SIPPresence * getPresence();
 
75
        /**
 
76
         * Data lock function
 
77
         */
 
78
        bool lock();
 
79
        /**
 
80
         * Data unlock function
 
81
         */
 
82
        void unlock();
 
83
        /**
 
84
         * Send a SUBCRIBE to the PXB or directly to a pres_client in the IP2IP context.
 
85
         */
 
86
        bool subscribe();
 
87
        /**
 
88
         * Send a SUBCRIBE to the PXB or directly to a pres_client in the IP2IP context but
 
89
         * the 0s timeout make the dialog expire immediatly.
 
90
         */
 
91
        bool unsubscribe();
 
92
        /**
 
93
         * Return  the monitor variable.
 
94
         */
 
95
        bool isSubscribed();
 
96
        /**
 
97
         * Return the pres_client URI
 
98
         */
 
99
        std::string getURI();
 
100
 
 
101
        /**
 
102
         * Is the buddy present
 
103
         */
 
104
        bool isPresent();
 
105
 
 
106
        /**
 
107
         * A message from the URIs
 
108
         */
 
109
        std::string getLineStatus();
 
110
 
 
111
 
 
112
        /**
 
113
         * TODO: explain this:
 
114
         */
 
115
        void incLock() {
 
116
            lock_count_++;
 
117
        }
 
118
        void decLock() {
 
119
            lock_count_--;
 
120
        }
 
121
 
 
122
    private:
 
123
 
 
124
        NON_COPYABLE(PresSubClient);
 
125
 
 
126
        /**
 
127
         * Transaction functions of event subscription client side.
 
128
         */
 
129
        static void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
 
130
        static void pres_client_evsub_on_tsx_state(pjsip_evsub *sub,
 
131
                pjsip_transaction *tsx,
 
132
                pjsip_event *event);
 
133
        static void pres_client_evsub_on_rx_notify(pjsip_evsub *sub,
 
134
                pjsip_rx_data *rdata,
 
135
                int *p_st_code,
 
136
                pj_str_t **p_st_text,
 
137
                pjsip_hdr *res_hdr,
 
138
                pjsip_msg_body **p_body);
 
139
        static void pres_client_timer_cb(pj_timer_heap_t *th, pj_timer_entry *entry);
 
140
 
 
141
        /**
 
142
         * Plan a retry or a renew a subscription.
 
143
         * @param reschedule    Allow for reschedule.
 
144
         * @param msec          Delay value in milliseconds.
 
145
         */
 
146
        void rescheduleTimer(bool reschedule, unsigned msec);
 
147
        /**
 
148
         * Callback after a presence notification was received.
 
149
         * Tranfert info to the SIP account.
 
150
         */
 
151
        void reportPresence();
 
152
        /**
 
153
         * Process the un/subscribe request transmission.
 
154
         */
 
155
        pj_status_t updateSubscription();
 
156
        /*
 
157
         * Compare the reason of a transaction end with the given string.
 
158
         */
 
159
        bool isTermReason(const std::string &);
 
160
        /**
 
161
         * return the code after a transaction is terminated.
 
162
         */
 
163
        unsigned getTermCode();
 
164
 
 
165
        SIPPresence      *pres_;        /**< Associated SIPPresence pointer */
 
166
        pj_str_t         uri_;          /**< pres_client URI. */
 
167
        pj_str_t         contact_;      /**< Contact learned from subscrp. */
 
168
        pj_str_t         display_;      /**< pres_client display name. */
 
169
        pjsip_dialog    *dlg_;          /**< The underlying dialog. */
 
170
        pj_bool_t        monitored_;      /**< Should we monitor? */
 
171
        pj_str_t         name_;         /**< pres_client name. */
 
172
        pj_caching_pool  cp_;
 
173
        pj_pool_t       *pool_;         /**< Pool for this pres_client. */
 
174
        pjsip_pres_status status_;  /**< pres_client presence status. */
 
175
        pjsip_evsub     *sub_;          /**< pres_client presence subscription */
 
176
        unsigned         term_code_;    /**< Subscription termination code */
 
177
        pj_str_t         term_reason_;  /**< Subscription termination reason */
 
178
        pj_timer_entry   timer_;        /**< Resubscription timer */
 
179
        void            *user_data_;        /**< Application data. */
 
180
        int lock_count_;
 
181
        int lock_flag_;
 
182
        static int modId_; // used to extract data structure from event_subscription
 
183
};
 
184
 
 
185
#endif    /*  PRES_SUB_CLIENT_H */