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.

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