sipXcallLib home page


PtProvider.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 _PtProvider_h_
13 #define _PtProvider_h_
14 
15 // SYSTEM INCLUDES
16 // APPLICATION INCLUDES
17 #include "os/OsDefs.h"
18 #include "os/OsBSem.h"
19 #include "os/OsProtectEventMgr.h"
20 #include "ptapi/PtDefs.h"
21 #include "tao/TaoDefs.h"
22 
23 // DEFINES
24 // MACROS
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // CONSTANTS
28 // STRUCTS
29 // TYPEDEFS
30 // FORWARD DECLARATIONS
31 class PtAddress;
32 class PtCall;
33 class PtProviderListener;
34 class PtTerminal;
35 class TaoClientTask;
36 class TaoServerTask;
37 class TaoReference;
38 class TaoObjectMap;
39 class CpCallManager;
40 
41 //:A PtProvider represents the software entity that interfaces with an
42 //:instance of the "Pingtel Server" to monitor and control a group of
43 //:Pingtel phones.
44 //
45 // <H3>Obtaining access to a Provider (Pingtel Server)</H3>
46 // A PtProvider object is created and returned by the static
47 // PtProvider::getProvider() method. This method sets up any needed
48 // communication paths between the application and the provider.
49 //
50 // <H3>Listeners and Events</H3>
51 // Each time a state change occurs on a provider, the application is notified
52 // via an event. These events are reported via PtProviderListener objects.
53 // Applications instantiate objects which are derived from the
54 // PtProviderListener class and use the PtProvider.addProviderListener()
55 // method to begin the delivery of events. Nearly all provider
56 // events reported via a PtProviderListener are instances of either the
57 // PtProviderEvent class or its descendants. The only exceptions are the
58 // PROVIDER_ADDRESS_ADDED and PROVIDER_ADDRESS_REMOVED events (which are
59 // instances of the PtAddressEvent class) and the PROVIDER_TERMINAL_ADDED
60 // and PROVIDER_TERMINAL_REMOVED events (which are instances of the
61 // PtTerminalEvent class).<br>
62 // <br>
63 // Applications may query the reported event object for
64 // the specific state change via the PtEvent.getId() method. When the
65 // provider changes state, a PtProviderEvent is reported via the
66 // PtProviderListener with one of the following event IDs:
67 // PROVIDER_IN_SERVICE, PROVIDER_OUT_OF_SERVICE, or PROVIDER_SHUTDOWN. A
68 // PtProviderEvent with an event ID of PROVIDER_EVENT_TRANSMISSION_ENDED is
69 // delivered to all PtProviderListeners when the provider becomes
70 // unobservable and is the final event delivered to the listener.
71 //
72 // <H3>Call Objects and Providers</H3>
73 // The PtProvider maintains knowledge of the calls currently associated with
74 // it. Applications may obtain an array of these calls via the
75 // PtProvider.getCalls() method. A PtProvider may have calls associated with
76 // it that were created before it came into existence. The provider maintains
77 // references to all calls until they move into the PtCall::INVALID state.<br>
78 // <br>
79 // Applications may create new calls using the PtProvider.createCall() method.
80 // A new call is returned in the PtCall::IDLE state. Applications may then
81 // use this idle call to place new phone calls. Once created, this new
82 // call object is returned via the PtProvider.getCalls() method.
83 //
84 // <H3>The Provider's domain</H3>
85 // The term "provider's domain" refers to the collection of PtAddress and
86 // PtTerminal objects which are local to the provider, and typically, can be
87 // controlled by the provider.
88 //
89 // <H3>Address and Terminal Objects</H3>
90 // A PtAddress object represents what we commonly think of as a "telephone
91 // number." For calls to IP telephony endpoints, the "telephone number" may
92 // actually be a URL or IP address identifying the endpoint. Regardless, it
93 // represents a logical endpoint of a phone call. A PtTerminal
94 // represents a physical endpoint connected to the telephone or IP network.
95 // An example of a terminal is a telephone that uses the Pingtel Telephony API.
96 // PtAddresses and PtTerminals are in a many-to-many relationship. A
97 // PtAddress may be associated with multiple PtTerminals, and PtTerminals
98 // may be associated with multiple PtAddresses. See the specifications for
99 // the PtAddress and PtTerminal classes for more information.<br>
100 // <br>
101 // Unlike PtCall objects, applications may not create PtTerminal or PtAddress
102 // objects. The PtProvider begins with knowledge of certain PtTerminal and
103 // PtAddress objects within its local domain. This list is quasi-static,
104 // changing only as logical and physical endpoints are added and removed in
105 // the phone system. The currently known addresses and terminals in the
106 // provider's domain are reported by the PtProvider.getAddresses() and
107 // PtProvider.getTerminals() methods, respectively.<br>
108 // <br>
109 // PtAddress and PtTerminal objects may also be created sometime during the
110 // operation of the PtProvider when the PtProvider learns of addresses and
111 // terminals that are outside of its domain. For example, if the PtProvider's
112 // domain is a PBX, the PtProvider will know about all PtAddresses and
113 // PtTerminals in the PBX. Any PtAddresses and PtTerminals it subsequently
114 // learns about that are outside the PBX are referred to as remote. These
115 // remote address and terminal objects are not reported by the
116 // PtProvider.getTerminals() and PtProvider.getAddresses() methods.
117 
119 {
120 /* //////////////////////////// PUBLIC //////////////////////////////////// */
121 public:
122 
124  {
128  };
132 
133 /* ============================ CREATORS ================================== */
134 
135  static PtStatus getProvider(const char* login, const char* password,
136  const char* server, const char* options,
137  CpCallManager* pCallMgr, PtProvider*& rpProvider);
138 
139  // static int getProvider(const char* login, const char* password,
140  // const char* server, const char* options,
141  // PtProvider& rProvider);
142  //:If successful, sets <i>rpProvider</i> to point to a PtProvider object.
149 
154 
155 /* ============================ MANIPULATORS ============================== */
156 
157  virtual PtStatus addProviderListener(PtProviderListener& rListener);
158  //:Adds a listener to the provider.
163 
164  virtual PtStatus createCall(PtCall& rCall);
165  //:If successful, sets <i>rpCall</i> to refer to a new PtCall object.
166  // The new PtCall object will be in the PtCall::IDLE state and have no
167  // connections.
172 
174  //:Removes the specified listener from the provider.
179 
180  virtual PtStatus shutdown(void);
181  //:Instructs the provider to shut itself down and perform all necessary
182  //:cleanup.
185 
186 /* ============================ ACCESSORS ================================= */
187 
188  virtual PtStatus getAddress(const char* phoneURL, PtAddress& rAddress);
189  //:Sets <i>rpAddress</i> to refer to the PtAddress corresponding to the
190  //:specified phone number or NULL if there is no corresponding address.
196 
197 // PtStatus getAddresses(PtAddress& arAddresses[], int size, int& nItems);
198  virtual PtStatus getAddresses(PtAddress arAddresses[], int size, int& nItems);
199  //: TRICKY: array of reference are illegal, avoid using reference here.
200  //:Returns an array of references to PtAddress objects that are known to
201  //:the provider and within its domain.
202  // The caller provides an array that can hold up to <i>size</i>
203  // PtAddress references. This method will fill in the <i>addresses</i>
204  // array with up to <i>size</i> references. The actual number of references
205  // filled in is passed back via the <i>nItems</i> argument.
212 
213  //PtStatus getCalls(PtCall& arCalls[], int size, int& nItems);
214  virtual PtStatus getCalls(PtCall arCalls[], int size, int& nItems);
215  //:WARNING: array of reference are illegal try to avoid it.
216  //:Returns an array of references to PtCall objects that are known to the
217  //:provider.
218  // The caller provides an array that can hold up to <i>size</i>
219  // PtCall references. This method will fill in the <i>calls</i> array with
220  // up to <i>size</i> references. The actual number of references filled in
221  // is passed back via the <i>nItems</i> argument.
228 
229  virtual PtStatus getProviderListeners(PtProviderListener* listeners[],
230  int size, int& nItems);
231  //:Returns an array of pointers to PtProviderListener objects that have
232  //:been registered with this provider.
233  // The caller provides an array that can hold up to <i>size</i>
234  // PtProviderListener pointers. This method will fill in the
235  // <i>listeners</i> array with up to <i>size</i> pointers. The actual
236  // number of pointers filled in is passed back via the <i>nItems</i>
237  // argument.
244 
245  virtual int getState(void);
246  //:Returns the current state of the provider, either IN_SERVICE,
247  //:OUT_OF_SERVICE or SHUTDOWN.
251 
252  virtual PtStatus getTerminal(const char* name, PtTerminal& rTerminal);
253  //:Assigns to <i>rTerminal</i> the PtTerminal corresponding to the
254  //:specified name.
260 // PtStatus getTerminals(PtTerminals& arTerms[], int size, int& nItems);
261  virtual PtStatus getTerminals(PtTerminal arTerms[], int size, int& nItems);
262  //:WARNING: avoid using array of reference.
263  //:Returns an array of references to PtTerminal objects that are known to
264  //:the provider and within its domain.
265  // The caller provides an array that can hold up to <i>size</i>
266  // PtTerminal references. This method will fill in the <i>terms</i> array
267  // with up to <i>size</i> references. The actual number of references
268  // filled in is passed back via the <i>nItems</i> argument.
275 
276  virtual PtStatus numAddresses(int& count);
277  //:Returns the number of addresses currently known to this provider and
278  //:within its domain.
282 
283  virtual PtStatus numCalls(int& count);
284  //:Returns the number of calls currently known to this provider.
288 
289  virtual PtStatus numProviderListeners(int& count);
290  //:Returns the number of PtProviderListeners currently registered with
291  //:this provider.
295 
296  virtual PtStatus numTerminals(int& count);
297  //:Returns the number of terminals currently known to this provider and
298  //:within its domain.
302 
303 /* ============================ INQUIRY =================================== */
304 
305 friend class PtTerminal;
306 
307 /* //////////////////////////// PROTECTED ///////////////////////////////// */
308 protected:
309  static OsBSem semInit ;
310  //: Binary Semaphore used to guard initialiation and tear down
311  static PtProvider* spInstance; // pointer to the single instance of
313 
315 
318 
321 
322  static unsigned int mRef;
323 
324 
325  UtlString mLogin;
326  UtlString mPass;
327 
329 
330  OsTime mTimeOut;
331 
332  void initialize();
333 
334  PtStatus createProvider(const char* login, const char* password,
335  const char* server, const char* options,
336  CpCallManager* pCallMgr = NULL);
337 
338  PtProvider(const char* login, const char* password,
339  const char* server, const char* options,
340  CpCallManager* pCallMgr = NULL);
341 
342  PtProvider(const PtProvider& rPtProvider);
343  //:Copy constructor (not implemented for this class)
344 
345  PtProvider& operator=(const PtProvider& rhs);
346  //:Assignment operator (not implemented for this class)
347 
348  PtProvider(UtlString& rLogin, UtlString& rPass);
349 
350  PtProvider();
351  //:Default constructor
352 
353  virtual
354  ~PtProvider();
355  //:Destructor
356 
357 /* //////////////////////////// PRIVATE /////////////////////////////////// */
358 private:
359  OsProtectEventMgr *mpEventMgr;
360  static UtlBoolean mbInvalidIP;
361  // the Pinger class
362  static OsBSem sLock; // semaphore used to ensure that there
363  // is only one instance of this class
364 
365  static UtlBoolean isLocal(const char* host);
366 
367 
368 
369 };
370 
371 /* ============================ INLINE METHODS ============================ */
372 
373 #endif // _PtProvider_h_
Definition: TaoReference.h:35
Abstract call manager.
Definition: CpCallManager.h:97
PtStatus
Definition: PtDefs.h:49
static TaoReference * mpTransactionCnt
Definition: PtProvider.h:314
static PtStatus getProvider(const char *login, const char *password, const char *server, const char *options, CpCallManager *pCallMgr, PtProvider *&rpProvider)
enumcode: IN_SERVICE - the provider is currently available for use enumcode: OUT_OF_SERVICE - the pro...
Definition: PtProvider.cpp:66
virtual PtStatus removeProviderListener(PtProviderListener &rListener)
param: (out) rCall - reference to the newly created call retcode: PT_SUCCESS - success retcode: PT_RE...
Definition: PtProvider.cpp:968
Definition: TaoObjectMap.h:56
virtual PtStatus addProviderListener(PtProviderListener &rListener)
param: (in) login - user identifier (used for authentication) param: (in) password - password (used f...
Definition: PtProvider.cpp:351
virtual PtStatus numProviderListeners(int &count)
param: (out) count - the number of calls known to this provider retcode: PT_SUCCESS - success retcode...
Definition: PtProvider.cpp:884
Definition: PtProviderListener.h:33
virtual PtStatus createCall(PtCall &rCall)
param: (in) rListener - the listener to add to this provider retcode: PT_SUCCESS - success retcode: P...
Definition: PtProvider.cpp:399
ProviderState mState
Definition: PtProvider.h:328
virtual int getState(void)
param: (out) listeners - the array of PtProviderListener pointers param: (in) size - the number of el...
Definition: PtProvider.cpp:651
virtual PtStatus getTerminal(const char *name, PtTerminal &rTerminal)
retcode: IN_SERVICE - the provider is available for use retcode: OUT_OF_SERVICE - the provider is tem...
Definition: PtProvider.cpp:695
OsTime mTimeOut
Definition: PtProvider.h:330
static TaoClientTask * mpClient
Definition: PtProvider.h:312
PtStatus createProvider(const char *login, const char *password, const char *server, const char *options, CpCallManager *pCallMgr=NULL)
Definition: PtProvider.cpp:102
static TaoReference * mpAddressCnt
Definition: PtProvider.h:320
Definition: PtProvider.h:127
virtual PtStatus getAddress(const char *phoneURL, PtAddress &rAddress)
retcode: PT_SUCCESS - success retcode: PT_PROVIDER_UNAVAILABLE - the provider is not available ...
Definition: PtProvider.cpp:447
static UtlBoolean mbInvalidIP
Definition: PtProvider.h:360
Definition: PtProvider.h:125
static TaoObjectMap * mpCalls
Definition: PtProvider.h:316
OsProtectEventMgr * mpEventMgr
Definition: PtProvider.h:359
virtual PtStatus numCalls(int &count)
param: (out) count - the number of addresses known to this provider retcode: PT_SUCCESS - success ret...
Definition: PtProvider.cpp:842
void initialize()
Definition: PtProvider.cpp:216
static PtProvider * spInstance
Definition: PtProvider.h:311
virtual ~PtProvider()
Definition: PtProvider.cpp:276
PtProvider & operator=(const PtProvider &rhs)
Definition: PtProvider.cpp:1046
Definition: PtProvider.h:126
virtual PtStatus getAddresses(PtAddress arAddresses[], int size, int &nItems)
param: (in) phoneURL - a URL representing the phone number to look up param: (out) rAddress - referen...
Definition: PtProvider.cpp:494
PtProvider()
Definition: PtProvider.cpp:239
virtual PtStatus numTerminals(int &count)
param: (out) count - the number of listeners known to this provider retcode: PT_SUCCESS - success ret...
Definition: PtProvider.cpp:926
UtlString mLogin
Definition: PtProvider.h:325
virtual PtStatus shutdown(void)
param: (in) rListener - the listener to remove from this provider retcode: PT_SUCCESS - success retco...
Definition: PtProvider.cpp:1016
virtual PtStatus getProviderListeners(PtProviderListener *listeners[], int size, int &nItems)
param: (out) arCalls - the array of PtCall pointers param: (in) size - the number of elements in the ...
Definition: PtProvider.cpp:600
Definition: PtTerminal.h:178
virtual PtStatus getTerminals(PtTerminal arTerms[], int size, int &nItems)
param: (in) name - the name to look up (typically the phone extension) param: (out) rpTerminal - the ...
Definition: PtProvider.cpp:743
Definition: TaoServerTask.h:49
UtlString mPass
Definition: PtProvider.h:326
virtual PtStatus getCalls(PtCall arCalls[], int size, int &nItems)
param: (out) arAddresses - the array of PtAddress references param: (in) size - the number of element...
Definition: PtProvider.cpp:552
static OsBSem semInit
Definition: PtProvider.h:309
static OsBSem sLock
Definition: PtProvider.h:362
Definition: PtCall.h:253
static TaoObjectMap * mpAddresses
Definition: PtProvider.h:319
Definition: PtAddress.h:189
static UtlBoolean isLocal(const char *host)
Definition: PtProvider.cpp:327
Definition: PtProvider.h:118
Definition: TaoClientTask.h:50
static TaoReference * mpCallCnt
Definition: PtProvider.h:317
static unsigned int mRef
Definition: PtProvider.h:322
ProviderState
Definition: PtProvider.h:123
virtual PtStatus numAddresses(int &count)
param: (out) arTerms - the array of PtTerminal references param: (in) size - the number of elements i...
Definition: PtProvider.cpp:800