Download Generated C Function Format and Calling Parameters
Transcript
Event Handler Interface In C++, these events are defined as unimplemented virtual methods in two base classes: Asn1NamedEventHandler (the first 3 events) and Asn1ErrorHandler (the error event). These classes are defined in the asn1CppEvtHndlr.h header file. In C, the first 3 event types are contained within a struct, Asn1NamedCEventHandler, defined in asn1CEvtHndlr.h, as consisting of function pointers. The error event, however, is not part of this struct and must be defined separately. The start and end element methods are invoked when an element is parsed within a constructed type. The start method is invoked as soon as the tag/length is parsed in a BER message or the preamble/length is parsed in a PER message. The end method is invoked after the contents of the field are processed. The signature of these methods, in C++, is as follows: virtual void startElement (const char* name, int index) = 0; virtual void endElement (const char* name, int index) = 0; and in C: typedef void (*rtxStartElement) (const char* name, int idx) ; typedef void (*rtxEndElement) (const char* name, int idx) ; The name argument is used pass the element name. The index argument is used for SEQUENCE OF/SET OF constructs only. It is used to pass the index of the item in the array. This argument is set to –1 for all other constructs. There is one contents method for passing each of the ASN.1 data types. Some methods are used to handle several different types. For example, the charValue method is used for values of all of the different character string types (IA5String, NumericString, PrintableString, etc.) as well as for big integer values. Note that this method is overloaded. The second implementation is for 16-bit character strings. These strings are represented as an array of unsigned short integers in ASN1C. All of the other contents methods correspond to a single equivalent ASN.1 primitive type. The C++ error handler base class has a single virtual method that must be implemented. This is the error method and this has the following signature: virtual int error (OSCTXT* pCtxt, ASN1CCB* pCCB, int stat) = 0; The C error handler function, unlike the other events in C, is not contained within a struct. Its signature is as follows: typedef int (*rtErrorHandler) (OSCTXT *pctxt, ASN1CCB *pCCB, int stat); In these definitions, pCtxt and pctxt are pointers to the standard ASN.1 context block that should already be familiar. The pCCB structure is known as a “Context Control Block”. This can be thought of as a sub-context used to control the parsing of nested constructed types within a message. It is included as a parameter to the error method mainly to allow access to the “seqx” field. This is the sequence element index used when parsing a SEQUENCE construct. If parsing a particular element is to be retried, this item must be decremented within the error handler. How to Use It In both C and C++, two things must be done to define event handlers: 1. In C++, one or more new classes must be derived from the Asn1NamedEventHandler and/or the Asn1ErrorHandler base classes. All pure virtual methods must be implemented. In C, a function with an appropriate signature must be created for each function pointer in the struct; the behavior of null function pointers is undefined. The error handler function, if one is desired, must also be defined. 2. Objects of these classes (or in C, an instance of the Asn1NamedCEventHandler struct) must be created and registered prior to calling the generated decode method or function. 285