Quellcode durchsuchen

feature: make method for finding data types public

Julius Pfrommer vor 8 Jahren
Ursprung
Commit
f8acccc62c
3 geänderte Dateien mit 21 neuen und 10 gelöschten Zeilen
  1. 9 0
      include/ua_types.h
  2. 1 10
      src/server/ua_services_attribute.c
  3. 11 0
      src/ua_types.c

+ 9 - 0
include/ua_types.h

@@ -766,6 +766,15 @@ struct UA_DataType {
     UA_DataTypeMember *members;
 };
 
+/**
+ * Builtin data types can be accessed as UA_TYPES[UA_TYPES_XXX], where XXX is
+ * the name of the data type. If only the NodeId of a type is known, use the
+ * following method to retrieve the data type description. */
+/* Returns the data type description for the type's identifier or NULL if no
+ * matching data type was found. */
+const UA_DataType UA_EXPORT *
+UA_findDataType(const UA_NodeId *typeId);
+
 /** The following functions are used for generic handling of data types. */
 
 /* Allocates and initializes a variable of type dataType

+ 1 - 10
src/server/ua_services_attribute.c

@@ -35,15 +35,6 @@ typeEquivalence(const UA_DataType *t) {
     return TYPE_EQUIVALENCE_NONE;
 }
 
-static const UA_DataType *
-findDataType(const UA_NodeId *typeId) {
-    for(size_t i = 0; i < UA_TYPES_COUNT; ++i) {
-        if(UA_TYPES[i].typeId.identifier.numeric == typeId->identifier.numeric)
-            return &UA_TYPES[i];
-    }
-    return NULL;
-}
-
 /* Test whether a valurank and the given arraydimensions are compatible. zero
  * array dimensions indicate a scalar */
 static UA_StatusCode
@@ -108,7 +99,7 @@ compatibleArrayDimensions(size_t constraintArrayDimensionsSize,
 static const UA_Variant *
 convertToMatchingValue(UA_Server *server, const UA_Variant *value,
                        const UA_NodeId *targetDataTypeId, UA_Variant *editableValue) {
-    const UA_DataType *targetDataType = findDataType(targetDataTypeId);
+    const UA_DataType *targetDataType = UA_findDataType(targetDataTypeId);
     if(!targetDataType)
         return NULL;
 

+ 11 - 0
src/ua_types.c

@@ -24,6 +24,17 @@ const UA_ExpandedNodeId UA_EXPANDEDNODEID_NULL = {
                   .identifier.numeric = 0 },
        .namespaceUri = {.length = 0, .data = NULL}, .serverIndex = 0 };
 
+/* TODO: The standard-defined types are ordered. See if binary search is more
+ * efficient. */
+const UA_DataType *
+UA_findDataType(const UA_NodeId *typeId) {
+    for(size_t i = 0; i < UA_TYPES_COUNT; ++i) {
+        if(UA_TYPES[i].typeId.identifier.numeric == typeId->identifier.numeric)
+            return &UA_TYPES[i];
+    }
+    return NULL;
+}
+
 /***************************/
 /* Random Number Generator */
 /***************************/