打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ONVIF Event消息解析(How to work with gSoap)

Prepare Requirements

ONVIF Event

gSoap reference

ONVIF Specification

问题描述

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

  1. <xs:element name="PullMessagesResponse">  
  2.     <xs:complexType>  
  3.        <xs:sequence>  
  4.           <xs:element name="CurrentTime" type="xs:dateTime">  
  5.              <xs:annotation>  
  6.                 <xs:documentation>The date and time when the messages have been delivered by the web server to the client.</xs:documentation>  
  7.              </xs:annotation>  
  8.           </xs:element>  
  9.           <xs:element name="TerminationTime" type="xs:dateTime">  
  10.              <xs:annotation>  
  11.                 <xs:documentation>Date time when the PullPoint will be shut down without further pull requests.</xs:documentation>  
  12.              </xs:annotation>  
  13.           </xs:element>  
  14.           <xs:element ref="wsnt:NotificationMessage" minOccurs="0" maxOccurs="unbounded">  
  15.              <xs:annotation>  
  16.                 <xs:documentation>List of messages. This list shall be empty in case of a timeout.</xs:documentation>  
  17.              </xs:annotation>  
  18.           </xs:element>  
  19.        </xs:sequence>  
  20.     </xs:complexType>  
  21.  </xs:element>  


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

  1. <!--================== Message Helper Types  =====================-->  
  2. <xsd:complexType name="NotificationMessageHolderType">  
  3.    <xsd:sequence>  
  4.       <xsd:element ref="wsnt:SubscriptionReference" minOccurs="0" maxOccurs="1"/>  
  5.       <xsd:element ref="wsnt:Topic" minOccurs="0" maxOccurs="1"/>  
  6.       <xsd:element ref="wsnt:ProducerReference" minOccurs="0" maxOccurs="1"/>  
  7.       <xsd:element name="Message">  
  8.          <xsd:complexType>  
  9.             <xsd:sequence>  
  10.                <xsd:any namespace="##any" processContents="lax" minOccurs="1" maxOccurs="1"/>  
  11.             </xsd:sequence>  
  12.          </xsd:complexType>  
  13.       </xsd:element>  
  14.    </xsd:sequence>  
  15. </xsd:complexType>  
  16. <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生成处理头文件.

  1. /// "http://docs.oasis-open.org/wsn/b-2":NotificationMessageHolderType is a complexType.  
  2. struct wsnt__NotificationMessageHolderType  
  3. {  
  4. /// Element reference "http://docs.oasis-open.org/wsn/b-2":SubscriptionReference.  
  5.     wsa5__EndpointReferenceType*         SubscriptionReference          0;<span style="white-space: pre;"> </span>///< Optional element.  
  6. /// Element reference "http://docs.oasis-open.org/wsn/b-2":Topic.  
  7.     struct wsnt__TopicExpressionType*    Topic                          0;<span style="white-space: pre;">   </span>///< Optional element.  
  8. /// Element reference "http://docs.oasis-open.org/wsn/b-2":ProducerReference.  
  9.     wsa5__EndpointReferenceType*         ProducerReference              0;<span style="white-space: pre;">   </span>///< Optional element.  
  10.     struct _wsnt__NotificationMessageHolderType_Message  
  11.     {  
  12. /// TODO: <any namespace="##any" minOccurs="1" maxOccurs="1">  
  13. /// TODO: Schema extensibility is user-definable.  
  14. ///       Consult the protocol documentation to change or insert declarations.  
  15. ///       Use wsdl2h option -x to remove this element.  
  16. ///       Use wsdl2h option -d for xsd__anyType DOM (soap_dom_element).  
  17.     xsd__anyType                         __any                         0;<span style="white-space: pre;">   </span>///< Catch any element content in DOM.  
  1.     }                                    Message                        1;<span style="white-space: pre;">    </span>///< Required element.  
  2. };  


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

