sipXcallLib home page


PtTerminalConnection.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 #ifndef _PtTerminalConnection_h_
12 #define _PtTerminalConnection_h_
13 
14 // SYSTEM INCLUDES
15 // APPLICATION INCLUDES
16 #include "ptapi/PtDefs.h"
17 #include "os/OsDefs.h"
18 #include "os/OsBSem.h"
19 #include "os/OsProtectEventMgr.h"
20 
21 // DEFINES
22 // MACROS
23 // EXTERNAL FUNCTIONS
24 // EXTERNAL VARIABLES
25 // CONSTANTS
26 // STRUCTS
27 // TYPEDEFS
28 // FORWARD DECLARATIONS
29 class PtConnection;
30 class PtTerminal;
31 class TaoClientTask;
32 class TaoServerTask;
33 class TaoReference;
34 class TaoObjectMap;
35 class MpStreamPlayer;
36 class MpStreamPlaylistPlayer;
37 
38 
39 //:A PtTerminalConnection object represents the relationship between a
40 //:PtConnection and a PtTerminal.
41 // A PtTerminalConnection object must always be associated with a
42 // PtConnection object and a PtTerminal object. The association of a
43 // PtConnection and PtTerminal object to the PtTerminalConnection does not
44 // change throughout the lifetime of the PtTerminalConnection. Applications
45 // obtain the PtConnection and PtTerminal associated with the
46 // PtTerminalConnection via the PtTerminalConnection.getConnection() and
47 // PtTerminalConnection.getTerminal() methods, respectively.<br>
48 // <br>
49 // Because a PtTerminalConnection is associated with a PtConnection, it is
50 // therefore also associated with some PtCall. The PtTerminalConnection
51 // describes the specific relationship between a physical PtTerminal endpoint
52 // with respect to an address on a call. PtTerminalConnections provide a
53 // physical view of a call. For a particular PtAddress endpoint on a PtCall,
54 // there may be zero or more PtTerminals at which the call terminates. The
55 // PtTerminalConnection describes each specific PtTerminal on the call that
56 // is associated with a particular PtAddress endpoint on the call. Many
57 // simple applications may not care about which specific PtTerminals are on
58 // the PtCall at a particular PtAddress endpoint. In these cases, the logical
59 // view provided by PtConnections is sufficient.
60 //
61 // <H3>TerminalConnection States</H3>
62 // <p>
63 // The PtTerminalConnection has a state that describes the current
64 // relationship between a PtTerminal and a PtConnection.
65 // PtTerminalConnection states are distinct from PtConnection states.
66 // PtConnection states describe the relationship between an entire PtAddress
67 // endpoint and a PtCall, whereas the PtTerminalConnection state describes
68 // the relationship between one of the terminals at the endpoint address on
69 // the call with respect to its connection. Different terminals on a call
70 // which are associated with the same connection may be in different
71 // states.
72 // <p>
73 // The PtTerminalConnection class defines six states in the real world terms
74 // given below:<br><br>
75 // <dl>
76 // <dt>
77 // <b>PtTerminalConnection::IDLE</B></dt>
78 // <dd>
79 // The initial state for all PtTerminalConnections.
80 // PtTerminalConnection objects do not stay in this state for long.
81 // They typically transition into another state quickly.</dd>
82 // <dt>
83 // <b>PtTerminalConnection::RINGING</B></dt>
84 // <dd>
85 // Indicates the terminal is ringing, indicating that the terminal
86 // has an incoming call.</dd>
87 // <dt>
88 // <b>PtTerminalConnection::TALKING</B></dt>
89 // <dd>
90 // Indicates that the terminal is actively part of a PtCall,
91 // typically "off-hook", and that the party is communicating on the telephone
92 // call.</dd>
93 // <dt>
94 // <b>PtTerminalConnection::HELD</B></dt>
95 // <dd>
96 // Indicates that a terminal is part of a PtCall, but is on hold.
97 // Other PtTerminals which are on the same PtCall and associated with the same
98 // PtConnection may or may not also be in this state.</dd>
99 // <dt>
100 // <b>PtTerminalConnection::DROPPED</B></dt>
101 // <dd>
102 // Indicates that a particular PtTerminal has permanently left the
103 // telephone call.</dd>
104 // <dt>
105 // <b>PtTerminalConnection::UNKNOWN</B></dt>
106 // <dd>
107 // Indicates that the implementation is unable to determine the
108 // state of the PtTerminalConnection. PtTerminalConnections may transition
109 // into and out of this state at any time.</dd>
110 // </dl>
111 // <p>
112 // When a PtTerminalConnection moves into the PtTerminalConnection::DROPPED
113 // state, it is no longer associated with its PtConnection and PtTerminal.
114 // That is, both of these objects lose their references to the
115 // PtTerminalConnection. However, the PtTerminalConnection still maintains
116 // its references to the PtConnection and PtTerminal object for application
117 // reference. That is, when a PtTerminalConnection moves into the
118 // PtTerminalConnection::DROPPED state, the methods
119 // PtTerminalConnection.getConnection() and PtTerminalConnection.getTerminal()
120 // still return valid object pointers.
121 //
122 // <H3>Listeners and Events</H3>
123 // All events pertaining to the PtTerminalConnection object are reported via
124 // the PtCallListener objects for the Call object associated with this
125 // terminal connection. Events are reported to a PtCallListener when a new
126 // terminal connection is created and whenever a terminal connection changes
127 // state. Listeners are added to PtCall objects via the PtCall.addListener()
128 // method and more indirectly via the PtAddress.addCallListener() and
129 // PtTerminal.addCallListener() methods.<br>
130 // <br>
131 // All events pertaining to the PtTerminalConnection object are reported via
132 // the PtTerminalConnectionListener objects for the PtCall object associated
133 // with this terminal connection. Events are reported to a
134 // PtTerminalConnectionListener when a new PtTerminalConnection is created
135 // and whenever a PtTerminalConnection changes state. Listeners
136 // are added to PtCall objects via the PtCall.addCallListener() method and
137 // more indirectly via the PtAddress.addCallListener() and
138 // PtTerminal.addCallListener() methods.
140 {
141 /* //////////////////////////// PUBLIC //////////////////////////////////// */
142 public:
143 
145  {
146  IDLE = 0x60,
147  RINGING = 0x61,
148  TALKING = 0x62,
149  HELD = 0x63,
150  BRIDGED = 0x64,
151  IN_USE = 0x65,
152  DROPPED = 0x66,
153  UNKNOWN = 0x67
154  };
155 
156 /* ============================ CREATORS ================================== */
157 
159  //:Default constructor
160 
162  const char* address,
163  const char* termName,
164  const char* callId,
165  int nIsLocal);
166 
167  PtTerminalConnection(const PtTerminalConnection& rPtTerminalConnection);
168  //:Copy constructor (not implemented for this class)
169 
170  virtual
172  //:Destructor
173 
174 /* ============================ MANIPULATORS ============================== */
175 
177  //:Assignment operator (not implemented for this class)
178 
179  virtual PtStatus answer();
180  //:Answers an incoming telephone call on this PtTerminalConnection.
184 
185  virtual PtStatus hold();
186  //:Places this PtTerminalConnection on hold with respect to the PtCall
187  //:of which it is a part.
191 
192  virtual PtStatus unhold();
193  //:Takes this PtTerminalConnection off hold with respect to the PtCall
194  //:of which it is a part.
198 
199  virtual PtStatus startTone(int toneId, UtlBoolean local,
200  UtlBoolean remote, const char* locale=NULL);
201  //:Starts playing the indicated tone
202  // "toneId" is an integer that identifies which tone to play.
203  // if "local" is TRUE, then play the tone for the near end listener.
204  // if "remote" is TRUE, then play the tone for the far end listener.
205  // The "locale" string is used for localization. If it is NULL
206  // play the tones that are appropriate for the U.S.A.
207  // <br>
208  // The current set of toneId's are assigned as follows:
209  // #define DTMF_TONES_BASE 512 (from .../include/mp/dtmflib.h)
228 
229 
230  virtual PtStatus stopTone(void);
231  //:Stops playing the tone
232 
233  virtual PtStatus playFile(const char* audioFileName, UtlBoolean repeat,
234  UtlBoolean local, UtlBoolean remote);
235  //:Play the audio file. The name of the file to play is passed
236  //:as an argument.
237  //:"audioFileName" is the name of the audio file
241 
242  virtual PtStatus playFile(FILE* audioFilePtr, UtlBoolean repeat,
243  UtlBoolean local, UtlBoolean remote);
244  //:Play the audio file. A pointer to the file to play is passed
245  //:as an argument.
246  //:"audioFilePtr" is a pointer to the open audio file
250 
251  virtual PtStatus stopPlay(UtlBoolean closeFile);
252  //:Stop playing the audio file
254 
255  virtual PtStatus createPlayer(MpStreamPlayer** pPlayer, const char* szStream, int flags);
256  //:Creates a Player
257 
258  virtual PtStatus destroyPlayer(MpStreamPlayer* pPlayer);
259  //:Destroys a player
260 
261  virtual PtStatus createPlaylistPlayer(MpStreamPlaylistPlayer** pPlayer);
262  //:Creates a playlist Player
263 
264  virtual PtStatus destroyPlaylistPlayer(MpStreamPlaylistPlayer* pPlayer);
265  //:Destroys a playlist player
266 
267 /* ============================ ACCESSORS ================================= */
268 
269  virtual PtStatus getConnection(PtConnection& rConnection);
270  //:Sets <i>rpConnection</i> to refer to the PtConnection corresponding
271  //:to this terminal connection.
275 
276  virtual PtStatus getState(int& rState);
277  //:Sets <i>rState</i> to the current state of the terminal connection,
278  //:either DROPPED, HELD, IDLE, RINGING, TALKING or UNKNOWN.
282 
283  virtual PtStatus getTerminal(PtTerminal& rTerminal);
284  //:Sets <i>rpTerminal</i> to refer to the PtTerminal corresponding
285  //:to this terminal connection.
289 
290  virtual PtStatus getTerminalName(UtlString& rTerminalName);
291  //:Sets <i>rpTerminal</i> to refer to the PtTerminal corresponding
292  //:to this terminal connection.
296 
297  virtual PtStatus getAddressName(UtlString& rAddress);
298  //:Sets <i>rpTerminal</i> to refer to the PtTerminal corresponding
299  //:to this terminal connection.
303 
304  virtual PtStatus getCallId(UtlString& rCallId);
305  //:Sets <i>rpTerminal</i> to refer to the PtTerminal corresponding
306  //:to this terminal connection.
310 
311 /* ============================ INQUIRY =================================== */
312  virtual PtStatus isLocal(UtlBoolean& local);
313 
315 
316 /* //////////////////////////// PROTECTED ///////////////////////////////// */
317 protected:
318  PtTerminalConnection(const char* address, const char* terminalName, const char* callId, int isLocal);
319  //:Protected constructor.
320 
321  OsTime mTimeOut;
322 
323  void initialize();
324 
325  UtlString mAddress;
326  UtlString mTerminalName;
327  UtlString mCallId;
328  char mState;
329  int mIsLocal;
330 
331  static OsBSem semInit ;
332  //: Binary Semaphore used to guard initialiation and tear down
334  static int mRef;
335 
337 
338 /* //////////////////////////// PRIVATE /////////////////////////////////// */
339 private:
340  OsProtectEventMgr *mpEventMgr;
341 
342 };
343 
344 /* ============================ INLINE METHODS ============================ */
345 
346 #endif // _PtTerminalConnection_h_
Definition: TaoReference.h:35
PtStatus
Definition: PtDefs.h:49
Definition: PtTerminalConnection.h:148
Definition: TaoObjectMap.h:56
virtual PtStatus destroyPlayer(MpStreamPlayer *pPlayer)
Definition: PtTerminalConnection.cpp:793
virtual PtStatus getTerminalName(UtlString &rTerminalName)
param: (out) rpTerminal - Reference to the PtTerminal object corresponding to this terminal connectio...
Definition: PtTerminalConnection.cpp:457
Definition: PtTerminalConnection.h:147
virtual PtStatus unhold()
retcode: PT_SUCCESS - Success retcode: PT_INVALID_STATE - This terminal connection is not in the PtTe...
Definition: PtTerminalConnection.cpp:299
UtlString mTerminalName
Definition: PtTerminalConnection.h:326
virtual PtStatus createPlayer(MpStreamPlayer **pPlayer, const char *szStream, int flags)
if "closeFile is TRUE, then close the audio file.
Definition: PtTerminalConnection.cpp:738
Definition: PtTerminalConnection.h:151
virtual PtStatus getState(int &rState)
param: (out) rpConnection - Reference to the PtConnection object corresponding to this terminal conne...
Definition: PtTerminalConnection.cpp:345
Definition: PtTerminalConnection.h:146
TerminalConnectionState
Definition: PtTerminalConnection.h:144
TaoClientTask * mpClient
Definition: PtTerminalConnection.h:336
virtual PtStatus createPlaylistPlayer(MpStreamPlaylistPlayer **pPlayer)
Definition: PtTerminalConnection.cpp:844
virtual ~PtTerminalConnection()
Definition: PtTerminalConnection.cpp:113
OsProtectEventMgr * mpEventMgr
Definition: PtTerminalConnection.h:340
virtual PtStatus isLocal(UtlBoolean &local)
param: (out) rCallId - Reference to the call id of this terminal connection retcode: PT_SUCCESS - Suc...
Definition: PtTerminalConnection.cpp:944
static TaoReference * mpTransactionCnt
Definition: PtTerminalConnection.h:333
Definition: PtTerminalConnection.h:139
PtTerminalConnection & operator=(const PtTerminalConnection &rhs)
Definition: PtTerminalConnection.cpp:132
virtual PtStatus getAddressName(UtlString &rAddress)
param: (out) rTerminalName - Reference to the terminal name of this terminal connection retcode: PT_S...
Definition: PtTerminalConnection.cpp:464
Definition: PtTerminalConnection.h:152
Definition: PtTerminalConnectionEvent.h:36
virtual PtStatus getConnection(PtConnection &rConnection)
Definition: PtTerminalConnection.cpp:200
virtual PtStatus playFile(const char *audioFileName, UtlBoolean repeat, UtlBoolean local, UtlBoolean remote)
Definition: PtTerminalConnection.cpp:581
PtTerminalConnection()
Definition: PtTerminalConnection.cpp:46
static int mRef
Definition: PtTerminalConnection.h:334
Definition: PtConnection.h:178
UtlString mAddress
Definition: PtTerminalConnection.h:325
Definition: PtTerminal.h:178
Definition: PtTerminalConnection.h:153
Definition: TaoServerTask.h:49
virtual PtStatus destroyPlaylistPlayer(MpStreamPlaylistPlayer *pPlayer)
Definition: PtTerminalConnection.cpp:893
virtual PtStatus answer()
Definition: PtTerminalConnection.cpp:154
virtual PtStatus getCallId(UtlString &rCallId)
param: (out) rAddress - Reference to the adrress name of this terminal connection retcode: PT_SUCCESS...
Definition: PtTerminalConnection.cpp:471
char mState
Definition: PtTerminalConnection.h:328
virtual PtStatus stopTone(void)
DTMF_0 = &#39;0&#39; DTMF_1 = &#39;1&#39; DTMF_2 = &#39;2&#39; DTMF_3 = &#39;3&#39; DTMF_4 = &#39;4&#39; DTMF_5 = &#39;5&#39; DTMF_6 = &#39;6&#39; DTMF_7 = &#39;...
Definition: PtTerminalConnection.cpp:540
virtual PtStatus startTone(int toneId, UtlBoolean local, UtlBoolean remote, const char *locale=NULL)
retcode: PT_SUCCESS - Success retcode: PT_INVALID_STATE - This terminal connection is not in the PtTe...
Definition: PtTerminalConnection.cpp:478
virtual PtStatus stopPlay(UtlBoolean closeFile)
if "repeat" is TRUE, then play the audio file in a loop if "local" is TRUE, then play the audio for t...
Definition: PtTerminalConnection.cpp:696
Definition: TaoClientTask.h:50
Definition: PtTerminalConnection.h:150
void initialize()
Definition: PtTerminalConnection.cpp:98
OsTime mTimeOut
Definition: PtTerminalConnection.h:321
virtual PtStatus hold()
retcode: PT_SUCCESS - Success retcode: PT_INVALID_STATE - Connection is in the PtConnection::DISCONNE...
Definition: PtTerminalConnection.cpp:252
static OsBSem semInit
Definition: PtTerminalConnection.h:331
UtlString mCallId
Definition: PtTerminalConnection.h:327
int mIsLocal
Definition: PtTerminalConnection.h:329
virtual PtStatus getTerminal(PtTerminal &rTerminal)
param: (out) rState - Set to the current state of the terminal connection retcode: PT_SUCCESS - Succe...
Definition: PtTerminalConnection.cpp:405
Definition: PtTerminalConnection.h:149