server_ctt.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #ifdef _MSC_VER
  4. #define _CRT_SECURE_NO_WARNINGS /* disable fopen deprication warning in msvs */
  5. #endif
  6. #include <signal.h>
  7. #include <errno.h> // errno, EINTR
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <open62541.h>
  12. #include "open62541.h"
  13. #include "common.h"
  14. /* This server is configured to the Compliance Testing Tools (CTT) against. The
  15. * corresponding CTT configuration is available at
  16. * https://github.com/open62541/open62541-ctt */
  17. UA_Boolean running = true;
  18. UA_Logger logger = UA_Log_Stdout;
  19. static const UA_NodeId baseDataVariableType = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_BASEDATAVARIABLETYPE}};
  20. static void
  21. stopHandler(int sign) {
  22. UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Received Ctrl-C");
  23. running = 0;
  24. }
  25. /* Datasource Example */
  26. static UA_StatusCode
  27. readTimeData(UA_Server *server,
  28. const UA_NodeId *sessionId, void *sessionContext,
  29. const UA_NodeId *nodeId, void *nodeContext,
  30. UA_Boolean sourceTimeStamp,
  31. const UA_NumericRange *range, UA_DataValue *value) {
  32. if(range) {
  33. value->hasStatus = true;
  34. value->status = UA_STATUSCODE_BADINDEXRANGEINVALID;
  35. return UA_STATUSCODE_GOOD;
  36. }
  37. UA_DateTime currentTime = UA_DateTime_now();
  38. UA_Variant_setScalarCopy(&value->value, &currentTime, &UA_TYPES[UA_TYPES_DATETIME]);
  39. value->hasValue = true;
  40. if(sourceTimeStamp) {
  41. value->hasSourceTimestamp = true;
  42. value->sourceTimestamp = currentTime;
  43. }
  44. return UA_STATUSCODE_GOOD;
  45. }
  46. /* Method Node Example */
  47. #ifdef UA_ENABLE_METHODCALLS
  48. static UA_StatusCode
  49. helloWorld(UA_Server *server,
  50. const UA_NodeId *sessionId, void *sessionContext,
  51. const UA_NodeId *methodId, void *methodContext,
  52. const UA_NodeId *objectId, void *objectContext,
  53. size_t inputSize, const UA_Variant *input,
  54. size_t outputSize, UA_Variant *output) {
  55. /* input is a scalar string (checked by the server) */
  56. UA_String *name = (UA_String *)input[0].data;
  57. UA_String hello = UA_STRING("Hello ");
  58. UA_String greet;
  59. greet.length = hello.length + name->length;
  60. greet.data = (UA_Byte *)UA_malloc(greet.length);
  61. memcpy(greet.data, hello.data, hello.length);
  62. memcpy(greet.data + hello.length, name->data, name->length);
  63. UA_Variant_setScalarCopy(output, &greet, &UA_TYPES[UA_TYPES_STRING]);
  64. UA_String_deleteMembers(&greet);
  65. return UA_STATUSCODE_GOOD;
  66. }
  67. static UA_StatusCode
  68. noargMethod(UA_Server *server,
  69. const UA_NodeId *sessionId, void *sessionContext,
  70. const UA_NodeId *methodId, void *methodContext,
  71. const UA_NodeId *objectId, void *objectContext,
  72. size_t inputSize, const UA_Variant *input,
  73. size_t outputSize, UA_Variant *output) {
  74. return UA_STATUSCODE_GOOD;
  75. }
  76. static UA_StatusCode
  77. outargMethod(UA_Server *server,
  78. const UA_NodeId *sessionId, void *sessionContext,
  79. const UA_NodeId *methodId, void *methodContext,
  80. const UA_NodeId *objectId, void *objectContext,
  81. size_t inputSize, const UA_Variant *input,
  82. size_t outputSize, UA_Variant *output) {
  83. UA_Int32 out = 42;
  84. UA_Variant_setScalarCopy(output, &out, &UA_TYPES[UA_TYPES_INT32]);
  85. return UA_STATUSCODE_GOOD;
  86. }
  87. #endif
  88. int
  89. main(int argc, char **argv) {
  90. signal(SIGINT, stopHandler); /* catches ctrl-c */
  91. signal(SIGTERM, stopHandler);
  92. #ifdef UA_ENABLE_ENCRYPTION
  93. if(argc < 3) {
  94. UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  95. "Missing arguments for encryption support. "
  96. "Arguments are <server-certificate.der> "
  97. "<private-key.der> [<trustlist1.crl>, ...]");
  98. return 1;
  99. }
  100. /* Load certificate and private key */
  101. UA_ByteString certificate = loadFile(argv[1]);
  102. UA_ByteString privateKey = loadFile(argv[2]);
  103. /* Load the trustlist */
  104. size_t trustListSize = 0;
  105. if(argc > 3)
  106. trustListSize = (size_t)argc-3;
  107. UA_STACKARRAY(UA_ByteString, trustList, trustListSize);
  108. for(size_t i = 0; i < trustListSize; i++)
  109. trustList[i] = loadFile(argv[i+3]);
  110. /* Loading of a revocation list currently unsupported */
  111. UA_ByteString *revocationList = NULL;
  112. size_t revocationListSize = 0;
  113. UA_ServerConfig *config =
  114. UA_ServerConfig_new_allSecurityPolicies(4840, &certificate, &privateKey,
  115. trustList, trustListSize,
  116. revocationList, revocationListSize);
  117. UA_ByteString_deleteMembers(&certificate);
  118. UA_ByteString_deleteMembers(&privateKey);
  119. for(size_t i = 0; i < trustListSize; i++)
  120. UA_ByteString_deleteMembers(&trustList[i]);
  121. if(!config) {
  122. UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  123. "Could not create the server config");
  124. return 1;
  125. }
  126. #else
  127. if(argc < 2) {
  128. UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  129. "Missing argument for the server certificate");
  130. return 1;
  131. }
  132. UA_ByteString certificate = loadFile(argv[1]);
  133. UA_ServerConfig *config = UA_ServerConfig_new_minimal(4840, &certificate);
  134. UA_ByteString_deleteMembers(&certificate);
  135. #endif
  136. /* uncomment next line to add a custom hostname */
  137. // UA_ServerConfig_set_customHostname(config, UA_STRING("custom"));
  138. UA_Server *server = UA_Server_new(config);
  139. if(server == NULL)
  140. return 1;
  141. /* add a static variable node to the server */
  142. UA_VariableAttributes myVar = UA_VariableAttributes_default;
  143. myVar.description = UA_LOCALIZEDTEXT("en-US", "the answer");
  144. myVar.displayName = UA_LOCALIZEDTEXT("en-US", "the answer");
  145. myVar.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  146. myVar.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  147. myVar.valueRank = -1;
  148. UA_Int32 myInteger = 42;
  149. UA_Variant_setScalarCopy(&myVar.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  150. const UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
  151. const UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
  152. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  153. UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  154. UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId,
  155. myIntegerName, baseDataVariableType, myVar, NULL, NULL);
  156. UA_Variant_deleteMembers(&myVar.value);
  157. /* add a static variable that is readable but not writable*/
  158. myVar = UA_VariableAttributes_default;
  159. myVar.description = UA_LOCALIZEDTEXT("en-US", "the answer - not readable");
  160. myVar.displayName = UA_LOCALIZEDTEXT("en-US", "the answer - not readable");
  161. myVar.accessLevel = UA_ACCESSLEVELMASK_WRITE;
  162. myVar.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  163. myVar.valueRank = -1;
  164. UA_Variant_setScalarCopy(&myVar.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  165. const UA_QualifiedName myInteger2Name = UA_QUALIFIEDNAME(1, "the answer - not readable");
  166. const UA_NodeId myInteger2NodeId = UA_NODEID_STRING(1, "the.answer.no.read");
  167. UA_Server_addVariableNode(server, myInteger2NodeId, parentNodeId, parentReferenceNodeId,
  168. myInteger2Name, baseDataVariableType, myVar, NULL, NULL);
  169. UA_Variant_deleteMembers(&myVar.value);
  170. /* add a variable with the datetime data source */
  171. UA_DataSource dateDataSource;
  172. dateDataSource.read = readTimeData;
  173. dateDataSource.write = NULL;
  174. UA_VariableAttributes v_attr = UA_VariableAttributes_default;
  175. v_attr.description = UA_LOCALIZEDTEXT("en-US", "current time");
  176. v_attr.displayName = UA_LOCALIZEDTEXT("en-US", "current time");
  177. v_attr.accessLevel = UA_ACCESSLEVELMASK_READ;
  178. v_attr.dataType = UA_TYPES[UA_TYPES_DATETIME].typeId;
  179. v_attr.valueRank = -1;
  180. const UA_QualifiedName dateName = UA_QUALIFIEDNAME(1, "current time");
  181. UA_Server_addDataSourceVariableNode(server, UA_NODEID_NULL, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  182. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), dateName,
  183. baseDataVariableType, v_attr, dateDataSource, NULL, NULL);
  184. /* Add HelloWorld method to the server */
  185. #ifdef UA_ENABLE_METHODCALLS
  186. /* Method with IO Arguments */
  187. UA_Argument inputArguments;
  188. UA_Argument_init(&inputArguments);
  189. inputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
  190. inputArguments.description = UA_LOCALIZEDTEXT("en-US", "Say your name");
  191. inputArguments.name = UA_STRING("Name");
  192. inputArguments.valueRank = -1; /* scalar argument */
  193. UA_Argument outputArguments;
  194. UA_Argument_init(&outputArguments);
  195. outputArguments.arrayDimensionsSize = 0;
  196. outputArguments.arrayDimensions = NULL;
  197. outputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
  198. outputArguments.description = UA_LOCALIZEDTEXT("en-US", "Receive a greeting");
  199. outputArguments.name = UA_STRING("greeting");
  200. outputArguments.valueRank = -1;
  201. UA_MethodAttributes addmethodattributes = UA_MethodAttributes_default;
  202. addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "Hello World");
  203. addmethodattributes.executable = true;
  204. addmethodattributes.userExecutable = true;
  205. UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, 62541),
  206. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  207. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  208. UA_QUALIFIEDNAME(1, "hello_world"), addmethodattributes,
  209. &helloWorld, /* callback of the method node */
  210. 1, &inputArguments, 1, &outputArguments, NULL, NULL);
  211. #endif
  212. /* Add folders for demo information model */
  213. #define DEMOID 50000
  214. #define SCALARID 50001
  215. #define ARRAYID 50002
  216. #define MATRIXID 50003
  217. #define DEPTHID 50004
  218. UA_ObjectAttributes object_attr = UA_ObjectAttributes_default;
  219. object_attr.description = UA_LOCALIZEDTEXT("en-US", "Demo");
  220. object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Demo");
  221. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, DEMOID),
  222. UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
  223. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_QUALIFIEDNAME(1, "Demo"),
  224. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
  225. object_attr.description = UA_LOCALIZEDTEXT("en-US", "Scalar");
  226. object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Scalar");
  227. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, SCALARID),
  228. UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  229. UA_QUALIFIEDNAME(1, "Scalar"),
  230. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
  231. object_attr.description = UA_LOCALIZEDTEXT("en-US", "Array");
  232. object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Array");
  233. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, ARRAYID),
  234. UA_NODEID_NUMERIC(1, DEMOID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  235. UA_QUALIFIEDNAME(1, "Array"),
  236. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
  237. object_attr.description = UA_LOCALIZEDTEXT("en-US", "Matrix");
  238. object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "Matrix");
  239. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, MATRIXID), UA_NODEID_NUMERIC(1, DEMOID),
  240. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_QUALIFIEDNAME(1, "Matrix"),
  241. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
  242. /* Fill demo nodes for each type*/
  243. UA_UInt32 id = 51000; // running id in namespace 0
  244. for(UA_UInt32 type = 0; type < UA_TYPES_DIAGNOSTICINFO; type++) {
  245. if(type == UA_TYPES_VARIANT || type == UA_TYPES_DIAGNOSTICINFO)
  246. continue;
  247. UA_VariableAttributes attr = UA_VariableAttributes_default;
  248. attr.valueRank = -2;
  249. attr.dataType = UA_TYPES[type].typeId;
  250. #ifndef UA_ENABLE_TYPENAMES
  251. char name[15];
  252. #if defined(_WIN32) && !defined(__MINGW32__)
  253. sprintf_s(name, 15, "%02d", type);
  254. #else
  255. sprintf(name, "%02d", type);
  256. #endif
  257. attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
  258. UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME(1, name);
  259. #else
  260. attr.displayName = UA_LOCALIZEDTEXT_ALLOC("en-US", UA_TYPES[type].typeName);
  261. UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME_ALLOC(1, UA_TYPES[type].typeName);
  262. #endif
  263. attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE;
  264. attr.writeMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
  265. attr.userWriteMask = UA_WRITEMASK_DISPLAYNAME | UA_WRITEMASK_DESCRIPTION;
  266. /* add a scalar node for every built-in type */
  267. void *value = UA_new(&UA_TYPES[type]);
  268. UA_Variant_setScalar(&attr.value, value, &UA_TYPES[type]);
  269. UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id),
  270. UA_NODEID_NUMERIC(1, SCALARID), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  271. qualifiedName, baseDataVariableType, attr, NULL, NULL);
  272. UA_Variant_deleteMembers(&attr.value);
  273. /* add an array node for every built-in type */
  274. UA_Variant_setArray(&attr.value, UA_Array_new(10, &UA_TYPES[type]), 10, &UA_TYPES[type]);
  275. UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), UA_NODEID_NUMERIC(1, ARRAYID),
  276. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), qualifiedName,
  277. baseDataVariableType, attr, NULL, NULL);
  278. UA_Variant_deleteMembers(&attr.value);
  279. /* add an matrix node for every built-in type */
  280. void *myMultiArray = UA_Array_new(9, &UA_TYPES[type]);
  281. attr.value.arrayDimensions = (UA_UInt32 *)UA_Array_new(2, &UA_TYPES[UA_TYPES_INT32]);
  282. attr.value.arrayDimensions[0] = 3;
  283. attr.value.arrayDimensions[1] = 3;
  284. attr.value.arrayDimensionsSize = 2;
  285. attr.value.arrayLength = 9;
  286. attr.value.data = myMultiArray;
  287. attr.value.type = &UA_TYPES[type];
  288. UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, ++id), UA_NODEID_NUMERIC(1, MATRIXID),
  289. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), qualifiedName,
  290. baseDataVariableType, attr, NULL, NULL);
  291. UA_Variant_deleteMembers(&attr.value);
  292. #ifdef UA_ENABLE_TYPENAMES
  293. UA_LocalizedText_deleteMembers(&attr.displayName);
  294. UA_QualifiedName_deleteMembers(&qualifiedName);
  295. #endif
  296. }
  297. /* Hierarchy of depth 10 for CTT testing with forward and inverse references */
  298. /* Enter node "depth 9" in CTT configuration - Project->Settings->Server
  299. Test->NodeIds->Paths->Starting Node 1 */
  300. object_attr.description = UA_LOCALIZEDTEXT("en-US", "DepthDemo");
  301. object_attr.displayName = UA_LOCALIZEDTEXT("en-US", "DepthDemo");
  302. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, DEPTHID), UA_NODEID_NUMERIC(1, DEMOID),
  303. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), UA_QUALIFIEDNAME(1, "DepthDemo"),
  304. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
  305. id = DEPTHID; // running id in namespace 0 - Start with Matrix NODE
  306. for(UA_UInt32 i = 1; i <= 20; i++) {
  307. char name[15];
  308. #if defined(_WIN32) && !defined(__MINGW32__)
  309. sprintf_s(name, 15, "depth%i", i);
  310. #else
  311. sprintf(name, "depth%i", i);
  312. #endif
  313. object_attr.description = UA_LOCALIZEDTEXT("en-US", name);
  314. object_attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
  315. UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, id + i),
  316. UA_NODEID_NUMERIC(1, i == 1 ? DEPTHID : id + i - 1),
  317. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
  318. UA_QUALIFIEDNAME(1, name),
  319. UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL);
  320. }
  321. /* Add the variable to some more places to get a node with three inverse references for the CTT */
  322. UA_ExpandedNodeId answer_nodeid = UA_EXPANDEDNODEID_STRING(1, "the.answer");
  323. UA_Server_addReference(server, UA_NODEID_NUMERIC(1, DEMOID),
  324. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), answer_nodeid, true);
  325. UA_Server_addReference(server, UA_NODEID_NUMERIC(1, SCALARID),
  326. UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), answer_nodeid, true);
  327. /* Example for manually setting an attribute within the server */
  328. UA_LocalizedText objectsName = UA_LOCALIZEDTEXT("en-US", "Objects");
  329. UA_Server_writeDisplayName(server, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), objectsName);
  330. #define NOARGID 60000
  331. #define INARGID 60001
  332. #define OUTARGID 60002
  333. #define INOUTARGID 60003
  334. #ifdef UA_ENABLE_METHODCALLS
  335. /* adding some more method nodes to pass CTT */
  336. /* Method without arguments */
  337. addmethodattributes = UA_MethodAttributes_default;
  338. addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "noarg");
  339. addmethodattributes.executable = true;
  340. addmethodattributes.userExecutable = true;
  341. UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, NOARGID),
  342. UA_NODEID_NUMERIC(1, DEMOID),
  343. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  344. UA_QUALIFIEDNAME(1, "noarg"), addmethodattributes,
  345. &noargMethod, /* callback of the method node */
  346. 0, NULL, 0, NULL, NULL, NULL);
  347. /* Method with in arguments */
  348. addmethodattributes = UA_MethodAttributes_default;
  349. addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "inarg");
  350. addmethodattributes.executable = true;
  351. addmethodattributes.userExecutable = true;
  352. UA_Argument_init(&inputArguments);
  353. inputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  354. inputArguments.description = UA_LOCALIZEDTEXT("en-US", "Input");
  355. inputArguments.name = UA_STRING("Input");
  356. inputArguments.valueRank = -1; //uaexpert will crash if set to 0 ;)
  357. UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, INARGID),
  358. UA_NODEID_NUMERIC(1, DEMOID),
  359. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  360. UA_QUALIFIEDNAME(1, "noarg"), addmethodattributes,
  361. &noargMethod, /* callback of the method node */
  362. 1, &inputArguments, 0, NULL, NULL, NULL);
  363. /* Method with out arguments */
  364. addmethodattributes = UA_MethodAttributes_default;
  365. addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "outarg");
  366. addmethodattributes.executable = true;
  367. addmethodattributes.userExecutable = true;
  368. UA_Argument_init(&outputArguments);
  369. outputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
  370. outputArguments.description = UA_LOCALIZEDTEXT("en-US", "Output");
  371. outputArguments.name = UA_STRING("Output");
  372. outputArguments.valueRank = -1;
  373. UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, OUTARGID),
  374. UA_NODEID_NUMERIC(1, DEMOID),
  375. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  376. UA_QUALIFIEDNAME(1, "outarg"), addmethodattributes,
  377. &outargMethod, /* callback of the method node */
  378. 0, NULL, 1, &outputArguments, NULL, NULL);
  379. /* Method with inout arguments */
  380. addmethodattributes = UA_MethodAttributes_default;
  381. addmethodattributes.displayName = UA_LOCALIZEDTEXT("en-US", "inoutarg");
  382. addmethodattributes.executable = true;
  383. addmethodattributes.userExecutable = true;
  384. UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1, INOUTARGID),
  385. UA_NODEID_NUMERIC(1, DEMOID),
  386. UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
  387. UA_QUALIFIEDNAME(1, "inoutarg"), addmethodattributes,
  388. &outargMethod, /* callback of the method node */
  389. 1, &inputArguments, 1, &outputArguments, NULL, NULL);
  390. #endif
  391. /* run server */
  392. UA_StatusCode retval = UA_Server_run(server, &running);
  393. UA_Server_delete(server);
  394. UA_ServerConfig_delete(config);
  395. return (int)retval;
  396. }