|
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/. */ |
|
4 |
|
5 #ifndef _CC_SIPCC_SERVICE_H |
|
6 #define _CC_SIPCC_SERVICE_H |
|
7 |
|
8 #include "CC_Service.h" |
|
9 |
|
10 extern "C" { |
|
11 // Callbacks from SIPCC. |
|
12 void configCtlFetchReq(int device_handle); |
|
13 char* platGetIPAddr(); |
|
14 |
|
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 } |
|
20 |
|
21 #include "VcmSIPCCBinding.h" |
|
22 #include "CSFAudioControlWrapper.h" |
|
23 #include "CSFVideoControlWrapper.h" |
|
24 #include "CSFMediaProvider.h" |
|
25 |
|
26 #include "base/lock.h" |
|
27 #include "base/waitable_event.h" |
|
28 |
|
29 #include <vector> |
|
30 #include <set> |
|
31 #include "mozilla/Mutex.h" |
|
32 |
|
33 namespace CSF |
|
34 { |
|
35 class PhoneConfig; |
|
36 DECLARE_NS_PTR(CC_SIPCCService); |
|
37 |
|
38 class CC_SIPCCService : public CC_Service, public StreamObserver, public MediaProviderObserver |
|
39 { |
|
40 friend void ::configCtlFetchReq(int device_handle); |
|
41 friend char* ::platGetIPAddr(); |
|
42 |
|
43 public: |
|
44 CC_SIPCCService(); |
|
45 virtual ~CC_SIPCCService(); |
|
46 |
|
47 /** |
|
48 * Public API |
|
49 */ |
|
50 virtual void addCCObserver ( CC_Observer * observer ); |
|
51 virtual void removeCCObserver ( CC_Observer * observer ); |
|
52 |
|
53 virtual bool init(const std::string& user, const std::string& password, const std::string& domain, const std::string& deviceName); |
|
54 virtual void destroy(); |
|
55 |
|
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); |
|
59 |
|
60 virtual bool startService(); |
|
61 virtual void stop(); |
|
62 |
|
63 virtual bool isStarted(); |
|
64 |
|
65 virtual CC_DevicePtr getActiveDevice(); |
|
66 virtual std::vector<CC_DevicePtr> getDevices(); |
|
67 |
|
68 virtual AudioControlPtr getAudioControl(); |
|
69 virtual VideoControlPtr getVideoControl(); |
|
70 |
|
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); |
|
76 |
|
77 virtual void onVideoModeChanged( bool enable ); |
|
78 virtual void onKeyFrameRequested( int stream ); |
|
79 virtual void onMediaLost( int callId ); |
|
80 virtual void onMediaRestored( int callId ); |
|
81 |
|
82 virtual bool setLocalVoipPort(int port); |
|
83 virtual bool setRemoteVoipPort(int port); |
|
84 virtual bool setP2PMode(bool mode); |
|
85 virtual bool setSDPMode(bool mode); |
|
86 |
|
87 /** |
|
88 * End of public API |
|
89 */ |
|
90 |
|
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); |
|
101 |
|
102 private: // Helper functions |
|
103 |
|
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); |
|
109 |
|
110 void endAllActiveCalls(); |
|
111 |
|
112 void applyLoggingMask(int newMask); |
|
113 void applyAudioVideoConfigSettings (PhoneConfig & phoneConfig); |
|
114 |
|
115 bool isValidMediaPortRange(int mediaStartPort, int mediaEndPort); |
|
116 bool isValidDSCPValue(int value); |
|
117 |
|
118 private: // Data Store |
|
119 // Singleton |
|
120 static CC_SIPCCService* _self; |
|
121 |
|
122 std::string deviceName; |
|
123 cc_int32_t loggingMask; |
|
124 |
|
125 //IP Address Info |
|
126 std::string localAddress; |
|
127 std::string defaultGW; |
|
128 |
|
129 // SIPCC lifecycle |
|
130 bool bCreated; |
|
131 bool bStarted; |
|
132 mozilla::Mutex m_lock; |
|
133 |
|
134 // Media Lifecycle |
|
135 VcmSIPCCBinding vcmMediaBridge; |
|
136 |
|
137 // Observers |
|
138 std::set<CC_Observer *> ccObservers; |
|
139 |
|
140 //AV Control Wrappers |
|
141 AudioControlWrapperPtr audioControlWrapper; |
|
142 VideoControlWrapperPtr videoControlWrapper; |
|
143 |
|
144 // Santization work |
|
145 bool bUseConfig; |
|
146 std::string sipUser; |
|
147 std::string sipPassword; |
|
148 std::string sipDomain; |
|
149 }; |
|
150 } |
|
151 |
|
152 #endif |