opcuaServer.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  3. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  4. */
  5. #include <stdio.h>
  6. #ifndef WIN32
  7. #include <sys/mman.h>
  8. #include <sys/wait.h>
  9. #include <unistd.h>
  10. #endif
  11. #include <sys/types.h>
  12. #include <sys/time.h>
  13. #include <fcntl.h>
  14. #include <signal.h>
  15. #include "server/ua_server.h"
  16. #include "logger_stdout.h"
  17. #include "networklayer_tcp.h"
  18. UA_Boolean running = UA_TRUE;
  19. void stopHandler(int sign) {
  20. running = UA_FALSE;
  21. }
  22. void serverCallback(UA_Server *server) {
  23. printf("does whatever servers do\n");
  24. }
  25. int main(int argc, char** argv) {
  26. signal(SIGINT, stopHandler); /* catches ctrl-c */
  27. UA_Server server;
  28. UA_String endpointUrl;
  29. UA_String_copycstring("no endpoint url",&endpointUrl);
  30. UA_Server_init(&server, &endpointUrl);
  31. Logger_Stdout_init(&server.logger);
  32. NetworklayerTCP* nl;
  33. NetworklayerTCP_new(&nl, UA_ConnectionConfig_standard, 16664);
  34. struct timeval callback_interval = {1, 0}; // 1 second
  35. UA_Int32 retval = NetworkLayerTCP_run(nl, &server, callback_interval,
  36. serverCallback, &running);
  37. NetworklayerTCP_delete(nl);
  38. UA_Server_deleteMembers(&server);
  39. return retval == UA_SUCCESS ? 0 : retval;
  40. }