Browse Source

define const global definitions for the default node attributes

Julius Pfrommer 7 years ago
parent
commit
b45a77a6db

+ 1 - 2
README.md

@@ -90,8 +90,7 @@ int main(int argc, char** argv)
 
     /* Add a variable node */
     /* 1) Define the node attributes */
-    UA_VariableAttributes attr;
-    UA_VariableAttributes_init(&attr);
+    UA_VariableAttributes attr = UA_VariableAttributes_default;
     attr.displayName = UA_LOCALIZEDTEXT("en_US", "the answer");
     UA_Int32 myInteger = 42;
     UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);

+ 13 - 14
examples/server_instantiation.c

@@ -30,33 +30,31 @@ int main(void) {
      *      + (V) Name
      */ 
     UA_StatusCode retval;
-    UA_ObjectTypeAttributes otAttr;
-    UA_ObjectTypeAttributes_init(&otAttr);
-    
+    UA_ObjectTypeAttributes otAttr = UA_ObjectTypeAttributes_default;
     otAttr.description = UA_LOCALIZEDTEXT("en_US", "A mamal");
     otAttr.displayName = UA_LOCALIZEDTEXT("en_US", "MamalType");
     UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 10000), 
-                                UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
+                                UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
+                                UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
                                 UA_QUALIFIEDNAME(1, "MamalType"), otAttr, NULL, NULL);
   
-    UA_VariableAttributes   vAttr;
-    UA_VariableAttributes_init(&vAttr);
-    vAttr.description =  UA_LOCALIZEDTEXT("en_US", "This mamals Age in months");
-    vAttr.displayName =  UA_LOCALIZEDTEXT("en_US", "Age");
+    UA_VariableAttributes vAttr = UA_VariableAttributes_default;
+    vAttr.description = UA_LOCALIZEDTEXT("en_US", "This mamals Age in months");
+    vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Age");
     UA_UInt32 ageVar = 0;
     UA_Variant_setScalarCopy(&vAttr.value, &ageVar, &UA_TYPES[UA_TYPES_UINT32]);
     UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 10001), 
                               UA_NODEID_NUMERIC(1, 10000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY),
                               UA_QUALIFIEDNAME(1, "Age"), UA_NODEID_NULL, vAttr, NULL, NULL);
   
-    UA_ObjectTypeAttributes_init(&otAttr);
+    otAttr = UA_ObjectTypeAttributes_default;
     otAttr.description = UA_LOCALIZEDTEXT("en_US", "A dog, subtype of mamal");
     otAttr.displayName = UA_LOCALIZEDTEXT("en_US", "DogType");
     UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 10002), 
                                 UA_NODEID_NUMERIC(1, 10000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
                                 UA_QUALIFIEDNAME(1, "DogType"), otAttr, NULL, NULL);
     
-    UA_VariableAttributes_init(&vAttr);
+    vAttr = UA_VariableAttributes_default;
     vAttr.description =  UA_LOCALIZEDTEXT("en_US", "This mamals Age in months");
     vAttr.displayName =  UA_LOCALIZEDTEXT("en_US", "Name");
     UA_String defaultName = UA_STRING("unnamed dog");
@@ -72,13 +70,14 @@ int main(void) {
      *     + Name
      */
     
-    UA_ObjectAttributes oAttr;
-    UA_ObjectAttributes_init(&oAttr);
+    UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
     oAttr.description = UA_LOCALIZEDTEXT("en_US", "A dog named Bello");
     oAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Bello");
     UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 0), 
-                            UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
-                            UA_QUALIFIEDNAME(1, "Bello"), UA_NODEID_NUMERIC(1, 10002), oAttr, NULL, NULL);
+                            UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
+                            UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
+                            UA_QUALIFIEDNAME(1, "Bello"), UA_NODEID_NUMERIC(1, 10002),
+                            oAttr, NULL, NULL);
     
     retval = UA_Server_run(server, &running);
     UA_Server_delete(server);

+ 12 - 24
examples/tutorial_server_object.c

