Browse Source

examples for user-facing API discussion

Julius Pfrommer 9 years ago
parent
commit
31156aa0e4
2 changed files with 46 additions and 0 deletions
  1. 19 0
      examples/api-design/open62541-server.h
  2. 27 0
      examples/api-design/server.c

+ 19 - 0
examples/api-design/open62541-server.h

@@ -0,0 +1,19 @@
+#include "open62541.h"
+
+struct UA_NetworkLayer;
+typedef struct UA_NetworkLayer UA_NetworkLayer;
+
+struct UA_Application;
+typedef struct UA_Application UA_Application;
+
+typedef struct UA_ServerConfiguration {
+	UA_String certificatePublic;
+	UA_String certificatePrivate;
+	UA_Networklayer *networklayer;
+} UA_ServerConfiguration;
+
+typedef struct UA_Server {
+	UA_ServerConfiguration configuration;
+	UA_Int32 applicationsSize;
+	UA_Application *applications;
+} UA_Server;

+ 27 - 0
examples/api-design/server.c

@@ -0,0 +1,27 @@
+#include "open62541.h"
+#include "open62541-server.h"
+#include "open62541-tcp.h"
+
+int main(int argc, char ** argv) {
+	UA_Server *server;
+	UA_Server_new(&server);
+
+	#define PORT 1234
+	#define MAX_CONNECTIONS 1024
+	UA_TcpNetworkLayer_new(&server.configuration.networklayer, PORT, MAX_CONNECTIONS);
+
+	UA_Application *application;
+	UA_Application_new(&application, UA_STRING_STATIC("MyApplication"));
+	UA_Application_addNamespace(application, 1);
+	UA_Server_addApplication(server, application);
+
+	UA_Int32 myInteger = 0;
+	UA_NodeId myIntegerNode = {1, UA_NODEIDTYPE_NUMERIC, 50};
+	UA_Application_addVariableNode(application, &myIntegerNode, UA_INT32, &myInteger);
+
+	UA_Server_start(server); // runs a loop until shutdown is triggered
+	UA_Application_delete(application);
+	UA_Server_delete(server);
+
+	return 0;
+}