you should have to see the line

  1. _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字段改成指定类型,然后我们再进入下一环节的讲述.

  

  1. /// Top-level root element "http://www.onvif.org/ver10/schema":Message  
  2.   
  3.   
  4. /// "http://www.onvif.org/ver10/schema":Message is a complexType.  
  5. struct _tt__Message  
  6. {  
  7. /// @brief Token value pairs that triggered this message. Typically only one item is present.  
  8. /// Element Source of type "http://www.onvif.org/ver10/schema":ItemList.  
  9.     struct tt__ItemList*                 Source                         0;<span style="white-space: pre;">  </span>///< Optional element.  
  10. /// Element Key of type "http://www.onvif.org/ver10/schema":ItemList.  
  11.     struct tt__ItemList*                 Key                            0;<span style="white-space: pre;">    </span>///< Optional element.  
  12. /// Element Data of type "http://www.onvif.org/ver10/schema":ItemList.  
  13.     struct tt__ItemList*                 Data                           0;<span style="white-space: pre;"> </span>///< Optional element.  
  14. /// Element Extension of type "http://www.onvif.org/ver10/schema":MessageExtension.  
  15.     struct tt__MessageExtension*         Extension                      0;<span style="white-space: pre;">   </span>///< Optional element.  
  16. /// Attribute UtcTime of type xs:dateTime.  
  17.    @time_t                               UtcTime                        1;<span style="white-space: pre;">   </span>///< Required attribute.  
  18. /// Attribute PropertyOperation of type "http://www.onvif.org/ver10/schema":PropertyOperation.  
  19.    @enum tt__PropertyOperation*          PropertyOperation              0;<span style="white-space: pre;">  </span>///< Optional attribute.  
  20. /// <anyAttribute namespace="##any">  
  21. /// TODO: Schema extensibility is user-definable.  
  22. ///       Consult the protocol documentation to change or insert declarations.  
  23. ///       Use wsdl2h option -x to remove this attribute.  
  24. ///       Use wsdl2h option -d for xsd__anyAttribute DOM (soap_dom_attribute).  
  25.    @xsd__anyAttribute                    __anyAttribute                ;<span style="white-space: pre;">  </span>///< Store anyAttribute content in DOM soap_dom_attribute linked node structure.  
  26. };  

由于我们参考阅读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++使用代码.

  1. #ifndef SOAP_TYPE__wsnt__NotificationMessageHolderType_Message  
  2. #define SOAP_TYPE__wsnt__NotificationMessageHolderType_Message (1303)  
  3. /* wsnt:NotificationMessageHolderType-Message */  
  4. struct _wsnt__NotificationMessageHolderType_Message  
  5. {  
  6.     struct _tt__Message *tt__Message;   /* optional element of type tt:Message */  
  7. };  
  8. #endif  
  9.   
  10. #ifndef SOAP_TYPE_wsnt__NotificationMessageHolderType  
  11. #define SOAP_TYPE_wsnt__NotificationMessageHolderType (1177)  
  12. /* wsnt:NotificationMessageHolderType */  
  13. struct wsnt__NotificationMessageHolderType  
  14. {  
  15.     struct wsa5__EndpointReferenceType *SubscriptionReference;  /* optional element of type wsa5:EndpointReferenceType */  
  16.     struct wsnt__TopicExpressionType *Topic;    /* optional element of type wsnt:TopicExpressionType */  
  17.     struct wsa5__EndpointReferenceType *ProducerReference;  /* optional element of type wsa5:EndpointReferenceType */  
  18.     struct _wsnt__NotificationMessageHolderType_Message Message;    /* required element of type wsnt:NotificationMessageHolderType-Message */  
  19. };  
  20. #endif  

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

  1. 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)  
  2. {  
  3.     (void)soap; (void)tag; (void)id; (void)type;  
  4.     if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE__wsnt__NotificationMessageHolderType_Message), type))  
  5.         return soap->error;  
  6.     if (soap_out_PointerTo_tt__Message(soap, "tt:Message", -1, &a->tt__Message, ""))  
  7.         return soap->error;  
  8.     return soap_element_end_out(soap, tag);  
  9. }  
  10.   
  11. 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)  
  12. {  
  13.     size_t soap_flag_tt__Message = 1;  
  14.     if (soap_element_begin_in(soap, tag, 0, type))  
  15.         return NULL;  
  16.     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);  
  17.     if (!a)  
  18.         return NULL;  
  19.     soap_default__wsnt__NotificationMessageHolderType_Message(soap, a);  
  20.     if (soap->body && !*soap->href)  
  21.     {  
  22.         for (;;)  
  23.         {   soap->error = SOAP_TAG_MISMATCH;  
  24.             if (soap_flag_tt__Message && soap->error == SOAP_TAG_MISMATCH)  
  25.                 if (soap_in_PointerTo_tt__Message(soap, "tt:Message", &a->tt__Message, ""))  
  26.                 {   soap_flag_tt__Message--;  
  27.                     continue;  
  28.                 }  
  29.             if (soap->error == SOAP_TAG_MISMATCH)  
  30.                 soap->error = soap_ignore_element(soap);  
  31.             if (soap->error == SOAP_NO_TAG)  
  32.                 break;  
  33.             if (soap->error)  
  34.                 return NULL;  
  35.         }  
  36.         if (soap_element_end_in(soap, tag))  
  37.             return NULL;  
  38.     }  
  39.     else  
  40.     {   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);  
  41.         if (soap->body && soap_element_end_in(soap, tag))  
  42.             return NULL;  
  43.     }  
  44.     return a;  
  45. }  



结述语

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

  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.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
onvif开发总结
gSOAP搭建ONVIF(C++)客户端开发框架--windows&ubuntu
WSDL文件简介(附例子)
Web Service基础(WSDL、SOAP)
ONVIF协议网络摄像机
WebServiceWSDL结构分析
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服