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.

226 lines
8.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __ONVIF_SERVER_EVENT__
  2. #define __ONVIF_SERVER_EVENT__
  3. #include <string>
  4. #include <map>
  5. #include <iostream>
  6. #include <list>
  7. #include <algorithm>
  8. #include <vector>
  9. #include "fast_mutex.h"
  10. #include "onvifclientdevice.hpp"
  11. #include "soapStub.h"
  12. #include "soapPullPointSubscriptionBindingProxy.h"
  13. #include "soapPullPointSubscriptionBindingService.h"
  14. #include "wsseapi.h"
  15. #include "wsaapi.h"
  16. #define INFO_LENGTH 128
  17. #define LARGE_INFO_LENGTH 1024
  18. using namespace std;
  19. class OnvifServerEventProducer
  20. {
  21. public:
  22. OnvifServerEventProducer();
  23. ~OnvifServerEventProducer();
  24. public:
  25. void AddConsumer(std::string consumerEndpoint );
  26. void NotifyMessage();
  27. void Lock()
  28. {
  29. m_pMutex.lock();
  30. }
  31. void UnLock()
  32. {
  33. m_pMutex.unlock();
  34. }
  35. private:
  36. tthread::fast_mutex m_pMutex;
  37. std::vector<std::string> m_subscribers;
  38. };
  39. inline OnvifServerEventProducer::OnvifServerEventProducer()
  40. {
  41. }
  42. inline OnvifServerEventProducer::~OnvifServerEventProducer()
  43. {
  44. }
  45. inline void OnvifServerEventProducer::NotifyMessage()
  46. {
  47. PullPointSubscriptionBindingProxy m_proxy(soap_new());
  48. SOAP_ENV__Header m_header;
  49. m_header.wsa5__Action = (char *) soap_malloc( m_proxy.soap, 1024 );
  50. strcpy(m_header.wsa5__Action, "http://docs.oasis-open.org/wsn/bw-2/NotificationConsumer/Notify");
  51. //m_header.wsa__MessageID = NULL;
  52. //m_header.wsa__To = NULL;
  53. //m_header.wsa__Action = NULL;
  54. m_proxy.soap->header = &m_header;
  55. _wsnt__Notify message;
  56. wsnt__NotificationMessageHolderType *holder = soap_instantiate_wsnt__NotificationMessageHolderType(m_proxy.soap, -1, "", "", NULL);
  57. wsnt__TopicExpressionType * topic = soap_instantiate_wsnt__TopicExpressionType(m_proxy.soap, -1, "", "", NULL );
  58. topic->Dialect = "http://docs.oasis-open.org/wsn/t-1/TopicExpression/Concrete";
  59. holder->Topic = topic;
  60. holder->SubscriptionReference = NULL;
  61. holder->ProducerReference = NULL;
  62. message.NotificationMessage.push_back(holder);
  63. Lock();
  64. std::vector<std::string> localSubs = m_subscribers;
  65. UnLock();
  66. for( std::vector<std::string>::const_iterator it = localSubs.begin();
  67. it != localSubs.end(); ++it )
  68. {
  69. printf("Notify %s\n", (*it).c_str());
  70. m_proxy.Notify((*it).c_str(),
  71. "http://docs.oasis-open.org/wsn/bw-2/NotificationConsumer/Notify", &message);
  72. }
  73. }
  74. inline void OnvifServerEventProducer::AddConsumer(std::string consumerEndpoint)
  75. {
  76. printf("OnvifServerEventProducer::AddConsumer %s\n", consumerEndpoint.c_str());
  77. Lock();
  78. if( std::find( m_subscribers.begin(), m_subscribers.end(), consumerEndpoint ) == m_subscribers.end() ) {
  79. m_subscribers.push_back( consumerEndpoint );
  80. }
  81. UnLock();
  82. return;
  83. }
  84. class OnvifServerEvent : public PullPointSubscriptionBindingService
  85. {
  86. public:
  87. OnvifServerEvent(struct soap* pData, OnvifServerEventProducer &pProducer, string strEventEndpoint)
  88. : m_EventCnt(0), PullPointSubscriptionBindingService(pData), m_Producer(pProducer), m_strEventEndpoint(strEventEndpoint)
  89. {
  90. }
  91. public:
  92. //TODO add callback to here
  93. virtual int Notify(_wsnt__Notify *wsnt__Notify)
  94. {
  95. //printf("\nMessage size %d\n", wsnt__Notify->NotificationMessage.size());
  96. if(wsnt__Notify->NotificationMessage.size() > 0 )
  97. {
  98. m_EventCnt ++;
  99. //printf("\nONVIF CPP Lib Event %d host %s __mixed: %s\n", m_EventCnt, soap->host,
  100. // wsnt__Notify->NotificationMessage[0]->Topic->__mixed);
  101. //printf("\t__any: %s\n", wsnt__Notify->NotificationMessage[0]->Topic->__any);
  102. //printf("\t__anyAttribute: %s\n", wsnt__Notify->NotificationMessage[0]->Topic->__anyAttribute);
  103. //printf("\tDialect: %s\n", wsnt__Notify->NotificationMessage[0]->Topic->Dialect.c_str());
  104. //printf("\tMessage %s\n", wsnt__Notify->NotificationMessage[0]->Message.__any);
  105. }
  106. return SOAP_OK;
  107. }
  108. public:
  109. virtual PullPointSubscriptionBindingService *copy()
  110. {
  111. return NULL;
  112. }
  113. /// Web service operation 'PullMessages' (returns error code or SOAP_OK)
  114. virtual int PullMessages(_tev__PullMessages *tev__PullMessages, _tev__PullMessagesResponse *tev__PullMessagesResponse)
  115. {return SOAP_OK;}
  116. /// Web service operation 'Seek' (returns error code or SOAP_OK)
  117. virtual int Seek(_tev__Seek *tev__Seek, _tev__SeekResponse *tev__SeekResponse)
  118. {return SOAP_OK;}
  119. /// Web service operation 'SetSynchronizationPoint' (returns error code or SOAP_OK)
  120. virtual int SetSynchronizationPoint(_tev__SetSynchronizationPoint *tev__SetSynchronizationPoint, _tev__SetSynchronizationPointResponse *tev__SetSynchronizationPointResponse)
  121. {return SOAP_OK;}
  122. /// Web service operation 'GetServiceCapabilities' (returns error code or SOAP_OK)
  123. virtual int GetServiceCapabilities(_tev__GetServiceCapabilities *tev__GetServiceCapabilities, _tev__GetServiceCapabilitiesResponse *tev__GetServiceCapabilitiesResponse)
  124. {return SOAP_OK;}
  125. /// Web service operation 'CreatePullPointSubscription' (returns error code or SOAP_OK)
  126. virtual int CreatePullPointSubscription(_tev__CreatePullPointSubscription *tev__CreatePullPointSubscription, _tev__CreatePullPointSubscriptionResponse *tev__CreatePullPointSubscriptionResponse)
  127. {return SOAP_OK;}
  128. /// Web service operation 'GetEventProperties' (returns error code or SOAP_OK)
  129. virtual int GetEventProperties(_tev__GetEventProperties *tev__GetEventProperties, _tev__GetEventPropertiesResponse *tev__GetEventPropertiesResponse)
  130. {return SOAP_OK;}
  131. /// Web service operation 'Renew' (returns error code or SOAP_OK)
  132. virtual int Renew(_wsnt__Renew *wsnt__Renew, _wsnt__RenewResponse *wsnt__RenewResponse)
  133. {return SOAP_OK;}
  134. /// Web service operation 'Unsubscribe' (returns error code or SOAP_OK)
  135. virtual int Unsubscribe(_wsnt__Unsubscribe *wsnt__Unsubscribe, _wsnt__UnsubscribeResponse *wsnt__UnsubscribeResponse)
  136. {return SOAP_OK;}
  137. /// Web service operation 'Subscribe' (returns error code or SOAP_OK)
  138. virtual int Subscribe(_wsnt__Subscribe *wsnt__Subscribe, _wsnt__SubscribeResponse *wsnt__SubscribeResponse)
  139. {
  140. std::string consumer( wsnt__Subscribe->ConsumerReference.Address );
  141. wsnt__SubscribeResponse->SubscriptionReference.Address = (char *) soap_malloc(soap, sizeof(char) * INFO_LENGTH);
  142. strcpy( wsnt__SubscribeResponse->SubscriptionReference.Address,
  143. m_strEventEndpoint.c_str() );
  144. time_t current = time(0);
  145. wsnt__SubscribeResponse->CurrentTime = (time_t *) soap_malloc(soap, sizeof(time_t *) );
  146. memcpy(wsnt__SubscribeResponse->CurrentTime, &current, sizeof(time_t));
  147. wsnt__SubscribeResponse->TerminationTime = (time_t *) soap_malloc(soap, sizeof(time_t *) );
  148. current += 1000000;
  149. memcpy(wsnt__SubscribeResponse->TerminationTime, &current, sizeof(time_t));
  150. m_Producer.AddConsumer( consumer );
  151. return SOAP_OK;
  152. }
  153. /// Web service operation 'GetCurrentMessage' (returns error code or SOAP_OK)
  154. virtual int GetCurrentMessage(_wsnt__GetCurrentMessage *wsnt__GetCurrentMessage, _wsnt__GetCurrentMessageResponse *wsnt__GetCurrentMessageResponse)
  155. {return SOAP_OK;}
  156. /// Web service operation 'GetMessages' (returns error code or SOAP_OK)
  157. virtual int GetMessages(_wsnt__GetMessages *wsnt__GetMessages, _wsnt__GetMessagesResponse *wsnt__GetMessagesResponse)
  158. {return SOAP_OK;}
  159. /// Web service operation 'DestroyPullPoint' (returns error code or SOAP_OK)
  160. virtual int DestroyPullPoint(_wsnt__DestroyPullPoint *wsnt__DestroyPullPoint, _wsnt__DestroyPullPointResponse *wsnt__DestroyPullPointResponse)
  161. {return SOAP_OK;}
  162. /// Web service one-way operation 'Notify' (return error code, SOAP_OK (no response), or send_Notify_empty_response())
  163. virtual int Notify_(_wsnt__Notify *wsnt__Notify)
  164. {return SOAP_OK;}
  165. /// Web service operation 'CreatePullPoint' (returns error code or SOAP_OK)
  166. virtual int CreatePullPoint(_wsnt__CreatePullPoint *wsnt__CreatePullPoint, _wsnt__CreatePullPointResponse *wsnt__CreatePullPointResponse)
  167. {return SOAP_OK;}
  168. /// Web service operation 'Renew' (returns error code or SOAP_OK)
  169. virtual int Renew_(_wsnt__Renew *wsnt__Renew, _wsnt__RenewResponse *wsnt__RenewResponse)
  170. {return SOAP_OK;}
  171. /// Web service operation 'Unsubscribe' (returns error code or SOAP_OK)
  172. virtual int Unsubscribe_(_wsnt__Unsubscribe *wsnt__Unsubscribe, _wsnt__UnsubscribeResponse *wsnt__UnsubscribeResponse)
  173. {return SOAP_OK;}
  174. /// Web service operation 'PauseSubscription' (returns error code or SOAP_OK)
  175. virtual int PauseSubscription(_wsnt__PauseSubscription *wsnt__PauseSubscription, _wsnt__PauseSubscriptionResponse *wsnt__PauseSubscriptionResponse)
  176. {return SOAP_OK;}
  177. /// Web service operation 'ResumeSubscription' (returns error code or SOAP_OK)
  178. virtual int ResumeSubscription(_wsnt__ResumeSubscription *wsnt__ResumeSubscription, _wsnt__ResumeSubscriptionResponse *wsnt__ResumeSubscriptionResponse)
  179. {return SOAP_OK;}
  180. private:
  181. int m_EventCnt;
  182. OnvifServerEventProducer &m_Producer;
  183. string m_strEventEndpoint;
  184. };
  185. #endif