Prepare Requirements

ONVIF Event

gSoap reference

ONVIF Specification

问题描述

Event是ONVIF核心规范中一块, 文档解释了如何基于WS-Notification框架体系来工作.但是依据Event.wsdl 生成的消息结构部分, wsdl没有给出参考标准.而是给出了一个可扩展定义的dom结点点位描述. 见下引用

        <xs:element name="PullMessagesResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="CurrentTime" type="xs:dateTime">
<xs:annotation>
<xs:documentation>The date and time when the messages have been delivered by the web server to the client.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="TerminationTime" type="xs:dateTime">
<xs:annotation>
<xs:documentation>Date time when the PullPoint will be shut down without further pull requests.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="wsnt:NotificationMessage" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>List of messages. This list shall be empty in case of a timeout.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

Okay, let's see the reference ="wsnt:NotificationMessage"

   <!--================== Message Helper Types  =====================-->
<xsd:complexType name="NotificationMessageHolderType">
<xsd:sequence>
<xsd:element ref="wsnt:SubscriptionReference" minOccurs="0" maxOccurs="1"/>
<xsd:element ref="wsnt:Topic" minOccurs="0" maxOccurs="1"/>
<xsd:element ref="wsnt:ProducerReference" minOccurs="0" maxOccurs="1"/>
<xsd:element name="Message">
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="##any" processContents="lax" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="NotificationMessage" type="wsnt:NotificationMessageHolderType"/>

you see. the element Message. no defined fixture struct.

Let's do somthing to watch the right truth. this way we will see how to work with gSoap to make the soap protocol comfortable.

执行wsdl2h生成处理头文件.

/// "http://docs.oasis-open.org/wsn/b-2":NotificationMessageHolderType is a complexType.
struct wsnt__NotificationMessageHolderType
{
/// Element reference "http://docs.oasis-open.org/wsn/b-2":SubscriptionReference.
    wsa5__EndpointReferenceType*         SubscriptionReference          0; ///< Optional element.
/// Element reference "http://docs.oasis-open.org/wsn/b-2":Topic.
    struct wsnt__TopicExpressionType*    Topic                          0; ///< Optional element.
/// Element reference "http://docs.oasis-open.org/wsn/b-2":ProducerReference.
    wsa5__EndpointReferenceType*         ProducerReference              0; ///< Optional element.
    struct _wsnt__NotificationMessageHolderType_Message
    {
/// TODO: <any namespace="##any" minOccurs="1" maxOccurs="1">
/// TODO: Schema extensibility is user-definable.
///       Consult the protocol documentation to change or insert declarations.
///       Use wsdl2h option -x to remove this element.
///       Use wsdl2h option -d for xsd__anyType DOM (soap_dom_element).
    xsd__anyType                         __any                         0; ///< Catch any element content in DOM.
    }                                    Message                        1;	///< Required element.
};

now, see it. this generation with no option specitied. 没有指定任何选项默认生成为C++的.h处理文件.

you should have to see the line

_XML                                 __any                         0; ///< Catch any element content in XML string.

每个ONVIF新手上来都会被这个字段搞迷糊. Message字段, 我们必需关注的内容.居然未被解析成可用类型的数据, 那我们依赖gSoap是为什么. 我们用它来生成.h, 进一步生成我们能调用的C/C++代码. 生成的代码量还是庞大可观的. 编译老费时间, 还需要stdsoap2.h/.c的支持, 还可能会用到gSoap/plugin中相关支持.

yes, it must be useful. 是的我们会发现gSoap带来给我很大解脱. 只要我们保持一颗乐观向上的心情, 保持上进的心态.

下面由请你把这个结构中的__any字段改成指定类型,然后我们再进入下一环节的讲述.

/// Top-level root element "http://www.onvif.org/ver10/schema":Message

/// "http://www.onvif.org/ver10/schema":Message is a complexType.
struct _tt__Message
{
/// @brief Token value pairs that triggered this message. Typically only one item is present.
/// Element Source of type "http://www.onvif.org/ver10/schema":ItemList.
    struct tt__ItemList*                 Source                         0; ///< Optional element.
/// Element Key of type "http://www.onvif.org/ver10/schema":ItemList.
    struct tt__ItemList*                 Key                            0; ///< Optional element.
/// Element Data of type "http://www.onvif.org/ver10/schema":ItemList.
    struct tt__ItemList*                 Data                           0; ///< Optional element.
/// Element Extension of type "http://www.onvif.org/ver10/schema":MessageExtension.
    struct tt__MessageExtension*         Extension                      0; ///< Optional element.
/// Attribute UtcTime of type xs:dateTime.
   @time_t                               UtcTime                        1; ///< Required attribute.
/// Attribute PropertyOperation of type "http://www.onvif.org/ver10/schema":PropertyOperation.
   @enum tt__PropertyOperation*          PropertyOperation              0; ///< Optional attribute.
/// <anyAttribute namespace="##any">
/// TODO: Schema extensibility is user-definable.
///       Consult the protocol documentation to change or insert declarations.
///       Use wsdl2h option -x to remove this attribute.
///       Use wsdl2h option -d for xsd__anyAttribute DOM (soap_dom_attribute).
   @xsd__anyAttribute                    __anyAttribute                ; ///< Store anyAttribute content in DOM soap_dom_attribute linked node structure.
};

