ONVIF GSOAP Development

From ago control wiki
Jump to: navigation, search

Contents

requirements

gsoap >= 2.8.10

typemap.dat addition for onvif

use the typemap from the gsoap archive and append the following:

#	ONVIF recommended prefixes
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"
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"
tdn	= "http://www.onvif.org/ver10/network/wsdl"
tt	= "http://www.onvif.org/ver10/schema"
#	OASIS recommended prefixes
wsnt	= "http://docs.oasis-open.org/wsn/b-2"
wsntw	= "http://docs.oasis-open.org/wsn/bw-2"
wsrfbf	= "http://docs.oasis-open.org/wsrf/bf-2"
wsrfr	= "http://docs.oasis-open.org/wsrf/r-2"
wsrfrw  = "http://docs.oasis-open.org/wsrf/rw-2"
wstop	= "http://docs.oasis-open.org/wsn/t-1"
#	WS-Discovery 1.0 remapping
wsdd10__HelloType		= | wsdd__HelloType
wsdd10__ByeType			= | wsdd__ByeType
wsdd10__ProbeType		= | wsdd__ProbeType
wsdd10__ProbeMatchesType	= | wsdd__ProbeMatchesType
wsdd10__ProbeMatchType		= | wsdd__ProbeMatchType
wsdd10__ResolveType		= | wsdd__ResolveType
wsdd10__ResolveMatchesType	= | wsdd__ResolveMatchesType
wsdd10__ResolveMatchType	= | wsdd__ResolveMatchType
#	SOAP-ENV mapping
SOAP_ENV__Envelope	= struct SOAP_ENV__Envelope { struct SOAP_ENV__Header *SOAP_ENV__Header; _XML SOAP_ENV__Body; }; | struct SOAP_ENV__Envelope
SOAP_ENV__Header	= | struct SOAP_ENV__Header
SOAP_ENV__Fault		= | struct SOAP_ENV__Fault
SOAP_ENV__Detail	= | struct SOAP_ENV__Detail
SOAP_ENV__Code		= | struct SOAP_ENV__Code
SOAP_ENV__Subcode	= | struct SOAP_ENV__Subcode
SOAP_ENV__Reason	= | struct SOAP_ENV__Reason

onvif.h.patch

--- onvif.h.orig	2013-07-30 14:18:39.393943995 +0200
+++ onvif.h	2013-07-30 14:18:58.417092962 +0200
@@ -101,6 +101,7 @@
 #import "wsdd10.h"	// wsdd10 = <http://schemas.xmlsoap.org/ws/2005/04/discovery>
 #import "xop.h"	// xop = <http://www.w3.org/2004/08/xop/include>
 #import "wsa5.h"	// wsa5 = <http://www.w3.org/2005/08/addressing>
