GSOAP编译,并生成ONVIF框架

4 篇文章 0 订阅
2 篇文章 0 订阅

最近又重新生成了一遍onvif的框架,相对于以前有了一些改变,例如onvif文档变成了https。
接下来将详细的生成过程进行描述:

本次生成过程是基于Redhat8.2的系统环境

  1. 下载GSOAP开源版
    下载gsoap

  2. GSOAP官方文档
    官方网页

  3. 编译前需要先编译安装bison、flex、openssl
    a. 下载flex2.6.4
    b. 下载bison3.8
    c. 下载openssl1.1.q openssl 可以用已经装好的版本

  4. 编译前还需安装部分东西

    yum install libtool
    yum install gettext gettext-devel gettext-common-devel
    yum -y install gcc automake autoconf libtool make
    yum -y install m4
    yum -y install bison flex
    
  5. 编译bison

    xz -d bison-3.8.tar.xz
    tar -xvf bison-3.8.tar
    cd bison-3.8/
    ./configure
    make -j 6
    make install
    
  6. 编译flex

    wget https://github.com/westes/flex/files/981163/flex-2.6.4.tar.gz
    tar -zxvf flex-2.6.4.tar.gz
    cd flex-2.6.4/
    mkdir build
    cd build
    ../configure
    make -j 6
    make install
    
  7. 编译gsoap

    wget https://udomain.dl.sourceforge.net/project/gsoap2/gsoap_2.8.122.zip
    unzip gsoap_2.8.122.zip
    cd gsoap-2.8/
    ./configure --help
    ./configure
    make -j 6
    make install
    ln -sf /usr/local/bin/wsdl2h /usr/bin/wsdl2h
    ln -sf /usr/local/bin/soapcpp2 /usr/bin/soapcpp2
    cd gsoap
    mkdir onvif
    vim typemap.dat
    #去掉xsd__duration = #import "custom/duration.h" | xsd__duration 前面的注释
    #修改命名空间如下
    tds     = "http://www.onvif.org/ver10/device/wsdl"
    tev     = "http://www.onvif.org/ver10/events/wsdl"
    tls     = "http://www.onvif.org/ver10/display/wsdl"
    tmd     = "http://www.onvif.org/ver10/deviceIO/wsdl"
    timg    = "http://www.onvif.org/ver20/imaging/wsdl"
    trt     = "http://www.onvif.org/ver10/media/wsdl"
    tr2     = "http://www.onvif.org/ver20/media/wsdl"
    tptz    = "http://www.onvif.org/ver20/ptz/wsdl"
    trv     = "http://www.onvif.org/ver10/receiver/wsdl"
    trc     = "http://www.onvif.org/ver10/recording/wsdl"
    tse     = "http://www.onvif.org/ver10/search/wsdl"
    trp     = "http://www.onvif.org/ver10/replay/wsdl"
    tan     = "http://www.onvif.org/ver20/analytics/wsdl"
    tad     = "http://www.onvif.org/ver10/analyticsdevice/wsdl"
    tas     = "http://www.onvif.org/ver10/advancedsecurity/wsdl"
    tdn     = "http://www.onvif.org/ver10/network/wsdl"
    tt      = "http://www.onvif.org/ver10/schema"
    
    tac     = "http://www.onvif.org/ver10/accesscontrol/wsdl"
    tar     = "http://www.onvif.org/ver10/accessrules/wsdl"
    tae     = "http://www.onvif.org/ver10/actionengine/wsdl"
    tas     = "http://www.onvif.org/ver10/advancedsecurity/wsdl"
    tab     = "http://www.onvif.org/ver10/authenticationbehavior/wsdl"
    tcr     = "http://www.onvif.org/ver10/credential/wsdl"
    tdc     = "http://www.onvif.org/ver10/doorcontrol/wsdl"
    tpv     = "http://www.onvif.org/ver10/provisioning/wsdl"
    tsc     = "http://www.onvif.org/ver10/schedule/wsdl"
    tth     = "http://www.onvif.org/ver10/thermal/wsdl"
    tup     = "http://www.onvif.org/ver10/uplink/wsdl"
    pt      = "http://www.onvif.org/ver10/pacs"
    thf     = "http://www.onvif.org/ver20/analytics/humanface"
    thb     = "http://www.onvif.org/ver20/analytics/humanbody"
    tns     = "http://www.onvif.org/onvif/ver10/network/wsdl"
    
    
    #输入指令
    wsdl2h -t ./typemap.dat -o onvif/onvif.h https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl https://www.onvif.org/ver10/events/wsdl/event.wsdl https://www.onvif.org/ver10/pacs/accesscontrol.wsdl https://www.onvif.org/ver10/actionengine.wsdl https://www.onvif.org/ver20/analytics/wsdl/analytics.wsdl https://www.onvif.org/ver10/authenticationbehavior/wsdl/authenticationbehavior.wsdl https://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 https://www.onvif.org/ver10/schedule/wsdl/schedule.wsdl https://www.onvif.org/ver10/advancedsecurity/wsdl/advancedsecurity.wsdl https://www.onvif.org/ver10/thermal/wsdl/thermal.wsdl  https://www.onvif.org/ver10/uplink/wsdl/uplink.wsdl http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl http://docs.oasis-open.org/wsn/bw-2.wsdl
    
    vim onvif/onvif.h
    # 添加 #import "wsse.h"
    soapcpp2 -2 -x -L -I import:custom -d onvif/ onvif/onvif.h
    cp stdsoap2.c stdsoap2.h dom.c plugin/wsaapi.c plugin/wsaapi.h custom/duration.c custom/duration.h plugin/threads.c plugin\threads.h plugin\smdevp.c plugin\smdevp.h plugin\mecevp.c plugin\mecevp.h plugin\wsseapi.h plugin\wsseapi.c plugin\wsddapi.h plugin\wsddapi.c onvif/
    # 将duration.c 修改为duration.cpp(duration.c 可能编译不过)
    # 完成编译
    
  8. 编写实例

    #编译实例
    #编译过程中有些警告或者类型转换错误,直接正常修改即可。
    #若出现无法链接的符合,加上-DWITH_OPENSSL试试
    #编译客户端或服务端的时候注意soapClient.cpp和soapServer.cpp只有一个
    #无法解析的外部符号namespaces,添加头文件#include “onvif.nsmap”
    #里面有多个nsmap,随便找一个重命名为onvif.nsmap
    #最后需要再 onvif\stdsoap2.c文件,在开头加入:#include “onvif.nsmap”

