# manager.h

Go to the documentation of this file.

    00001 /*
    00002  * manager.h
    00003  *
    00004  * OPAL system manager.
    00005  *
    00006  * Open Phone Abstraction Library (OPAL)
    00007  * Formally known as the Open H323 project.
    00008  *
    00009  * Copyright (c) 2001 Equivalence Pty. Ltd.
    00010  *
    00011  * The contents of this file are subject to the Mozilla Public License
    00012  * Version 1.0 (the "License"); you may not use this file except in
    00013  * compliance with the License. You may obtain a copy of the License at
    00014  * http://www.mozilla.org/MPL/
    00015  *
    00016  * Software distributed under the License is distributed on an "AS IS"
    00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00018  * the License for the specific language governing rights and limitations
    00019  * under the License.
    00020  *
    00021  * The Original Code is Open Phone Abstraction Library.
    00022  *
    00023  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
    00024  *
    00025  * Contributor(s): ______________________________________.
    00026  *
    00027  * $Revision: 20867 $
    00028  * $Author: dsandras $
    00029  * $Date: 2008-09-05 11:11:56 +0000 (Fri, 05 Sep 2008) $
    00030  */
    00031
    00032 #ifndef __OPAL_MANAGER_H
    00033 #define __OPAL_MANAGER_H
    00034
    00035 #ifdef P_USE_PRAGMA
    00036 #pragma interface
    00037 #endif
    00038
    00039 #include <opal/buildopts.h>
    00040
    00041 #include <opal/call.h>
    00042 #include <opal/connection.h> //OpalConnection::AnswerCallResponse
    00043 #include <opal/guid.h>
    00044 #include <opal/audiorecord.h>
    00045 #include <codec/silencedetect.h>
    00046 #include <codec/echocancel.h>
    00047 #include <ptclib/pstun.h>
    00048
    00049 #if OPAL_VIDEO
    00050 #include <ptlib/videoio.h>
    00051 #endif
    00052
    00053 class OpalEndPoint;
    00054 class OpalMediaPatch;
    00055
    00072 class OpalManager : public PObject
    00073 {
    00074     PCLASSINFO(OpalManager, PObject);
    00075   public:
    00080     OpalManager();
    00081
    00086     ~OpalManager();
    00088
    00098     void AttachEndPoint(
    00099       OpalEndPoint * endpoint,
    00100       const PString & prefix = PString::Empty()
    00101     );
    00102
    00106     void DetachEndPoint(
    00107       const PString & prefix
    00108     );
    00109     void DetachEndPoint(
    00110       OpalEndPoint * endpoint
    00111     );
    00112
    00115     OpalEndPoint * FindEndPoint(
    00116       const PString & prefix
    00117     );
    00118
    00121     PList<OpalEndPoint> GetEndPoints() const;
    00122
    00128     void ShutDownEndpoints();
    00130
    00152     virtual PBoolean SetUpCall(
    00153       const PString & partyA,
    00154       const PString & partyB,
    00155       PString & token,
    00156       void * userData = NULL,
    00157       unsigned options = 0,
    00158       OpalConnection::StringOptions * stringOptions = NULL
    00159     );
    00160
    00169     virtual void OnEstablishedCall(
    00170       OpalCall & call
    00171     );
    00172
    00178     virtual PBoolean HasCall(
    00179       const PString & token
    00180     ) { return activeCalls.FindWithLock(token, PSafeReference) != NULL; }
    00181
    00184     PINDEX GetCallCount() const { return activeCalls.GetSize(); }
    00185
    00186
    00193     virtual PBoolean IsCallEstablished(
    00194       const PString & token
    00195     );
    00196
    00205     PSafePtr<OpalCall> FindCallWithLock(
    00206       const PString & token,
    00207       PSafetyMode mode = PSafeReadWrite
    00208     ) { return activeCalls.FindWithLock(token, mode); }
    00209
    00217     virtual PBoolean ClearCall(
    00218       const PString & token,
    00219       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
    00220       PSyncPoint * sync = NULL
    00221     );
    00222
    00230     virtual PBoolean ClearCallSynchronous(
    00231       const PString & token,
    00232       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser
    00233     );
    00234
    00240     virtual void ClearAllCalls(
    00241       OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
    00242       PBoolean wait = PTrue
    00243     );
    00244
    00258     virtual void OnClearedCall(
    00259       OpalCall & call
    00260     );
    00261
    00270     virtual OpalCall * CreateCall(
    00271       void * userData
    00272     );
    00273     virtual OpalCall * CreateCall();
    00274     OpalCall * InternalCreateCall();
    00275
    00284     virtual void DestroyCall(
    00285       OpalCall * call
    00286     );
    00287
    00291     PString GetNextCallToken();
    00293
    00330     virtual PBoolean MakeConnection(
    00331       OpalCall & call,
    00332       const PString & party,
    00333       void * userData = NULL,
    00334       unsigned int options = 0,
    00335       OpalConnection::StringOptions * stringOptions = NULL
    00336     );
    00337
    00364     virtual PBoolean OnIncomingConnection(
    00365       OpalConnection & connection,
    00366       unsigned options,
    00367       OpalConnection::StringOptions * stringOptions
    00368     );
    00369     virtual PBoolean OnIncomingConnection(
    00370       OpalConnection & connection,
    00371       unsigned options
    00372     );
    00373     virtual PBoolean OnIncomingConnection(
    00374       OpalConnection & connection
    00375     );
    00376
    00383     virtual bool OnRouteConnection(
    00384       const PString & a_party,
    00385       const PString & b_party,
    00386       OpalCall & call,
    00387       unsigned options,
    00388       OpalConnection::StringOptions * stringOptions
    00389     );
    00390
    00407     virtual void OnAlerting(
    00408       OpalConnection & connection
    00409     );
    00410
    00411     virtual OpalConnection::AnswerCallResponse
    00412        OnAnswerCall(OpalConnection & connection,
    00413                      const PString & caller
    00414     );
    00415
    00427     virtual void OnConnected(
    00428       OpalConnection & connection
    00429     );
    00430
    00444     virtual void OnEstablished(
    00445       OpalConnection & connection
    00446     );
    00447
    00463     virtual void OnReleased(
    00464       OpalConnection & connection
    00465     );
    00466
    00473     virtual void OnHold(
    00474       OpalConnection & connection,
    00475       bool fromRemote,
    00476       bool onHold
    00477     );
    00478     virtual void OnHold(OpalConnection & connection); // For backward compatibility
    00479
    00484     virtual PBoolean OnForwarded(
    00485       OpalConnection & connection,
    00486       const PString & remoteParty
    00487     );
    00489
    00501     virtual void AdjustMediaFormats(
    00502       const OpalConnection & connection,
    00503       OpalMediaFormatList & mediaFormats
    00504     ) const;
    00505
    00508     virtual PBoolean IsMediaBypassPossible(
    00509       const OpalConnection & source,
    00510       const OpalConnection & destination,
    00511       unsigned sessionID
    00512     ) const;
    00513
    00529     virtual PBoolean OnOpenMediaStream(
    00530       OpalConnection & connection,
    00531       OpalMediaStream & stream
    00532     );
    00533
    00541     virtual void OnRTPStatistics(
    00542       const OpalConnection & connection,
    00543       const RTP_Session & session
    00544     );
    00545
    00550     virtual void OnClosedMediaStream(
    00551       const OpalMediaStream & stream
    00552     );
    00553
    00554 #if OPAL_VIDEO
    00555
    00560     virtual void AddVideoMediaFormats(
    00561       OpalMediaFormatList & mediaFormats,
    00562       const OpalConnection * connection = NULL
    00563     ) const;
    00564
    00567     virtual PBoolean CreateVideoInputDevice(
    00568       const OpalConnection & connection,
    00569       const OpalMediaFormat & mediaFormat,
    00570       PVideoInputDevice * & device,
    00571       PBoolean & autoDelete
    00572     );
    00573
    00577     virtual PBoolean CreateVideoOutputDevice(
    00578       const OpalConnection & connection,
    00579       const OpalMediaFormat & mediaFormat,
    00580       PBoolean preview,
    00581       PVideoOutputDevice * & device,
    00582       PBoolean & autoDelete
    00583     );
    00584 #endif
    00585
    00593     virtual OpalMediaPatch * CreateMediaPatch(
    00594       OpalMediaStream & source,
    00595       PBoolean requiresPatchThread = PTrue
    00596     );
    00597
    00602     virtual void DestroyMediaPatch(
    00603       OpalMediaPatch * patch
    00604     );
    00605
    00613     virtual PBoolean OnStartMediaPatch(
    00614       const OpalMediaPatch & patch
    00615     );
    00617
    00625     virtual void OnUserInputString(
    00626       OpalConnection & connection,
    00627       const PString & value
    00628     );
    00629
    00636     virtual void OnUserInputTone(
    00637       OpalConnection & connection,
    00638       char tone,
    00639       int duration
    00640     );
    00641
    00644     virtual PString ReadUserInput(
    00645       OpalConnection & connection,
    00646       const char * terminators = "#\r\n",
    00647       unsigned lastDigitTimeout = 4,
    00648       unsigned firstDigitTimeout = 30
    00649     );
    00651
    00654     enum MessageWaitingType {
    00655       NoMessageWaiting,
    00656       VoiceMessageWaiting,
    00657       FaxMessageWaiting,
    00658       PagerMessageWaiting,
    00659       MultimediaMessageWaiting,
    00660       TextMessageWaiting,
    00661       NumMessageWaitingTypes
    00662     };
    00663
    00666     virtual void OnMWIReceived(
    00667       const PString & party,
    00668       MessageWaitingType type,
    00669       const PString & extraInfo
    00670     );
    00671
    00672
    00673     class RouteEntry : public PObject
    00674     {
    00675         PCLASSINFO(RouteEntry, PObject);
    00676       public:
    00677         RouteEntry(const PString & pat, const PString & dest);
    00678         void PrintOn(ostream & strm) const;
    00679         PString            pattern;
    00680         PString            destination;
    00681         PRegularExpression regex;
    00682     };
    00683     PARRAY(RouteTable, RouteEntry);
    00684
    00795     virtual PBoolean AddRouteEntry(
    00796       const PString & spec
    00797     );
    00798
    00805     PBoolean SetRouteTable(
    00806       const PStringArray & specs
    00807     );
    00808
    00813     void SetRouteTable(
    00814       const RouteTable & table
    00815     );
    00816
    00819     const RouteTable & GetRouteTable() const { return routeTable; }
    00820
    00828     virtual PString ApplyRouteTable(
    00829       const PString & source,
    00830       const PString & destination,
    00831       PINDEX & entry
    00832     );
    00834
    00839     const OpalProductInfo & GetProductInfo() const { return productInfo; }
    00840
    00843     void SetProductInfo(
    00844       const OpalProductInfo & info,
    00845       bool updateAll = true
    00846     );
    00847
    00850     const PString & GetDefaultUserName() const { return defaultUserName; }
    00851
    00854     void SetDefaultUserName(
    00855       const PString & name,
    00856       bool updateAll = true
    00857     );
    00858
    00861     const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
    00862
    00865     void SetDefaultDisplayName(
    00866       const PString & name,
    00867       bool updateAll = true
    00868     );
    00869
    00870 #if OPAL_VIDEO
    00871
    00874     PBoolean CanAutoStartReceiveVideo() const { return autoStartReceiveVideo; }
    00875
    00878     void SetAutoStartReceiveVideo(PBoolean can) { autoStartReceiveVideo = can; }
    00879
    00882     PBoolean CanAutoStartTransmitVideo() const { return autoStartTransmitVideo; }
    00883
    00886     void SetAutoStartTransmitVideo(PBoolean can) { autoStartTransmitVideo = can; }
    00887
    00888 #endif
    00889
    00896     virtual PBoolean IsLocalAddress(
    00897       const PIPSocket::Address & remoteAddress
    00898     ) const;
    00899
    00917     virtual PBoolean IsRTPNATEnabled(
    00918       OpalConnection & connection,
    00919       const PIPSocket::Address & localAddr,
    00920       const PIPSocket::Address & peerAddr,
    00921       const PIPSocket::Address & signalAddr,
    00922       PBoolean incoming
    00923     );
    00924
    00931     virtual PBoolean TranslateIPAddress(
    00932       PIPSocket::Address & localAddress,
    00933       const PIPSocket::Address & remoteAddress
    00934     );
    00935
    00938     const PString & GetTranslationHost() const { return translationHost; }
    00939
    00942     bool SetTranslationHost(
    00943       const PString & host
    00944     );
    00945
    00948     const PIPSocket::Address & GetTranslationAddress() const { return translationAddress; }
    00949
    00952     void SetTranslationAddress(
    00953       const PIPSocket::Address & address
    00954     );
    00955
    00961     virtual PNatMethod * GetNatMethod(
    00962       const PIPSocket::Address & remoteAddress = PIPSocket::GetDefaultIpAny()
    00963     ) const;
    00964
    00969     PSTUNClient::NatTypes SetSTUNServer(
    00970       const PString & server
    00971     );
    00972
    00975     const PString & GetSTUNServer() const { return stunServer; }
    00976
    00979     PSTUNClient * GetSTUNClient() const { return stun; }
    00980
    00983     WORD GetTCPPortBase() const { return tcpPorts.base; }
    00984
    00987     WORD GetTCPPortMax() const { return tcpPorts.max; }
    00988
    00991     void SetTCPPorts(unsigned tcpBase, unsigned tcpMax);
    00992
    00995     WORD GetNextTCPPort();
    00996
    00999     WORD GetUDPPortBase() const { return udpPorts.base; }
    01000
    01003     WORD GetUDPPortMax() const { return udpPorts.max; }
    01004
    01007     void SetUDPPorts(unsigned udpBase, unsigned udpMax);
    01008
    01011     WORD GetNextUDPPort();
    01012
    01015     WORD GetRtpIpPortBase() const { return rtpIpPorts.base; }
    01016
    01019     WORD GetRtpIpPortMax() const { return rtpIpPorts.max; }
    01020
    01023     void SetRtpIpPorts(unsigned udpBase, unsigned udpMax);
    01024
    01027     WORD GetRtpIpPortPair();
    01028
    01031     BYTE GetRtpIpTypeofService() const { return rtpIpTypeofService; }
    01032
    01035     void SetRtpIpTypeofService(unsigned tos) { rtpIpTypeofService = (BYTE)tos; }
    01036
    01041     PINDEX GetMaxRtpPayloadSize() const { return rtpPayloadSizeMax; }
    01042
    01047     void SetMaxRtpPayloadSize(
    01048       PINDEX size,
    01049       bool mtu = false
    01050     ) { rtpPayloadSizeMax = size - (mtu ? (20+16+12) : 0); }
    01051
    01055     unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
    01056
    01060     unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
    01061
    01071     void SetAudioJitterDelay(
    01072       unsigned minDelay,
    01073       unsigned maxDelay
    01074     );
    01075
    01078     const PStringArray & GetMediaFormatOrder() const { return mediaFormatOrder; }
    01079
    01082     void SetMediaFormatOrder(
    01083       const PStringArray & order
    01084     );
    01085
    01088     const PStringArray & GetMediaFormatMask() const { return mediaFormatMask; }
    01089
    01092     void SetMediaFormatMask(
    01093       const PStringArray & mask   //< New mask
    01094     );
    01095
    01098     virtual void SetSilenceDetectParams(
    01099       const OpalSilenceDetector::Params & params
    01100     ) { silenceDetectParams = params; }
    01101
    01104     const OpalSilenceDetector::Params & GetSilenceDetectParams() const { return silenceDetectParams; }
    01105
    01108     virtual void SetEchoCancelParams(
    01109       const OpalEchoCanceler::Params & params
    01110     ) { echoCancelParams = params; }
    01111
    01114     const OpalEchoCanceler::Params & GetEchoCancelParams() const { return echoCancelParams; }
    01115
    01116 #if OPAL_VIDEO
    01117
    01125     virtual PBoolean SetVideoInputDevice(
    01126       const PVideoDevice::OpenArgs & deviceArgs
    01127     );
    01128
    01132     const PVideoDevice::OpenArgs & GetVideoInputDevice() const { return videoInputDevice; }
    01133
    01141     virtual PBoolean SetVideoPreviewDevice(
    01142       const PVideoDevice::OpenArgs & deviceArgs
    01143     );
    01144
    01148     const PVideoDevice::OpenArgs & GetVideoPreviewDevice() const { return videoPreviewDevice; }
    01149
    01157     virtual PBoolean SetVideoOutputDevice(
    01158       const PVideoDevice::OpenArgs & deviceArgs
    01159     );
    01160
    01164     const PVideoDevice::OpenArgs & GetVideoOutputDevice() const { return videoOutputDevice; }
    01165
    01166 #endif
    01167
    01168     PBoolean DetectInBandDTMFDisabled() const
    01169       { return disableDetectInBandDTMF; }
    01170
    01173     void DisableDetectInBandDTMF(
    01174       PBoolean mode
    01175     ) { disableDetectInBandDTMF = mode; }
    01176
    01179     const PTimeInterval & GetNoMediaTimeout() const { return noMediaTimeout; }
    01180
    01183     PBoolean SetNoMediaTimeout(
    01184       const PTimeInterval & newInterval
    01185     );
    01186
    01189     const PString & GetDefaultILSServer() const { return ilsServer; }
    01190
    01193     void SetDefaultILSServer(
    01194       const PString & server
    01195     ) { ilsServer = server; }
    01197
    01198     // needs to be public for gcc 3.4
    01199     void GarbageCollection();
    01200
    01206     virtual void OnNewConnection(
    01207       OpalConnection & connection
    01208     );
    01209
    01210     virtual void SetDefaultSecurityMode(const PString & v)
    01211     { defaultSecurityMode = v; }
    01212
    01213     virtual PString GetDefaultSecurityMode() const
    01214     { return defaultSecurityMode; }
    01215
    01216     virtual PBoolean UseRTPAggregation() const;
    01217
    01218     OpalRecordManager & GetRecordManager()
    01219     { return recordManager; }
    01220
    01221     virtual PBoolean StartRecording(const PString & callToken, const PFilePath & fn);
    01222     virtual bool IsRecording(const PString & callToken);
    01223     virtual void StopRecording(const PString & callToken);
    01224
    01225   protected:
    01226     // Configuration variables
    01227     OpalProductInfo productInfo;
    01228
    01229     PString       defaultUserName;
    01230     PString       defaultDisplayName;
    01231
    01232 #if OPAL_VIDEO
    01233     PBoolean          autoStartReceiveVideo;
    01234     PBoolean          autoStartTransmitVideo;
    01235 #endif
    01236
    01237     BYTE          rtpIpTypeofService;
    01238     PINDEX        rtpPayloadSizeMax;
    01239     unsigned      minAudioJitterDelay;
    01240     unsigned      maxAudioJitterDelay;
    01241     PStringArray  mediaFormatOrder;
    01242     PStringArray  mediaFormatMask;
    01243     PBoolean          disableDetectInBandDTMF;
    01244     PTimeInterval noMediaTimeout;
    01245     PString       ilsServer;
    01246
    01247     OpalSilenceDetector::Params silenceDetectParams;
    01248     OpalEchoCanceler::Params echoCancelParams;
    01249
    01250 #if OPAL_VIDEO
    01251     PVideoDevice::OpenArgs videoInputDevice;
    01252     PVideoDevice::OpenArgs videoPreviewDevice;
    01253     PVideoDevice::OpenArgs videoOutputDevice;
    01254 #endif
    01255
    01256     struct PortInfo {
    01257       void Set(
    01258         unsigned base,
    01259         unsigned max,
    01260         unsigned range,
    01261         unsigned dflt
    01262       );
    01263       WORD GetNext(
    01264         unsigned increment
    01265       );
    01266
    01267       PMutex mutex;
    01268       WORD   base;
    01269       WORD   max;
    01270       WORD   current;
    01271     } tcpPorts, udpPorts, rtpIpPorts;
    01272
    01273     class InterfaceMonitor : public PInterfaceMonitorClient
    01274     {
    01275       PCLASSINFO(InterfaceMonitor, PInterfaceMonitorClient);
    01276
    01277       enum {
    01278         OpalManagerInterfaceMonitorClientPriority = 100,
    01279       };
    01280       public:
    01281         InterfaceMonitor(OpalManager & manager);
    01282
    01283       protected:
    01284         virtual void OnAddInterface(const PIPSocket::InterfaceEntry & entry);
    01285         virtual void OnRemoveInterface(const PIPSocket::InterfaceEntry & entry);
    01286
    01287         OpalManager & m_manager;
    01288     };
    01289
    01290     PString            translationHost;
    01291     PIPSocket::Address translationAddress;
    01292     PString            stunServer;
    01293     PSTUNClient      * stun;
    01294     InterfaceMonitor * interfaceMonitor;
    01295
    01296     RouteTable routeTable;
    01297     PMutex     routeTableMutex;
    01298
    01299     // Dynamic variables
    01300     PReadWriteMutex     endpointsMutex;
    01301     PList<OpalEndPoint> endpointList;
    01302     std::map<PString, OpalEndPoint *> endpointMap;
    01303
    01304     PAtomicInteger lastCallTokenID;
    01305
    01306     class CallDict : public PSafeDictionary<PString, OpalCall>
    01307     {
    01308       public:
    01309         CallDict(OpalManager & mgr) : manager(mgr) { }
    01310         virtual void DeleteObject(PObject * object) const;
    01311         OpalManager & manager;
    01312     } activeCalls;
    01313
    01314     PBoolean     clearingAllCalls;
    01315     PSyncPoint   allCallsCleared;
    01316     PThread    * garbageCollector;
    01317     PSyncPoint   garbageCollectExit;
    01318     PDECLARE_NOTIFIER(PThread, OpalManager, GarbageMain);
    01319
    01320     PString defaultSecurityMode;
    01321
    01322 #if OPAL_RTP_AGGREGATE
    01323     PBoolean useRTPAggregation;
    01324 #endif
    01325
    01326     OpalRecordManager recordManager;
    01327
    01328     friend OpalCall::OpalCall(OpalManager & mgr);
    01329     friend void OpalCall::OnReleased(OpalConnection & connection);
    01330 };
    01331
    01332
    01333 PString  OpalGetVersion();
    01334 unsigned OpalGetMajorVersion();
    01335 unsigned OpalGetMinorVersion();
    01336 unsigned OpalGetBuildNumber();
    01337
    01338
    01339 #endif // __OPAL_MANAGER_H
    01340
    01341
    01342 // End of File ///////////////////////////////////////////////////////////////