由于我们参考阅读ONVIF事件一块的文档资料以及通过odm及wireshark工具抓包分析可了解到, 国内使用的许多IPC都基本上使用已有的事件消息结构来填充上面提到的_wsnt__NotificationMessageHolderType_Message内容, 即被解释为_tt__Message的参考结构.

好吧, 那我们就来把 那行代码改掉

_XML                                 __any;

改成

_tt__Message                  tt__Message;

为什么要这样修改,后面我们会了解,这个字段命名也是有规则的. 在生成soapC.cpp的时候,会依赖字段来生成相应的解析标签, tt__Message被soapcpp2理解为一个tt:Message的标签元素,所以他解析与序列化组装消息都会依赖这个规则.

执行soapcpp2生成C/C++使用代码.

#ifndef SOAP_TYPE__wsnt__NotificationMessageHolderType_Message
#define SOAP_TYPE__wsnt__NotificationMessageHolderType_Message (1303)
/* wsnt:NotificationMessageHolderType-Message */
struct _wsnt__NotificationMessageHolderType_Message
{
struct _tt__Message *tt__Message; /* optional element of type tt:Message */
};
#endif #ifndef SOAP_TYPE_wsnt__NotificationMessageHolderType
#define SOAP_TYPE_wsnt__NotificationMessageHolderType (1177)
/* wsnt:NotificationMessageHolderType */
struct wsnt__NotificationMessageHolderType
{
struct wsa5__EndpointReferenceType *SubscriptionReference; /* optional element of type wsa5:EndpointReferenceType */
struct wsnt__TopicExpressionType *Topic; /* optional element of type wsnt:TopicExpressionType */
struct wsa5__EndpointReferenceType *ProducerReference; /* optional element of type wsa5:EndpointReferenceType */
struct _wsnt__NotificationMessageHolderType_Message Message; /* required element of type wsnt:NotificationMessageHolderType-Message */
};
#endif

gSoap对消息解析一块生成的代码,let's look.

SOAP_FMAC3 int SOAP_FMAC4 soap_out__wsnt__NotificationMessageHolderType_Message(struct soap *soap, const char *tag, int id, const struct _wsnt__NotificationMessageHolderType_Message *a, const char *type)
{
(void)soap; (void)tag; (void)id; (void)type;
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE__wsnt__NotificationMessageHolderType_Message), type))
return soap->error;
if (soap_out_PointerTo_tt__Message(soap, "tt:Message", -1, &a->tt__Message, ""))
return soap->error;
return soap_element_end_out(soap, tag);
} SOAP_FMAC3 struct _wsnt__NotificationMessageHolderType_Message * SOAP_FMAC4 soap_in__wsnt__NotificationMessageHolderType_Message(struct soap *soap, const char *tag, struct _wsnt__NotificationMessageHolderType_Message *a, const char *type)
{
size_t soap_flag_tt__Message = 1;
if (soap_element_begin_in(soap, tag, 0, type))
return NULL;
a = (struct _wsnt__NotificationMessageHolderType_Message *)soap_id_enter(soap, soap->id, a, SOAP_TYPE__wsnt__NotificationMessageHolderType_Message, sizeof(struct _wsnt__NotificationMessageHolderType_Message), 0, NULL, NULL, NULL);
if (!a)
return NULL;
soap_default__wsnt__NotificationMessageHolderType_Message(soap, a);
if (soap->body && !*soap->href)
{
for (;;)
{ soap->error = SOAP_TAG_MISMATCH;
if (soap_flag_tt__Message && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTo_tt__Message(soap, "tt:Message", &a->tt__Message, ""))
{ soap_flag_tt__Message--;
continue;
}
if (soap->error == SOAP_TAG_MISMATCH)
soap->error = soap_ignore_element(soap);
if (soap->error == SOAP_NO_TAG)
break;
if (soap->error)
return NULL;
}
if (soap_element_end_in(soap, tag))
return NULL;
}
else
{ a = (struct _wsnt__NotificationMessageHolderType_Message *)soap_id_forward(soap, soap->href, (void*)a, 0, SOAP_TYPE__wsnt__NotificationMessageHolderType_Message, 0, sizeof(struct _wsnt__NotificationMessageHolderType_Message), 0, NULL);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
}
return a;
}

结述语

最后由我来总结性的提些问题.

  1. 请问你使用gSoap的目的是为什么?
  2. 请问你觉得gSoap是用于处理什么样事情的?
  3. 请问ONVIF是什么?

对于问题1,我想大多数人都回答是出于工作需要才用到它的. 毫不例外我也是, 而且技术决策完全不是由我们来决定的. 因为我们完全无法推断上级的意志. 但BOSS的意志是必须执行的.所以我们路途就算会艰辛一点吧.

