sipXcallLib home page


PtConnection.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _PtConnection_h_
13 #define _PtConnection_h_
14 
15 // SYSTEM INCLUDES
16 
17 // APPLICATION INCLUDES
18 #include <ptapi/PtDefs.h>
19 #include "ptapi/PtSessionDesc.h"
20 #include <os/OsBSem.h>
21 #include "os/OsProtectEventMgr.h"
22 
23 // DEFINES
24 // MACROS
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // CONSTANTS
28 // STRUCTS
29 // TYPEDEFS
30 // FORWARD DECLARATIONS
31 class PtCall;
33 class PtAddress;
34 class PtProviderListener;
35 class PtTerminal;
36 class TaoClientTask;
37 class TaoServerTask;
38 class TaoReference;
39 class TaoObjectMap;
40 
41 
42 
43 //:A PtConnection represents a link, or association, between a PtCall
44 //:object and a PtAddress object.
45 // The purpose of a PtConnection object is to describe the relationship
46 // between a PtCall object and a PtAddress object. A PtConnection object
47 // exists if the PtAddress is a part of the telephone call. Each PtConnection
48 // has a state that describes the particular stage of the relationship
49 // between the call and address. These states and their meanings are described
50 // below. Applications use the PtConnection.getCall() and
51 // PtConnection.getAddress() methods respectively to obtain the call and
52 // address associated with this connection.
53 // <p>
54 // From one perspective, an application may view a call only in terms of the
55 // PtAddress/PtConnection objects that are part of the call. This is termed
56 // a logical view of the call because it ignores the details provided by the
57 // PtTerminal and PtTerminalConnection objects that are also associated with
58 // a call. In many instances, simple applications (such as an outcall program)
59 // may only need to concern themselves with the logical view. In this logical
60 // view, a telephone call is viewed as two or more endpoint addresses in
61 // communication. The PtConnection object describes the state of each of these
62 // endpoint addresses with respect to the call.
63 //
64 // <H3>Calls and Addresses</H3>
65 // PtConnection objects are immutable in terms of their PtCall and PtAddress
66 // references. In other words, the association of a PtCall and PtAddress
67 // object to the PtConnection does not change throughout the lifetime of the
68 // PtConnection object instance. The same PtConnection object cannot be used
69 // in another telephone call. The existence of a PtConnection implies that
70 // its address is associated with its call in the manner described by the
71 // PtConnection's state.<br>
72 // <br>
73 // Although a PtConnection's PtAddress and PtCall references remain valid
74 // throughout the lifetime of the PtConnection object, the same is not true
75 // for the PtCall and PtAddress object's references to this PtConnection.
76 // Particularly, when a PtConnection moves into the
77 // PtConnection::DISCONNECTED state, it is no longer listed by the
78 // PtCall.getConnections() and PtAddress.getConnections() methods.
79 //
80 // <H3>PtTerminalConnections</H3>
81 // PtConnection objects are containers for zero or more PtTerminalConnection
82 // objects. PtConnection objects represent the relationship between the PtCall
83 // and the PtAddress, whereas PtTerminalConnection objects represent the
84 // relationship between the PtConnection and the PtTerminal. The relationship
85 // between the PtCall and the PtAddress may be viewed as a logical view of the
86 // call. The relationship between a PtConnection and a PtTerminal represents
87 // the physical view of the call, i.e., at which PtTerminal the telephone call
88 // terminates. For more information on PtTerminalConnections see the
89 // specification for that class.
90 //
91 // <H3>Connection States</H3>
92 // Descriptions in real world terms of each PtConnection state follow.
93 // These real world descriptions have no bearing on the specifications of
94 // methods, but serve to provide a more intuitive understanding of what
95 // is going on.<p>
96 // <dl>
97 // <dt><b>PtConnection::IDLE</b><br>
98 // <dd>The initial state for all new connections. Connections
99 // which are in the PtConnection::IDLE state are not actively part of a
100 // telephone call, yet their references to the PtCall and PtAddress objects
101 // are valid. Connections typically do not stay in the PtConnection::IDLE
102 // state for long; they transition quickly to other states.<br>
103 // <br>
104 // <dt><b>PtConnection::OFFERED</b><br>
105 // <dd>Indicates that an incoming call is being offered to the
106 // PtAddress associated with the PtConnection. Typically, applications must
107 // either accept or reject this offered call before the called party is
108 // alerted to the incoming telephone call. Alternatively, the application
109 // may use PtAddress.setOfferedTimeout() to specify how long the connection
110 // should remain in the PtConnection::OFFERED state before automatically
111 // transitioning to the PtConnection::ALERTING state.<br>
112 // <br>
113 // <dt><b>PtConnection::QUEUED</b><br>
114 // <dd>Indicates that a PtConnection is queued at the particular
115 // PtAddress associated with the PtConnection. For example, some telephony
116 // platforms permit the "queuing" of an incoming telephone call to a
117 // PtAddress when the PtAddress is busy.<br>
118 // <br>
119 // <dt><b>PtConnection::NETWORK_REACHED</b><br>
120 // <dd>Indicates that an outgoing telephone call has reached the
121 // network. Applications may not receive further events about this leg of
122 // the telephone call, depending upon the ability of the telephone network
123 // to provide additional progress information. Applications must decide
124 // whether to treat this as a connected telephone call.<br>
125 // <br>
126 // <dt><b>PtConnection::NETWORK_ALERTING</b><br>
127 // <dd>Indicates that an outgoing telephone call is alerting at the
128 // destination end, which was previously only known to have reached the
129 // network. Typically, PtConnections transition into this state from the
130 // PtConnection::NETWORK_REACHED state. This state results from additional
131 // progress information being sent from the telephone network.<br>
132 // <br>
133 // <dt><b>PtConnection::ALERTING</b><br>
134 // <dd>Implies that the address is being notified of an incoming
135 // call.<br>
136 // <br>
137 // <dt><b>PtConnection::INITIATED</B><br>
138 // <dd>Indicates the originating end of a telephone call has begun
139 // the process of placing a telephone call, but the dialing of the destination
140 // telephone address has not yet begun. Typically, a telephone associated
141 // with the PtAddress has gone "off hook."<br>
142 // <br>
143 // <dt><b>PtConnection::DIALING</b><br>
144 // <dd>Indicates the originating end of a telephone call has begun
145 // the process of dialing a destination telephone address, but has not yet
146 // completed dialing.<br>
147 // <br>
148 // <dt><b>PtConnection::ESTABLISHED</B><br>
149 // <dd>Implies that a connection and its address are actively part of
150 // a telephone call. For example, two people talking to one another are
151 // represented by two connections in the PtConnection::ESTABLISHED state.<br>
152 // <br>
153 // <dt><b>PtConnection::DISCONNECTED</B><br>
154 // <dd>Implies it is no longer part of the telephone call, although
155 // its references to PtCall and PtAddress still remain valid. A connection in
156 // this state is interpreted as once previously belonging to this telephone
157 // call.<br>
158 // <br>
159 // <dt><b>PtConnection::FAILED</B><br>
160 // <dd>Indicates that a connection to that end of the call has failed
161 // for some reason. One reason why a connection would be in the
162 // PtConnection::FAILED state is because the party was busy.<br>
163 // <br>
164 // <dt><b>PtConnection::UNKNOWN</B><br>
165 // <dd>Implies that the implementation is unable to determine the
166 // current state of the connection. Typically, methods are invalid on
167 // connections which are in this state. Connections may move in and out of
168 // the PtConnection::UNKNOWN state at any time.
169 // </dl>
170 // <H3>Listeners and Events</H3>
171 // All events pertaining to the PtConnection object are reported via the
172 // PtConnectionListener objects for the PtCall object associated with this
173 // connection. Events are reported to a PtConnectionListener when a new
174 // connection is created and whenever a connection changes state. Listeners
175 // are added to PtCall objects via the PtCall.addCallListener() method and
176 // more indirectly via the PtAddress.addCallListener() and
177 // PtTerminal.addCallListener() methods.
179 {
180 /* //////////////////////////// PUBLIC //////////////////////////////////// */
181 public:
182 
183  /*
184  * WARNING: These values are used by java. Please also change these values
185  * in PtConnection.java
186  */
188  {
189  IDLE = 0x50,
190  OFFERED = 0x51,
191  QUEUED = 0x52,
192  ALERTING = 0x53,
193  INITIATED = 0x54,
194  DIALING = 0x55,
197  ESTABLISHED = 0x58,
198  DISCONNECTED = 0x59,
199  FAILED = 0x5A,
200  UNKNOWN = 0x5B
201  };
202 
203 /* ============================ CREATORS ================================== */
204  PtConnection();
205  //:Default constructor
206 
207  PtConnection(TaoClientTask *pClient, const char *address, const char *callId);
208 
209  PtConnection(const PtConnection& rPtConnection);
210  //:Copy constructor
211 
212  PtConnection& operator=(const PtConnection& rhs);
213  //:Assignment operator
214 
215  PtConnection(const char* address, const char* callId);
216 
217  virtual
218  ~PtConnection();
219  //:Destructor
220 
221 /* ============================ MANIPULATORS ============================== */
222 
223  virtual PtStatus accept(void);
224  //:Accepts a telephone call incoming to a PtAddress.
228 
229  virtual PtStatus disconnect(void);
230  //:Drops this connection from an active telephone call.
234 
235  virtual PtStatus park(char* destinationURL, PtConnection& rNewConnection);
236  //:Parks a PtConnection at the indicated destination telephone address.
237  // Parking a PtConnection at a destination address drops this
238  // PtConnection from the PtCall and sets <i>rpNewConnection</i> to point
239  // to a new PtConnection at the specified destination address. The new
240  // PtConnection will be in the PtConnection::QUEUED state.
246 
247  virtual PtStatus redirect(char* destinationURL, PtConnection& rNewConnection);
248  //:Redirects an incoming telephone call to another telephone address.
249  // This method is very similar to the transfer feature, however,
250  // applications may invoke this method before first answering the
251  // telephone call. This method redirects the telephone call to another
252  // destination address provided as the argument to this method. Redirecting
253  // a PtConnection to a destination address drops this PtConnection from the
254  // PtCall and sets <i>rpNewConnection</i> to point to a new PtConnection at
255  // the specified destination address.
261 
262  virtual PtStatus reject(void);
263  //:Rejects a telephone call incoming to a PtAddress.
267 
268 /* ============================ ACCESSORS ================================= */
269 
270  virtual PtStatus getAddress(PtAddress& rAddress);
271  //:Sets <i>rpAddress</i> to point to the PtAddress corresponding to this
272  //:connection.
276 
277  virtual PtStatus getCall(PtCall& rCall);
278  //:Sets <i>rpCall</i> to point to the PtCall corresponding to this
279  //:connection.
283 
284  virtual PtStatus getSessionInfo(PtSessionDesc& rSession);
285  //:Sets <i>rSession</i> to the current session of the connection.
289 
290  virtual PtStatus getState(int& rState);
291  //:Sets <i>rState</i> to the current state of the connection, either
292  //:ALERTING, DIALING, DISCONNECTED, ESTABLISHED, FAILED, IDLE,
293  //:INITIATED, NETWORK_REACHED, NETWORK_ALERTING, OFFERED, QUEUED, or
294  //:UNKNOWN.
298 
299  virtual PtStatus getTerminalConnections(PtTerminalConnection termConnections[],
300  int size, int& nItems);
301  //:Returns an array of pointers to PtTerminalConnection objects currently
302  //:associated with this connection.
303  // The caller provides an array that can hold up to <i>size</i>
304  // PtTerminalConnection pointers. This method will fill in the
305  // <i>termConnections</i> array with up to <i>size</i> pointers. The
306  // actual number of pointers filled in is passed back via the
307  // <i>nItems</i> argument.
314 
315  virtual PtStatus numTerminalConnections(int& count);
316  //:Returns the number of terminal connections associated with this
317  //:connection.
321 
322  virtual PtStatus getToField(char* pName, int len);
323  //:Returns the SIP To field, upto len bytes
325 
326  virtual PtStatus getFromField(char* pName, int len);
327  //:Returns the SIP From field, upto len bytes
329 
330 /* ============================ INQUIRY =================================== */
331 friend class PtConnectionEvent;
332 
333 /* //////////////////////////// PROTECTED ///////////////////////////////// */
334 protected:
335 
336  UtlString mAddress;
337  UtlString mCallId;
338  int mState;
339 
340  static OsBSem semInit ;
341  //: Binary Semaphore used to guard initialiation and tear down
343  static unsigned int mRef;
344 
347 
348  OsTime mTimeOut;
349  void initialize();
350 
351 /* //////////////////////////// PRIVATE /////////////////////////////////// */
352 private:
353  OsProtectEventMgr *mpEventMgr;
354 
355 
356 };
357 
358 /* ============================ INLINE METHODS ============================ */
359 
360 #endif // _PtConnection_h_
Definition: TaoReference.h:35
PtStatus
Definition: PtDefs.h:49
virtual PtStatus reject(void)
param: (in) destinationURL - The destination URL where the call should be redirected. param: (out) rpNewConnection - Set to point to the PtConnection representing the redirect destination. retcode: PT_SUCCESS - Success retcode: PT_INVALID_STATE - Connection was not in either the OFFERED or ALERTING states. retcode: PT_PROVIDER_UNAVAILABLE - The provider is not available
Definition: PtConnection.cpp:721
virtual PtStatus getFromField(char *pName, int len)
param: (in) len - length of the string to store the To field
Definition: PtConnection.cpp:513
Definition: TaoObjectMap.h:56
Definition: PtConnection.h:190
PtConnection & operator=(const PtConnection &rhs)
Definition: PtConnection.cpp:122
Definition: PtConnection.h:199
Definition: PtProviderListener.h:33
Definition: PtConnection.h:197
int mState
Definition: PtConnection.h:338
PtConnection * mpConnection
Definition: PtConnection.h:345
virtual ~PtConnection()
Definition: PtConnection.cpp:90
ConnectionState
Definition: PtConnection.h:187
UtlString mAddress
Definition: PtConnection.h:336
virtual PtStatus accept(void)
Definition: PtConnection.cpp:140
PtConnection()
Definition: PtConnection.cpp:50
Definition: PtConnectionEvent.h:32
Definition: PtConnection.h:196
virtual PtStatus getAddress(PtAddress &rAddress)
retcode: PT_SUCCESS - Success retcode: PT_INVALID_STATE - Connection was not in either the OFFERED or...
Definition: PtConnection.cpp:303
virtual PtStatus numTerminalConnections(int &count)
param: (out) termConnections - The array of PtTerminalConnection pointers param: (in) size - The numb...
Definition: PtConnection.cpp:572
static TaoReference * mpTransactionCnt
Definition: PtConnection.h:342
virtual PtStatus getCall(PtCall &rCall)
param: (out) rpAddress - Pointer to the address object corresponding to this connection retcode: PT_S...
Definition: PtConnection.cpp:320
Definition: PtConnection.h:194
UtlString mCallId
Definition: PtConnection.h:337
Definition: PtConnection.h:193
virtual PtStatus getState(int &rState)
param: (out) rSession - Set to the current session of the connection retcode: PT_SUCCESS - Success re...
Definition: PtConnection.cpp:396
virtual PtStatus getToField(char *pName, int len)
param: (out) count - The number of terminal connections associated with this connection retcode: PT_S...
Definition: PtConnection.cpp:455
virtual PtStatus getSessionInfo(PtSessionDesc &rSession)
param: (out) rpCall - Pointer to the call object corresponding to this connection retcode: PT_SUCCESS...
Definition: PtConnection.cpp:336
Definition: PtTerminalConnection.h:139
TaoClientTask * mpClient
Definition: PtConnection.h:346
virtual PtStatus redirect(char *destinationURL, PtConnection &rNewConnection)
param: (in) destinationURL - The destination URL where the call should be parked. param: (out) rpNewC...
Definition: PtConnection.cpp:668
virtual PtStatus disconnect(void)
retcode: PT_SUCCESS - Success retcode: PT_INVALID_STATE - Connection was not in either the OFFERED or...
Definition: PtConnection.cpp:182
OsTime mTimeOut
Definition: PtConnection.h:348
Definition: PtConnection.h:178
Definition: PtConnection.h:189
Definition: PtSessionDesc.h:32
void initialize()
Definition: PtConnection.cpp:105
static OsBSem semInit
Definition: PtConnection.h:340
Definition: PtTerminal.h:178
virtual PtStatus getTerminalConnections(PtTerminalConnection termConnections[], int size, int &nItems)
param: (out) rState - Set to the current state of the connection retcode: PT_SUCCESS - Success retcod...
Definition: PtConnection.cpp:229
Definition: TaoServerTask.h:49
virtual PtStatus park(char *destinationURL, PtConnection &rNewConnection)
retcode: PT_SUCCESS - Success retcode: PT_INVALID_STATE - Connection was not in an appropriate state ...
Definition: PtConnection.cpp:625
static unsigned int mRef
Definition: PtConnection.h:343
Definition: PtConnection.h:198
Definition: PtConnection.h:200
Definition: PtCall.h:253
Definition: PtAddress.h:189
Definition: TaoClientTask.h:50
Definition: PtConnection.h:191
Definition: PtConnection.h:192
OsProtectEventMgr * mpEventMgr
Definition: PtConnection.h:353
Definition: PtConnection.h:195