michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _CC_SIPCC_SERVICE_H michael@0: #define _CC_SIPCC_SERVICE_H michael@0: michael@0: #include "CC_Service.h" michael@0: michael@0: extern "C" { michael@0: // Callbacks from SIPCC. michael@0: void configCtlFetchReq(int device_handle); michael@0: char* platGetIPAddr(); michael@0: michael@0: void CCAPI_DeviceListener_onDeviceEvent(ccapi_device_event_e type, cc_device_handle_t hDevice, cc_deviceinfo_ref_t dev_info); michael@0: void CCAPI_DeviceListener_onFeatureEvent(ccapi_device_event_e type, cc_deviceinfo_ref_t /* device_info */, cc_featureinfo_ref_t feature_info); michael@0: void CCAPI_LineListener_onLineEvent(ccapi_line_event_e eventType, cc_lineid_t line, cc_lineinfo_ref_t info); michael@0: void CCAPI_CallListener_onCallEvent(ccapi_call_event_e eventType, cc_call_handle_t handle, cc_callinfo_ref_t info); michael@0: } michael@0: michael@0: #include "VcmSIPCCBinding.h" michael@0: #include "CSFAudioControlWrapper.h" michael@0: #include "CSFVideoControlWrapper.h" michael@0: #include "CSFMediaProvider.h" michael@0: michael@0: #include "base/lock.h" michael@0: #include "base/waitable_event.h" michael@0: michael@0: #include michael@0: #include michael@0: #include "mozilla/Mutex.h" michael@0: michael@0: namespace CSF michael@0: { michael@0: class PhoneConfig; michael@0: DECLARE_NS_PTR(CC_SIPCCService); michael@0: michael@0: class CC_SIPCCService : public CC_Service, public StreamObserver, public MediaProviderObserver michael@0: { michael@0: friend void ::configCtlFetchReq(int device_handle); michael@0: friend char* ::platGetIPAddr(); michael@0: michael@0: public: michael@0: CC_SIPCCService(); michael@0: virtual ~CC_SIPCCService(); michael@0: michael@0: /** michael@0: * Public API michael@0: */ michael@0: virtual void addCCObserver ( CC_Observer * observer ); michael@0: virtual void removeCCObserver ( CC_Observer * observer ); michael@0: michael@0: virtual bool init(const std::string& user, const std::string& password, const std::string& domain, const std::string& deviceName); michael@0: virtual void destroy(); michael@0: michael@0: virtual void setDeviceName(const std::string& deviceName); michael@0: virtual void setLoggingMask(int mask); michael@0: virtual void setLocalAddressAndGateway(const std::string& localAddress, const std::string& defaultGW); michael@0: michael@0: virtual bool startService(); michael@0: virtual void stop(); michael@0: michael@0: virtual bool isStarted(); michael@0: michael@0: virtual CC_DevicePtr getActiveDevice(); michael@0: virtual std::vector getDevices(); michael@0: michael@0: virtual AudioControlPtr getAudioControl(); michael@0: virtual VideoControlPtr getVideoControl(); michael@0: michael@0: // From the StreamObserver interface michael@0: virtual void registerStream(cc_call_handle_t call, int streamId, bool isVideo); michael@0: virtual void deregisterStream(cc_call_handle_t call, int streamId); michael@0: virtual void dtmfBurst(int digit, int direction, int duration); michael@0: virtual void sendIFrame(cc_call_handle_t call); michael@0: michael@0: virtual void onVideoModeChanged( bool enable ); michael@0: virtual void onKeyFrameRequested( int stream ); michael@0: virtual void onMediaLost( int callId ); michael@0: virtual void onMediaRestored( int callId ); michael@0: michael@0: virtual bool setLocalVoipPort(int port); michael@0: virtual bool setRemoteVoipPort(int port); michael@0: virtual bool setP2PMode(bool mode); michael@0: virtual bool setSDPMode(bool mode); michael@0: michael@0: /** michael@0: * End of public API michael@0: */ michael@0: michael@0: public: michael@0: // These are used by the C callback functions to raise events. michael@0: // This layer: michael@0: // - converts the C handles to C++ objects michael@0: // - invokes the member notify* functions to propagate events upwards michael@0: // - invokes any other functions needed to perform "value added" event handling in ECC. michael@0: static void onDeviceEvent(ccapi_device_event_e type, cc_device_handle_t hDevice, cc_deviceinfo_ref_t dev_info); michael@0: static void onFeatureEvent(ccapi_device_event_e type, cc_deviceinfo_ref_t /* device_info */, cc_featureinfo_ref_t feature_info); michael@0: static void onLineEvent(ccapi_line_event_e eventType, cc_lineid_t line, cc_lineinfo_ref_t info); michael@0: static void onCallEvent(ccapi_call_event_e eventType, cc_call_handle_t handle, cc_callinfo_ref_t info); michael@0: michael@0: private: // Helper functions michael@0: michael@0: //These notify functions call through to CallControlManager michael@0: void notifyDeviceEventObservers (ccapi_device_event_e deviceEvent, CC_DevicePtr devicePtr, CC_DeviceInfoPtr info); michael@0: void notifyFeatureEventObservers (ccapi_device_event_e deviceEvent, CC_DevicePtr devicePtr, CC_FeatureInfoPtr info); michael@0: void notifyCallEventObservers (ccapi_call_event_e callEvent, CC_CallPtr callPtr, CC_CallInfoPtr info); michael@0: void notifyLineEventObservers (ccapi_line_event_e lineEvent, CC_LinePtr linePtr, CC_LineInfoPtr info); michael@0: michael@0: void endAllActiveCalls(); michael@0: michael@0: void applyLoggingMask(int newMask); michael@0: void applyAudioVideoConfigSettings (PhoneConfig & phoneConfig); michael@0: michael@0: bool isValidMediaPortRange(int mediaStartPort, int mediaEndPort); michael@0: bool isValidDSCPValue(int value); michael@0: michael@0: private: // Data Store michael@0: // Singleton michael@0: static CC_SIPCCService* _self; michael@0: michael@0: std::string deviceName; michael@0: cc_int32_t loggingMask; michael@0: michael@0: //IP Address Info michael@0: std::string localAddress; michael@0: std::string defaultGW; michael@0: michael@0: // SIPCC lifecycle michael@0: bool bCreated; michael@0: bool bStarted; michael@0: mozilla::Mutex m_lock; michael@0: michael@0: // Media Lifecycle michael@0: VcmSIPCCBinding vcmMediaBridge; michael@0: michael@0: // Observers michael@0: std::set ccObservers; michael@0: michael@0: //AV Control Wrappers michael@0: AudioControlWrapperPtr audioControlWrapper; michael@0: VideoControlWrapperPtr videoControlWrapper; michael@0: michael@0: // Santization work michael@0: bool bUseConfig; michael@0: std::string sipUser; michael@0: std::string sipPassword; michael@0: std::string sipDomain; michael@0: }; michael@0: } michael@0: michael@0: #endif