|
| 1 | +/* |
| 2 | + * Licensed to Systerel under one or more contributor license |
| 3 | + * agreements. See the NOTICE file distributed with this work |
| 4 | + * for additional information regarding copyright ownership. |
| 5 | + * Systerel licenses this file to you under the Apache |
| 6 | + * License, Version 2.0 (the "License"); you may not use this |
| 7 | + * file except in compliance with the License. You may obtain |
| 8 | + * a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +/** |
| 21 | + * \file sopc_encodeabletype.h |
| 22 | + * |
| 23 | + * \brief Encodeable type and services |
| 24 | + */ |
| 25 | + |
| 26 | +#ifndef SOPC_ENCODEABLETYPE_H_ |
| 27 | +#define SOPC_ENCODEABLETYPE_H_ |
| 28 | + |
| 29 | +#include <stddef.h> |
| 30 | +#include <stdint.h> |
| 31 | + |
| 32 | +#include "sopc_buffer.h" |
| 33 | +#include "sopc_enums.h" |
| 34 | + |
| 35 | +/** |
| 36 | + * \brief Initialization function generic signature for an encodeable object |
| 37 | + */ |
| 38 | +typedef void(SOPC_EncodeableObject_PfnInitialize)(void* value); |
| 39 | + |
| 40 | +/** |
| 41 | + * \brief Clear function generic signature for an encodeable object |
| 42 | + */ |
| 43 | +typedef void(SOPC_EncodeableObject_PfnClear)(void* value); |
| 44 | + |
| 45 | +/** |
| 46 | + * \brief Get size function generic signature for an encodeable object |
| 47 | + * Note: Unused in S2OPC, NULL pointer may be provided instead of function pointer |
| 48 | + */ |
| 49 | +typedef void(SOPC_EncodeableObject_PfnGetSize)(void); |
| 50 | + |
| 51 | +/** |
| 52 | + * \brief Encoding function generic signature for an encodeable object |
| 53 | + */ |
| 54 | +typedef SOPC_ReturnStatus(SOPC_EncodeableObject_PfnEncode)(const void* value, |
| 55 | + SOPC_Buffer* msgBuffer, |
| 56 | + uint32_t nestedStructLevel); |
| 57 | + |
| 58 | +/** |
| 59 | + * \brief Decoding function generic signature for an encodeable object |
| 60 | + */ |
| 61 | +typedef SOPC_ReturnStatus(SOPC_EncodeableObject_PfnDecode)(void* value, |
| 62 | + SOPC_Buffer* msgBuffer, |
| 63 | + uint32_t nestedStructLevel); |
| 64 | + |
| 65 | +/* |
| 66 | + * \brief Description of an encodeable type field. |
| 67 | + * |
| 68 | + * This structure has been designed to be very compact and fit into 8 bytes. |
| 69 | + * The \c isBuiltIn field indicates whether the field type is built-in or |
| 70 | + * defined in the address space. In the first case, the type index is a member |
| 71 | + * of the \c SOPC_BuiltinId enumeration. In the second case, it is a member of |
| 72 | + * the \c SOPC_TypeInternalIndex enumeration. |
| 73 | + * |
| 74 | + * The \c isArrayLength field indicates whether this field contains the length |
| 75 | + * of an array. When true, the field must be of built-in type \c Int32, and the |
| 76 | + * array is described by the next field. |
| 77 | + * |
| 78 | + * The \c isToEncode field indicates whether this field shall be encoded and |
| 79 | + * decoded. When false, the field is only initialized and cleared. |
| 80 | + * |
| 81 | + * Finally, the \c offset field gives the offset in bytes of the field in the |
| 82 | + * object structure. |
| 83 | + */ |
| 84 | +typedef struct SOPC_EncodeableType_FieldDescriptor |
| 85 | +{ |
| 86 | + bool isBuiltIn : 1; |
| 87 | + bool isArrayLength : 1; |
| 88 | + bool isToEncode : 1; |
| 89 | + uint32_t typeIndex : 29; |
| 90 | + uint32_t offset; |
| 91 | +} SOPC_EncodeableType_FieldDescriptor; |
| 92 | + |
| 93 | +/** |
| 94 | + * \brief Encodeable object type structure definition. It provides all the services |
| 95 | + * functions associated with the encodeable object for encoding needs. |
| 96 | + */ |
| 97 | +typedef struct SOPC_EncodeableType |
| 98 | +{ |
| 99 | + char* TypeName; |
| 100 | + uint32_t TypeId; |
| 101 | + uint32_t BinaryEncodingTypeId; |
| 102 | + uint32_t XmlEncodingTypeId; |
| 103 | + char* NamespaceUri; |
| 104 | + size_t AllocationSize; |
| 105 | + SOPC_EncodeableObject_PfnInitialize* Initialize; |
| 106 | + SOPC_EncodeableObject_PfnClear* Clear; |
| 107 | + SOPC_EncodeableObject_PfnGetSize* GetSize; |
| 108 | + SOPC_EncodeableObject_PfnEncode* Encode; |
| 109 | + SOPC_EncodeableObject_PfnDecode* Decode; |
| 110 | + int32_t NoOfFields; |
| 111 | + const SOPC_EncodeableType_FieldDescriptor* Fields; |
| 112 | +} SOPC_EncodeableType; |
| 113 | + |
| 114 | +/** |
| 115 | + * \brief Registers a user-defined encodeable type. |
| 116 | + * further calls to SOPC_EncodeableType_GetEncodeableType |
| 117 | + * will successfully identify the registered encodeable type |
| 118 | + * |
| 119 | + * \note All registered encoders must be freed by |
| 120 | + * SOPC_EncodeableType_RemoveUserType |
| 121 | + * |
| 122 | + * \param encoder The encoder definition to register |
| 123 | + * \return A status code indicating the result of operation |
| 124 | + */ |
| 125 | +SOPC_ReturnStatus SOPC_EncodeableType_AddUserType(SOPC_EncodeableType* encoder); |
| 126 | + |
| 127 | +/** |
| 128 | + * \brief Removes a user-defined encodeable type previously created by |
| 129 | + * SOPC_EncodeableType_AddUserType |
| 130 | + * |
| 131 | + * \param encoder The encoder definition to register |
| 132 | + * \return A status code indicating the result of operation |
| 133 | + */ |
| 134 | +SOPC_ReturnStatus SOPC_EncodeableType_RemoveUserType(SOPC_EncodeableType* encoder); |
| 135 | + |
| 136 | +/** |
| 137 | + * \brief Retrieve a defined encodeable object type with the given type Id. |
| 138 | + * |
| 139 | + * \param typeId Type identifier for which corresponding encodeable object type must be returned |
| 140 | + * \return The searched encodeable type or NULL if parameters are incorrect or type is not found |
| 141 | + */ |
| 142 | +SOPC_EncodeableType* SOPC_EncodeableType_GetEncodeableType(uint32_t typeId); |
| 143 | + |
| 144 | +const char* SOPC_EncodeableType_GetName(SOPC_EncodeableType* encType); |
| 145 | + |
| 146 | +/** |
| 147 | + * \brief Initialize an encodeable object. |
| 148 | + * |
| 149 | + * The \c pValue parameter shall correspond to an object of the appropriate |
| 150 | + * type. |
| 151 | + */ |
| 152 | +void SOPC_EncodeableObject_Initialize(SOPC_EncodeableType* type, void* pValue); |
| 153 | + |
| 154 | +/** |
| 155 | + * \brief Clear an encodeable object. |
| 156 | + * |
| 157 | + * The \c pValue parameter shall correspond to an object of the appropriate |
| 158 | + * type. |
| 159 | + */ |
| 160 | +void SOPC_EncodeableObject_Clear(SOPC_EncodeableType* type, void* pValue); |
| 161 | + |
| 162 | +/** |
| 163 | + * \brief Encode an encodeable object. |
| 164 | + * |
| 165 | + * The \c pValue parameter shall correspond to an object of the appropriate |
| 166 | + * type. |
| 167 | + */ |
| 168 | +SOPC_ReturnStatus SOPC_EncodeableObject_Encode(SOPC_EncodeableType* type, |
| 169 | + const void* pValue, |
| 170 | + SOPC_Buffer* buf, |
| 171 | + uint32_t nestedStructLevel); |
| 172 | + |
| 173 | +/** |
| 174 | + * \brief Decode an encodeable object. |
| 175 | + * |
| 176 | + * The \c pValue parameter shall correspond to an object of the appropriate |
| 177 | + * type. |
| 178 | + */ |
| 179 | +SOPC_ReturnStatus SOPC_EncodeableObject_Decode(SOPC_EncodeableType* type, |
| 180 | + void* pValue, |
| 181 | + SOPC_Buffer* buf, |
| 182 | + uint32_t nestedStructLevel); |
| 183 | + |
| 184 | +#endif /* SOPC_ENCODEABLETYPE_H_ */ |
0 commit comments