Skip to content

Commit

Permalink
endpoints in the server config; new/delete functions for the server c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
mlgiraud authored and jpfr committed Aug 15, 2017
1 parent 03369fd commit a8012d3
Show file tree
Hide file tree
Showing 47 changed files with 615 additions and 626 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
${PROJECT_SOURCE_DIR}/include/ua_plugin_network.h
${PROJECT_SOURCE_DIR}/include/ua_plugin_log.h
${PROJECT_SOURCE_DIR}/include/ua_plugin_access_control.h
${PROJECT_SOURCE_DIR}/include/ua_plugin_securitypolicy.h
${PROJECT_SOURCE_DIR}/include/ua_server.h
${PROJECT_SOURCE_DIR}/include/ua_client.h
${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h
Expand Down Expand Up @@ -328,7 +329,6 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
${PROJECT_SOURCE_DIR}/src/client/ua_client_discovery.c
${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c

# dependencies
${PROJECT_SOURCE_DIR}/deps/libc_time.c
${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
Expand All @@ -338,6 +338,7 @@ set(default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c)

if(UA_DEBUG_DUMP_PKGS)
list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/plugins/ua_debug_dump_pkgs.c)
endif()
Expand Down Expand Up @@ -677,5 +678,5 @@ set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_CmakePredifinedTargets"
set_target_properties(open62541 PROPERTIES FOLDER "open62541/lib")
set_target_properties(open62541-object PROPERTIES FOLDER "open62541/lib")
set_target_properties(lint PROPERTIES FOLDER "CodeAnalysis")
set_target_properties(open62541_amalgamation_header PROPERTIES FOLDER "open62541/lib")
set_target_properties(open62541_amalgamation_source PROPERTIES FOLDER "open62541/lib")
set_target_properties(open62541-amalgamation-header PROPERTIES FOLDER "open62541/lib")
set_target_properties(open62541-amalgamation-source PROPERTIES FOLDER "open62541/lib")
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ int main(int argc, char** argv)
{
signal(SIGINT, signalHandler); /* catch ctrl-c */

/* Create a server with one network layer listening on port 4840 */
UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840);
config.networkLayers = &nl;
config.networkLayersSize = 1;
/* Create a server listening on port 4840 */
UA_ServerConfig *config = UA_ServerConfig_new_default();
UA_Server *server = UA_Server_new(config);

/* Add a variable node */
Expand All @@ -109,7 +106,7 @@ int main(int argc, char** argv)
/* Run the server loop */
UA_StatusCode status = UA_Server_run(server, &running);
UA_Server_delete(server);
nl.deleteMembers(&nl);
UA_ServerConfig_delete(config);
return status;
}
```
Expand All @@ -122,7 +119,7 @@ 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);
UA_Client *client = UA_Client_new(UA_ClientConfig_default);
UA_StatusCode status = UA_Client_connect(client, "opc.tcp://localhost:4840");
if(status != UA_STATUSCODE_GOOD) {
UA_Client_delete(client);
Expand Down
10 changes: 5 additions & 5 deletions examples/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, voi
}

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

/* Listing endpoints */
UA_EndpointDescription* endpointArray = NULL;
size_t endpointArraySize = 0;
UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:16664",
UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:4840",
&endpointArraySize, &endpointArray);
if(retval != UA_STATUSCODE_GOOD) {
UA_Array_delete(endpointArray, endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
Expand All @@ -45,8 +45,8 @@ int main(int argc, char *argv[]) {
UA_Array_delete(endpointArray,endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);

/* Connect to a server */
/* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); */
retval = UA_Client_connect_username(client, "opc.tcp://localhost:16664", "user1", "password");
/* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); */
retval = UA_Client_connect_username(client, "opc.tcp://localhost:4840", "user1", "password");
if(retval != UA_STATUSCODE_GOOD) {
UA_Client_delete(client);
return (int)retval;
Expand Down Expand Up @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) {
#ifdef UA_ENABLE_SUBSCRIPTIONS
/* Create a subscription */
UA_UInt32 subId = 0;
UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_standard, &subId);
UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
if(subId)
printf("Create subscription succeeded, id %u\n", subId);
/* Add a MonitoredItem */
Expand Down
28 changes: 15 additions & 13 deletions examples/discovery/client_find_servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ int main(void) {
UA_ServerOnNetwork *serverOnNetwork = NULL;
size_t serverOnNetworkSize = 0;

UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
UA_Client *client = UA_Client_new(UA_ClientConfig_default);
UA_StatusCode retval = UA_Client_findServersOnNetwork(client, DISCOVERY_SERVER_ENDPOINT, 0, 0,
0, NULL, &serverOnNetworkSize, &serverOnNetwork);
if (retval != UA_STATUSCODE_GOOD) {
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not call FindServersOnNetwork service. Is the discovery server started? StatusCode %s",
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER,
"Could not call FindServersOnNetwork service. "
"Is the discovery server started? StatusCode %s",
UA_StatusCode_name(retval));
UA_Client_delete(client);
return (int) retval;
Expand All @@ -36,30 +38,30 @@ int main(void) {
// output all the returned/registered servers
for (size_t i = 0; i < serverOnNetworkSize; i++) {
UA_ServerOnNetwork *server = &serverOnNetwork[i];
printf("Server[%lu]: %.*s", (unsigned long) i, (int) server->serverName.length, server->serverName.data);
printf("Server[%lu]: %.*s", (unsigned long) i,
(int) server->serverName.length, server->serverName.data);
printf("\n\tRecordID: %d", server->recordId);
printf("\n\tDiscovery URL: %.*s", (int) server->discoveryUrl.length, server->discoveryUrl.data);
printf("\n\tDiscovery URL: %.*s", (int) server->discoveryUrl.length,
server->discoveryUrl.data);
printf("\n\tCapabilities: ");
for (size_t j = 0; j < server->serverCapabilitiesSize; j++) {
printf("%.*s,", (int) server->serverCapabilities[j].length, server->serverCapabilities[j].data);
printf("%.*s,", (int) server->serverCapabilities[j].length,
server->serverCapabilities[j].data);
}
printf("\n\n");
}

UA_Array_delete(serverOnNetwork, serverOnNetworkSize, &UA_TYPES[UA_TYPES_SERVERONNETWORK]);
UA_Array_delete(serverOnNetwork, serverOnNetworkSize,
&UA_TYPES[UA_TYPES_SERVERONNETWORK]);
}

/*
* Example for calling FindServers
*/


/* Example for calling FindServers */
UA_ApplicationDescription *applicationDescriptionArray = NULL;
size_t applicationDescriptionArraySize = 0;

UA_StatusCode retval;
{
UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
UA_Client *client = UA_Client_new(UA_ClientConfig_default);
retval = UA_Client_findServers(client, DISCOVERY_SERVER_ENDPOINT, 0, NULL, 0, NULL,
&applicationDescriptionArraySize, &applicationDescriptionArray);
UA_Client_delete(client);
Expand Down Expand Up @@ -126,7 +128,7 @@ int main(void) {
printf("\nEndpoints for Server[%lu]: %.*s\n", (unsigned long) i,
(int) description->applicationUri.length, description->applicationUri.data);

UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
UA_Client *client = UA_Client_new(UA_ClientConfig_default);

char *discoveryUrl = (char *) UA_malloc(sizeof(char) * description->discoveryUrls[0].length + 1);
memcpy(discoveryUrl, description->discoveryUrls[0].data, description->discoveryUrls[0].length);
Expand Down
23 changes: 9 additions & 14 deletions examples/discovery/server_lds.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,28 @@ int main(void) {
signal(SIGINT, stopHandler);
signal(SIGTERM, stopHandler);

UA_ServerConfig config = UA_ServerConfig_standard;
config.applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
config.applicationDescription.applicationUri =
UA_ServerConfig *config = UA_ServerConfig_new_default();
config->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
UA_String_deleteMembers(&config->applicationDescription.applicationUri);
config->applicationDescription.applicationUri =
UA_String_fromChars("urn:open62541.example.local_discovery_server");
config.mdnsServerName = UA_String_fromChars("LDS");
config->mdnsServerName = UA_String_fromChars("LDS");
// See http://www.opcfoundation.org/UA/schemas/1.03/ServerCapabilities.csv
config.serverCapabilitiesSize = 1;
config->serverCapabilitiesSize = 1;
UA_String *caps = UA_String_new();
*caps = UA_String_fromChars("LDS");
config.serverCapabilities = caps;
config->serverCapabilities = caps;
/* timeout in seconds when to automatically remove a registered server from
* the list, if it doesn't re-register within the given time frame. A value
* of 0 disables automatic removal. Default is 60 Minutes (60*60). Must be
* bigger than 10 seconds, because cleanup is only triggered approximately
* ervery 10 seconds. The server will still be removed depending on the
* state of the semaphore file. */
// config.discoveryCleanupTimeout = 60*60;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840);
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);

UA_StatusCode retval = UA_Server_run(server, &running);
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Array_delete(config.serverCapabilities, config.serverCapabilitiesSize, &UA_TYPES[UA_TYPES_STRING]);
UA_String_deleteMembers(&config.mdnsServerName);
UA_Server_delete(server);
nl.deleteMembers(&nl);
return (int) retval;
UA_ServerConfig_delete(config);
return (int)retval;
}
40 changes: 12 additions & 28 deletions examples/discovery/server_multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,19 @@ int main(int argc, char **argv) {
signal(SIGINT, stopHandler); /* catches ctrl-c */
signal(SIGTERM, stopHandler);

UA_ServerConfig config = UA_ServerConfig_standard;
UA_ServerConfig *config = UA_ServerConfig_new_default();
// To enable mDNS discovery, set application type to discovery server.
config.applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
config.applicationDescription.applicationUri =
config->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
UA_String_deleteMembers(&config->applicationDescription.applicationUri);
config->applicationDescription.applicationUri =
UA_String_fromChars("urn:open62541.example.server_multicast");
config.mdnsServerName = UA_String_fromChars("Sample Multicast Server");
config->mdnsServerName = UA_String_fromChars("Sample Multicast Server");
// See http://www.opcfoundation.org/UA/schemas/1.03/ServerCapabilities.csv
//config.serverCapabilitiesSize = 1;
//UA_String caps = UA_String_fromChars("LDS");
//config.serverCapabilities = &caps;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16665);
config.networkLayers = &nl;
config.networkLayersSize = 1;
UA_Server *server = UA_Server_new(config);
self_discovery_url = &nl.discoveryUrl;
self_discovery_url = &config->networkLayers[0].discoveryUrl;

/* add a variable node to the address space */
UA_Int32 myInteger = 42;
Expand Down Expand Up @@ -129,9 +127,8 @@ int main(int argc, char **argv) {
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER,
"Could not start the server. StatusCode %s",
UA_StatusCode_name(retval));
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Server_delete(server);
nl.deleteMembers(&nl);
UA_ServerConfig_delete(config);
UA_free(discovery_url);
return 1;
}
Expand All @@ -140,9 +137,8 @@ int main(int argc, char **argv) {
while (running && discovery_url == NULL)
UA_Server_run_iterate(server, true);
if (!running) {
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Server_delete(server);
nl.deleteMembers(&nl);
UA_ServerConfig_delete(config);
UA_free(discovery_url);
return 1;
}
Expand All @@ -155,10 +151,8 @@ int main(int argc, char **argv) {
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER,
"Could not create periodic job for server register. StatusCode %s",
UA_StatusCode_name(retval));
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Server_delete(server);
nl.deleteMembers(&nl);
UA_free(discovery_url);
UA_ServerConfig_delete(config);
return 1;
}

Expand All @@ -170,23 +164,13 @@ int main(int argc, char **argv) {
// UNregister the server from the discovery server.
retval = UA_Server_unregister_discovery(server, discovery_url);
//retval = UA_Server_unregister_discovery(server, "opc.tcp://localhost:4840" );
if (retval != UA_STATUSCODE_GOOD) {
if(retval != UA_STATUSCODE_GOOD)
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER,
"Could not unregister server from discovery server. "
"StatusCode %s", UA_StatusCode_name(retval));
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Server_delete(server);
nl.deleteMembers(&nl);
UA_free(discovery_url);
return (int) retval;
}

UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_String_deleteMembers(&config.mdnsServerName);
//UA_Array_delete(config.serverCapabilities, config.serverCapabilitiesSize, &UA_TYPES[UA_TYPES_STRING]);
UA_Server_delete(server);
nl.deleteMembers(&nl);
UA_ServerConfig_delete(config);
UA_free(discovery_url);

return (int) retval;
return (int)retval;
}
37 changes: 13 additions & 24 deletions examples/discovery/server_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ int main(int argc, char **argv) {
signal(SIGINT, stopHandler); /* catches ctrl-c */
signal(SIGTERM, stopHandler);

UA_ServerConfig config = UA_ServerConfig_standard;
config.applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.example.server_register");
config.mdnsServerName = UA_String_fromChars("Sample Server");
UA_ServerConfig *config = UA_ServerConfig_new_default();
UA_String_deleteMembers(&config->applicationDescription.applicationUri);
config->applicationDescription.applicationUri =
UA_String_fromChars("urn:open62541.example.server_register");
config->mdnsServerName = UA_String_fromChars("Sample Server");
// See http://www.opcfoundation.org/UA/schemas/1.03/ServerCapabilities.csv
//config.serverCapabilitiesSize = 1;
//UA_String caps = UA_String_fromChars("LDS");
//config.serverCapabilities = &caps;
UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
config.networkLayers = &nl;
config.networkLayersSize = 1;

UA_Server *server = UA_Server_new(config);

/* add a variable node to the address space */
Expand Down Expand Up @@ -91,41 +91,30 @@ int main(int argc, char **argv) {
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER,
"Could not create periodic job for server register. StatusCode %s",
UA_StatusCode_name(retval));
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Server_delete(server);
nl.deleteMembers(&nl);
return (int) retval;
UA_ServerConfig_delete(config);
return (int)retval;
}

retval = UA_Server_run(server, &running);
if (retval != UA_STATUSCODE_GOOD) {
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER,
"Could not start the server. StatusCode %s",
UA_StatusCode_name(retval));
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Server_delete(server);
nl.deleteMembers(&nl);
return (int) retval;
UA_ServerConfig_delete(config);
return (int)retval;
}

// UNregister the server from the discovery server.
retval = UA_Server_unregister_discovery(server, DISCOVERY_SERVER_ENDPOINT);
//retval = UA_Server_unregister_discovery(server, "opc.tcp://localhost:4840" );
if (retval != UA_STATUSCODE_GOOD) {
if(retval != UA_STATUSCODE_GOOD)
UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER,
"Could not unregister server from discovery server. StatusCode %s",
UA_StatusCode_name(retval));
UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_Server_delete(server);
nl.deleteMembers(&nl);
return (int) retval;
}

UA_String_deleteMembers(&config.applicationDescription.applicationUri);
UA_String_deleteMembers(&config.mdnsServerName);
//UA_Array_delete(config.serverCapabilities, config.serverCapabilitiesSize, &UA_TYPES[UA_TYPES_STRING]);
UA_Server_delete(server);
nl.deleteMembers(&nl);

return (int) retval;
UA_ServerConfig_delete(config);
return (int)retval;
}
Loading

0 comments on commit a8012d3

Please sign in to comment.