/*---------------------------------------------------------------------------*/ /* plantronics_headset.h */ /* copyright (c) innovaphone 2012 */ /* */ /*---------------------------------------------------------------------------*/ #include "Spokes3G.h" NAMESPACE_BEGIN #define PLANTRONICS_DEVICE_ID_SIZE 1024 #define PLANTRONICS_DEVICE_NAME_SIZE 512 #define PLANTRONICS_DEVICE_PATH_SIZE 512 #define MAX_PLANTRONICS_DEVICES 16 #define PLANTRONICS_CALL_NUMBER_SIZE 256 #define PLANTRONICS_CALL_NAME_SIZE 256 #define PLANTRONICS_EVENT_QUEUE_SIZE_BITS 14 #define PLANTRONICS_EVENT_QUEUE_SIZE (1 << PLANTRONICS_EVENT_QUEUE_SIZE_BITS) #define PLANTRONICS_LOG_DEVICE_EVENT_SIZE 128 #define MAX_PLANTRONICS_LOG_DEVICE_EVENTS 16 #ifdef _WINDOWS #else typedef void *HMODULE; #endif struct PlantronicsDevice { unsigned short productID; unsigned short vendorID; char deviceName[PLANTRONICS_DEVICE_NAME_SIZE]; char devicePath[PLANTRONICS_DEVICE_PATH_SIZE]; }; class PlantronicsCall : public ICall { private: int32_t m_id; public: virtual int32_t getID() { return m_id; } virtual void setID(int32_t id) { m_id = id; } virtual int32_t getConferenceID() { return 0; } virtual void setConferenceID(int32_t id) { /*no op*/ } virtual bool getInConference() { return false; } virtual void setInConference(bool bConference) { /*no op*/ } private: void operator delete(void *p) { ::operator delete(p); } }; class PlantronicsContact : public IContact { private: int32_t m_id; wchar_t m_phone[PLANTRONICS_CALL_NUMBER_SIZE]; wchar_t m_sip[PLANTRONICS_CALL_NUMBER_SIZE]; wchar_t m_name[PLANTRONICS_CALL_NAME_SIZE]; public: virtual const wchar_t *getName() const { return ((m_name[0] != 0) ? m_name : NULL); } virtual void setName(const wchar_t *pName) { int i; i = 0; if (pName) { while (pName[i]) { m_name[i] = pName[i]; i++; } } m_name[i] = 0; } virtual const wchar_t *getFriendlyName() const { return NULL; } virtual void setFriendlyName(const wchar_t *pFName) {} virtual int32_t getID() const { return m_id; } virtual void setID(int32_t id) { m_id = id; } virtual const wchar_t *getSipUri() const { return ((m_sip[0] != 0) ? m_sip : NULL); } virtual void setSipUri(const wchar_t *pSip) { int i; i = 0; if (pSip) { while (pSip[i]) { m_sip[i] = pSip[i]; i++; } } m_sip[i] = 0; } virtual const wchar_t *getPhone() const { return ((m_phone[0] != 0) ? m_phone : NULL); } virtual void setPhone(const wchar_t *pPhone) { int i; i = 0; if (pPhone) { while (pPhone[i]) { m_phone[i] = pPhone[i]; i++; } } m_phone[i] = 0; } virtual const wchar_t *getEmail() const { return NULL; } virtual void setEmail(const wchar_t *pEmail) {} virtual const wchar_t *getWorkPhone() const { return NULL; } virtual void setWorkPhone(const wchar_t *pWPhone) {} virtual const wchar_t *getMobilePhone() const { return NULL; } virtual void setMobilePhone(const wchar_t *pMPhone) {} virtual const wchar_t *getHomePhone() const { return NULL; } virtual void setHomePhone(const wchar_t *pHPhone) {} private: void operator delete(void *p) { ::operator delete(p); } }; class PlantronicsSessionManagerEvents : public ISessionManagerEvents { bool OnCallStateChanged(CallStateEventArgs const &args); bool OnDeviceStateChanged(DeviceStateEventArgs const &args); private: void operator delete(void *p) { ::operator delete(p); } }; class PlantronicsCallEvents : public ICallEvents { bool OnCallStateChanged(CallStateEventArgs const &args); bool OnCallRequest(CallRequestEventArgs const &args) { return true; }; private: void operator delete(void *p) { ::operator delete(p); } }; class PlantronicsHeadsetProvider : public IHeadsetProvider { char tag[16]; struct { int32_t id; bool originated; byte state; char number[PLANTRONICS_CALL_NUMBER_SIZE]; char name[PLANTRONICS_CALL_NAME_SIZE]; } calls[4]; bool mute; unsigned deviceCount; struct PlantronicsDevice devices[MAX_PLANTRONICS_DEVICES]; char activeDeviceId[PLANTRONICS_DEVICE_ID_SIZE]; bool serviceStarted; void Connect(); unsigned GetCurrentCall(int32_t callId, bool originated, const char * number, const char * name); void CallStateChanged(const char *devicePath, byte deviceEventKind, byte callState, int32_t callId); void UpdateDevice(const char *deviceId, bool active); public: UHeadsetProvider *user; HMODULE plantronicsDll; ISessionManager *sessionManager; ISession *session; ICallCommand *callCommand; PlantronicsCall call; PlantronicsContact contact; PlantronicsSessionManagerEvents sessionManagerEvents; PlantronicsCallEvents callEvents; volatile unsigned logDeviceEventPos; volatile unsigned logDeviceEventAck; volatile unsigned logDeviceEventIds[MAX_PLANTRONICS_LOG_DEVICE_EVENTS]; char logDeviceEvents[MAX_PLANTRONICS_LOG_DEVICE_EVENTS][PLANTRONICS_LOG_DEVICE_EVENT_SIZE]; unsigned eventQueueFill; volatile unsigned eventQueuePos; volatile unsigned eventQueueAck; byte eventQueue[PLANTRONICS_EVENT_QUEUE_SIZE]; void eventPut(const void *p, unsigned l); void eventSend(const void *p, unsigned l); void eventGet(void *p, unsigned l); PlantronicsHeadsetProvider(); ~PlantronicsHeadsetProvider(); void Initialize(UHeadsetProvider * const user); void DevicesDetected(unsigned detectedDevices, const char * const *deviceIds, word *vendorIds, word *productIds); word GetVendorId(const char *deviceId, word *productId); void StartHookDevice(const char *deviceId); void StopHookDevice(const char *deviceId); void SendHookKey(const char *deviceId, byte key, byte callId, const char * number, const char * name); void SetMicrophoneMute(bool mute); void Close(); void OnDispatch(); }; NAMESPACE_END