opcuaServer.c 1.0 KB

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