onvif 笔记五(discovery client)
2012-11-19 14:03
337 查看
onvif discovery 客户端
其他部分源码参见之前的博文。
其他部分源码参见之前的博文。
#include <sys/time.h> #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <string.h> #include "soapH.h" #include "soapStub.h" static char uuid[128] = {0}; static char probeType[128] = {0}; static char wsaTo[128] = {0}; static char wsaAction[128] = {0}; SOAP_FMAC5 int SOAP_FMAC6 soap_discovery_start(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct d__ProbeType *d__Probe) { struct __dndl__Probe soap_tmp___dndl__Probe; if (!soap_action) soap_action = "http://www.onvif.org/ver10/network/wsdl/Probe"; soap->encodingStyle = NULL; soap_tmp___dndl__Probe.d__Probe = d__Probe; soap_begin(soap); soap_serializeheader(soap); soap_serialize___dndl__Probe(soap, &soap_tmp___dndl__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___dndl__Probe(soap, &soap_tmp___dndl__Probe, "-dndl:Probe", NULL) || 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___dndl__Probe(soap, &soap_tmp___dndl__Probe, "-dndl:Probe", NULL) || 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_discovery_recv(struct soap *soap, struct d__ProbeMatchesType *d__ProbeMatches) { if (!d__ProbeMatches) { soap_closesock(soap); return -1; } soap_default_d__ProbeMatchesType(soap, d__ProbeMatches); 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_d__ProbeMatchesType(soap, d__ProbeMatches, "d:ProbeMatches", "d:ProbeMatchesType"); if (soap->error) { soap_recv_fault(soap, 0); return -1; } if (soap_body_end_in(soap) || soap_envelope_end_in(soap) || soap_end_recv(soap)) { soap_closesock(soap); return -1; } return SOAP_OK; } SOAP_FMAC5 int SOAP_FMAC6 soap_discovery_stop(struct soap *soap) { return soap_closesock(soap); } int main() { struct soap *soap; int result = 0; struct d__ProbeType req; struct d__ProbeMatchesType resp; struct d__ScopesType sScope; struct SOAP_ENV__Header header; int count = 0; soap = soap_new(); if(soap == NULL) { printf("sopa new error\r\n"); return -1; } soap_set_namespaces(soap, namespaces); soap->recv_timeout = 10; soap_default_SOAP_ENV__Header(soap, &header); getMyUuid(uuid); sprintf(wsaTo, "urn:schemas-xmlsoap-org:ws:2005:04:discovery"); sprintf(wsaAction, "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe"); header.wsa__MessageID = uuid; header.wsa__To = wsaTo; header.wsa__Action = wsaAction; soap->header = &header; soap_default_d__ScopesType(soap, &sScope); sScope.__item = ""; soap_default_d__ProbeType(soap, &req); req.Scopes = &sScope; req.Types = "";//"dn:NetworkVideoTransmitter"; int i = 0; result = soap_discovery_start(soap, "soap.udp://239.255.255.250:3702", NULL, &req); while(result == SOAP_OK) { result = soap_discovery_recv(soap, &resp); if(result == SOAP_OK) { if(soap->error) { printf("soap error 1: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap)); result = soap->error; } else { printf("====================================================================\r\n"); if(soap->header->wsa__MessageID) { printf("MessageID : %s\r\n", soap->header->wsa__MessageID); } if(soap->header->wsa__RelatesTo && soap->header->wsa__RelatesTo->__item) { printf("RelatesTo : %s\r\n", soap->header->wsa__RelatesTo->__item); } if(soap->header->wsa__To) { printf("To : %s\r\n", soap->header->wsa__To); } if(soap->header->wsa__Action) { printf("Action : %s\r\n", soap->header->wsa__Action); } for(i = 0; i < resp.__sizeProbeMatch; i++) { printf("__sizeProbeMatch : %d\r\n", resp.__sizeProbeMatch); printf("Target EP Address : %p\r\n", resp.ProbeMatch[i].wsa__EndpointReference); printf("Target EP Address : %s\r\n", resp.ProbeMatch[i].wsa__EndpointReference.Address); printf("Target Type : %s\r\n", resp.ProbeMatch[i].Types); printf("Target Service Address : %s\r\n", resp.ProbeMatch[i].XAddrs); printf("Target Metadata Version : %d\r\n", resp.ProbeMatch[i].MetadataVersion); if(resp.ProbeMatch[i].Scopes) { printf("Target Scopes Address : %s\r\n", resp.ProbeMatch[i].Scopes->__item); } } } } else if (soap->error) { printf("soap error 2: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap)); result = soap->error; } } soap_discovery_stop(soap); soap_destroy(soap); // remove deserialized class instances (C++ only) soap_end(soap); // clean up and remove deserialized data soap_free(soap);//detach and free runtime context soap_done(soap); // detach context (last use and no longer in scope) return result; }
相关文章推荐
- onvif_discovery_client搜索多个网段内的onvif设备(IPC)
- [文章笔记]Web Service Discovery and Client Goals(Computers, 2009)
- onvif client Discovery实现
- onvif 笔记二(discovery server)
- ET框架---ClientDispatcher学习笔记
- 【STM32F429-DISCOVERY学习笔记】STM32F429驱动SDRAM(IS42S16400J)详解
- 有关SharePoint Client Object应用的笔记
- SpringCloud的注解:EnableEurekaClient vs EnableDiscoveryClient
- 【应用篇】WCF学习笔记(一):Host、Client、MetadataExchage 【应用篇】WCF学习笔记(二):ServiceContract、DataContract
- java nio mina 学习笔记1 Simple Server and Client
- web前端学习笔记---scrollWidth,clientWidth,offsetWidth的区别
- 【论文笔记】Unsupervised Discovery of Mid-Level Discriminative Patches
- filezilla client代码阅读笔记(一)
- git client学习笔记
- onvif规范的实现:server端Discovery实现,通过OnvifTestTool12.06
- HttpClient学习笔记一
- androidpn-client笔记及BUG修改
- Jakarta Commons HttpClient 学习笔记