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