|
|
#include "onvifclientevent.hpp"
OnvifClientEventNotify::OnvifClientEventNotify(struct soap* pData): m_EventCnt(0), PullPointSubscriptionBindingService(*pData){
}
inline OnvifClientEvent::OnvifClientEvent(OnvifClientDevice &device): m_Device(device), eventBinding(SOAP_C_UTFSTRING){
}
inline OnvifClientEvent::~OnvifClientEvent(){
}
ONVIFLIB_API inline int OnvifClientEvent::Subscribe(string ¬ifyUrl){ string strUrl; string strUser; string strPass; _wsnt__Subscribe subscribe; _wsnt__SubscribeResponse subscribeResponse; string strTimeOut = "PT60S"; if (m_Device.GetUserPasswd(strUser, strPass) == false || m_Device.GetEventUrl(strUrl) == false) { return SOAP_ERR; } subscribe.ConsumerReference.Address = (char *)(notifyUrl.c_str()); subscribe.InitialTerminationTime = &strTimeOut; eventBinding.soap_endpoint = strUrl.c_str(); soap_wsse_add_Security(&eventBinding); soap_wsse_add_UsernameTokenDigest(&eventBinding, "Id", strUser.c_str() , strPass.c_str()); soap_wsa_add_From(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous"); soap_wsa_add_ReplyTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous"); soap_wsa_add_FaultTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
int ret = eventBinding.Subscribe(&subscribe,&subscribeResponse); if (ret == SOAP_OK) { m_RenewEndpoint = subscribeResponse.SubscriptionReference.Address; printf("SubscriptionReference %s\n", m_RenewEndpoint.c_str()); } return ret;}
ONVIFLIB_API int OnvifClientEvent::UnSubscribe(){ string strUrl; string strUser; string strPass; _wsnt__Unsubscribe unsubscribe; _wsnt__UnsubscribeResponse unsubscribeResponse; if (m_Device.GetUserPasswd(strUser, strPass) == false || m_Device.GetEventUrl(strUrl) == false) { return SOAP_ERR; } eventBinding.soap_endpoint = strUrl.c_str(); soap_wsse_add_Security(&eventBinding); soap_wsse_add_UsernameTokenDigest(&eventBinding, "Id", strUser.c_str() , strPass.c_str()); soap_wsa_add_From(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous"); soap_wsa_add_ReplyTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous"); soap_wsa_add_FaultTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous"); eventBinding.header->wsa5__To = const_cast<char *>(m_RenewEndpoint.c_str()); return eventBinding.Unsubscribe(&unsubscribe,&unsubscribeResponse);
}ONVIFLIB_API int OnvifClientEvent::Renew(){ string strUrl; string strUser; string strPass; _wsnt__Renew req; _wsnt__RenewResponse resp; string strTimeOut = "PT60S"; if (m_Device.GetUserPasswd(strUser, strPass) == false || m_Device.GetEventUrl(strUrl) == false) { return SOAP_ERR; } req.TerminationTime = &strTimeOut; eventBinding.soap_endpoint = strUrl.c_str(); soap_wsse_add_Security(&eventBinding); soap_wsse_add_UsernameTokenDigest(&eventBinding, "Id", strUser.c_str() , strPass.c_str()); //soap_wsa_add_From(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
soap_wsa_add_ReplyTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous"); //soap_wsa_add_FaultTo(&eventBinding, "http://www.w3.org/2005/08/addressing/anonymous");
eventBinding.header->wsa5__To = const_cast<char *>(m_RenewEndpoint.c_str());
int ret = eventBinding.Renew(&req,&resp); return ret;}
|