Allow H.323 Plus library to be used in addition to the OpenH323 library
[asterisk/asterisk.git] / channels / h323 / compat_h323.h
1 #ifndef COMPAT_H323_H
2 #define COMPAT_H323_H
3
4 #include "ast_ptlib.h"
5
6 #if VERSION(OPENH323_MAJOR,OPENH323_MINOR,OPENH323_BUILD) < VERSION(1,17,3)
7 /**
8  *  Workaround for broken (less than 1.17.3) OpenH323 stack to be able to
9  *  make TCP connections from specific address
10  */
11 class MyH323TransportTCP : public H323TransportTCP
12 {
13         PCLASSINFO(MyH323TransportTCP, H323TransportTCP);
14
15 public:
16         MyH323TransportTCP(
17                 H323EndPoint & endpoint,    ///<  H323 End Point object
18                 PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(), ///<  Local interface to use
19                 PBoolean listen = FALSE         ///<  Flag for need to wait for remote to connect
20         );
21         /**Connect to the remote party.
22          */
23         virtual PBoolean Connect();
24 };
25 #else
26 #define MyH323TransportTCP H323TransportTCP
27 #endif /* <VERSION(1,17,3) */
28
29 class MyH323TransportUDP: public H323TransportUDP
30 {
31         PCLASSINFO(MyH323TransportUDP, H323TransportUDP);
32
33 public:
34         MyH323TransportUDP(H323EndPoint &endpoint,
35                 PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),
36                 WORD localPort = 0,
37                 WORD remotePort = 0): H323TransportUDP(endpoint, binding, localPort, remotePort)
38         {
39         }
40         virtual PBoolean DiscoverGatekeeper(H323Gatekeeper &,
41                 H323RasPDU &,
42                 const H323TransportAddress &);
43 protected:
44         PDECLARE_NOTIFIER(PThread, MyH323TransportUDP, DiscoverMain);
45         H323Gatekeeper *discoverGatekeeper;
46         H323RasPDU *discoverPDU;
47         const H323TransportAddress *discoverAddress;
48         PBoolean discoverResult;
49         PBoolean discoverReady;
50         PMutex discoverMutex;
51 };
52
53 template <class _Abstract_T, typename _Key_T = PString>
54 class MyPFactory: public PFactory<_Abstract_T, _Key_T>
55 {
56 public:
57         template <class _Concrete_T> class Worker: public PFactory<_Abstract_T, _Key_T>::WorkerBase
58         {
59         public:
60                 Worker(const _Key_T &_key, bool singleton = false)
61                         :PFactory<_Abstract_T, _Key_T>::WorkerBase(singleton), key(_key)
62                 {
63                         PFactory<_Abstract_T, _Key_T>::Register(key, this);
64                 }
65                 ~Worker()
66                 {
67                         PFactory<_Abstract_T, _Key_T>::Unregister(key);
68                 }
69         protected:
70                 virtual _Abstract_T *Create(const _Key_T &) const { return new _Concrete_T; }
71
72         private:
73                 PString key;
74     };
75 };
76
77 #ifdef H323_REGISTER_CAPABILITY
78 #undef H323_REGISTER_CAPABILITY
79 #endif
80 #define H323_REGISTER_CAPABILITY(cls, capName) static MyPFactory<H323Capability>::Worker<cls> cls##Factory(capName, true)
81
82 #ifdef OPAL_MEDIA_FORMAT_DECLARE
83 #undef OPAL_MEDIA_FORMAT_DECLARE
84 #endif
85
86 #define OPAL_MEDIA_FORMAT_DECLARE(classname, _fullName, _defaultSessionID, _rtpPayloadType, _needsJitter,_bandwidth, _frameSize, _frameTime, _timeUnits, _timeStamp) \
87 class classname : public OpalMediaFormat \
88 { \
89   public: \
90     classname() \
91       : OpalMediaFormat(_fullName, _defaultSessionID, _rtpPayloadType, _needsJitter, _bandwidth, \
92         _frameSize, _frameTime, _timeUnits, _timeStamp){} \
93 }; \
94 static MyPFactory<OpalMediaFormat>::Worker<classname> classname##Factory(_fullName, true)
95
96 #endif /* !defined AST_H323_H */