#ifndef __ONVIF_MEDIA_OBSERVER_HEADER__ #define __ONVIF_MEDIA_OBSERVER_HEADER__ #ifdef __linux__ #include #else #include #endif #include #include #include #include "../../components/base/basicLogCollection.h" #include "../../components/base/basicSettingsProvider.h" #include "../protocol/xmlParser.h" #pragma warning(disable: 4251) #define MAX_BUFF_SIZE 102400 //100K #define HTTPMU_HOST_ADDRESS "239.255.255.250" #define HTTPMU_HOST_PORT 3702 /* #define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\nST:ssdp:all\r\nMX: 3\r\nMAN:\"ssdp:discover\"\r\nHOST: 239.255.255.250:1900\r\n\r\n" //*/ /* #define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\n" \ "ST:ssdp:all\r\n" \ "MX: 3\r\n" \ "MAN:\"ssdp:discover\"\r\n" \ "HOST: 239.255.255.250:3702\r\n" \ "\r\n" //*/ #define SEARCH_REQUEST_STRING_0 "\n" \ "\n" \ "\n" \ "urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7\n" \ "\n" \ "http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \ "\n" \ "urn:schemas-xmlsoap-org:ws:2005:04:discovery\n" \ "\n" \ "\n" \ "\n" \ "ssdp:any\n" \ "\n" \ "\n" \ "\r\n\r\n" #define SEARCH_REQUEST_STRING_1 "" \ "" \ "" \ "urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7" \ "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous\n" \ "http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches" \ "" \ "" \ "" \ "" \ "dn:NetworkVideoTransmitter tds:Device" \ "onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/hardware/HD_PREDATOR onvif://www.onvif.org/name/PREDATOR onvif://www.onvif.org/location/" \ "SERVICE_URI" \ "1" \ "" \ "" \ "\n" \ "dn:NetworkVideoTransmitter tds:Device\n" \ "\n" \ "" \ "" #define SEARCH_REQUEST_STRING "" \ " " \ "" \ "uuid:84ede3de-7dec-11d0-c360-f01234567890" \ "urn:schemas-xmlsoap-org:ws:2005:04:discovery" \ "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe" \ "" \ "dn:NetworkVideoTransmitter" #define HTTP_OK "200 OK" #define DEFAULT_HTTP_PORT 80 /****************************************************************** ** Action Defines * *******************************************************************/ #define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \ "HOST: %s:%u\r\n" \ "SOAPACTION:\"%s#%s\"\r\n" \ "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\ "Content-Length: %d \r\n\r\n" #define SOAP_ACTION "\r\n" \ "\r\n" \ "\r\n" \ "\r\n%s" \ "\r\n" \ "\r\n" \ "\r\n" #define PORT_MAPPING_LEASE_TIME "63072000" //two year #define ADD_PORT_MAPPING_PARAMS "\r\n" \ "%u\r\n"\ "%s\r\n" \ "%u\r\n"\ "%s\r\n" \ "1\r\n" \ "%s\r\n" \ "" \ PORT_MAPPING_LEASE_TIME \ "\r\n" class onvifMediaObserver; typedef struct S_resultWoWo{ int wowoID; char Types[256]; char XAddrs[1024]; }resultWoWo; typedef vector vectorWoWoResults; typedef struct S_probeWoWo{ int AddressID; char IpAddress[16]; int Port; int socketFD; char buff[MAX_BUFF_SIZE + 1]; CSTR send_buff; CSTR recv_buff; struct sockaddr_in r_address; bool bOptVal; int bOptLen; int iOptLen; int RetVal; int index; int step; onvifMediaObserver *observer; }probeWoWo; typedef struct S_onvifObserverThread{ #ifdef __linux__ int m_dwThreadID; pthread_t m_hThreadHandle; #else DWORD m_dwThreadID; HANDLE m_hThreadHandle; #endif probeWoWo *context; }onvifObserverThread; typedef vector onvifObserverThreads; /** * TODO: Add class description * * @author Gagua */ class onvifMediaObserver{ private: basicLogCollection *m_pLog; basicSettingsProvider *m_pSettings; config_setting_t *m_pSettingsNode; enumeratorInfo m_vLocalDevices; localIpAddresses *m_pIpAddresses; sourcePool m_vUsedDevices; vectorWoWoResults m_vResultPool; onvifObserverThreads m_vThreads; bool m_bWSAOK; int m_nStatus; //OnvifClientDevice *m_pDevice; public: // Method to fetch singleton instance. static onvifMediaObserver* getInstance(); // Destructor virtual ~onvifMediaObserver(); int getNetworkCounts(){ return m_pIpAddresses->size(); }; bool startDiscovery( void ); localIpAddresses *getNetworks(void){ return m_pIpAddresses; }; vectorWoWoResults *getResults(void){ return &m_vResultPool; }; int getStatus(){ return m_nStatus; }; protected: // Constructor - protected so users cannot call it. onvifMediaObserver(); private: bool startProbe(CSTR IP, int ID, int stp); bool loadAssignedSources(void); static void *probeThreadProc(void *); probeWoWo *init_WoWo(CSTR ADR, int ID, int stp = 1); // private static member referencing the single instance of the object // TODO: Replace mediaVideoSourceManager with the type of object you want to // return the single instance of static onvifMediaObserver* _instance; // Copy constructor // Declared but not defined to prevent auto-generated // copy constructor. Refer to "Effective C++" by Meyers onvifMediaObserver(const onvifMediaObserver& src); // Assignment operator // Declared but not defined to prevent auto-generated // assignment operator. Refer to "Effective C++" by Meyers onvifMediaObserver& operator=(const onvifMediaObserver& src); }; // Destructor implementation inline onvifMediaObserver::~onvifMediaObserver(){ }; // TODO: Uncomment the copy constructor when you need it. //inline mediaVideoSourceManager::mediaVideoSourceManager(const mediaVideoSourceManager& src) //{ // // TODO: copy //} // TODO: Uncomment the assignment operator when you need it. //inline mediaVideoSourceManager& mediaVideoSourceManager::operator=(const mediaVideoSourceManager& rhs) //{ // if (this == &rhs) { // return *this; // } // // // TODO: assignment // // return *this; //} #endif