gsoap 生成onvif 代理源码

WSDL自动生成源代码

可以分为在线配置和本地配置(本文仅会介绍在Ubuntu中自动生成源码的方法,在Windows或OS,以及生成java/js等其他目标源码的方法可以自己尝试):

本地配置:

可通过onvif官网地址右键另存文件如图:
把下载好的wsdl文件放在onvif目录:

可以自己编写一个这样的脚本wsdl2hOnvif.sh:
#!/bin/bash
/usr/local/gSOAP/bin/wsdl2h -c++ -s -t typemap.dat -o ./onvif.h onvif/devicemgmt.wsdl onvif/event.wsdl onvif/accesscontrol.wsdl onvif/accessrules.wsdl onvif/advancedsecurity.wsdl onvif/analytics.wsdl onvif/credential.wsdl onvif/deviceio.wsdl onvif/display.wsdl onvif/doorcontrol.wsdl onvif/imaging.wsdl onvif/media.wsdl onvif/media2.wsdl onvif/provisioning.wsdl onvif/ptz.wsdl onvif/receiver.wsdl onvif/recording.wsdl onvif/search.wsdl onvif/replay.wsdl onvif/schedule.wsdl onvif/thermal.wsdl onvif/analyticsdevice.wsdl onvif/remotediscovery.wsdl

