2013年9月11日 星期三

ONVIF -- Support Customized Event

If you want to support a customized event which not belong to ONVIF spec.
You can follow below setup to re-generate your gSoap code by gSOAP.

1. Revise WS-typemap.dat to add customized namespace
tnsMy = <http://www.avigilon.com/onvif/ver10/topics>

2. Revise topic.wsdl for customized event
If the event topic is "tnsMy:MotionDetection" under VideoAnalytics
 1 <xs:element name="VideoAnalytics">
 2     <xs:complexType>
 3        <xs:sequence>
 4           <xs:element name="tnsMy:MotionDetection" type="MsgDefDataType" minOccurs="0" maxOccurs="1" />       
 5           <xs:element name="MotionDetection" type="MsgDefDataType" minOccurs="0" maxOccurs="1" /> 
 6        </xs:sequence>
 7      </xs:complexType>
 8 </xs:element> 

3. Generate the header file and check the header file
We should have a data structure for customized event
 1 /// "http://www.onvif.org/ver10/topics":VideoAnalytics is a complexType.
 2 struct _tns1__VideoAnalytics
 3 {
 4    /// Element tnsMy:MotionDetection of type "":MsgDefDataType.
 5    struct tns1__MsgDefDataType*         tnsMy__MotionDetection        0; ///< Optional element.
 6    
 7    /// Element MotionDetection of type "":MsgDefDataType.
 8    struct tns1__MsgDefDataType*         MotionDetection                0; ///< Optional element.
 9 };


4. generate code by the customized header file
use soapcpp2 -S -I ../../import mime.h to generate code, you should have a function that can parse "tnsMy__MotionDetection" in function _tns1__VideoAnalytics()
 1 SOAP_FMAC3 struct _tns1__VideoAnalytics * SOAP_FMAC4 soap_in__tns1__VideoAnalytics(struct soap *soap, const char *tag, struct _tns1__VideoAnalytics *a, const char *type)
 2 {
 3    size_t soap_flag_tnsMy__MotionDetection = 1;
 4    size_t soap_flag_MotionDetection = 1;
 5    if (soap_element_begin_in(soap, tag, 0, type))
 6       return NULL;
 7    a = (struct _tns1__VideoAnalytics *)soap_id_enter(soap, soap->id, a, SOAP_TYPE__tns1__VideoAnalytics, sizeof(struct _tns1__VideoAnalytics), 0, NULL, NULL, NULL);
 8    if (!a)
 9       return NULL;
10    soap_default__tns1__VideoAnalytics(soap, a);
11    if (soap->body && !*soap->href)
12    {
13       for (;;)
14       { soap->error = SOAP_TAG_MISMATCH;
15          if (soap_flag_tnsMy__MotionDetection && soap->error == SOAP_TAG_MISMATCH)
16             if (soap_in_PointerTotns1__MsgDefDataType(soap, "tnsMy:MotionDetection", &a->tnsMy__MotionDetection, "tns1:MsgDefDataType"))
17             { soap_flag_tnsMy__MotionDetection--;
18                continue;
19             }
20          if (soap_flag_MotionDetection && soap->error == SOAP_TAG_MISMATCH)
21             if (soap_in_PointerTotns1__MsgDefDataType(soap, "MotionDetection", &a->MotionDetection, "tns1:MsgDefDataType"))
22             { soap_flag_MotionDetection--;
23                continue;
24             }
25          if (soap->error == SOAP_TAG_MISMATCH)
26             soap->error = soap_ignore_element(soap);
27          if (soap->error == SOAP_NO_TAG)
28             break;
29          if (soap->error)
30             return NULL;
31       }
32       if (soap_element_end_in(soap, tag))
33          return NULL;
34    }
35    else
36    { a = (struct _tns1__VideoAnalytics *)soap_id_forward(soap, soap->href, (void*)a, 0, SOAP_TYPE__tns1__VideoAnalytics, 0, sizeof(struct _tns1__VideoAnalytics), 0, NULL);
37       if (soap->body && soap_element_end_in(soap, tag))
38          return NULL;
39    }
40    return a;
41 }

5. Verfication
Use ONVIF opertaion GetEventPropertiesResponse to check if everything is fine. 
If you use ONVIF 13.06, you can run below test case to see if the event is correct response.
  • RTSS-4-1-2 NOTIFICATION
  • EVENT-1-1-2 GET EVENT PROPERTIES

Reference:

  1. http://www.cs.fsu.edu/~engelen/soap.html