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); ...
随机推荐
- WordPress BulletProof Security插件多个HTML注入漏洞
漏洞名称: WordPress BulletProof Security插件多个HTML注入漏洞 CNNVD编号: CNNVD-201308-023 发布时间: 2013-08-06 更新时间: 20 ...
- joelonsoftware 读书摘录
joelonsoftware 读书摘录 <五个为什么> 1.“黑天鹅难题”,代表外来因素,是一个超出正常预料之外的事件. 2.丰田佐吉的“五个为什么”,当某个地方出现问题时,你就一 ...
- 福州大学 Problem 2169 shadow
http://acm.fzu.edu.cn/problem.php?pid=2169 思路:建立一个邻接表,利用搜索中回溯把走过的路标记为1,然后把这些标记为1的值全部加起来. Problem 216 ...
- [Locked] Binary Tree Upside Down
Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes with a s ...
- Codeforces Round #335 (Div. 1)--C. Freelancer's Dreams 线性规划对偶问题+三分
题意:p, q,都是整数. sigma(Ai * ki)>= p, sigma(Bi * ki) >= q; ans = sigma(ki).输出ans的最小值 约束条件2个,但是变量k有 ...
- openfire for mac 无法启动
http://blog.csdn.net/winer888/article/details/49886281 ①:sudo chmod -R 777 /usr/local/openfire/bin ② ...
- 【repost】如何学好编程 (精挑细选编程教程,帮助现在在校学生学好编程,让你门找到编程的方向)四个方法总有一个学好编程的方法适合你
方法(一)编了这么久的程序,一直想找机会总结下其中的心得和方法,但回想我这段编程道路,又很难说清楚,如果按照我走过的所有路来说,显然是不可能的!当我看完了云风的<游戏之旅--编程感悟>和梁 ...
- 【asp.net爬虫】asp.NET分页控件抓取第n页数据 javascript:__doPostBack
最近在模拟HTTP请求抓取数据,但是服务器是asp.net开发的 分页控件代码 <tr> <td align="left">共 210&am ...
- 传智播客课程——Lucene搜索引擎
Lucene不是一个现成的程序,类似文件搜索程序或web网络爬行器或是一个网站的搜索引擎.Lucene是一个软件库,一个开发工具包,而不是一个具有完整特征的搜索应用程序.它本身只关注文本的索引和搜索. ...
- SCI科技论文写作技巧-核心价值
第一次写SCI论文写作技巧,本身不是大牛,也许没有资金格谈论这个. 这里仅仅是一些个人思考,不正确,好还是不好.而当另一种理论. 对于工程专业的学生,谁往往应用,书写SCI事情.当然,也不是没可能.全 ...