@@ -61,8 +61,7 @@
 static void
 manuallyDefinePump(UA_Server *server) {
     UA_NodeId pumpId; /* get the nodeid assigned by the server */
-    UA_ObjectAttributes oAttr;
-    UA_ObjectAttributes_init(&oAttr);
+    UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
     oAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Pump (Manual)");
     UA_Server_addObjectNode(server, UA_NODEID_NULL,
                             UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
@@ -70,8 +69,7 @@ manuallyDefinePump(UA_Server *server) {
                             UA_QUALIFIEDNAME(1, "Pump (Manual)"), UA_NODEID_NULL,
                             oAttr, NULL, &pumpId);
 
-    UA_VariableAttributes mnAttr;
-    UA_VariableAttributes_init(&mnAttr);
+    UA_VariableAttributes mnAttr = UA_VariableAttributes_default;
     UA_String manufacturerName = UA_STRING("Pump King Ltd.");
     UA_Variant_setScalar(&mnAttr.value, &manufacturerName, &UA_TYPES[UA_TYPES_STRING]);
     mnAttr.displayName = UA_LOCALIZEDTEXT("en_US", "ManufacturerName");
@@ -80,8 +78,7 @@ manuallyDefinePump(UA_Server *server) {
                               UA_QUALIFIEDNAME(1, "ManufacturerName"),
                               UA_NODEID_NULL, mnAttr, NULL, NULL);
 
-    UA_VariableAttributes modelAttr;
-    UA_VariableAttributes_init(&modelAttr);
+    UA_VariableAttributes modelAttr = UA_VariableAttributes_default;
     UA_String modelName = UA_STRING("Mega Pump 3000");
     UA_Variant_setScalar(&modelAttr.value, &modelName, &UA_TYPES[UA_TYPES_STRING]);
     modelAttr.displayName = UA_LOCALIZEDTEXT("en_US", "ModelName");
@@ -90,8 +87,7 @@ manuallyDefinePump(UA_Server *server) {
                               UA_QUALIFIEDNAME(1, "ModelName"),
                               UA_NODEID_NULL, modelAttr, NULL, NULL);
 
-    UA_VariableAttributes statusAttr;
-    UA_VariableAttributes_init(&statusAttr);
+    UA_VariableAttributes statusAttr = UA_VariableAttributes_default;
     UA_Boolean status = true;
     UA_Variant_setScalar(&statusAttr.value, &status, &UA_TYPES[UA_TYPES_BOOLEAN]);
     statusAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Status");
@@ -100,8 +96,7 @@ manuallyDefinePump(UA_Server *server) {
                               UA_QUALIFIEDNAME(1, "Status"),
                               UA_NODEID_NULL, statusAttr, NULL, NULL);
 
-    UA_VariableAttributes rpmAttr;
-    UA_VariableAttributes_init(&rpmAttr);
+    UA_VariableAttributes rpmAttr = UA_VariableAttributes_default;
     UA_Double rpm = 50.0;
     UA_Variant_setScalar(&rpmAttr.value, &rpm, &UA_TYPES[UA_TYPES_DOUBLE]);
     rpmAttr.displayName = UA_LOCALIZEDTEXT("en_US", "MotorRPM");
@@ -174,8 +169,7 @@ static void
 defineObjectTypes(UA_Server *server) {
     /* Define the object type for "Device" */
     UA_NodeId deviceTypeId; /* get the nodeid assigned by the server */
-    UA_ObjectTypeAttributes dtAttr;
-    UA_ObjectTypeAttributes_init(&dtAttr);
+    UA_ObjectTypeAttributes dtAttr = UA_ObjectTypeAttributes_default;
     dtAttr.displayName = UA_LOCALIZEDTEXT("en_US", "DeviceType");
     UA_Server_addObjectTypeNode(server, UA_NODEID_NULL,
                                 UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
@@ -183,8 +177,7 @@ defineObjectTypes(UA_Server *server) {
                                 UA_QUALIFIEDNAME(1, "DeviceType"), dtAttr,
                                 NULL, &deviceTypeId);
 
-    UA_VariableAttributes mnAttr;
-    UA_VariableAttributes_init(&mnAttr);
+    UA_VariableAttributes mnAttr = UA_VariableAttributes_default;
     mnAttr.displayName = UA_LOCALIZEDTEXT("en_US", "ManufacturerName");
     UA_NodeId manufacturerNameId;
     UA_Server_addVariableNode(server, UA_NODEID_NULL, deviceTypeId,
@@ -197,8 +190,7 @@ defineObjectTypes(UA_Server *server) {
                            UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_MODELLINGRULE_MANDATORY), true);
 
 
-    UA_VariableAttributes modelAttr;
-    UA_VariableAttributes_init(&modelAttr);
+    UA_VariableAttributes modelAttr = UA_VariableAttributes_default;
     modelAttr.displayName = UA_LOCALIZEDTEXT("en_US", "ModelName");
     UA_Server_addVariableNode(server, UA_NODEID_NULL, deviceTypeId,
                               UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
@@ -206,16 +198,14 @@ defineObjectTypes(UA_Server *server) {
                               UA_NODEID_NULL, modelAttr, NULL, NULL);
 
     /* Define the object type for "Pump" */
-    UA_ObjectTypeAttributes ptAttr;
-    UA_ObjectTypeAttributes_init(&ptAttr);
+    UA_ObjectTypeAttributes ptAttr = UA_ObjectTypeAttributes_default;
     ptAttr.displayName = UA_LOCALIZEDTEXT("en_US", "PumpType");
     UA_Server_addObjectTypeNode(server, pumpTypeId,
                                 deviceTypeId, UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
                                 UA_QUALIFIEDNAME(1, "PumpType"), ptAttr,
                                 NULL, NULL);
 
-    UA_VariableAttributes statusAttr;
-    UA_VariableAttributes_init(&statusAttr);
+    UA_VariableAttributes statusAttr = UA_VariableAttributes_default;
     statusAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Status");
     statusAttr.valueRank = -1;
     UA_NodeId statusId;
@@ -228,8 +218,7 @@ defineObjectTypes(UA_Server *server) {
                            UA_NODEID_NUMERIC(0, UA_NS0ID_HASMODELLINGRULE),
                            UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_MODELLINGRULE_MANDATORY), true);
 
-    UA_VariableAttributes rpmAttr;
-    UA_VariableAttributes_init(&rpmAttr);
+    UA_VariableAttributes rpmAttr = UA_VariableAttributes_default;
     rpmAttr.displayName = UA_LOCALIZEDTEXT("en_US", "MotorRPM");
     rpmAttr.valueRank = -1;
     UA_Server_addVariableNode(server, UA_NODEID_NULL, pumpTypeId,
@@ -248,8 +237,7 @@ defineObjectTypes(UA_Server *server) {
 
 static void
 addPumpObjectInstance(UA_Server *server, char *name) {
-    UA_ObjectAttributes oAttr;
-    UA_ObjectAttributes_init(&oAttr);
+    UA_ObjectAttributes oAttr = UA_ObjectAttributes_default;
     oAttr.displayName = UA_LOCALIZEDTEXT("en_US", name);
     UA_Server_addObjectNode(server, UA_NODEID_NULL,
                             UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),

+ 1 - 2
examples/tutorial_server_variable.c

@@ -18,8 +18,7 @@
 static void
 addVariable(UA_Server *server) {
     /* Define the attribute of the myInteger variable node */
-    UA_VariableAttributes attr;
-    UA_VariableAttributes_init(&attr);
+    UA_VariableAttributes attr = UA_VariableAttributes_default;
     UA_Int32 myInteger = 42;
     UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
     attr.description = UA_LOCALIZEDTEXT("en_US","the answer");

+ 3 - 6
examples/tutorial_server_variabletype.c

@@ -25,8 +25,7 @@ static UA_NodeId pointTypeId;
 
 static void
 addVariableType2DPoint(UA_Server *server) {
-    UA_VariableTypeAttributes vtAttr;
-    UA_VariableTypeAttributes_init(&vtAttr);
+    UA_VariableTypeAttributes vtAttr = UA_VariableTypeAttributes_default;
     vtAttr.dataType = UA_TYPES[UA_TYPES_DOUBLE].typeId;
     vtAttr.valueRank = 1; /* array with one dimension */
     UA_UInt32 arrayDims[1] = {2};
@@ -56,8 +55,7 @@ static UA_NodeId pointVariableId;
 static void
 addVariable(UA_Server *server) {
     /* Prepare the node attributes */
-    UA_VariableAttributes vAttr;
-    UA_VariableAttributes_init(&vAttr);
+    UA_VariableAttributes vAttr = UA_VariableAttributes_default;
     vAttr.dataType = UA_TYPES[UA_TYPES_DOUBLE].typeId;
     vAttr.valueRank = 1; /* array with one dimension */
     UA_UInt32 arrayDims[1] = {2};
@@ -83,8 +81,7 @@ addVariable(UA_Server *server) {
 static void
 addVariableFail(UA_Server *server) {
     /* Prepare the node attributes */
-    UA_VariableAttributes vAttr;
-    UA_VariableAttributes_init(&vAttr);
+    UA_VariableAttributes vAttr = UA_VariableAttributes_default;
     vAttr.dataType = UA_TYPES[UA_TYPES_DOUBLE].typeId;
     vAttr.valueRank = -1; /* a scalar. this is not allowed per the variable type */
     vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "2DPoint Variable (fail)");

+ 17 - 0
include/ua_client_highlevel.h

@@ -413,6 +413,23 @@ UA_StatusCode UA_EXPORT
 UA_Client_deleteNode(UA_Client *client, const UA_NodeId nodeId,
                      UA_Boolean deleteTargetReferences);
 
+/* Protect against redundant definitions for server/client */
+#ifndef UA_DEFAULT_ATTRIBUTES_DEFINED
+#define UA_DEFAULT_ATTRIBUTES_DEFINED
+/* The default for variables is "BaseDataType" for the datatype, -2 for the
+ * valuerank and a read-accesslevel. */
+UA_EXPORT extern const UA_VariableAttributes UA_VariableAttributes_default;
+UA_EXPORT extern const UA_VariableTypeAttributes UA_VariableTypeAttributes_default;
+/* Methods are executable by default */
+UA_EXPORT extern const UA_MethodAttributes UA_MethodAttributes_default;
+/* The remaining attribute definitions are currently all zeroed out */
+UA_EXPORT extern const UA_ObjectAttributes UA_ObjectAttributes_default;
+UA_EXPORT extern const UA_ObjectTypeAttributes UA_ObjectTypeAttributes_default;
+UA_EXPORT extern const UA_ReferenceTypeAttributes UA_ReferenceTypeAttributes_default;
+UA_EXPORT extern const UA_DataTypeAttributes UA_DataTypeAttributes_default;
+UA_EXPORT extern const UA_ViewAttributes UA_ViewAttributes_default;
+#endif
+
 /* Don't call this function, use the typed versions */
 UA_StatusCode UA_EXPORT
 __UA_Client_addNode(UA_Client *client, const UA_NodeClass nodeClass,

+ 18 - 0
include/ua_server.h

@@ -772,6 +772,24 @@ UA_Server_setMethodNode_callback(UA_Server *server, const UA_NodeId methodNodeId
  * pointing to a memory location on the stack. If you need changes to a variable
  * value to manifest at a specific memory location, please use a
  * :ref:`datasource` or a :ref:`value-callback`. */
+
+/* Protect against redundant definitions for server/client */
+#ifndef UA_DEFAULT_ATTRIBUTES_DEFINED
+#define UA_DEFAULT_ATTRIBUTES_DEFINED
+/* The default for variables is "BaseDataType" for the datatype, -2 for the
+ * valuerank and a read-accesslevel. */
+UA_EXPORT extern const UA_VariableAttributes UA_VariableAttributes_default;
+UA_EXPORT extern const UA_VariableTypeAttributes UA_VariableTypeAttributes_default;
+/* Methods are executable by default */
+UA_EXPORT extern const UA_MethodAttributes UA_MethodAttributes_default;
+/* The remaining attribute definitions are currently all zeroed out */
+UA_EXPORT extern const UA_ObjectAttributes UA_ObjectAttributes_default;
+UA_EXPORT extern const UA_ObjectTypeAttributes UA_ObjectTypeAttributes_default;
+UA_EXPORT extern const UA_ReferenceTypeAttributes UA_ReferenceTypeAttributes_default;
+UA_EXPORT extern const UA_DataTypeAttributes UA_DataTypeAttributes_default;
+UA_EXPORT extern const UA_ViewAttributes UA_ViewAttributes_default;
+#endif
+
 /* The instantiation callback is used to track the addition of new nodes. It is
  * also called for all sub-nodes contained in an object or variable type node
  * that is instantiated. */

+ 23 - 51
src/server/ua_server_ns0.c

@@ -180,8 +180,7 @@ addReferenceInternal(UA_Server *server, UA_UInt32 sourceId, UA_UInt32 refTypeId,
 static void
 addDataTypeNode(UA_Server *server, char* name, UA_UInt32 datatypeid,
                 UA_Boolean isAbstract, UA_UInt32 parentid) {
-    UA_DataTypeAttributes attr;
-    UA_DataTypeAttributes_init(&attr);
+    UA_DataTypeAttributes attr = UA_DataTypeAttributes_default;
     attr.displayName = UA_LOCALIZEDTEXT("en_US", name);
     attr.isAbstract = isAbstract;
     UA_Server_addDataTypeNode(server, UA_NODEID_NUMERIC(0, datatypeid),
@@ -192,8 +191,7 @@ addDataTypeNode(UA_Server *server, char* name, UA_UInt32 datatypeid,
 static void
 addObjectTypeNode(UA_Server *server, char* name, UA_UInt32 objecttypeid,
                   UA_Boolean isAbstract, UA_UInt32 parentid) {
-    UA_ObjectTypeAttributes attr;
-    UA_ObjectTypeAttributes_init(&attr);
+    UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;
     attr.displayName = UA_LOCALIZEDTEXT("en_US", name);
     attr.isAbstract = isAbstract;
     UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(0, objecttypeid),
@@ -204,8 +202,7 @@ addObjectTypeNode(UA_Server *server, char* name, UA_UInt32 objecttypeid,
 static void
 addObjectNode(UA_Server *server, char* name, UA_UInt32 objectid,
               UA_UInt32 parentid, UA_UInt32 referenceid, UA_UInt32 type_id) {
-    UA_ObjectAttributes object_attr;
-    UA_ObjectAttributes_init(&object_attr);
+    UA_ObjectAttributes object_attr = UA_ObjectAttributes_default;
     object_attr.displayName = UA_LOCALIZEDTEXT("en_US", name);
     UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(0, objectid),
                             UA_NODEID_NUMERIC(0, parentid),
@@ -219,8 +216,7 @@ addObjectNode(UA_Server *server, char* name, UA_UInt32 objectid,
 static void
 addReferenceTypeNode(UA_Server *server, char* name, char *inverseName, UA_UInt32 referencetypeid,
                      UA_Boolean isabstract, UA_Boolean symmetric, UA_UInt32 parentid) {
-    UA_ReferenceTypeAttributes reference_attr;
-    UA_ReferenceTypeAttributes_init(&reference_attr);
+    UA_ReferenceTypeAttributes reference_attr = UA_ReferenceTypeAttributes_default;
     reference_attr.displayName = UA_LOCALIZEDTEXT("en_US", name);
     reference_attr.isAbstract = isabstract;
     reference_attr.symmetric = symmetric;
@@ -235,11 +231,10 @@ static void
 addVariableTypeNode(UA_Server *server, char* name, UA_UInt32 variabletypeid,
                     UA_Boolean isAbstract, UA_Int32 valueRank, UA_UInt32 dataType,
                     const UA_DataType *type, UA_UInt32 parentid) {
-    UA_VariableTypeAttributes attr;
-    UA_VariableTypeAttributes_init(&attr);
+    UA_VariableTypeAttributes attr = UA_VariableTypeAttributes_default;
     attr.displayName = UA_LOCALIZEDTEXT("en_US", name);
-    attr.isAbstract = isAbstract;
     attr.dataType = UA_NODEID_NUMERIC(0, dataType);
+    attr.isAbstract = isAbstract;
     attr.valueRank = valueRank;
     if(type) {
         void *val = UA_alloca(type->memSize);
@@ -255,12 +250,10 @@ static void
 addVariableNode(UA_Server *server, UA_UInt32 nodeid, char* name, UA_Int32 valueRank,
                 const UA_NodeId *dataType, UA_Variant *value, UA_UInt32 parentid,
                 UA_UInt32 referenceid, UA_UInt32 type_id) {
-    UA_VariableAttributes attr;
-    UA_VariableAttributes_init(&attr);
+    UA_VariableAttributes attr = UA_VariableAttributes_default;
     attr.displayName = UA_LOCALIZEDTEXT("en_US", name);
-    attr.dataType = *dataType;
     attr.valueRank = valueRank;
-    attr.accessLevel = UA_ACCESSLEVELMASK_READ;
+    attr.dataType = *dataType;
     if(value)
         attr.value = *value;
     UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(0, nodeid), UA_NODEID_NUMERIC(0, parentid),
@@ -272,12 +265,10 @@ static void
 addDataSourceVariableNode(UA_Server *server, UA_UInt32 nodeid, char* name, UA_Int32 valueRank,
                 const UA_NodeId *dataType, UA_DataSource *dataSource, UA_UInt32 parentid,
                 UA_UInt32 referenceid, UA_UInt32 type_id) {
-    UA_VariableAttributes attr;
-    UA_VariableAttributes_init(&attr);
+    UA_VariableAttributes attr = UA_VariableAttributes_default;
     attr.displayName = UA_LOCALIZEDTEXT("en_US", name);
-    attr.dataType = *dataType;
     attr.valueRank = valueRank;
-    attr.accessLevel = UA_ACCESSLEVELMASK_READ;
+    attr.dataType = *dataType;
     UA_Server_addDataSourceVariableNode(server, UA_NODEID_NUMERIC(0, nodeid), UA_NODEID_NUMERIC(0, parentid),
                                         UA_NODEID_NUMERIC(0, referenceid), UA_QUALIFIEDNAME(0, name),
                                         UA_NODEID_NUMERIC(0, type_id), attr, *dataSource, NULL);
@@ -294,8 +285,7 @@ void UA_Server_createNS0(UA_Server *server) {
     /*********************************/
 
     /* Bootstrap References and HasSubtype */
-    UA_ReferenceTypeAttributes references_attr;
-    UA_ReferenceTypeAttributes_init(&references_attr);
+    UA_ReferenceTypeAttributes references_attr = UA_ReferenceTypeAttributes_default;
     references_attr.displayName = UA_LOCALIZEDTEXT("en_US", "References");
     references_attr.isAbstract = true;
     references_attr.symmetric = true;
@@ -303,8 +293,7 @@ void UA_Server_createNS0(UA_Server *server) {
     UA_Server_addReferenceTypeNode_begin(server, UA_NODEID_NUMERIC(0, UA_NS0ID_REFERENCES),
                                          UA_QUALIFIEDNAME(0, "References"), references_attr, NULL);
 
-    UA_ReferenceTypeAttributes hassubtype_attr;
-    UA_ReferenceTypeAttributes_init(&hassubtype_attr);
+    UA_ReferenceTypeAttributes hassubtype_attr = UA_ReferenceTypeAttributes_default;
     hassubtype_attr.displayName = UA_LOCALIZEDTEXT("en_US", "HasSubtype");
     hassubtype_attr.isAbstract = false;
     hassubtype_attr.symmetric = false;
@@ -368,8 +357,7 @@ void UA_Server_createNS0(UA_Server *server) {
     /**************/
 
     /* Bootstrap BaseDataType */
-    UA_DataTypeAttributes basedatatype_attr;
-    UA_DataTypeAttributes_init(&basedatatype_attr);
+    UA_DataTypeAttributes basedatatype_attr = UA_DataTypeAttributes_default;
     basedatatype_attr.displayName = UA_LOCALIZEDTEXT("en_US", "BaseDataType");
     basedatatype_attr.isAbstract = true;
     UA_Server_addDataTypeNode_begin(server, UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATATYPE),
@@ -413,8 +401,7 @@ void UA_Server_createNS0(UA_Server *server) {
     /*****************/
 
     /* Bootstrap BaseVariableType */
-    UA_VariableTypeAttributes basevar_attr;
-    UA_VariableTypeAttributes_init(&basevar_attr);
+    UA_VariableTypeAttributes basevar_attr = UA_VariableTypeAttributes_default;
     basevar_attr.displayName = UA_LOCALIZEDTEXT("en_US", "BaseVariableType");
     basevar_attr.isAbstract = true;
     basevar_attr.valueRank = -2;
@@ -441,8 +428,7 @@ void UA_Server_createNS0(UA_Server *server) {
     /***************/
 
     /* Bootstrap BaseObjectType */
-    UA_ObjectTypeAttributes baseobj_attr;
-    UA_ObjectTypeAttributes_init(&baseobj_attr);
+    UA_ObjectTypeAttributes baseobj_attr = UA_ObjectTypeAttributes_default;
     baseobj_attr.displayName = UA_LOCALIZEDTEXT("en_US", "BaseObjectType");
     UA_Server_addObjectTypeNode_begin(server, UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
                                       UA_QUALIFIEDNAME(0, "BaseObjectType"), baseobj_attr, NULL);
@@ -466,8 +452,7 @@ void UA_Server_createNS0(UA_Server *server) {
     /* Root and below */
     /******************/
 
-    UA_ObjectAttributes root_attr;
-    UA_ObjectAttributes_init(&root_attr);
+    UA_ObjectAttributes root_attr = UA_ObjectAttributes_default;
     root_attr.displayName = UA_LOCALIZEDTEXT("en_US", "Root");
     UA_Server_addObjectNode_begin(server, UA_NODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER),
                                   UA_QUALIFIEDNAME(0, "Root"), root_attr, NULL);
@@ -524,8 +509,7 @@ void UA_Server_createNS0(UA_Server *server) {
                        resets the variant internally */
 
     /* Begin Server object */ 
-    UA_ObjectAttributes server_attr;
-    UA_ObjectAttributes_init(&server_attr);
+    UA_ObjectAttributes server_attr = UA_ObjectAttributes_default;
     server_attr.displayName = UA_LOCALIZEDTEXT("en_US", "Server");
     UA_Server_addObjectNode_begin(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER),
                                   UA_QUALIFIEDNAME(0, "Server"), server_attr, NULL);
@@ -538,8 +522,7 @@ void UA_Server_createNS0(UA_Server *server) {
                     UA_NS0ID_SERVER, UA_NS0ID_HASPROPERTY, UA_NS0ID_PROPERTYTYPE);
     
     /* NamespaceArray */
-    UA_VariableAttributes nsarray_attr;
-    UA_VariableAttributes_init(&nsarray_attr);
+    UA_VariableAttributes nsarray_attr = UA_VariableAttributes_default;
     nsarray_attr.displayName = UA_LOCALIZEDTEXT("en_US", "NamespaceArray");
     nsarray_attr.valueRank = 1;
     nsarray_attr.minimumSamplingInterval = 50.0;
@@ -560,8 +543,7 @@ void UA_Server_createNS0(UA_Server *server) {
                              UA_NODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE), NULL);
 
     /* Begin ServerCapabilities */
-    UA_ObjectAttributes servercap_attr;
-    UA_ObjectAttributes_init(&servercap_attr);
+    UA_ObjectAttributes servercap_attr = UA_ObjectAttributes_default;
     servercap_attr.displayName = UA_LOCALIZEDTEXT("en_US", "ServerCapabilities");
     UA_Server_addObjectNode_begin(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERCAPABILITIES),
                                   UA_QUALIFIEDNAME(0, "ServerCapabilities"), servercap_attr, NULL);
@@ -636,8 +618,7 @@ void UA_Server_createNS0(UA_Server *server) {
                              UA_NODEID_NUMERIC(0, UA_NS0ID_SERVERCAPABILITIESTYPE), NULL);
 
     /* Begin ServerDiagnostics */
-    UA_ObjectAttributes serverdiag_attr;
-    UA_ObjectAttributes_init(&serverdiag_attr);
+    UA_ObjectAttributes serverdiag_attr = UA_ObjectAttributes_default;
     serverdiag_attr.displayName = UA_LOCALIZEDTEXT("en_US", "ServerDiagnostics");
     UA_Server_addObjectNode_begin(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERDIAGNOSTICS),
                                   UA_QUALIFIEDNAME(0, "ServerDiagnostics"), serverdiag_attr, NULL);
@@ -654,11 +635,7 @@ void UA_Server_createNS0(UA_Server *server) {
                              UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
                              UA_NODEID_NUMERIC(0, UA_NS0ID_SERVERDIAGNOSTICSTYPE), NULL);
 
-    UA_DataSource statusDS = {
-        server, //handle
-        readStatus, //read
-        NULL //write
-    };
+    UA_DataSource statusDS = {server, readStatus, NULL};
     addDataSourceVariableNode(server, UA_NS0ID_SERVER_SERVERSTATUS, "ServerStatus", -1,
                               &UA_TYPES[UA_TYPES_SERVERSTATUSDATATYPE].typeId, &statusDS,
                               UA_NS0ID_SERVER, UA_NS0ID_HASCOMPONENT, UA_NS0ID_BASEDATAVARIABLETYPE);
@@ -668,11 +645,7 @@ void UA_Server_createNS0(UA_Server *server) {
                     &UA_TYPES[UA_TYPES_DATETIME].typeId, &var, UA_NS0ID_SERVER_SERVERSTATUS,
                     UA_NS0ID_HASCOMPONENT, UA_NS0ID_BASEDATAVARIABLETYPE);
 
-    UA_DataSource currentDS = {
-        NULL, //handle
-        readCurrentTime, //read
-        NULL //write
-    };
+    UA_DataSource currentDS = {NULL, readCurrentTime, NULL};
     addDataSourceVariableNode(server, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME, "CurrentTime", -1,
                               &UA_TYPES[UA_TYPES_DATETIME].typeId, &currentDS,
                               UA_NS0ID_SERVER_SERVERSTATUS, UA_NS0ID_HASCOMPONENT,
@@ -763,8 +736,7 @@ void UA_Server_createNS0(UA_Server *server) {
 
 #if defined(UA_ENABLE_METHODCALLS) && defined(UA_ENABLE_SUBSCRIPTIONS)
     /* Add method node */
-    UA_MethodAttributes addmethodattributes;
-    UA_MethodAttributes_init(&addmethodattributes);
+    UA_MethodAttributes addmethodattributes = UA_MethodAttributes_default;
     addmethodattributes.displayName = UA_LOCALIZEDTEXT("", "GetMonitoredItems");
     addmethodattributes.executable = true;
     addmethodattributes.userExecutable = true;

+ 85 - 0
src/server/ua_server_utils.c

@@ -260,3 +260,88 @@ UA_Server_processServiceOperations(UA_Server *server, UA_Session *session,
     }
     return UA_STATUSCODE_GOOD;
 }
+
+/*********************************/
+/* Default attribute definitions */
+/*********************************/
+
+const UA_ObjectAttributes UA_ObjectAttributes_default = {
+    0,                      /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}}, /* displayName */
+    {{0, NULL}, {0, NULL}}, /* description */
+    0, 0,                   /* writeMask (userWriteMask) */
+    0                       /* eventNotifier */
+};
+
+const UA_VariableAttributes UA_VariableAttributes_default = {
+    0,                           /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}},      /* displayName */
+    {{0, NULL}, {0, NULL}},      /* description */
+    0, 0,                        /* writeMask (userWriteMask) */
+    {NULL, UA_VARIANT_DATA,
+     0, NULL, 0, NULL},          /* value */
+    {0, UA_NODEIDTYPE_NUMERIC,
+     {UA_NS0ID_BASEDATATYPE}},   /* dataType */
+    -2,                          /* valueRank */
+    0, NULL,                     /* arrayDimensions */
+    UA_ACCESSLEVELMASK_READ, 0,  /* accessLevel (userAccessLevel) */
+    0.0,                         /* minimumSamplingInterval */
+    false                        /* historizing */
+};
+
+const UA_MethodAttributes UA_MethodAttributes_default = {
+    0,                      /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}}, /* displayName */
+    {{0, NULL}, {0, NULL}}, /* description */
+    0, 0,                   /* writeMask (userWriteMask) */
+    true, true              /* executable (userExecutable) */
+};
+
+const UA_ObjectTypeAttributes UA_ObjectTypeAttributes_default = {
+    0,                      /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}}, /* displayName */
+    {{0, NULL}, {0, NULL}}, /* description */
+    0, 0,                   /* writeMask (userWriteMask) */
+    false                   /* isAbstract */
+};
+
+const UA_VariableTypeAttributes UA_VariableTypeAttributes_default = {
+    0,                           /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}},      /* displayName */
+    {{0, NULL}, {0, NULL}},      /* description */
+    0, 0,                        /* writeMask (userWriteMask) */
+    {NULL, UA_VARIANT_DATA,
+     0, NULL, 0, NULL},          /* value */
+    {0, UA_NODEIDTYPE_NUMERIC,
+     {UA_NS0ID_BASEDATATYPE}},   /* dataType */
+    -2,                          /* valueRank */
+    0, NULL,                     /* arrayDimensions */
+    false                        /* isAbstract */
+};
+
+const UA_ReferenceTypeAttributes UA_ReferenceTypeAttributes_default = {
+    0,                      /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}}, /* displayName */
+    {{0, NULL}, {0, NULL}}, /* description */
+    0, 0,                   /* writeMask (userWriteMask) */
+    false,                  /* isAbstract */
+    false,                  /* symmetric */
+    {{0, NULL}, {0, NULL}}  /* inverseName */
+};
+
+const UA_DataTypeAttributes UA_DataTypeAttributes_default = {
+    0,                      /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}}, /* displayName */
+    {{0, NULL}, {0, NULL}}, /* description */
+    0, 0,                   /* writeMask (userWriteMask) */
+    false                   /* isAbstract */
+};
+
+const UA_ViewAttributes UA_ViewAttributes_default = {
+    0,                      /* specifiedAttributes */
+    {{0, NULL}, {0, NULL}}, /* displayName */
+    {{0, NULL}, {0, NULL}}, /* description */
+    0, 0,                   /* writeMask (userWriteMask) */
+    false,                  /* containsNoLoops */
+    0                       /* eventNotifier */
+};