OPAL  Version 3.14.3
capi_ep.h
Go to the documentation of this file.
1 /*
2  * capi_ep.h
3  *
4  * ISDN via CAPI EndPoint
5  *
6  * Open Phone Abstraction Library
7  *
8  * Copyright (c) 2010 Vox Lucida Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open H323 Library.
21  *
22  * The Initial Developer of the Original Code is Vox Lucida Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 31407 $
27  * $Author: rjongbloed $
28  * $Date: 2014-02-07 18:19:26 +1100 (Fri, 07 Feb 2014) $
29  */
30 
31 #ifndef OPAL_LIDS_CAPI_EP_H
32 #define OPAL_LIDS_CAPI_EP_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <opal_config.h>
39 
40 #if OPAL_CAPI
41 
42 #include <opal/endpoint.h>
43 #include <ptclib/qchannel.h>
44 
45 
46 class OpalCapiFunctions;
47 class OpalCapiConnection;
48 struct OpalCapiMessage;
49 
50 
51 #define OPAL_OPT_CAPI_B_PROTO "B-Proto"
52 
53 
56 class OpalCapiEndPoint : public OpalEndPoint
57 {
58  PCLASSINFO(OpalCapiEndPoint, OpalEndPoint);
59 
60  public:
65  OpalCapiEndPoint(
66  OpalManager & manager
67  );
68 
70  ~OpalCapiEndPoint();
72 
98  virtual PSafePtr<OpalConnection> MakeConnection(
99  OpalCall & call,
100  const PString & party,
101  void * userData = NULL,
102  unsigned int options = 0,
103  OpalConnection::StringOptions * stringOptions = NULL
104  );
105 
115  virtual OpalMediaFormatList GetMediaFormats() const;
117 
120  virtual OpalCapiConnection * CreateConnection(
121  OpalCall & call,
122  void * userData,
123  unsigned int options,
124  OpalConnection::StringOptions * stringOptions,
125  unsigned controller,
126  unsigned bearer
127  );
129 
134  unsigned OpenControllers();
135 
139  PString GetDriverInfo() const;
141 
144 
145 
146  protected:
147  bool GetFreeLine(unsigned & controller, unsigned & bearer);
148  PDECLARE_NOTIFIER(PThread, OpalCapiEndPoint, ProcessMessages);
149  virtual void ProcessMessage(const OpalCapiMessage & message);
150  void ProcessConnectInd(const OpalCapiMessage & message);
151  virtual bool PutMessage(OpalCapiMessage & message);
152 
153  OpalCapiFunctions * m_capi;
154  PThread * m_thread;
155  unsigned m_applicationId;
156  PSyncPoint m_listenCompleted;
157 
158  struct Controller {
159  Controller() : m_active(false) { }
160 
161  bool GetFreeLine(unsigned & bearer);
162 
163  bool m_active;
164  vector<bool> m_bearerInUse;
165  };
166  typedef std::vector<Controller> ControllerVector;
167  ControllerVector m_controllers;
168  PMutex m_controllerMutex;
169 
170  struct IdToConnMap : public std::map<unsigned, PSafePtr<OpalCapiConnection> >
171  {
172  bool Forward(const OpalCapiMessage & message, unsigned id);
173  PMutex m_mutex;
174  };
175 
176  IdToConnMap m_cbciToConnection;
177  IdToConnMap m_plciToConnection;
178 
179  friend class OpalCapiConnection;
180 };
181 
182 
185 class OpalCapiConnection : public OpalConnection
186 {
187  PCLASSINFO(OpalCapiConnection, OpalConnection);
188 
189  public:
194  OpalCapiConnection(
195  OpalCall & call,
196  OpalCapiEndPoint & endpoint,
197  unsigned int options,
198  OpalConnection::StringOptions * stringOptions,
199  unsigned controller,
200  unsigned bearer
201  );
203 
214  virtual bool IsNetworkConnection() const;
215 
222  virtual PBoolean SetUpConnection();
223 
234  virtual PBoolean SetAlerting(
235  const PString & calleeName,
236  PBoolean withMedia
237  );
238 
243  virtual PBoolean SetConnected();
244 
263  virtual void OnReleased();
264 
271  virtual PString GetDestinationAddress();
272 
279  virtual OpalMediaFormatList GetMediaFormats() const;
280 
296  const OpalMediaFormat & mediaFormat,
297  unsigned sessionID,
298  PBoolean isSource
299  );
300 
307  virtual PBoolean SendUserInputTone(
308  char tone,
309  int duration
310  );
311 
313  virtual void OnApplyStringOptions();
315 
318 
319 
320  protected:
321  virtual void ProcessMessage(const OpalCapiMessage & message);
322  virtual bool PutMessage(OpalCapiMessage & message);
323 
324  OpalCapiEndPoint & m_endpoint;
325  unsigned m_controller; // 1..127
326  unsigned m_bearer;
327  DWORD m_PLCI;
328  DWORD m_NCCI;
329 
330  PSyncPoint m_disconnected;
331 
332  PBYTEArray m_Bprotocol;
333 
334  friend class OpalCapiEndPoint;
335  friend struct OpalCapiEndPoint::IdToConnMap;
336  friend class OpalCapiMediaStream;
337 };
338 
339 
343 class OpalCapiMediaStream : public OpalMediaStream
344 {
345  PCLASSINFO(OpalCapiMediaStream, OpalMediaStream);
346  public:
351  OpalCapiMediaStream(
352  OpalCapiConnection & conn,
353  const OpalMediaFormat & mediaFormat,
354  unsigned sessionID,
355  PBoolean isSource
356  );
358 
359 
365  virtual PBoolean ReadData(
366  BYTE * data,
367  PINDEX size,
368  PINDEX & length
369  );
370 
374  virtual PBoolean WriteData(
375  const BYTE * data,
376  PINDEX length,
377  PINDEX & written
378  );
379 
383  virtual PBoolean IsSynchronous() const;
385 
388 
389 
390  protected:
391  virtual void InternalClose();
392 
393  OpalCapiConnection & m_connection;
394  PQueueChannel m_queue;
395  PSyncPoint m_written;
396  PAdaptiveDelay m_delay;
397 
398  friend class OpalCapiConnection;
399 };
400 
401 
402 #endif // OPAL_CAPI
403 
404 #endif // OPAL_LIDS_CAPI_EP_H
405 
406 
407 // End of File ///////////////////////////////////////////////////////////////