+#import "wsse.h"
 
 /******************************************************************************\
  *                                                                            *

generate gsoap classes

#!/bin/bash
GSOAPDIR=./gsoap-2.8
GSOAP_IMPORT=${GSOAPDIR}/gsoap/import:${GSOAPDIR}/gsoap/custom:${GSOAPDIR}/gsoap
SOAPCPP2=${GSOAPDIR}/gsoap/bin/linux386/soapcpp2
SOAPCPP2_OPTS="-2 -C -x -i"
WSDL2H=${GSOAPDIR}/gsoap/wsdl/wsdl2h
WSDL2H_OPTS="-k -t ./typemap.dat"
OUTPUT_DIR=./onvif
ONVIF_WSDL=\
"http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl \
http://www.onvif.org/onvif/ver10/event/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"

# ------------ 

test -d ${OUTPUT_DIR} || mkdir -p ${OUTPUT_DIR}
#touch ${OUTPUT_DIR}/env.h
#soapcpp2 -c -penv -I/usr/share/gsoap/import -I/usr/share/gsoap env.h
${WSDL2H} ${WSDL2H_OPTS} -o ${OUTPUT_DIR}/onvif.h -I${GSOAP_IMPORT} ${ONVIF_WSDL}
pushd .
cd ${OUTPUT_DIR}
patch < onvif.h.patch 
popd
$SOAPCPP2 ${SOAPCPP2_OPTS} -d ${OUTPUT_DIR} -I${GSOAP_IMPORT} ${OUTPUT_DIR}/onvif.h

Discovery without proxy class

	/*
	struct soap *soap;
	struct wsdd__ProbeType probeType;
	struct __wsdd__ProbeMatches matches;
	struct wsdd__ScopesType scopesType;
	struct SOAP_ENV__Header header;

	char uuid_string[37];
	std::string tmpuuid = "urn:uuid:" +  generateUuid();
	printf("tmpuuid: %s\n", tmpuuid.c_str());
	strncpy (uuid_string, tmpuuid.c_str(), 37);

	soap = soap_new();
	if(soap==NULL) {
		printf("ERROR: Can't initalize soap\n");
		return -1;
	}

	soap_set_namespaces(soap, namespaces);
	soap->recv_timeout=5;

	// set header
	soap_default_SOAP_ENV__Header(soap, &header);
	header.wsa__MessageID = uuid_string;
	header.wsa__To = (char *)"urn:schemas-xmlsoap-org:ws:2005:04:discovery";
	header.wsa__Action = (char *)"http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";
	soap->header = &header;

	soap_default_wsdd__ScopesType (soap, &scopesType);
	scopesType.__item = (char *)"onvif://www.onvif.org";
	soap_default_wsdd__ProbeType(soap, &probeType);
	probeType.Scopes = &scopesType;

	probeType.Types = (char *)"tdn:NetworkVideoTransmitter";

	if (soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702/", NULL, &probeType) == -1) {
		printf("SOAP error occured: %d %s - %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
		return soap->error;
	} else {
		while (soap_recv___wsdd__ProbeMatches(soap, &matches) != -1) {
			printf("match size: %d\n",matches.wsdd__ProbeMatches->__sizeProbeMatch);
			printf("Endpoint Addr: %s\n",matches.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address);
			printf("Service Addr: %s\n", matches.wsdd__ProbeMatches->ProbeMatch->XAddrs);
			printf("Type: %s\n", matches.wsdd__ProbeMatches->ProbeMatch->Types);
			printf("Metadata Ver: %d\n",matches.wsdd__ProbeMatches->ProbeMatch->MetadataVersion);
			printf("Scopes Addr: %s\n", matches.wsdd__ProbeMatches->ProbeMatch->Scopes->__item);
		}
	} */

discovery with wsdd proxy class

	struct wsdd__ProbeType probe;
	struct __wsdd__ProbeMatches matches;
	probe.Scopes = new struct wsdd__ScopesType();
	probe.Types = (char*)"tdn:NetworkVideoTransmitter";

	std::string tmpuuid = "urn:uuid:" +  generateUuid();

	wsddProxy *discoverProxy = new wsddProxy("soap.udp://239.255.255.250:3702/");
	discoverProxy->soap_header((char*)tmpuuid.c_str(), NULL, NULL, NULL, NULL, "urn:schemas-xmlsoap-org:ws:2005:04:discovery",
                        "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	discoverProxy->recv_timeout=3;

	printf("Sending probe\n");
	discoverProxy->send_Probe(&probe);
	printf("waiting for matches\n");
	while ( discoverProxy->recv_ProbeMatches(matches) == SOAP_OK) {
		printf("Service Addr: %s\n", matches.wsdd__ProbeMatches->ProbeMatch->XAddrs);
		//printf("Type: %s\n", matches.wsdd__ProbeMatches->ProbeMatch->Types);
		//printf("Metadata Ver: %d\n",matches.wsdd__ProbeMatches->ProbeMatch->MetadataVersion);
	}
	discoverProxy->destroy();
Personal tools