You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __ONVIF_MEDIA_OBSERVER_HEADER__
  2. #define __ONVIF_MEDIA_OBSERVER_HEADER__
  3. #ifdef __linux__
  4. #include <pthread.h>
  5. #include <unistd.h>
  6. #include <fcntl.h>
  7. #include <netdb.h>
  8. #include <sys/types.h>
  9. #include <sys/socket.h>
  10. #include <arpa/inet.h>
  11. #include <netinet/in.h>
  12. #else
  13. #include <winsock2.h>
  14. #include <winsock.h>
  15. #include <iostream>
  16. #endif
  17. #include <string>
  18. #include <vector>
  19. #include "../../components/base/basicLogCollection.h"
  20. #include "../../components/base/basicSettingsProvider.h"
  21. #include "xmlParser.h"
  22. #pragma warning(disable: 4251)
  23. #define MAX_BUFF_SIZE 102400 //100K
  24. #define HTTPMU_HOST_ADDRESS "239.255.255.250"
  25. #define HTTPMU_HOST_PORT 3702
  26. //#define DEBUG_ONVIF_PRINTOUT_MESSAGES
  27. /*
  28. #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"
  29. //*/
  30. /*
  31. #define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\n" \
  32. "ST:ssdp:all\r\n" \
  33. "MX: 3\r\n" \
  34. "MAN:\"ssdp:discover\"\r\n" \
  35. "HOST: 239.255.255.250:3702\r\n" \
  36. "\r\n"
  37. //*/
  38. #define SEARCH_REQUEST_STRING "<?xml version=\"1.0\" encoding=\"UTF-8\"?><e:Envelope xmlns:e=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\"><e:Header><w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID><w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></e:Header><e:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></e:Body></e:Envelope>"
  39. #define SEARCH_REQUEST_STRING2323 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" \
  40. "<SOAP:Envelope xmlns:SOAP=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:DISCOVERY=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:ssdp=\"http://example.com/wsdp/sample/print\">\n" \
  41. "<SOAP:Header>\n" \
  42. "<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>\n" \
  43. "<wsa:Action>\n" \
  44. "http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \
  45. "</wsa:Action>\n" \
  46. "<wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>\n" \
  47. "</SOAP:Header>\n" \
  48. "<SOAP:Body>\n" \
  49. "<DISCOVERY:Probe>\n" \
  50. "<DISCOVERY:Types>ssdp:any</DISCOVERY:Types>\n" \
  51. "</DISCOVERY:Probe>\n" \
  52. "</SOAP:Body>\n" \
  53. "</SOAP:Envelope>\r\n\r\n"
  54. #define HTTP_OK "200 OK"
  55. #define DEFAULT_HTTP_PORT 80
  56. /******************************************************************
  57. ** Action Defines *
  58. *******************************************************************/
  59. #define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \
  60. "HOST: %s:%u\r\n" \
  61. "SOAPACTION:\"%s#%s\"\r\n" \
  62. "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\
  63. "Content-Length: %d \r\n\r\n"
  64. #define SOAP_ACTION "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
  65. "<s:Envelope xmlns:s=" \
  66. "\"http://schemas.xmlsoap.org/soap/envelope/\" " \
  67. "s:encodingStyle=" \
  68. "\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \
  69. "<s:Body>\r\n" \
  70. "<u:%s xmlns:u=\"%s\">\r\n%s" \
  71. "</u:%s>\r\n" \
  72. "</s:Body>\r\n" \
  73. "</s:Envelope>\r\n"
  74. #define PORT_MAPPING_LEASE_TIME "63072000" //two year
  75. #define ADD_PORT_MAPPING_PARAMS "<NewRemoteHost></NewRemoteHost>\r\n" \
  76. "<NewExternalPort>%u</NewExternalPort>\r\n"\
  77. "<NewProtocol>%s</NewProtocol>\r\n" \
  78. "<NewInternalPort>%u</NewInternalPort>\r\n"\
  79. "<NewInternalClient>%s</NewInternalClient>\r\n" \
  80. "<NewEnabled>1</NewEnabled>\r\n" \
  81. "<NewPortMappingDescription>%s</NewPortMappingDescription>\r\n" \
  82. "<NewLeaseDuration>" \
  83. PORT_MAPPING_LEASE_TIME \
  84. "</NewLeaseDuration>\r\n"
  85. class onvifMediaObserver;
  86. typedef struct S_resultWoWo{
  87. int wowoID;
  88. char RefID[CTEXT];
  89. char Type[CTEXT];
  90. char MAC[CTEXT];
  91. char Hardware[CTEXT];
  92. char Name[CTEXT];
  93. char XAddrs[CTEXT];
  94. }resultWoWo;
  95. typedef vector<resultWoWo*> vectorWoWoResults;
  96. typedef struct S_probeWoWo{
  97. int AddressID;
  98. char IpAddress[16];
  99. int Port;
  100. int socketFD;
  101. char buff[MAX_BUFF_SIZE + 1];
  102. CSTR send_buff;
  103. CSTR recv_buff;
  104. struct sockaddr_in r_address;
  105. bool bOptVal;
  106. int bOptLen;
  107. int iOptLen;
  108. int RetVal;
  109. int index;
  110. int step;
  111. onvifMediaObserver *observer;
  112. }probeWoWo;
  113. typedef struct S_onvifObserverThread{
  114. DWORD m_dwThreadID;
  115. #ifdef __linux__
  116. pthread_t m_hThreadHandle;
  117. #else
  118. HANDLE m_hThreadHandle;
  119. #endif
  120. probeWoWo *context;
  121. }onvifObserverThread;
  122. typedef vector<onvifObserverThread*> onvifObserverThreads;
  123. /**
  124. * TODO: Add class description
  125. *
  126. * @author Gagua
  127. */
  128. class onvifMediaObserver{
  129. private:
  130. basicLogCollection *m_pLog;
  131. //basicSettingsProvider *m_pSettings;
  132. //config_setting_t *m_pSettingsNode;
  133. enumeratorInfo m_vLocalDevices;
  134. localIpAddresses *m_pIpAddresses;
  135. sourcePool m_vUsedDevices;
  136. vectorWoWoResults m_vResultPool;
  137. onvifObserverThreads m_vThreads;
  138. bool m_bWSAOK;
  139. int m_nStatus;
  140. public:
  141. // Method to fetch singleton instance.
  142. static onvifMediaObserver* getInstance();
  143. // Destructor
  144. virtual ~onvifMediaObserver();
  145. int getNetworkCounts(){ return m_pIpAddresses->size(); };
  146. bool startDiscovery( void );
  147. localIpAddresses *getNetworks(void){ return m_pIpAddresses; };
  148. vectorWoWoResults *getResults(void){ return &m_vResultPool; };
  149. int getStatus(){ return m_nStatus; };
  150. protected:
  151. // Constructor - protected so users cannot call it.
  152. onvifMediaObserver();
  153. private:
  154. bool startProbe(CSTR IP, int ID, int stp);
  155. bool loadAssignedSources(void);
  156. static void *probeThreadProc(void *);
  157. probeWoWo *init_WoWo(CSTR ADR, int ID, int stp = 1);
  158. // private static member referencing the single instance of the object
  159. // TODO: Replace mediaVideoSourceManager with the type of object you want to
  160. // return the single instance of
  161. static onvifMediaObserver* _instance;
  162. // Copy constructor
  163. // Declared but not defined to prevent auto-generated
  164. // copy constructor. Refer to "Effective C++" by Meyers
  165. onvifMediaObserver(const onvifMediaObserver& src);
  166. // Assignment operator
  167. // Declared but not defined to prevent auto-generated
  168. // assignment operator. Refer to "Effective C++" by Meyers
  169. onvifMediaObserver& operator=(const onvifMediaObserver& src);
  170. };
  171. // TODO: Uncomment the copy constructor when you need it.
  172. //inline mediaVideoSourceManager::mediaVideoSourceManager(const mediaVideoSourceManager& src)
  173. //{
  174. // // TODO: copy
  175. //}
  176. // TODO: Uncomment the assignment operator when you need it.
  177. //inline mediaVideoSourceManager& mediaVideoSourceManager::operator=(const mediaVideoSourceManager& rhs)
  178. //{
  179. // if (this == &rhs) {
  180. // return *this;
  181. // }
  182. //
  183. // // TODO: assignment
  184. //
  185. // return *this;
  186. //}
  187. #endif