Onvif之框架生成-基于gsoap2.8.27

Onvif之框架生成-基于gsoap2.8.27

Onvif的框架生成可以说是实现onvif协议的第一步了,当然也可以不用工具生成框架,完全按照协议来自己实现,但是有现成的工具不用白不用。

整个框架搭建可谓是费尽周折,这要感谢众多博主的开源精神。写这篇文章的目的一个是总结一下整个过程,另一个是将自己的经验奉献出来。好了废话不多说,进入正题。

工具及平台:
Gsoap版本:Gsoap2.8.27 http://sourceforge.net/projects/gsoap2/files/gSOAP/
Onvif :WSDL文档(2015.12.15最新文档)
框架代码生成:windows下wsdl2、soapcpp2(win下和linux生成一样的)
编译链为:Linux gcc4.4.3

  1. 使用wsdl2h生成onvif.h,这里使用在线的方式,免得还要手动添加好多.xsd文件
    wsdl2h -o onvif.h -c -s -t typemap.dat http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl
    http://www.onvif.org/onvif/ver10/events/wsdl/event.wsdl
    http://www.onvif.org/onvif/ver10/display.wsdl
    http://www.onvif.org/onvif/ver10/deviceio.wsdl
    http://www.onvif.org/onvif/ver20/imaging/wsdl/imaging.wsdl
    http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl
    http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl
    http://www.onvif.org/onvif/ver10/receiver.wsdl
    http://www.onvif.org/onvif/ver10/recording.wsdl
    http://www.onvif.org/onvif/ver10/search.wsdl
    http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl
    http://www.onvif.org/onvif/ver10/replay.wsdl
    http://www.onvif.org/onvif/ver20/analytics/wsdl/analytics.wsdl
    http://www.onvif.org/onvif/ver10/analyticsdevice.wsdl
    http://www.onvif.org/onvif/ver10/schema/onvif.xsd
    http://www.onvif.org/ver10/actionengine.wsdl
    http://www.onvif.org/ver10/pacs/accesscontrol.wsdl
    http://www.onvif.org/ver10/pacs/doorcontrol.wsdl
    http://www.onvif.org/ver10/advancedsecurity/wsdl/advancedsecurity.wsdl
    http://www.onvif.org/ver10/accessrules/wsdl/accessrules.wsdl
    http://www.onvif.org/ver10/credential/wsdl/credential.wsdl
    http://www.onvif.org/ver10/schedule/wsdl/schedule.wsdl

  2. 在onvif.h中加入#import “wsse.h”,用来做安全验证
    这里写图片描述

  3. 使用soapcpp2生成C文件
    soapcpp2 -c onvif.h -x
    -I D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\import
    -I D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap
    注意:做服务器端开发,server和client端的代码都要生成,因为sever端的代码要用到client中的函数这样就不需要自己写了。
  4. 目前为止所有的文件都具备了,下面将整个工程需要的文件整合一下。
    复制soapClient.c soapServer.c soapServerLib.c soapC.c soapH.h soapStub.h wsdd.nsmap
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\ stdsoap2.c
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\ stdsoap2.h
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\ dom.c
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\custom\
    duration.c
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\custom\
    duration.c
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\plugin\ threads.c
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\plugin\ threads.h
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\plugin\ wsaapi.c
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\plugin\ wsaapi.h
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\plugin\ wsddpi.c
    复制D:\work\onvif_frame\gsoap_2.8.27\gsoap-2.8\gsoap\plugin\ wsddpi.h
    这里写图片描述
  5. 修改文件
    1>删除soapServerLib.c中#include “soapC.c” #include “soapServer.c”
    2>注释soapClient.c中soap_send_SOAP_ENV__Fault函数
    soap_recv_SOAP_ENV__Fault函数
    3>注释soapServer.c中soap_serve_SOAP_ENV__Fault函数
    4>注释soapStub.h中 #define SOAP_WSA_2005
    5>注释soapStub.h中soap_send_SOAP_ENV__Fault函数
    SOAP_ENV__Fault函数

  6. 在soapServerLib.c中实现soapStub.h下以双下划线开头的函数,只写一个return语句即可。
    Onvif之框架生成-基于gsoap2.8.27_第1张图片

  7. 在wsddapi.c中实现6个函数,同样只需写一个return语句即可。
int SOAP_ENV__Fault(struct soap* soap, char *faultcode, char *faultstring, char *faultactor,
                            struct SOAP_ENV__Detail *detail, struct SOAP_ENV__Code *SOAP_ENV__Code,
                            struct SOAP_ENV__Reason *SOAP_ENV__Reason,
                            char *SOAP_ENV__Node, char *SOAP_ENV__Role,
                            struct SOAP_ENV__Detail *SOAP_ENV__Detail )
{
    return 0;
}

void wsdd_event_Hello(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *MessageID,
const char *RelatesTo, const char *EndpointReference, const char *Types, const char *Scopes, const char *MatchBy, const char *XAddrs, unsigne
d int MetadataVersion)
{
}

void wsdd_event_Bye(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *MessageID, co
nst char *RelatesTo, const char *EndpointReference, const char *Types, const char *Scopes, const char *MatchBy, const char *XAddrs, unsigned
int *MetadataVersion)
{
}

soap_wsdd_mode wsdd_event_Probe(struct soap *soap, const char *MessageID, const char *ReplyTo, const char *Types, const char *Scopes, const c
har *MatchBy, struct wsdd__ProbeMatchesType *matches)
{
    return SOAP_WSDD_MANAGED;
}

void wsdd_event_ProbeMatches(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *Mess
ageID, const char *RelatesTo, struct wsdd__ProbeMatchesType *matches)
{
}

soap_wsdd_mode wsdd_event_Resolve(struct soap *soap, const char *MessageID, const char *ReplyTo, const char *EndpointReference, struct wsdd__
ResolveMatchType *match)
{
    return SOAP_WSDD_MANAGED;
}

Onvif之框架生成-基于gsoap2.8.27_第2张图片

终于该我们的main函数登场了。 再工程下建立main.c文件,只写一个main函数即可。
Onvif之框架生成-基于gsoap2.8.27_第3张图片
至此整个ONVIF框架搭建完成。

你可能感兴趣的:(框架,开源,经验,gsoap,onvif)