您的位置:首页 > 其它

onvif开发系列之--------关于gsoap的预备知识

2014-12-03 16:42 585 查看
一、关于gsoap的预备知识
gsoap 2.x 新增函数
FunctionDescription
soap_init(struct soap *soap)Initializes a context (required only once)
struct soap *soap_new()Allocates, initializes, and returns a pointer to a runtime context
struct soap *soap_copy(structsoap *soap)Allocates a new runtime context and copies contents of the context such that the new environment does not share any data with the original context
    struct soap 是环境变量,可重复使用,动态申请的soap需要使用soap_free释放。
如:
int main()
{
struct soap soap;
...
soap_init(&soap); // initialize runtime context
...
soap_call_ns__method1(&soap, ...); // make a remote call
...
soap_call_ns__method2(&soap, ...); // make another remote call
...
soap_destroy(&soap); // remove deserialized class instances (C++ only)
soap_end(&soap); // clean up and remove deserialized data
soap_done(&soap); // detach context (last use and no longer in scope)
...
}

也可以进行堆分配:
int main()
{
struct soap *soap;
...
soap = soap_new(); // allocate and initialize runtime context
if (!soap) // couldn't allocate: stop
...
soap_call_ns__method1(soap, ...); // make a remote call
...
soap_call_ns__method2(soap, ...); // make another remote call
...
soap_destroy(soap); // remove deserialized class instances (C++ only)
soap_end(soap); // clean up and remove deserialized data
soap_free(soap); // detach and free runtime context
}

服务端调用soap_server()前必须对环境进行初始化 soap_init()
int main() 



   struct soap soap; 

   soap_init(&soap); 

   soap_serve(&soap); 

}

int main() 



   soap_serve(soap_new()); 

}

服务端可使用多线程来响应请求,当其他代码在调用服务操作时。
int main()
{
struct soap soap1, soap2;
pthread_t tid;
...
soap_init(&soap1);
if (soap_bind(&soap1, host, port, backlog) < 0) exit(1);
if (soap_accept(&soap1) < 0) exit(1);
pthread_create(&tid, NULL, (void*(*)(void*))soap_serve, (void*)&soap1);
...
soap_init(&soap2);
soap_call_ns__method(&soap2, ...); // make a remote call
...
soap_end(&soap2);
...
pthread_join(tid, NULL); // wait for thread to terminate
soap_end(&soap1); // release its data
}

soap_print_fault() 打印错误信息。

FunctionDescription
soap_init(struct soap *soap)Initializes a runtime context
soap_init1(struct soap *soap, soap_mode iomode)Initializes a runtime context and set in/out mode flags
soap_init2(struct soap *soap, soap_mode imode, soap_mode omode)Initializes a runtime context and set in/out mode flags
struct soap *soap_new()Allocates, initializes, and returns a pointer to a runtime context
struct soap *soap_new1(soap_mode iomode)Allocates, initializes, and returns a pointer to a runtime context and set in/out mode flags
struct soap *soap_new2(soap_mode imode, soap_mode omode)Allocates, initializes, and returns a pointer to a runtime context and set in/out mode flags
struct soap *soap_copy(struct soap *soap)Allocates a new runtime context and copies a context (deep copy, i.e. the new context does not share any data with the other context)
soap_done(struct soap *soap)Reset, close communications, and remove callbacks
soap_free(struct soap *soap)Reset and deallocate the context created with soap_new or soap_copy
soap_bind(struct soap *soap, char *host, int port, int backlog)Returns master socket (backlog = max. queue size for requests). When host==NULL: host is the machine on which the service runs
soap_accept(struct soap *soap)Returns slave socket
soap_end(struct soap *soap)Clean up deserialized data (except class instances) and temporary data
soap_free_temp(struct soap *soap)Clean up temporary data only
FunctionDescription
void soap_begin_send(struct soap*)start a send/write phase
int soap_end_send(struct soap*)flush the buffer
int soap_begin_recv(struct soap*)start a rec/read phase (if an HTTP header is present, parse it first)
int soap_end_recv(struct soap*)perform a id/href consistency check on deserialized data
二、wsdl2h 选项
   wsdl2h是把wsdl或xml文件生成.h文件的工具

OptionDescription
-agenerate indexed struct names for local elements with anonymous types
-bbi-directional operations to serve one-way response messages (duplex)
-cgenerate C source code
-duse DOM to populate xs:any and xsd:anyType elements
-edon't qualify enum names
This option is for backward compatibility with gSOAP 2.4.1 and earlier.
The option does not produce code that conforms to WS-I Basic Profile 1.0a.
-fgenerate flat C++ class hierarchy for schema extensions
-ggenerate global top-level element declarations
-hprint help information
-I pathuse path to locate source files for #import
-idon't import (advanced option)
-jdon't generate SOAP_ENV__Header and SOAP_ENV__Detail definitions
-kdon't generate SOAP_ENV__Header mustUnderstand qualifiers
-linclude license information in output
-muse xsd.h module to import primitive types
-N nameuse name for service prefixes to produce a service for each binding
-n nameuse name as the base namespace prefix name instead of ns
-o fileoutput to file
-Pdon't create polymorphic types inherited from xsd__anyType
-pcreate polymorphic types inherited from base xsd__anyType
This is automatically performed when WSDL contains polymorphic definitions
-q nameuse name for the C++ namespace of all declarations
-r host[:port[:uid:pwd]]connect via proxy host, port, and proxy credentials
-r:uid:pwdconnect with authentication credentials (digest auth requires SSL)
-Rgenerate REST operations for REST bindings in the WSDL
-sdon't generate STL code (no std::string and no std::vector)
-t fileuse type map file instead of the default file typemap.dat
-udon't generate unions
-vverbose output
-Wsuppress warnings
-walways wrap response parameters in a response struct
-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.15: qualify element/attribute referenced members
-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
-z5compatibility up to 2.8.17
-_don't generate _USCORE (replace with UNICODE _x005f)
三、使用soapcpp2 工具生成c/c++框架代码

