onvif client Discovery实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了onvif client Discovery实现相关的知识,希望对你有一定的参考价值。
省略:onvif client soapRemoteDiscoveryBindingProxy 由 gsoap C++ 方式生成
#include "soapRemoteDiscoveryBindingProxy.h"
#include "RemoteDiscoveryBinding.nsmap"
#include<string>
using namespace std;
SOAP_FMAC5 int SOAP_FMAC6 soap_send___wsdd__Probe(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct wsdd__ProbeType *wsdd__Probe)
{ struct __wsdd__Probe soap_tmp___wsdd__Probe;
if (soap_action == NULL)
soap_action = "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Probe";
soap_tmp___wsdd__Probe.wsdd__Probe = wsdd__Probe;
soap_begin(soap);
soap_set_version(soap, 2); /* SOAP1.2 */
soap->encodingStyle = NULL;
soap_serializeheader(soap);
soap_serialize___wsdd__Probe(soap, &soap_tmp___wsdd__Probe);
if (soap_begin_count(soap))
return soap->error;
if (soap->mode & SOAP_IO_LENGTH)
{ if (soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put___wsdd__Probe(soap, &soap_tmp___wsdd__Probe, "-wsdd:Probe", "")
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap->error;
}
if (soap_end_count(soap))
return soap->error;
if (soap_connect(soap, soap_endpoint, soap_action)
|| soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put___wsdd__Probe(soap, &soap_tmp___wsdd__Probe, "-wsdd:Probe", "")
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap)
|| soap_end_send(soap))
return soap_closesock(soap);
return SOAP_OK;
}
SOAP_FMAC5 int SOAP_FMAC6 soap_recv___wsdd__ProbeMatches(struct soap *soap, struct __wsdd__ProbeMatches *_param_1)
{
soap_default___wsdd__ProbeMatches(soap, _param_1);
soap_begin(soap);
if (soap_begin_recv(soap)
|| soap_envelope_begin_in(soap)
|| soap_recv_header(soap)
|| soap_body_begin_in(soap))
return soap_closesock(soap);
soap_get___wsdd__ProbeMatches(soap, _param_1, "-wsdd:ProbeMatches", NULL);
if (soap->error == SOAP_TAG_MISMATCH && soap->level == 2)
soap->error = SOAP_OK;
if (soap->error
|| soap_body_end_in(soap)
|| soap_envelope_end_in(soap)
|| soap_end_recv(soap))
return soap_closesock(soap);
return soap_closesock(soap);
}
int main()
{
struct soap *soap;
struct wsdd__ProbeType req;
struct __wsdd__ProbeMatches resp;
struct wsdd__ScopesType sScope;
struct SOAP_ENV__Header header;
int count = 0;
int result = 0;
char guid_string[100];
soap = soap_new();
if (soap == NULL)
{
return -1;
}
soap_set_namespaces(soap, namespaces);
soap->recv_timeout = 3; //超过x秒钟没有数据就退出
soap_default_SOAP_ENV__Header(soap, &header);
header.wsa__MessageID = guid_string;
header.wsa__To = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
header.wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";
soap->header = &header;
soap_default_wsdd__ScopesType(soap, &sScope);
sScope.__item = "";
soap_default_wsdd__ProbeType(soap, &req);
req.Scopes = &sScope;
req.Types = "dn:NetworkVideoTransmitter";
result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702", NULL, &req);
int i = 0,nFindDev=0;
while (i++<10)
{
printf("soap_discovery_recv...\n");
result = soap_recv___wsdd__ProbeMatches(soap,&resp);
if (result == SOAP_OK)
{
if (!(soap->header))
{
printf("continue++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
continue;
}
nFindDev++;
cout << "=========================================" << endl;
cout << "Match size:" << resp.wsdd__ProbeMatches->__sizeProbeMatch << endl;
cout << "xsd-unsignedInt:" << resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion << endl;
cout << "scopes item:" << resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item << endl;
cout << "QName:" << resp.wsdd__ProbeMatches->ProbeMatch->Types << endl;
cout << "xsd:string:" << resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address << endl;
cout << "xsd:QName:" << resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.PortType << endl;
cout << "wsa:ServiceNameType:" << resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.ServiceName << endl;
cout << "sequence of elements:" << resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__size << endl;
cout << "xsd:anyType:" << resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__anyAttribute << endl;
cout << "endpoint any:" << resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__any << endl;
cout << "wsdd:UriListType:" << resp.wsdd__ProbeMatches->ProbeMatch->XAddrs << endl;
}
else
{
printf("2soap error: %d, %s, %[email protected]@@@@@@@@@@\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
break;
}
}
printf("exit while,find dev:%d\n", nFindDev);
// remove deserialized class instances (C++ only)
soap_destroy(soap);
// clean up and remove deserialized data
soap_end(soap);
////////////////////////////////////////////////////////////////////////////
soap_free(soap);//detach and free runtime context
soap_done(soap); // detach context (last use and no longer in scope)
return result;
}
以上是关于onvif client Discovery实现的主要内容,如果未能解决你的问题,请参考以下文章
为啥在 Asp.Net Core 中使用 Steeltoe.Discovery.Client 库会不断增加内存?
已解决:org.springframework.cloud.client.discovery.EnableDiscoveryClient 不存在
已解决:org.springframework.cloud.client.discovery.EnableDiscoveryClient 不存在
SpringCloud 教程 之二 服务发现(Eureka Discovery Client + Ribbon)
Spring Actuator - 服务发现 - /health "description":"Discovery Client not initialized"