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
使用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
修改文件
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函数
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;
}
终于该我们的main函数登场了。 再工程下建立main.c文件,只写一个main函数即可。
至此整个ONVIF框架搭建完成。