wsdl指令介绍:
Usage: wsdl2h [-a] [-b] [-c|-c++|-c++11] [-d] [-e] [-f] [-g] [-h] [-I(大写i) path] [-i] [-j] [-k] [-l] [-m] [-M] [-N name] [-n name] [-P|-p] [-q name] [-R] [-r proxyhost[:port[:uid:pwd]]] [-r:userid:passwd] [-s] [-t typemapfile] [-U] [-u] [-V] [-v] [-w] [-W] [-x] [-y] [-z#] [-_] [-o outfile.h] infile.wsdl infile.xsd http://www... ...

argsdiscribe
-agenerate indexed struct names for local elements with anonymous types
-bbi-directional operations (duplex ops) added to serve one-way responses
-cgenerate C source code
-c++generate C++ source code (default)
-c++11generate C++11 source code
-duse DOM to populate xs:any, xs:anyType, and xs:anyAttribute
-edon't qualify enum names
-fgenerate flat C++ class hierarchy
-ggenerate global top-level element declarations
-hdisplay help info
-I(大写i)pathuse path to find files
-idon't import (advanced option)
-jdon't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions
-kdon't generate SOAP_ENV__Header mustUnderstand qualifiers
-ldisplay license information
-muse xsd.h module to import primitive types
-Msuppress error "must understand element with wsdl:required='true'"
-Nnameuse name for service prefixes to produce a service for each binding
-nnameuse name as the base namespace prefix instead of 'ns'
-ofileoutput to file
-Pdon't create polymorphic types inherited from xsd__anyType
-pcreate polymorphic types inherited from base xsd__anyType
-qnameuse name for the C++ namespace of all declarations
-Rgenerate REST operations for REST bindings specified in a WSDL
-rhost[:port[:uid:pwd]]connect via proxy host, port, and proxy credentials
-r:uid:pwdconnect with authentication credentials (digest auth requires SSL)
-sdon't generate STL code (no std::string and no std::vector)
-tfileuse type map file instead of the default file typemap.dat
-Uallow UTF8-encoded Unicode C/C++ identifiers when mapping XML tag names
-udon't generate unions
-Vdisplay the current version and exit
-vverbose output
-Wsuppress warnings
-walways wrap response parameters in a response struct (<=1.1.4 behavior)
-xdon't generate _XML any/anyAttribute extensibility elements
-ygenerate typedef synonyms for structs and enums
-z1compatibility with 2.7.6e: generate pointer-based arrays
-z2compatibility with 2.7.7 to 2.7.15: qualify element/attribute references
-z3compatibility with 2.7.16 to 2.8.7: qualify element/attribute references
-z4compatibility up to 2.8.11: don't generate union structs in std::vector
-z5compatibility up to 2.8.15
-z6compatibility up to 2.8.17
-_don't generate _USCORE (replace with UNICODE _x005f)
infile.wsdlinfile.xsd http://www... list of input sources (if none reads stdin)

本地文件在编译时由于路径问题可能导致编译失败,修改对应路径即可,编译成功后会自动生成一个onvif.h文件。
修改为本地文件对应目录:

编译成功后结果:

在线配置:

在可以直接连接onvif网站且网络速度较好情况下,推荐使用在线配置方式,可以避免路径文件不正常问题,但比较依赖网络,配置时间可能较长。
可以自己编写一个这样的脚本wsdl2hOnvif_Online.sh:

#!/bin/bash
/usr/local/gSOAP/bin/wsdl2h -c++ -s -t typemap.dat -o ./onvif.h https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl https://www.onvif.org/ver10/events/wsdl/event.wsdl ohttps://www.onvif.org/ver10/pacs/accesscontrol.wsdl https://www.onvif.org/ver10/pacs/accessrules.wsdl https://www.onvif.org/ver10/actionengine.wsdl https://www.onvif.org/ver10/advancedsecurity/wsdl/advancedsecurity.wsdl https://www.onvif.org/ver20/analytics/wsdl/analytics.wsdl http://www.onvif.org/ver10/credential/wsdl/credential.wsdl https://www.onvif.org/ver10/deviceio.wsdl https://www.onvif.org/ver10/display.wsdl https://www.onvif.org/ver10/pacs/doorcontrol.wsdl https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl https://www.onvif.org/ver10/media/wsdl/media.wsdl https://www.onvif.org/ver20/media/wsdl/media.wsdl https://www.onvif.org/ver10/provisioning/wsdl/provisioning.wsdl https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl https://www.onvif.org/ver10/receiver.wsdl https://www.onvif.org/ver10/recording.wsdl https://www.onvif.org/ver10/search.wsdl https://www.onvif.org/ver10/replay.wsdl http://www.onvif.org/ver10/schedule/wsdl/schedule.wsdl https://www.onvif.org/ver10/thermal/wsdl/thermal.wsdl https://www.onvif.org/ver10/analyticsdevice.wsdl https://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl 

编译成功结果:

生成onvif.h文件后,就可以通过onvif.h文件生成对应的cpp源码:
可以自己编写一个这样的脚本soapcpp2Onvif.sh:
#!/bin/bash
rm ./onvif_out/* -rf
/usr/local/gSOAP/bin/soapcpp2 -C -L -c++ -d ./onvif_out -i -I ../gsoap-2.8/gsoap:../gsoap-2.8/gsoap/import:../gsoap-2.8/gsoap/custom:../gsoap-2.8/gsoap/extras -x onvif.h
/usr/local/gSOAP/bin/soapcpp2 -C -L -c++ -d ./onvif_out -I ../gsoap-2.8/gsoap:../gsoap-2.8/gsoap/import:../gsoap-2.8/gsoap/custom:../gsoap-2.8/gsoap/extras -x onvif.h
soapcpp2指令介绍:
Usage: soapcpp2 [-0|-1|-2] [-C|-S] [-T] [-Ecdt] [-L] [-a] [-A] [-b] [-c|-c++|-c++11] [-d path] [-e] [-f N] [-h] [-i] [-I(大写i) path:path:...] [-l] [-m] [-n] [-p name] [-Q name] [-q name] [-r] [-s] [-t] [-u] [-V] [-v] [-w] [-x] [-y] [-z#] [infile]

argsdiscribe
-1generate SOAP 1.1 bindings
-2generate SOAP 1.2 bindings
-0no SOAP bindings, use REST
-Cgenerate client-side code only
-Sgenerate server-side code only
-Tgenerate server auto-test code
-Ecgenerate extra routines for deep copying
-Edgenerate extra routines for deep deletion
-Etgenerate extra routines for data traversals with walker functions
-Ldon't generate soapClientLib/soapServerLib
-ause SOAPAction with WS-Addressing to invoke server-side operations
-Arequire SOAPAction to invoke server-side operations
-bserialize byte arrays char[N] as string
-cgenerate C source code
-c++generate C++ source code (default)
-c++11generate C++ source code optimized for C++11 (compile with -std=c++11)
-dpathuse path to save files
-egenerate SOAP RPC encoding style bindings (also use -1 or -2)
-fNmultiple soapC files, with N serializer definitions per file (N>=10)
-hdisplay help info
-I(大写i)pathuse path(s) for #import (paths separated with ':')
-igenerate C++ service proxies and objects inherited from soap struct
-jgenerate C++ service proxies and objects that share a soap struct
-lgenerate linkable modules (experimental)
-mgenerate Matlab(tm) code for MEX compiler (deprecated)
-nuse service name to rename service functions and namespace table
-pnamesave files with new prefix name instead of 'soap'
-Qnameuse name as the C++ namespace for decls, including custom serializers
-qnameuse name as the C++ namespace for decls, excluding custom serializers
-rgenerate soapReadme.md report
-sgenerate deserialization code with strict XML validation checks
-tgenerate code for fully xsi:type typed SOAP/XML messaging
-uuncomment comments in WSDL/schema output by suppressing XML comments
-Vdisplay the current version and exit
-vverbose output
-wdon't generate WSDL and schema files
-xdon't generate sample XML message files
-yinclude C/C++ type access information in sample XML messages
-z1compatibility: generate old-style C++ service proxies and objects
-z2compatibility with 2.7.x: omit XML output for NULL pointers
-z3compatibility with 2.8.30 and earlier: _param_N is indexed globally
infileheader file to parse (if none reads stdin)

编译成功结果:

编译后的文件列表:

有了这些文件后就可以开始通过soapClient接口来实现各项onvif的功能了。下一篇将会介绍相关onvif的功能实现。


转换链接:https://www.jianshu.com/p/3678a738f764
来源:简书
 

  • 29
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用gSOAP生成ONVIF框架代码需要遵循以下步骤: 1. 下载gSOAP工具包并安装到本地。 2. 下载ONVIF设备WSDL文件,例如https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl。 3. 使用gSOAP工具包中的wsdl2h工具将WSDL文件转换为头文件。 4. 使用soapcpp2工具生成ONVIF框架代码,例如: ```bash soapcpp2 -Iimport devicemgmt.h ``` 5. 在生成的代码中实现ONVIF设备的具体操作。 以下是在Linux系统中使用gSOAP生成ONVIF框架代码的示例: 1. 下载gSOAP工具包并安装到本地: ```bash wget https://sourceforge.net/projects/gsoap2/files/gSOAP/gsoap_2.8.112.zip unzip gsoap_2.8.112.zip cd gsoap-2.8 ./configure make sudo make install ``` 2. 下载ONVIF设备WSDL文件: ```bash wget https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl ``` 3. 使用wsdl2h工具将WSDL文件转换为头文件: ```bash wsdl2h -o onvif.h devicemgmt.wsdl ``` 4. 使用soapcpp2工具生成ONVIF框架代码: ```bash soapcpp2 -Iimport onvif.h ``` 5. 在生成的代码中实现ONVIF设备的具体操作。 在生成的代码中,每个ONVIF操作都有对应的函数,例如`SOAP_FMAC5 int SOAP_FMAC6 __tds__GetDeviceInformation(struct soap* soap, _tds__GetDeviceInformation* tds__GetDeviceInformation, _tds__GetDeviceInformationResponse &tds__GetDeviceInformationResponse)`就是获取设备信息的函数。您可以在这些函数中实现具体的操作。 另外,生成的代码中还有一些辅助函数和结构体,您也可以根据需要使用它们。 例如,以下代码片段演示了如何创建一个SOAP客户端并调用`__tds__GetDeviceInformation`函数: ```c++ #include "soapDeviceBindingProxy.h" const char* endpoint = "http://192.168.1.100/onvif/device_service"; DeviceBindingProxy proxy; proxy.soap_endpoint = endpoint; _tds__GetDeviceInformation tds__GetDeviceInformation; _tds__GetDeviceInformationResponse tds__GetDeviceInformationResponse; proxy.__tds__GetDeviceInformation(&tds__GetDeviceInformation, tds__GetDeviceInformationResponse); // 处理返回值 ``` 在使用时,需要将`endpoint`替换为实际的设备IP地址和ONVIF服务端口号。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值