使用举例:

int main()
{    
        struct soap* soap = soap_new();
        soap->send_timeout = 5;
        soap->recv_timeout = 5;
        soap->connect_timeout = 5;

        do 
        {
            soap->user = (char*)_strUserName.c_str();
            soap->passwd = (char*)_strPassword.c_str();
            _tds__GetDeviceInformation req;
            _tds__GetDeviceInformationResponse rsp;

            soap_wsse_add_UsernameTokenDigest(soap, NULL, _strUserName.c_str(), _strPassword.c_str());

            auto ret = soap_call___tds__GetDeviceInformation(soap,
                strDevAddr.c_str(), NULL, &req, rsp);
            if (ret != SOAP_OK)
            {
                LOG_ERROR(*context_onvif->pLogger, "<%s>: soap_call___tds__GetDeviceInformation failed. soap code: %?d, ip: %s id: %s",
                    string(__FUNCTION__), ret, _strDeviceIp, _strDeviceId);
                break;
            }

            LOG_INFO(*context_onvif->pLogger, "<%s>: device Info: %s-%s-%s-%s-%s. ip: %s id: %s",
                string(__FUNCTION__), rsp.FirmwareVersion, rsp.HardwareId, rsp.HardwareId, rsp.Manufacturer, rsp.Model, _strDeviceIp, _strDeviceId);
        } while (false);

        soap_destroy(soap); // delete managed objects
        soap_end(soap);     // delete managed data and temporaries 
        soap_free(soap);    // finalize and delete the context
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值