Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef _CC_SIPCC_SERVICE_H
6 #define _CC_SIPCC_SERVICE_H
8 #include "CC_Service.h"
10 extern "C" {
11 // Callbacks from SIPCC.
12 void configCtlFetchReq(int device_handle);
13 char* platGetIPAddr();
15 void CCAPI_DeviceListener_onDeviceEvent(ccapi_device_event_e type, cc_device_handle_t hDevice, cc_deviceinfo_ref_t dev_info);
16 void CCAPI_DeviceListener_onFeatureEvent(ccapi_device_event_e type, cc_deviceinfo_ref_t /* device_info */, cc_featureinfo_ref_t feature_info);
17 void CCAPI_LineListener_onLineEvent(ccapi_line_event_e eventType, cc_lineid_t line, cc_lineinfo_ref_t info);
18 void CCAPI_CallListener_onCallEvent(ccapi_call_event_e eventType, cc_call_handle_t handle, cc_callinfo_ref_t info);
19 }
21 #include "VcmSIPCCBinding.h"
22 #include "CSFAudioControlWrapper.h"
23 #include "CSFVideoControlWrapper.h"
24 #include "CSFMediaProvider.h"
26 #include "base/lock.h"
27 #include "base/waitable_event.h"
29 #include <vector>
30 #include <set>
31 #include "mozilla/Mutex.h"
33 namespace CSF
34 {
35 class PhoneConfig;
36 DECLARE_NS_PTR(CC_SIPCCService);
38 class CC_SIPCCService : public CC_Service, public StreamObserver, public MediaProviderObserver
39 {
40 friend void ::configCtlFetchReq(int device_handle);
41 friend char* ::platGetIPAddr();
43 public:
44 CC_SIPCCService();
45 virtual ~CC_SIPCCService();
47 /**
48 * Public API
49 */
50 virtual void addCCObserver ( CC_Observer * observer );
51 virtual void removeCCObserver ( CC_Observer * observer );
53 virtual bool init(const std::string& user, const std::string& password, const std::string& domain, const std::string& deviceName);
54 virtual void destroy();
56 virtual void setDeviceName(const std::string& deviceName);
57 virtual void setLoggingMask(int mask);
58 virtual void setLocalAddressAndGateway(const std::string& localAddress, const std::string& defaultGW);
60 virtual bool startService();
61 virtual void stop();
63 virtual bool isStarted();
65 virtual CC_DevicePtr getActiveDevice();
66 virtual std::vector<CC_DevicePtr> getDevices();
68 virtual AudioControlPtr getAudioControl();
69 virtual VideoControlPtr getVideoControl();
71 // From the StreamObserver interface
72 virtual void registerStream(cc_call_handle_t call, int streamId, bool isVideo);
73 virtual void deregisterStream(cc_call_handle_t call, int streamId);
74 virtual void dtmfBurst(int digit, int direction, int duration);
75 virtual void sendIFrame(cc_call_handle_t call);
77 virtual void onVideoModeChanged( bool enable );
78 virtual void onKeyFrameRequested( int stream );
79 virtual void onMediaLost( int callId );
80 virtual void onMediaRestored( int callId );
82 virtual bool setLocalVoipPort(int port);
83 virtual bool setRemoteVoipPort(int port);
84 virtual bool setP2PMode(bool mode);
85 virtual bool setSDPMode(bool mode);
87 /**
88 * End of public API
89 */
91 public:
92 // These are used by the C callback functions to raise events.
93 // This layer:
94 // - converts the C handles to C++ objects
95 // - invokes the member notify* functions to propagate events upwards
96 // - invokes any other functions needed to perform "value added" event handling in ECC.
97 static void onDeviceEvent(ccapi_device_event_e type, cc_device_handle_t hDevice, cc_deviceinfo_ref_t dev_info);
98 static void onFeatureEvent(ccapi_device_event_e type, cc_deviceinfo_ref_t /* device_info */, cc_featureinfo_ref_t feature_info);
99 static void onLineEvent(ccapi_line_event_e eventType, cc_lineid_t line, cc_lineinfo_ref_t info);
100 static void onCallEvent(ccapi_call_event_e eventType, cc_call_handle_t handle, cc_callinfo_ref_t info);
102 private: // Helper functions
104 //These notify functions call through to CallControlManager
105 void notifyDeviceEventObservers (ccapi_device_event_e deviceEvent, CC_DevicePtr devicePtr, CC_DeviceInfoPtr info);
106 void notifyFeatureEventObservers (ccapi_device_event_e deviceEvent, CC_DevicePtr devicePtr, CC_FeatureInfoPtr info);
107 void notifyCallEventObservers (ccapi_call_event_e callEvent, CC_CallPtr callPtr, CC_CallInfoPtr info);
108 void notifyLineEventObservers (ccapi_line_event_e lineEvent, CC_LinePtr linePtr, CC_LineInfoPtr info);
110 void endAllActiveCalls();
112 void applyLoggingMask(int newMask);
113 void applyAudioVideoConfigSettings (PhoneConfig & phoneConfig);
115 bool isValidMediaPortRange(int mediaStartPort, int mediaEndPort);
116 bool isValidDSCPValue(int value);
118 private: // Data Store
119 // Singleton
120 static CC_SIPCCService* _self;
122 std::string deviceName;
123 cc_int32_t loggingMask;
125 //IP Address Info
126 std::string localAddress;
127 std::string defaultGW;
129 // SIPCC lifecycle
130 bool bCreated;
131 bool bStarted;
132 mozilla::Mutex m_lock;
134 // Media Lifecycle
135 VcmSIPCCBinding vcmMediaBridge;
137 // Observers
138 std::set<CC_Observer *> ccObservers;
140 //AV Control Wrappers
141 AudioControlWrapperPtr audioControlWrapper;
142 VideoControlWrapperPtr videoControlWrapper;
144 // Santization work
145 bool bUseConfig;
146 std::string sipUser;
147 std::string sipPassword;
148 std::string sipDomain;
149 };
150 }
152 #endif