选项

OptionDescription
-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
-LDo not generate soapClientLib/soapServerLib
-aUse SOAPAction with WS-Addressing to invoke server-side operations
-ARequire SOAPAction to invoke server-side operations
-bserialize byte arrays char
 as string
-cGenerate pure C code
-d < path >Save sources in directory specified by < path >
-eGenerate SOAP RPC encoding style bindings
-f NFile split of N XML serializer implementations per file
-hPrint a brief usage message
-iGenerate service proxies and objects inherited from soap struct
-jGenerate C++ service proxies and objects that can share a soap struct
-I < path >Use < path > for #import (paths separated with ':' or ';' for windows)
-kgenerate data structure walkers (experimental)
-lGenerate linkable modules (experimental)
-mGenerate Matlabtm code for MEX compiler
-nWhen used with -p, enables multi-client and multi-server builds:
Sets compiler option WITH_NONAMESPACES, see Section 9.11
Saves the namespace mapping table with name < name > _namespaces instead of namespaces
Renames soap_serve() into < name > _serve() and soap_destroy() into <
name > _destroy()
-p < name >Save sources with file name prefix < name > instead of "soap"
-q < name >Use name for the C++ namespace of all declarations
-sGenerates deserialization code with strict XML validation checks
-tGenerates code to send typed messages (with the 
xsi:type
 attribute)
-uuncomment comments in WSDL/schema output by suppressing XML comments
-vDisplay version info
-wDo not generate WSDL and schema files
-xDo not 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
生成的代码:
  
File Name
------------------------------
Description
soapStub.hA modified and annotated header file produced from the input header file
soapH.hMain header file to be included by all client and service sources
soapC.cppSerializers and deserializers for the specified data structures
soapClient.cppClient stub routines for remote operations
soapServer.cppService skeleton routines
soapClientLib.cppClient stubs combined with local static (de)serializers
soapServerLib.cppService skeletons combined with local static (de)serializers
soapXYZProxy.hA C++ proxy object (link with soapC.cpp soapClient.cpp)
soapXYZProxy.hWith option -i: proxy object (link with soapC.cpp and soapXYZProxy.cpp)
soapXYZProxy.cppWith option -i: proxy code
soapXYZObject.hA C++ server object (link with soapC.cpp and soapServer.cpp)
soapXYZService.hWith option -i: server object (link with soapC.cpp and soapXYZService.cpp)
soapXYZService.cppWith option -i: server code
.xsdAn ns.xsd file is generated with an XML Schema for each namespace prefix ns used by a data structure in the header file input to the compiler,
.wsdlA ns.wsdl file is generated with an WSDL description for each namespace prefix ns used by a service operation in the header file input to the compiler
.xmlSeveral SOAP/XML request and response files are generated. These are example message files are valid provided that sufficient schema namespace directives are added to the header file or the generated .nsmap namespace table for the client/service is not modified
by hand
.nsmapA ns.nsmap file is generated for each namespace prefix ns used by a service operation in the header file input to the compiler, see Section 7.2.9.
The file contains a namespace mapping table that can be used in the client/service sources
会使用到的gsoap包

File NameDescription
stdsoap2.hHeader file of stdsoap2.cpp runtime library
stdsoap2.cRuntime C library with XML parser and run-time support routines
stdsoap2.cppRuntime C++ library identical to stdsoap2.c
四、内存管理 
Function CallDescription
soap_destroy(struct soap *soap)Remove all dynamically allocated C++ objects.
must be called before soap_end()
soap_end(struct soap *soap)Remove temporary data and deserialized data except
class instances
soap_free_temp(struct soap *soap)Instead of soap_destroy and soap_end:
remove temporary data only
soap_dealloc(struct soap *soap, void *p)Remove malloced data at p. When p==NULL: remove all
dynamically allocated (deserialized) data except class instances
soap_delete(struct soap *soap, void *p)Remove class instance at p. When p==NULL: remove all
dynamically allocated (deserialized) class instances
(this is identical to calling soap_destroy(struct soap *soap))
soap_unlink(struct soap *soap, void *p)Unlink data/object at p from gSOAP's deallocation chain
so gSOAP won't deallocate it
soap_done(struct soap *soap)Detach context (reset runtime context)
soap_free(struct soap *soap)Detach and free context (allocated with soap_new)
使用以下函数来分配临时数据,可以自动回收
Function CallDescription
void *soap_malloc(struct soap *soap, size_t n)return pointer to n bytes
Class *soap_new_Class(struct soap
*soap)
instantiate Class
Class *soap_new_Class(struct soap
*soap, int n)
instantiate array of n objects
Class *soap_new_set_Class(struct soap
*soap, m1, ..., mn)
instantiate and set members mi
Class *soap_new_req_Class(struct soap
*soap, m1, ..., mn)
instantiate and set required-only mi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  onvif