Skip to content

Commit

Permalink
move logger and connection-function into the client config (open62541…
Browse files Browse the repository at this point in the history
…#585)

* move logger and connection-function into the client config;
move the standard config definition into a plugin

* remove redundant definition from example servers
  • Loading branch information
jpfr committed Apr 19, 2016
1 parent 344f83b commit 5e87c1d
Show file tree
Hide file tree
Showing 26 changed files with 226 additions and 197 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
${PROJECT_SOURCE_DIR}/include/ua_client.h
${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h
${PROJECT_SOURCE_DIR}/plugins/networklayer_tcp.h
${PROJECT_SOURCE_DIR}/plugins/logger_stdout.h)
${PROJECT_SOURCE_DIR}/plugins/logger_stdout.h
${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.h)
set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
${PROJECT_SOURCE_DIR}/deps/libc_time.h
Expand Down Expand Up @@ -216,6 +217,7 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
${PROJECT_SOURCE_DIR}/plugins/networklayer_tcp.c
${PROJECT_SOURCE_DIR}/plugins/logger_stdout.c
${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
${PROJECT_SOURCE_DIR}/deps/libc_time.c
${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
##TODO: make client stuff optional
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ int main(int argc, char** argv)
/* init the server */
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, PORT);
UA_ServerConfig config = UA_ServerConfig_standard;
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down Expand Up @@ -91,9 +90,8 @@ int main(int argc, char** argv)
int main(int argc, char *argv[])
{
/* create a client and connect */
UA_Client *client = UA_Client_new(UA_ClientConfig_standard, Logger_Stdout);
UA_StatusCode retval = UA_Client_connect(client, UA_ClientConnectionTCP,
"opc.tcp://localhost:16664");
UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664");
if(retval != UA_STATUSCODE_GOOD) {
UA_Client_delete(client);
return retval;
Expand Down
15 changes: 9 additions & 6 deletions examples/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# include "ua_client_highlevel.h"
# include "ua_nodeids.h"
# include "networklayer_tcp.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "ua_types_encoding_binary.h"
#else
# include "open62541.h"
Expand All @@ -23,20 +23,23 @@ static UA_StatusCode
nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, void *handle) {
UA_NodeId *parent = (UA_NodeId *) handle;

if (!isInverse) {
printf("%d, %d --- %d ---> NodeId %d, %d\n", parent->namespaceIndex, parent->identifier.numeric, referenceTypeId.identifier.numeric, childId.namespaceIndex, childId.identifier.numeric);
if(!isInverse) {
printf("%d, %d --- %d ---> NodeId %d, %d\n",
parent->namespaceIndex, parent->identifier.numeric,
referenceTypeId.identifier.numeric, childId.namespaceIndex,
childId.identifier.numeric);
}
return UA_STATUSCODE_GOOD;
}

int main(int argc, char *argv[]) {
UA_Client *client = UA_Client_new(UA_ClientConfig_standard, Logger_Stdout);
UA_Client *client = UA_Client_new(UA_ClientConfig_standard);

//listing endpoints
UA_EndpointDescription* endpointArray = NULL;
size_t endpointArraySize = 0;
UA_StatusCode retval =
UA_Client_getEndpoints(client, UA_ClientConnectionTCP, "opc.tcp://localhost:16664",
UA_Client_getEndpoints(client, "opc.tcp://localhost:16664",
&endpointArraySize, &endpointArray);

//freeing the endpointArray
Expand All @@ -57,7 +60,7 @@ int main(int argc, char *argv[]) {

//connect to a server
//anonymous connect would be: retval = UA_Client_connect_username(client, UA_ClientConnectionTCP, "opc.tcp://localhost:16664");
retval = UA_Client_connect_username(client, UA_ClientConnectionTCP, "opc.tcp://localhost:16664", "user1", "password");
retval = UA_Client_connect_username(client, "opc.tcp://localhost:16664", "user1", "password");

if(retval != UA_STATUSCODE_GOOD) {
UA_Client_delete(client);
Expand Down
11 changes: 4 additions & 7 deletions examples/client_firstSteps.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
#include <stdio.h>

#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "networklayer_tcp.h"
# include "ua_client.h"
# include "ua_config_standard.h"
#else
# include "open62541.h"
#endif

int main(void) {
UA_Client *client = UA_Client_new(UA_ClientConfig_standard, Logger_Stdout);
UA_StatusCode retval = UA_Client_connect(client, UA_ClientConnectionTCP,
"opc.tcp://localhost:16664");
UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664");
if(retval != UA_STATUSCODE_GOOD) {
UA_Client_delete(client);
return (int)retval;
Expand Down
3 changes: 1 addition & 2 deletions examples/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# include <time.h>
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand Down Expand Up @@ -214,7 +214,6 @@ int main(int argc, char** argv) {

UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
UA_ServerConfig config = UA_ServerConfig_standard;
config.logger = Logger_Stdout;
config.serverCertificate = loadCertificate();
config.networkLayers = &nl;
config.networkLayersSize = 1;
Expand Down
1 change: 0 additions & 1 deletion examples/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ int main() {

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
3 changes: 1 addition & 2 deletions examples/server_datasource.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand Down Expand Up @@ -54,7 +54,6 @@ int main(int argc, char** argv) {

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
3 changes: 1 addition & 2 deletions examples/server_firstSteps.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand All @@ -24,7 +24,6 @@ int main(void) {

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
3 changes: 1 addition & 2 deletions examples/server_mainloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand All @@ -35,7 +35,6 @@ int main(int argc, char** argv) {

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
3 changes: 1 addition & 2 deletions examples/server_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand Down Expand Up @@ -71,7 +71,6 @@ int main(int argc, char** argv) {
/* initialize the server */
UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
3 changes: 1 addition & 2 deletions examples/server_nodeset.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand All @@ -32,7 +32,6 @@ int main(int argc, char** argv) {
/* initialize the server */
UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
5 changes: 2 additions & 3 deletions examples/server_readspeed.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# include "ua_types.h"
# include "ua_types_generated.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand All @@ -32,8 +32,7 @@ int main(int argc, char** argv) {
signal(SIGINT, stopHandler); /* catches ctrl-c */

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664, logger);
config.logger = Logger_Stdout;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
3 changes: 1 addition & 2 deletions examples/server_repeated_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand All @@ -31,7 +31,6 @@ int main(int argc, char** argv) {

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
3 changes: 1 addition & 2 deletions examples/server_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifdef UA_NO_AMALGAMATION
# include "ua_types.h"
# include "ua_server.h"
# include "logger_stdout.h"
# include "ua_config_standard.h"
# include "networklayer_tcp.h"
#else
# include "open62541.h"
Expand All @@ -35,7 +35,6 @@ int main(int argc, char** argv) {

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.logger = Logger_Stdout;
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
Expand Down
Loading

0 comments on commit 5e87c1d

Please sign in to comment.