ua_server.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. #include "ua_types.h"
  2. #include "ua_server_internal.h"
  3. #include "ua_securechannel_manager.h"
  4. #include "ua_session_manager.h"
  5. #include "ua_util.h"
  6. #include "ua_services.h"
  7. #include "ua_nodeids.h"
  8. const char *UA_LoggerCategoryNames[3] = {"communication", "server", "userland"};
  9. const UA_ServerConfig UA_ServerConfig_standard = {
  10. UA_TRUE,
  11. UA_TRUE,
  12. (char *[]){"user"},
  13. (char *[]){"password"},
  14. 1,
  15. "urn:unconfigured:open62541:open62541Server"
  16. };
  17. /**********************/
  18. /* Namespace Handling */
  19. /**********************/
  20. static void UA_ExternalNamespace_init(UA_ExternalNamespace *ens) {
  21. ens->index = 0;
  22. UA_String_init(&ens->url);
  23. }
  24. static void UA_ExternalNamespace_deleteMembers(UA_ExternalNamespace *ens) {
  25. UA_String_deleteMembers(&ens->url);
  26. ens->externalNodeStore.destroy(ens->externalNodeStore.ensHandle);
  27. }
  28. /*****************/
  29. /* Configuration */
  30. /*****************/
  31. void UA_Server_addNetworkLayer(UA_Server *server, UA_ServerNetworkLayer networkLayer) {
  32. UA_ServerNetworkLayer *newlayers =
  33. UA_realloc(server->nls, sizeof(UA_ServerNetworkLayer)*(server->nlsSize+1));
  34. if(!newlayers) {
  35. UA_LOG_ERROR(server->logger, UA_LOGGERCATEGORY_SERVER, "Networklayer added");
  36. return;
  37. }
  38. server->nls = newlayers;
  39. server->nls[server->nlsSize] = networkLayer;
  40. server->nlsSize++;
  41. if(networkLayer.discoveryUrl){
  42. if(server->description.discoveryUrlsSize < 0)
  43. server->description.discoveryUrlsSize = 0;
  44. UA_String* newUrls = UA_realloc(server->description.discoveryUrls,
  45. sizeof(UA_String)*(server->description.discoveryUrlsSize+1));
  46. if(!newUrls) {
  47. UA_LOG_ERROR(server->logger, UA_LOGGERCATEGORY_SERVER, "Adding discoveryUrl");
  48. return;
  49. }
  50. server->description.discoveryUrls = newUrls;
  51. UA_String_copy(networkLayer.discoveryUrl,
  52. &server->description.discoveryUrls[server->description.discoveryUrlsSize]);
  53. server->description.discoveryUrlsSize++;
  54. }
  55. }
  56. void UA_Server_setServerCertificate(UA_Server *server, UA_ByteString certificate) {
  57. for(UA_Int32 i = 0; i < server->endpointDescriptionsSize; i++)
  58. UA_ByteString_copy(&certificate, &server->endpointDescriptions[i].serverCertificate);
  59. }
  60. void UA_Server_setLogger(UA_Server *server, UA_Logger logger) {
  61. server->logger = logger;
  62. }
  63. UA_UInt16 UA_Server_addNamespace(UA_Server *server, const char* name) {
  64. server->namespaces = UA_realloc(server->namespaces, sizeof(UA_String) * (server->namespacesSize+1));
  65. server->namespaces[server->namespacesSize] = UA_STRING_ALLOC(name);
  66. server->namespacesSize++;
  67. return server->namespacesSize-1;
  68. }
  69. /**********/
  70. /* Server */
  71. /**********/
  72. /* The server needs to be stopped before it can be deleted */
  73. void UA_Server_delete(UA_Server *server) {
  74. // Delete the timed work
  75. UA_Server_deleteTimedWork(server);
  76. // Delete all internal data
  77. UA_ApplicationDescription_deleteMembers(&server->description);
  78. UA_SecureChannelManager_deleteMembers(&server->secureChannelManager);
  79. UA_SessionManager_deleteMembers(&server->sessionManager);
  80. UA_NodeStore_delete(server->nodestore);
  81. UA_ByteString_deleteMembers(&server->serverCertificate);
  82. UA_Array_delete(server->namespaces, &UA_TYPES[UA_TYPES_STRING], server->namespacesSize);
  83. UA_Array_delete(server->endpointDescriptions, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION],
  84. server->endpointDescriptionsSize);
  85. // Delete the network layers
  86. for(UA_Int32 i = 0; i < server->nlsSize; i++) {
  87. server->nls[i].free(server->nls[i].nlHandle);
  88. }
  89. UA_free(server->nls);
  90. #ifdef UA_MULTITHREADING
  91. pthread_cond_destroy(&server->dispatchQueue_condition); // so the workers don't spin if the queue is empty
  92. rcu_barrier(); // wait for all scheduled call_rcu work to complete
  93. #endif
  94. UA_free(server);
  95. }
  96. static UA_StatusCode readStatus(void *handle, UA_Boolean sourceTimeStamp, UA_DataValue *value) {
  97. UA_ServerStatusDataType *status = UA_ServerStatusDataType_new();
  98. status->startTime = ((const UA_Server*)handle)->startTime;
  99. status->currentTime = UA_DateTime_now();
  100. status->state = UA_SERVERSTATE_RUNNING;
  101. status->buildInfo.productUri = UA_STRING_ALLOC("http://www.open62541.org");
  102. status->buildInfo.manufacturerName = UA_STRING_ALLOC("open62541");
  103. status->buildInfo.productName = UA_STRING_ALLOC("open62541 OPC UA Server");
  104. #define STRINGIFY(x) #x //some magic
  105. #define TOSTRING(x) STRINGIFY(x) //some magic
  106. status->buildInfo.softwareVersion = UA_STRING_ALLOC(TOSTRING(OPEN62541_VERSION_MAJOR) "." TOSTRING(OPEN62541_VERSION_MINOR) "." TOSTRING(OPEN62541_VERSION_PATCH));
  107. status->buildInfo.buildNumber = UA_STRING_ALLOC("0");
  108. status->buildInfo.buildDate = ((const UA_Server*)handle)->buildDate;
  109. status->secondsTillShutdown = 0;
  110. value->value.type = &UA_TYPES[UA_TYPES_SERVERSTATUSDATATYPE];
  111. value->value.arrayLength = -1;
  112. value->value.data = status;
  113. value->value.arrayDimensionsSize = -1;
  114. value->value.arrayDimensions = UA_NULL;
  115. value->hasValue = UA_TRUE;
  116. if(sourceTimeStamp) {
  117. value->hasSourceTimestamp = UA_TRUE;
  118. value->sourceTimestamp = UA_DateTime_now();
  119. }
  120. return UA_STATUSCODE_GOOD;
  121. }
  122. static void releaseStatus(void *handle, UA_DataValue *value) {
  123. UA_DataValue_deleteMembers(value);
  124. }
  125. static UA_StatusCode readNamespaces(void *handle, UA_Boolean sourceTimestamp, UA_DataValue *value) {
  126. UA_Server *server = (UA_Server*)handle;
  127. value->hasValue = UA_TRUE;
  128. value->value.storageType = UA_VARIANT_DATA_NODELETE;
  129. value->value.type = &UA_TYPES[UA_TYPES_STRING];
  130. value->value.arrayLength = server->namespacesSize;
  131. value->value.data = server->namespaces;
  132. if(sourceTimestamp) {
  133. value->hasSourceTimestamp = UA_TRUE;
  134. value->sourceTimestamp = UA_DateTime_now();
  135. }
  136. return UA_STATUSCODE_GOOD;
  137. }
  138. static void releaseNamespaces(void *handle, UA_DataValue *value) {
  139. }
  140. static UA_StatusCode readCurrentTime(void *handle, UA_Boolean sourceTimeStamp, UA_DataValue *value) {
  141. UA_DateTime *currentTime = UA_DateTime_new();
  142. if(!currentTime)
  143. return UA_STATUSCODE_BADOUTOFMEMORY;
  144. *currentTime = UA_DateTime_now();
  145. value->value.type = &UA_TYPES[UA_TYPES_DATETIME];
  146. value->value.arrayLength = -1;
  147. value->value.data = currentTime;
  148. value->value.arrayDimensionsSize = -1;
  149. value->value.arrayDimensions = NULL;
  150. value->hasValue = UA_TRUE;
  151. if(sourceTimeStamp) {
  152. value->hasSourceTimestamp = UA_TRUE;
  153. value->sourceTimestamp = *currentTime;
  154. }
  155. return UA_STATUSCODE_GOOD;
  156. }
  157. static void releaseCurrentTime(void *handle, UA_DataValue *value) {
  158. UA_DateTime_delete((UA_DateTime*)value->value.data);
  159. }
  160. static void copyNames(UA_Node *node, char *name) {
  161. node->browseName = UA_QUALIFIEDNAME_ALLOC(0, name);
  162. node->displayName = UA_LOCALIZEDTEXT_ALLOC("", name);
  163. node->description = UA_LOCALIZEDTEXT_ALLOC("", name);
  164. }
  165. static void addDataTypeNode(UA_Server *server, char* name, UA_UInt32 datatypeid, UA_Int32 parent) {
  166. UA_DataTypeNode *datatype = UA_DataTypeNode_new();
  167. copyNames((UA_Node*)datatype, name);
  168. datatype->nodeId.identifier.numeric = datatypeid;
  169. UA_Server_addNode(server, (UA_Node*)datatype,
  170. &UA_EXPANDEDNODEID_NUMERIC(0, parent),
  171. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  172. }
  173. static UA_VariableTypeNode*
  174. createVariableTypeNode(UA_Server *server, char* name, UA_UInt32 variabletypeid,
  175. UA_Int32 parent, UA_Boolean abstract)
  176. {
  177. UA_VariableTypeNode *variabletype = UA_VariableTypeNode_new();
  178. copyNames((UA_Node*)variabletype, name);
  179. variabletype->nodeId.identifier.numeric = variabletypeid;
  180. variabletype->isAbstract = abstract;
  181. variabletype->value.variant.type = &UA_TYPES[UA_TYPES_VARIANT];
  182. return variabletype;
  183. }
  184. static void addVariableTypeNode_organized(UA_Server *server, char* name, UA_UInt32 variabletypeid,
  185. UA_Int32 parent, UA_Boolean abstract) {
  186. UA_VariableTypeNode *variabletype = createVariableTypeNode(server, name, variabletypeid, parent, abstract);
  187. UA_Server_addNode(server, (UA_Node*)variabletype,
  188. &UA_EXPANDEDNODEID_NUMERIC(0, parent),
  189. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  190. }
  191. static void addVariableTypeNode_subtype(UA_Server *server, char* name, UA_UInt32 variabletypeid,
  192. UA_Int32 parent, UA_Boolean abstract) {
  193. UA_VariableTypeNode *variabletype = createVariableTypeNode(server, name, variabletypeid, parent, abstract);
  194. UA_Server_addNode(server, (UA_Node*)variabletype,
  195. &UA_EXPANDEDNODEID_NUMERIC(0, parent),
  196. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  197. }
  198. UA_Server * UA_Server_new(UA_ServerConfig config) {
  199. UA_Server *server = UA_malloc(sizeof(UA_Server));
  200. if(!server)
  201. return UA_NULL;
  202. //FIXME: config contains strings, for now its okay, but consider copying them aswell
  203. server->config = config;
  204. LIST_INIT(&server->timedWork);
  205. #ifdef UA_MULTITHREADING
  206. rcu_init();
  207. cds_wfcq_init(&server->dispatchQueue_head, &server->dispatchQueue_tail);
  208. server->delayedWork = UA_NULL;
  209. #endif
  210. // logger
  211. server->logger = (UA_Logger){ UA_NULL, UA_NULL, UA_NULL, UA_NULL, UA_NULL, UA_NULL };
  212. // random seed
  213. server->random_seed = (UA_UInt32)UA_DateTime_now();
  214. // networklayers
  215. server->nls = UA_NULL;
  216. server->nlsSize = 0;
  217. UA_ByteString_init(&server->serverCertificate);
  218. // mockup application description
  219. UA_ApplicationDescription_init(&server->description);
  220. server->description.productUri = UA_STRING_ALLOC(PRODUCT_URI);
  221. server->description.applicationUri = UA_STRING_ALLOC(server->config.Application_applicationURI);
  222. server->description.discoveryUrlsSize = 0;
  223. server->description.applicationName = UA_LOCALIZEDTEXT_ALLOC("", "Unconfigured open62541 application");
  224. server->description.applicationType = UA_APPLICATIONTYPE_SERVER;
  225. server->externalNamespacesSize = 0;
  226. server->externalNamespaces = UA_NULL;
  227. server->namespaces = UA_String_new();
  228. *server->namespaces = UA_STRING_ALLOC("http://opcfoundation.org/UA/");
  229. server->namespacesSize = 1;
  230. server->endpointDescriptions = UA_NULL;
  231. server->endpointDescriptionsSize = 0;
  232. UA_EndpointDescription *endpoint = UA_EndpointDescription_new(); // todo: check return code
  233. if(endpoint) {
  234. endpoint->securityMode = UA_MESSAGESECURITYMODE_NONE;
  235. endpoint->securityPolicyUri = UA_STRING_ALLOC("http://opcfoundation.org/UA/SecurityPolicy#None");
  236. endpoint->transportProfileUri = UA_STRING_ALLOC("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary");
  237. int size = 0;
  238. if(server->config.Login_enableAnonymous){
  239. size++;
  240. }
  241. if(server->config.Login_enableUsernamePassword){
  242. size++;
  243. }
  244. endpoint->userIdentityTokensSize = size;
  245. endpoint->userIdentityTokens = UA_Array_new(&UA_TYPES[UA_TYPES_USERTOKENPOLICY], size);
  246. int currentIndex = 0;
  247. if(server->config.Login_enableAnonymous){
  248. UA_UserTokenPolicy_init(&endpoint->userIdentityTokens[currentIndex]);
  249. endpoint->userIdentityTokens[currentIndex].tokenType = UA_USERTOKENTYPE_ANONYMOUS;
  250. endpoint->userIdentityTokens[currentIndex].policyId = UA_STRING_ALLOC(ANONYMOUS_POLICY); // defined per server
  251. currentIndex++;
  252. }
  253. if(server->config.Login_enableUsernamePassword){
  254. UA_UserTokenPolicy_init(&endpoint->userIdentityTokens[currentIndex]);
  255. endpoint->userIdentityTokens[currentIndex].tokenType = UA_USERTOKENTYPE_USERNAME;
  256. endpoint->userIdentityTokens[currentIndex].policyId = UA_STRING_ALLOC(USERNAME_POLICY); // defined per server
  257. currentIndex++;
  258. }
  259. /* UA_String_copy(endpointUrl, &endpoint->endpointUrl); */
  260. /* /\* The standard says "the HostName specified in the Server Certificate is the */
  261. /* same as the HostName contained in the endpointUrl provided in the */
  262. /* EndpointDescription *\/ */
  263. /* UA_String_copy(&server->serverCertificate, &endpoint->serverCertificate); */
  264. UA_ApplicationDescription_copy(&server->description, &endpoint->server);
  265. server->endpointDescriptions = endpoint;
  266. server->endpointDescriptionsSize = 1;
  267. }
  268. #define MAXCHANNELCOUNT 100
  269. #define STARTCHANNELID 1
  270. #define TOKENLIFETIME 600000
  271. #define STARTTOKENID 1
  272. UA_SecureChannelManager_init(&server->secureChannelManager, MAXCHANNELCOUNT,
  273. TOKENLIFETIME, STARTCHANNELID, STARTTOKENID);
  274. #define MAXSESSIONCOUNT 1000
  275. #define MAXSESSIONLIFETIME 10000
  276. #define STARTSESSIONID 1
  277. UA_SessionManager_init(&server->sessionManager, MAXSESSIONCOUNT, MAXSESSIONLIFETIME, STARTSESSIONID);
  278. server->nodestore = UA_NodeStore_new();
  279. /**************/
  280. /* References */
  281. /**************/
  282. /* bootstrap by manually inserting "references" and "hassubtype" */
  283. UA_ReferenceTypeNode *references = UA_ReferenceTypeNode_new();
  284. copyNames((UA_Node*)references, "References");
  285. references->nodeId.identifier.numeric = UA_NS0ID_REFERENCES;
  286. references->isAbstract = UA_TRUE;
  287. references->symmetric = UA_TRUE;
  288. // this node has no parent??
  289. UA_NodeStore_insert(server->nodestore, (UA_Node*)references, UA_NULL);
  290. UA_ReferenceTypeNode *hassubtype = UA_ReferenceTypeNode_new();
  291. copyNames((UA_Node*)hassubtype, "HasSubtype");
  292. hassubtype->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "HasSupertype");
  293. hassubtype->nodeId.identifier.numeric = UA_NS0ID_HASSUBTYPE;
  294. hassubtype->isAbstract = UA_FALSE;
  295. hassubtype->symmetric = UA_FALSE;
  296. UA_NodeStore_insert(server->nodestore, (UA_Node*)hassubtype, UA_NULL);
  297. /* continue adding reference types with normal "addnode" */
  298. UA_ReferenceTypeNode *hierarchicalreferences = UA_ReferenceTypeNode_new();
  299. copyNames((UA_Node*)hierarchicalreferences, "Hierarchicalreferences");
  300. hierarchicalreferences->nodeId.identifier.numeric = UA_NS0ID_HIERARCHICALREFERENCES;
  301. hierarchicalreferences->isAbstract = UA_TRUE;
  302. hierarchicalreferences->symmetric = UA_FALSE;
  303. UA_Server_addNode(server, (UA_Node*)hierarchicalreferences,
  304. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_REFERENCES),
  305. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  306. UA_ReferenceTypeNode *nonhierarchicalreferences = UA_ReferenceTypeNode_new();
  307. copyNames((UA_Node*)nonhierarchicalreferences, "NonHierarchicalReferences");
  308. nonhierarchicalreferences->nodeId.identifier.numeric = UA_NS0ID_NONHIERARCHICALREFERENCES;
  309. nonhierarchicalreferences->isAbstract = UA_TRUE;
  310. nonhierarchicalreferences->symmetric = UA_FALSE;
  311. UA_Server_addNode(server, (UA_Node*)nonhierarchicalreferences,
  312. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_REFERENCES),
  313. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  314. UA_ReferenceTypeNode *haschild = UA_ReferenceTypeNode_new();
  315. copyNames((UA_Node*)haschild, "HasChild");
  316. haschild->nodeId.identifier.numeric = UA_NS0ID_HASCHILD;
  317. haschild->isAbstract = UA_TRUE;
  318. haschild->symmetric = UA_FALSE;
  319. UA_Server_addNode(server, (UA_Node*)haschild,
  320. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  321. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  322. UA_ReferenceTypeNode *organizes = UA_ReferenceTypeNode_new();
  323. copyNames((UA_Node*)organizes, "Organizes");
  324. organizes->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "OrganizedBy");
  325. organizes->nodeId.identifier.numeric = UA_NS0ID_ORGANIZES;
  326. organizes->isAbstract = UA_FALSE;
  327. organizes->symmetric = UA_FALSE;
  328. UA_Server_addNode(server, (UA_Node*)organizes,
  329. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  330. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  331. UA_ReferenceTypeNode *haseventsource = UA_ReferenceTypeNode_new();
  332. copyNames((UA_Node*)haseventsource, "HasEventSource");
  333. haseventsource->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "EventSourceOf");
  334. haseventsource->nodeId.identifier.numeric = UA_NS0ID_HASEVENTSOURCE;
  335. haseventsource->isAbstract = UA_FALSE;
  336. haseventsource->symmetric = UA_FALSE;
  337. UA_Server_addNode(server, (UA_Node*)haseventsource,
  338. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HIERARCHICALREFERENCES),
  339. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  340. UA_ReferenceTypeNode *hasmodellingrule = UA_ReferenceTypeNode_new();
  341. copyNames((UA_Node*)hasmodellingrule, "HasModellingRule");
  342. hasmodellingrule->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ModellingRuleOf");
  343. hasmodellingrule->nodeId.identifier.numeric = UA_NS0ID_HASMODELLINGRULE;
  344. hasmodellingrule->isAbstract = UA_FALSE;
  345. hasmodellingrule->symmetric = UA_FALSE;
  346. UA_Server_addNode(server, (UA_Node*)hasmodellingrule,
  347. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  348. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  349. UA_ReferenceTypeNode *hasencoding = UA_ReferenceTypeNode_new();
  350. copyNames((UA_Node*)hasencoding, "HasEncoding");
  351. hasencoding->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "EncodingOf");
  352. hasencoding->nodeId.identifier.numeric = UA_NS0ID_HASENCODING;
  353. hasencoding->isAbstract = UA_FALSE;
  354. hasencoding->symmetric = UA_FALSE;
  355. UA_Server_addNode(server, (UA_Node*)hasencoding,
  356. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  357. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  358. UA_ReferenceTypeNode *hasdescription = UA_ReferenceTypeNode_new();
  359. copyNames((UA_Node*)hasdescription, "HasDescription");
  360. hasdescription->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "DescriptionOf");
  361. hasdescription->nodeId.identifier.numeric = UA_NS0ID_HASDESCRIPTION;
  362. hasdescription->isAbstract = UA_FALSE;
  363. hasdescription->symmetric = UA_FALSE;
  364. UA_Server_addNode(server, (UA_Node*)hasdescription,
  365. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  366. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  367. UA_ReferenceTypeNode *hastypedefinition = UA_ReferenceTypeNode_new();
  368. copyNames((UA_Node*)hastypedefinition, "HasTypeDefinition");
  369. hastypedefinition->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "TypeDefinitionOf");
  370. hastypedefinition->nodeId.identifier.numeric = UA_NS0ID_HASTYPEDEFINITION;
  371. hastypedefinition->isAbstract = UA_FALSE;
  372. hastypedefinition->symmetric = UA_FALSE;
  373. UA_Server_addNode(server, (UA_Node*)hastypedefinition,
  374. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  375. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  376. UA_ReferenceTypeNode *generatesevent = UA_ReferenceTypeNode_new();
  377. copyNames((UA_Node*)generatesevent, "GeneratesEvent");
  378. generatesevent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "GeneratedBy");
  379. generatesevent->nodeId.identifier.numeric = UA_NS0ID_GENERATESEVENT;
  380. generatesevent->isAbstract = UA_FALSE;
  381. generatesevent->symmetric = UA_FALSE;
  382. UA_Server_addNode(server, (UA_Node*)generatesevent,
  383. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  384. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  385. UA_ReferenceTypeNode *aggregates = UA_ReferenceTypeNode_new();
  386. copyNames((UA_Node*)aggregates, "Aggregates");
  387. // Todo: Is there an inverse name?
  388. aggregates->nodeId.identifier.numeric = UA_NS0ID_AGGREGATES;
  389. aggregates->isAbstract = UA_TRUE;
  390. aggregates->symmetric = UA_FALSE;
  391. UA_Server_addNode(server, (UA_Node*)aggregates,
  392. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASCHILD),
  393. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  394. // complete bootstrap of hassubtype
  395. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_HASCHILD), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  396. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  397. UA_ReferenceTypeNode *hasproperty = UA_ReferenceTypeNode_new();
  398. copyNames((UA_Node*)hasproperty, "HasProperty");
  399. hasproperty->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "PropertyOf");
  400. hasproperty->nodeId.identifier.numeric = UA_NS0ID_HASPROPERTY;
  401. hasproperty->isAbstract = UA_FALSE;
  402. hasproperty->symmetric = UA_FALSE;
  403. UA_Server_addNode(server, (UA_Node*)hasproperty,
  404. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_AGGREGATES),
  405. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  406. UA_ReferenceTypeNode *hascomponent = UA_ReferenceTypeNode_new();
  407. copyNames((UA_Node*)hascomponent, "HasComponent");
  408. hascomponent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ComponentOf");
  409. hascomponent->nodeId.identifier.numeric = UA_NS0ID_HASCOMPONENT;
  410. hascomponent->isAbstract = UA_FALSE;
  411. hascomponent->symmetric = UA_FALSE;
  412. UA_Server_addNode(server, (UA_Node*)hascomponent,
  413. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_AGGREGATES),
  414. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  415. UA_ReferenceTypeNode *hasnotifier = UA_ReferenceTypeNode_new();
  416. copyNames((UA_Node*)hasnotifier, "HasNotifier");
  417. hasnotifier->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "NotifierOf");
  418. hasnotifier->nodeId.identifier.numeric = UA_NS0ID_HASNOTIFIER;
  419. hasnotifier->isAbstract = UA_FALSE;
  420. hasnotifier->symmetric = UA_FALSE;
  421. UA_Server_addNode(server, (UA_Node*)hasnotifier,
  422. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASEVENTSOURCE),
  423. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  424. UA_ReferenceTypeNode *hasorderedcomponent = UA_ReferenceTypeNode_new();
  425. copyNames((UA_Node*)hasorderedcomponent, "HasOrderedComponent");
  426. hasorderedcomponent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "OrderedComponentOf");
  427. hasorderedcomponent->nodeId.identifier.numeric = UA_NS0ID_HASORDEREDCOMPONENT;
  428. hasorderedcomponent->isAbstract = UA_FALSE;
  429. hasorderedcomponent->symmetric = UA_FALSE;
  430. UA_Server_addNode(server, (UA_Node*)hasorderedcomponent,
  431. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  432. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  433. UA_ReferenceTypeNode *hasmodelparent = UA_ReferenceTypeNode_new();
  434. copyNames((UA_Node*)hasmodelparent, "HasModelParent");
  435. hasmodelparent->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ModelParentOf");
  436. hasmodelparent->nodeId.identifier.numeric = UA_NS0ID_HASMODELPARENT;
  437. hasmodelparent->isAbstract = UA_FALSE;
  438. hasmodelparent->symmetric = UA_FALSE;
  439. UA_Server_addNode(server, (UA_Node*)hasmodelparent,
  440. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  441. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  442. UA_ReferenceTypeNode *fromstate = UA_ReferenceTypeNode_new();
  443. copyNames((UA_Node*)fromstate, "FromState");
  444. fromstate->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "ToTransition");
  445. fromstate->nodeId.identifier.numeric = UA_NS0ID_FROMSTATE;
  446. fromstate->isAbstract = UA_FALSE;
  447. fromstate->symmetric = UA_FALSE;
  448. UA_Server_addNode(server, (UA_Node*)fromstate,
  449. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  450. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  451. UA_ReferenceTypeNode *tostate = UA_ReferenceTypeNode_new();
  452. copyNames((UA_Node*)tostate, "ToState");
  453. tostate->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "FromTransition");
  454. tostate->nodeId.identifier.numeric = UA_NS0ID_TOSTATE;
  455. tostate->isAbstract = UA_FALSE;
  456. tostate->symmetric = UA_FALSE;
  457. UA_Server_addNode(server, (UA_Node*)tostate,
  458. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  459. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  460. UA_ReferenceTypeNode *hascause = UA_ReferenceTypeNode_new();
  461. copyNames((UA_Node*)hascause, "HasCause");
  462. hascause->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "MayBeCausedBy");
  463. hascause->nodeId.identifier.numeric = UA_NS0ID_HASCAUSE;
  464. hascause->isAbstract = UA_FALSE;
  465. hascause->symmetric = UA_FALSE;
  466. UA_Server_addNode(server, (UA_Node*)hascause,
  467. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  468. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  469. UA_ReferenceTypeNode *haseffect = UA_ReferenceTypeNode_new();
  470. copyNames((UA_Node*)haseffect, "HasEffect");
  471. haseffect->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "MayBeEffectedBy");
  472. haseffect->nodeId.identifier.numeric = UA_NS0ID_HASEFFECT;
  473. haseffect->isAbstract = UA_FALSE;
  474. haseffect->symmetric = UA_FALSE;
  475. UA_Server_addNode(server, (UA_Node*)haseffect,
  476. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_NONHIERARCHICALREFERENCES),
  477. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  478. UA_ReferenceTypeNode *hashistoricalconfiguration = UA_ReferenceTypeNode_new();
  479. copyNames((UA_Node*)hashistoricalconfiguration, "HasHistoricalConfiguration");
  480. hashistoricalconfiguration->inverseName = UA_LOCALIZEDTEXT_ALLOC("", "HistoricalConfigurationOf");
  481. hashistoricalconfiguration->nodeId.identifier.numeric = UA_NS0ID_HASHISTORICALCONFIGURATION;
  482. hashistoricalconfiguration->isAbstract = UA_FALSE;
  483. hashistoricalconfiguration->symmetric = UA_FALSE;
  484. UA_Server_addNode(server, (UA_Node*)hashistoricalconfiguration,
  485. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_AGGREGATES),
  486. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE));
  487. /**********************/
  488. /* Basic Object Types */
  489. /**********************/
  490. UA_ObjectTypeNode *baseObjectType = UA_ObjectTypeNode_new();
  491. baseObjectType->nodeId.identifier.numeric = UA_NS0ID_BASEOBJECTTYPE;
  492. copyNames((UA_Node*)baseObjectType, "BaseObjectType");
  493. UA_NodeStore_insert(server->nodestore, (UA_Node*)baseObjectType, UA_NULL);
  494. UA_ObjectTypeNode *baseDataVarialbeType = UA_ObjectTypeNode_new();
  495. baseDataVarialbeType->nodeId.identifier.numeric = UA_NS0ID_BASEDATAVARIABLETYPE;
  496. copyNames((UA_Node*)baseDataVarialbeType, "BaseDataVariableType");
  497. UA_NodeStore_insert(server->nodestore, (UA_Node*)baseDataVarialbeType, UA_NULL);
  498. UA_ObjectTypeNode *folderType = UA_ObjectTypeNode_new();
  499. folderType->nodeId.identifier.numeric = UA_NS0ID_FOLDERTYPE;
  500. copyNames((UA_Node*)folderType, "FolderType");
  501. UA_NodeStore_insert(server->nodestore, (UA_Node*)folderType, UA_NULL);
  502. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
  503. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  504. /*****************/
  505. /* Basic Folders */
  506. /*****************/
  507. UA_ObjectNode *root = UA_ObjectNode_new();
  508. copyNames((UA_Node*)root, "Root");
  509. root->nodeId.identifier.numeric = UA_NS0ID_ROOTFOLDER;
  510. UA_NodeStore_insert(server->nodestore, (UA_Node*)root, UA_NULL);
  511. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  512. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  513. UA_ObjectNode *objects = UA_ObjectNode_new();
  514. copyNames((UA_Node*)objects, "Objects");
  515. objects->nodeId.identifier.numeric = UA_NS0ID_OBJECTSFOLDER;
  516. UA_Server_addNode(server, (UA_Node*)objects,
  517. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER),
  518. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  519. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  520. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  521. UA_ObjectNode *types = UA_ObjectNode_new();
  522. copyNames((UA_Node*)types, "Types");
  523. types->nodeId.identifier.numeric = UA_NS0ID_TYPESFOLDER;
  524. UA_Server_addNode(server, (UA_Node*)types,
  525. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER),
  526. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  527. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_TYPESFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  528. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  529. UA_ObjectNode *views = UA_ObjectNode_new();
  530. copyNames((UA_Node*)views, "Views");
  531. views->nodeId.identifier.numeric = UA_NS0ID_VIEWSFOLDER;
  532. UA_Server_addNode(server, (UA_Node*)views,
  533. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_ROOTFOLDER),
  534. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  535. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  536. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  537. /**********************/
  538. /* Further Data Types */
  539. /**********************/
  540. UA_ObjectNode *datatypes = UA_ObjectNode_new();
  541. copyNames((UA_Node*)datatypes, "DataTypes");
  542. datatypes->nodeId.identifier.numeric = UA_NS0ID_DATATYPESFOLDER;
  543. UA_Server_addNode(server, (UA_Node*)datatypes,
  544. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_TYPESFOLDER),
  545. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  546. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_DATATYPESFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  547. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  548. addDataTypeNode(server, "BaseDataType", UA_NS0ID_BASEDATATYPE, UA_NS0ID_DATATYPESFOLDER);
  549. addDataTypeNode(server, "Boolean", UA_NS0ID_BOOLEAN, UA_NS0ID_BASEDATATYPE);
  550. addDataTypeNode(server, "Number", UA_NS0ID_NUMBER, UA_NS0ID_BASEDATATYPE);
  551. addDataTypeNode(server, "Float", UA_NS0ID_FLOAT, UA_NS0ID_NUMBER);
  552. addDataTypeNode(server, "Double", UA_NS0ID_DOUBLE, UA_NS0ID_NUMBER);
  553. addDataTypeNode(server, "Integer", UA_NS0ID_INTEGER, UA_NS0ID_NUMBER);
  554. addDataTypeNode(server, "SByte", UA_NS0ID_SBYTE, UA_NS0ID_INTEGER);
  555. addDataTypeNode(server, "Int16", UA_NS0ID_INT16, UA_NS0ID_INTEGER);
  556. addDataTypeNode(server, "Int32", UA_NS0ID_INT32, UA_NS0ID_INTEGER);
  557. addDataTypeNode(server, "Int64", UA_NS0ID_INT64, UA_NS0ID_INTEGER);
  558. addDataTypeNode(server, "UInteger", UA_NS0ID_UINTEGER, UA_NS0ID_INTEGER);
  559. addDataTypeNode(server, "Byte", UA_NS0ID_BYTE, UA_NS0ID_UINTEGER);
  560. addDataTypeNode(server, "UInt16", UA_NS0ID_UINT16, UA_NS0ID_UINTEGER);
  561. addDataTypeNode(server, "UInt32", UA_NS0ID_UINT32, UA_NS0ID_UINTEGER);
  562. addDataTypeNode(server, "UInt64", UA_NS0ID_UINT64, UA_NS0ID_UINTEGER);
  563. addDataTypeNode(server, "String", UA_NS0ID_STRING, UA_NS0ID_BASEDATATYPE);
  564. addDataTypeNode(server, "DateTime", UA_NS0ID_DATETIME, UA_NS0ID_BASEDATATYPE);
  565. addDataTypeNode(server, "Guid", UA_NS0ID_GUID, UA_NS0ID_BASEDATATYPE);
  566. addDataTypeNode(server, "ByteString", UA_NS0ID_BYTESTRING, UA_NS0ID_BASEDATATYPE);
  567. addDataTypeNode(server, "XmlElement", UA_NS0ID_XMLELEMENT, UA_NS0ID_BASEDATATYPE);
  568. addDataTypeNode(server, "NodeId", UA_NS0ID_NODEID, UA_NS0ID_BASEDATATYPE);
  569. addDataTypeNode(server, "ExpandedNodeId", UA_NS0ID_EXPANDEDNODEID, UA_NS0ID_BASEDATATYPE);
  570. addDataTypeNode(server, "StatusCode", UA_NS0ID_STATUSCODE, UA_NS0ID_BASEDATATYPE);
  571. addDataTypeNode(server, "QualifiedName", UA_NS0ID_QUALIFIEDNAME, UA_NS0ID_BASEDATATYPE);
  572. addDataTypeNode(server, "LocalizedText", UA_NS0ID_LOCALIZEDTEXT, UA_NS0ID_BASEDATATYPE);
  573. addDataTypeNode(server, "Structure", UA_NS0ID_STRUCTURE, UA_NS0ID_BASEDATATYPE);
  574. addDataTypeNode(server, "DataValue", UA_NS0ID_DATAVALUE, UA_NS0ID_BASEDATATYPE);
  575. addDataTypeNode(server, "DiagnosticInfo", UA_NS0ID_DIAGNOSTICINFO, UA_NS0ID_BASEDATATYPE);
  576. addDataTypeNode(server, "Enumeration", UA_NS0ID_ENUMERATION, UA_NS0ID_BASEDATATYPE);
  577. addDataTypeNode(server, "ServerState", UA_NS0ID_SERVERSTATE, UA_NS0ID_ENUMERATION);
  578. UA_ObjectNode *variabletypes = UA_ObjectNode_new();
  579. copyNames((UA_Node*)variabletypes, "VariableTypes");
  580. variabletypes->nodeId.identifier.numeric = UA_NS0ID_VARIABLETYPESFOLDER;
  581. UA_Server_addNode(server, (UA_Node*)variabletypes,
  582. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_TYPESFOLDER),
  583. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  584. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_VARIABLETYPESFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  585. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  586. addVariableTypeNode_organized(server, "BaseVariableType", UA_NS0ID_BASEVARIABLETYPE, UA_NS0ID_VARIABLETYPESFOLDER, UA_TRUE);
  587. addVariableTypeNode_subtype(server, "PropertyType", UA_NS0ID_PROPERTYTYPE, UA_NS0ID_BASEVARIABLETYPE, UA_FALSE);
  588. /*******************/
  589. /* Further Objects */
  590. /*******************/
  591. UA_ObjectNode *servernode = UA_ObjectNode_new();
  592. copyNames((UA_Node*)servernode, "Server");
  593. servernode->nodeId.identifier.numeric = UA_NS0ID_SERVER;
  594. UA_Server_addNode(server, (UA_Node*)servernode,
  595. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  596. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  597. UA_VariableNode *namespaceArray = UA_VariableNode_new();
  598. copyNames((UA_Node*)namespaceArray, "NamespaceArray");
  599. namespaceArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_NAMESPACEARRAY;
  600. namespaceArray->valueSource = UA_VALUESOURCE_DATASOURCE;
  601. namespaceArray->value.dataSource = (UA_DataSource) {.handle = server, .read = readNamespaces,
  602. .release = releaseNamespaces, .write = UA_NULL};
  603. namespaceArray->valueRank = 1;
  604. namespaceArray->minimumSamplingInterval = 1.0;
  605. namespaceArray->historizing = UA_FALSE;
  606. UA_Server_addNode(server, (UA_Node*)namespaceArray,
  607. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  608. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY));
  609. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_NAMESPACEARRAY),
  610. UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  611. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
  612. UA_VariableNode *serverArray = UA_VariableNode_new();
  613. copyNames((UA_Node*)serverArray, "ServerArray");
  614. serverArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERARRAY;
  615. serverArray->value.variant.data = UA_Array_new(&UA_TYPES[UA_TYPES_STRING], 1);
  616. serverArray->value.variant.arrayLength = 1;
  617. serverArray->value.variant.type = &UA_TYPES[UA_TYPES_STRING];
  618. *(UA_String *)serverArray->value.variant.data = UA_STRING_ALLOC(server->config.Application_applicationURI);
  619. serverArray->valueRank = 1;
  620. serverArray->minimumSamplingInterval = 1.0;
  621. serverArray->historizing = UA_FALSE;
  622. UA_Server_addNode(server, (UA_Node*)serverArray,
  623. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  624. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY));
  625. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERARRAY),
  626. UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  627. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
  628. UA_ObjectNode *servercapablities = UA_ObjectNode_new();
  629. copyNames((UA_Node*)servercapablities, "ServerCapabilities");
  630. servercapablities->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERCAPABILITIES;
  631. UA_Server_addNode(server, (UA_Node*)servercapablities,
  632. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  633. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT));
  634. UA_VariableNode *localeIdArray = UA_VariableNode_new();
  635. copyNames((UA_Node*)localeIdArray, "LocaleIdArray");
  636. localeIdArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERCAPABILITIES_LOCALEIDARRAY;
  637. localeIdArray->value.variant.data = UA_Array_new(&UA_TYPES[UA_TYPES_STRING], 2);
  638. localeIdArray->value.variant.arrayLength = 2;
  639. localeIdArray->value.variant.type = &UA_TYPES[UA_TYPES_STRING];
  640. *(UA_String *)localeIdArray->value.variant.data = UA_STRING_ALLOC("en");
  641. localeIdArray->valueRank = 1;
  642. localeIdArray->minimumSamplingInterval = 1.0;
  643. localeIdArray->historizing = UA_FALSE;
  644. UA_Server_addNode(server, (UA_Node*)localeIdArray,
  645. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERCAPABILITIES),
  646. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY));
  647. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERCAPABILITIES_LOCALEIDARRAY), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  648. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
  649. UA_VariableNode *serverstatus = UA_VariableNode_new();
  650. copyNames((UA_Node*)serverstatus, "ServerStatus");
  651. serverstatus->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS);
  652. serverstatus->valueSource = UA_VALUESOURCE_DATASOURCE;
  653. serverstatus->value.dataSource = (UA_DataSource) {.handle = server, .read = readStatus,
  654. .release = releaseStatus, .write = UA_NULL};
  655. UA_Server_addNode(server, (UA_Node*)serverstatus, &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER),
  656. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT));
  657. UA_VariableNode *state = UA_VariableNode_new();
  658. UA_ServerState *stateEnum = UA_ServerState_new();
  659. *stateEnum = UA_SERVERSTATE_RUNNING;
  660. copyNames((UA_Node*)state, "State");
  661. state->nodeId.identifier.numeric = UA_NS0ID_SERVER_SERVERSTATUS_STATE;
  662. state->value.variant.type = &UA_TYPES[UA_TYPES_SERVERSTATE];
  663. state->value.variant.arrayLength = -1;
  664. state->value.variant.data = stateEnum; // points into the other object.
  665. UA_NodeStore_insert(server->nodestore, (UA_Node*)state, UA_NULL);
  666. ADDREFERENCE(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS), UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  667. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
  668. UA_VariableNode *currenttime = UA_VariableNode_new();
  669. copyNames((UA_Node*)currenttime, "CurrentTime");
  670. currenttime->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
  671. currenttime->valueSource = UA_VALUESOURCE_DATASOURCE;
  672. currenttime->value.dataSource = (UA_DataSource) {.handle = NULL, .read = readCurrentTime,
  673. .release = releaseCurrentTime, .write = UA_NULL};
  674. UA_Server_addNode(server, (UA_Node*)currenttime, &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS),
  675. &UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT));
  676. #ifdef DEMO_NODESET
  677. /**************/
  678. /* Demo Nodes */
  679. /**************/
  680. #define DEMOID 990
  681. UA_ObjectNode *demo = UA_ObjectNode_new();
  682. copyNames((UA_Node*)demo, "Demo");
  683. demo->nodeId = UA_NODEID_NUMERIC(1, DEMOID);
  684. UA_Server_addNode(server, (UA_Node*)demo,
  685. &UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  686. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  687. ADDREFERENCE(UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  688. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  689. #define SCALARID 991
  690. UA_ObjectNode *scalar = UA_ObjectNode_new();
  691. copyNames((UA_Node*)scalar, "Scalar");
  692. scalar->nodeId = UA_NODEID_NUMERIC(1, SCALARID);
  693. UA_Server_addNode(server, (UA_Node*)scalar,
  694. &UA_EXPANDEDNODEID_NUMERIC(1, DEMOID),
  695. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  696. ADDREFERENCE(UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  697. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  698. #define ARRAYID 992
  699. UA_ObjectNode *array = UA_ObjectNode_new();
  700. copyNames((UA_Node*)array, "Arrays");
  701. array->nodeId = UA_NODEID_NUMERIC(1, ARRAYID);
  702. UA_Server_addNode(server, (UA_Node*)array,
  703. &UA_EXPANDEDNODEID_NUMERIC(1, DEMOID),
  704. &UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  705. ADDREFERENCE(UA_NODEID_NUMERIC(1, ARRAYID), UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION),
  706. UA_EXPANDEDNODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE));
  707. UA_UInt32 id = 1000; //running id in namespace 1
  708. for(UA_UInt32 type = 0; UA_IS_BUILTIN(type); type++) {
  709. if(type == UA_TYPES_VARIANT || type == UA_TYPES_DIAGNOSTICINFO)
  710. continue;
  711. //add a scalar node for every built-in type
  712. void *value = UA_new(&UA_TYPES[type]);
  713. UA_Variant *variant = UA_Variant_new();
  714. UA_Variant_setScalar(variant, value, &UA_TYPES[type]);
  715. char name[15];
  716. sprintf(name, "%02d", type);
  717. UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, name);
  718. UA_Server_addVariableNode(server, variant, myIntegerName, UA_NODEID_NUMERIC(1, ++id),
  719. UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  720. //add an array node for every built-in type
  721. UA_Variant *arrayvar = UA_Variant_new();
  722. UA_Variant_setArray(arrayvar, UA_Array_new(&UA_TYPES[type], 10), 10, &UA_TYPES[type]);
  723. UA_Server_addVariableNode(server, arrayvar, myIntegerName, UA_NODEID_NUMERIC(1, ++id),
  724. UA_NODEID_NUMERIC(1, ARRAYID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES));
  725. }
  726. #endif
  727. return server;
  728. }