ONVIF Event消息解析(How to work with gSoap)
Prepare Requirements
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;
}
结述语
最后由我来总结性的提些问题.
- 请问你使用gSoap的目的是为什么?
- 请问你觉得gSoap是用于处理什么样事情的?
- 请问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)的更多相关文章
- XML消息解析_php
初识php——微信消息处理 <?php $test = new weixin(); $test->Message(); class weixin{ public function Mess ...
- 微信推送给服务器的XML消息解析-springmvc 解析xml数据流
微信推送给服务器的XML消息解析: 可以使用request.getInputStream(); 获取输入的消息流:但是需要自己解析流: spring mvc自带解析功能: controller中: @ ...
- laravel框架中Job和事件event的解析
本篇文章给大家带来的内容是关于laravel框架中Job和事件event的解析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 在做项目的时候,一直对Job和Event有个疑惑.感觉两 ...
- Netty 中的消息解析和编解码器
本篇内容主要梳理一下 Netty 中编解码器的逻辑和编解码器在 Netty 整个链路中的位置. 前面我们在分析 ChannelPipeline 的时候说到入站和出站事件的处理都在 pipeline 中 ...
- 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 ...
- CEdit 样式与消息 解析
编辑框(Edit)控件实际上是一个简易的文本编辑器,用户可以在编辑框中输入可添加或插入文本.还有复制.粘贴.剪切.删除等编辑功能. 应用程序用CreateWindowEx创建编辑框控件时,可根据控件的 ...
- iOS 远程推送消息解析及逻辑处理
关于远程推送的相关配置网上已经有足够多的教程,这里就不复述了.这里讲述当客户端收到推送消息后,应怎样对其进行相应的逻辑处理. 工程的AppDelegate.m文件里提供了如下方法: //当应用程序启动 ...
- javascript event 事件解析
event对象只在事件发生的过程中才有效. event的某些属性只对特定的事件有意义.比如,fromElement 和 toElement 属性只对 onmouseover 和 onmouseout ...
- event.target解析
event.target返回最初触发事件的DOM对象. Vue例子: main.js methods:{ fan:function(event){ console.log(event.target); ...
随机推荐
- 【图片处理】ImageMagick, gm
ImageMagick: Convert, Edit, Or Compose Bitmap Images http://www.imagemagick.org/script/binary-releas ...
- 通过redis-rdb-tools分析redis内存使用量
背景:生产上一台redis服务器,物理内存32G,几个项目都在用,经常不足一月内存就会耗尽,然后开始使用swap,当swap也用尽的时候,系统就宕机.redis配置也优化过几次,但未见成效.因此决定看 ...
- QQ空间自动发广告解决方法
最近空间好多人QQ都中了毒.每天我都有几十个好友刷空间话费.流量广告! QQ空间自动发广告的原因: 最近使用了刷赞或者其他QQ外挂软件(有些开发者或破解者会在这样的软件上留后门,请自己判断). 或者最 ...
- ltp工具使用配置
ltp是一个比较全的自然语言处理工具,可以用它进行分词.词性标注.语法分析等任务. ---- 准备 下载 下载ltp和ltp4j,在cmake官网下载并安装相应版本的cmake,并且下载ant. 构建 ...
- [置顶] ruby变量详解(收集+整理)
ruby的变量有局部变量,全局变量,实例变量,类变量,常量. 1.局部变量 局部变量以一个小写字母开头或下划线开头 局部变量有局部作用域限制(比如一个block内),它的作用域起始于声明处,结束于该声 ...
- ReportViewer中设置ServerReport.ReportServerCredentials属性的方法
当使用SSRS技术来布置报表,可能使用MS自带的ReportViewer控件来读取报表. 它分为Web和Windows两种版本;此处Web版. ServerReport.ReportServerCre ...
- Solr系列一:Solr与Tomcat的整合
第一次尝试着去写一个系列的教程,希望自己能坚持下去,也希望自己能够通过博客的编写来加深自己对solr搜索的理解. Solr与Tomcat的整合网上有很多教程,我就以我的整合为例来讲述一下我的整合过程, ...
- Java中this的功能与作用
粗粒度上来说,Java中关键字this主要有2个功能: 1.表示“当前对象”的引用 (1)作为参数传入 [程序实例1] public class MyObject { public Integer v ...
- Git 中README.md中MarkDown语法示例
转 http://blog.csdn.net/brokge/article/details/38388757 简介 Markdown的语法简洁明了.学习容易,而且功能比纯文本更强,因此有很多人用它写博 ...
- Dijkstra算法为什么权值不能为负
Dijkstra算法当中将节点分为已求得最短路径的集合(记为S)和未确定最短路径的个集合(记为U),归入S集合的节点的最短路径及其长度不再变更,如果边上的权值允许为负值,那么有可能出现当与S内某点(记 ...