问题2 你可能会觉得和问题1没有什么两样, 但是你只要认真思考了问题1, 也就不难醒悟到, gSoap基本是soap协议的一个库支持. 依赖于gSoap方能使们从消息的封装与解析的繁琐工作中解放出来. gSoap为我们做的事情就是帮我组装序列化好的消息以便于发送, 并且能够将解析好的消息结构提供给我们以开发者真正关系的数据型态.

问题3 Sorry. ONVIF是一个市场标准, 由几个大企业协商制定的一个访问接口标准. 不是什么高级的东西.如果我们能加入该讨论社区我们也将参考标准的制定.

any way. let's talking on the Group 251296672 by QQ.

ONVIF Event消息解析(How to work with gSoap)的更多相关文章

  1. XML消息解析_php

    初识php——微信消息处理 <?php $test = new weixin(); $test->Message(); class weixin{ public function Mess ...

  2. 微信推送给服务器的XML消息解析-springmvc 解析xml数据流

    微信推送给服务器的XML消息解析: 可以使用request.getInputStream(); 获取输入的消息流:但是需要自己解析流: spring mvc自带解析功能: controller中: @ ...

  3. laravel框架中Job和事件event的解析

    本篇文章给大家带来的内容是关于laravel框架中Job和事件event的解析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 在做项目的时候,一直对Job和Event有个疑惑.感觉两 ...

  4. Netty 中的消息解析和编解码器

    本篇内容主要梳理一下 Netty 中编解码器的逻辑和编解码器在 Netty 整个链路中的位置. 前面我们在分析 ChannelPipeline 的时候说到入站和出站事件的处理都在 pipeline 中 ...

  5. NDEF消息解析实例[转]

      问题:按照NDEF消息格式来解析下列Hex串? D1 02 1F 53 70 91 01 0E 54 02  65 6E 68 65 6C 6C 6F 20 77 6F  72 6C 64 51 ...

  6. CEdit 样式与消息 解析

    编辑框(Edit)控件实际上是一个简易的文本编辑器,用户可以在编辑框中输入可添加或插入文本.还有复制.粘贴.剪切.删除等编辑功能. 应用程序用CreateWindowEx创建编辑框控件时,可根据控件的 ...

  7. iOS 远程推送消息解析及逻辑处理

    关于远程推送的相关配置网上已经有足够多的教程,这里就不复述了.这里讲述当客户端收到推送消息后,应怎样对其进行相应的逻辑处理. 工程的AppDelegate.m文件里提供了如下方法: //当应用程序启动 ...

  8. javascript event 事件解析

    event对象只在事件发生的过程中才有效. event的某些属性只对特定的事件有意义.比如,fromElement 和 toElement 属性只对 onmouseover 和 onmouseout ...

  9. event.target解析

    event.target返回最初触发事件的DOM对象. Vue例子: main.js methods:{ fan:function(event){ console.log(event.target); ...

随机推荐

  1. ♫【RequireJS】grunt-contrib-requirejs

    gruntjs / grunt-contrib-requirejs 使用r.js优化require.js项目 define("b",[],function(){return fun ...

  2. javascript 基础学习整理 二 之 html对象总结,参考W3C

    Anchor 对象 更改一个链接的文本.URL 以及 target 使用 focus() 和 blur() 向超链接添加快捷键 Document 对象 使用 document.write() 向输出流 ...

  3. Light OJ 1011 - Marriage Ceremonies(状压DP)

    题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少?   状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...

  4. Maximum Subarray——LeetCode

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  5. HDOJ(HDU) 2106 decimal system(进制相互转换问题)

    Problem Description As we know , we always use the decimal system in our common life, even using the ...

  6. scipy安装失败

    pip install scipy安装失败 可以从uci网站下载wheel安装包然后执行pip install xx.whl进行安装 http://www.lfd.uci.edu/~gohlke/py ...

  7. Java自动装箱和自动拆箱操作

    1.Java数据类型 在介绍Java的自动装箱和拆箱之前,我们先来了解一下Java的基本数据类型. 在Java中,数据类型可以分为两大种,Primitive Type(基本类型)和Reference ...

  8. cgdb调试postgresql

    之前一直用gdb调试代码,最近在搞pg的时候用了一个cgdb,体验很好,调试pg代码的时候真的很方便. 本文主要讲解在进行pg内核开发的时候,如何搭建一个环境,用cgdb方便快捷的调试postgres ...

  9. Android 网络框架---Volley

    /** * Volley 可以同时请求多个,允许高并发 * 特性: * 1.JSON.图片等的异步下载 * 2.网络请求的排序(Scheduling) * 3.网络请求的优先级处理 * 4.缓存 * ...

  10. 【转】string常用函数

    原文地址:http://hi.baidu.com/baowup/blog/item/3a27465c86d71546faf2c066.html/cmtid/de1ef3f0de7554a0a40f52 ...