High Performance OPC UA Server SDK  1.2.0.193
main.c
/*****************************************************************************
* *
* Copyright (c) 2006-2016 Unified Automation GmbH. All rights reserved. *
* *
* Software License Agreement ("SLA") Version 2.6 *
* *
* Unless explicitly acquired and licensed from Licensor under another *
* license, the contents of this file are subject to the Software License *
* Agreement ("SLA") Version 2.6, or subsequent versions as allowed by the *
* SLA, and You may not copy or use this file in either source code or *
* executable form, except in compliance with the terms and conditions of *
* the SLA. *
* *
* All software distributed under the SLA is provided strictly on an "AS *
* IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, *
* AND LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT *
* LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR *
* PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the SLA for specific *
* language governing rights and limitations under the SLA. *
* *
* The complete license agreement can be found here: *
* http://unifiedautomation.com/License/SLA/2.6/ *
* *
*****************************************************************************/
#include <getopt.h>
#include <platform/file.h>
#include <platform/shutdown.h>
#include <memory/memory.h>
#include <appconfig.h>
#include <uaapplication/application.h>
#include <trace/trace.h>
#include <common/errors.h>
#include "sampleclient.h"
static struct uaapplication g_app;
static struct sample_client g_ctx;
static char url[128] = "opc.tcp://localhost:4840";
#ifdef HAVE_CRYPTO
static char config_file[UA_PATH_MAX] = "settings.conf";
#else
static char config_file[UA_PATH_MAX] = "settings_micro.conf";
#endif
struct appconfig g_appconfig;
static void usage(const char *appname)
{
printf("Usage: %s [-d debug_level] [-f facility_mask] [-c config_file] [-u <url>] [-l] [-h]\n", appname);
printf(" -d: sets the debug level bit mask of the trace output (default=ERROR)\n");
printf(" -f: sets the facility bit mask of the trace output (default=ALL)\n");
printf(" -c: sets the configuration file to use\n");
printf(" -l: lists all debug_levels and facility_masks\n");
printf(" -u: Sets the URL to use (default=opc.tcp://localhost:4840)\n" );
printf(" -h: prints this help\n");
}
static void print_debug_flags(void)
{
printf("debug levels:\n");
printf(" TRACE_LEVEL_DEBUG 1\n");
printf(" TRACE_LEVEL_DATA 2\n");
printf(" TRACE_LEVEL_INFO 4\n");
printf(" TRACE_LEVEL_FUNC_ENTER 8\n");
printf(" TRACE_LEVEL_FUNC_LEAVE 16\n");
printf(" TRACE_LEVEL_FUNC 24\n");
printf(" TRACE_LEVEL_NOTICE 32\n");
printf(" TRACE_LEVEL_WARNING 64\n");
printf(" TRACE_LEVEL_ERROR 128\n");
printf(" TRACE_LEVEL_INSANE 256\n");
printf(" TRACE_LEVEL_ALL 511\n");
printf("debug facilities:\n");
printf(" TRACE_FAC_PLATFORM 1\n");
printf(" TRACE_FAC_NETWORK 2\n");
printf(" TRACE_FAC_CRYPTO 4\n");
printf(" TRACE_FAC_IPC 8\n");
printf(" TRACE_FAC_BASE 16\n");
printf(" TRACE_FAC_MEMORY 32\n");
printf(" TRACE_FAC_UATCP 64\n");
printf(" TRACE_FAC_ENCODER 128\n");
printf(" TRACE_FAC_SESSION 256\n");
printf(" TRACE_FAC_PROVIDER 512\n");
printf(" TRACE_FAC_APPLICATION 1024\n");
printf(" TRACE_FAC_ADDRSPACE 2048\n");
printf(" TRACE_FAC_TIMER 4096\n");
printf(" TRACE_FAC_PKI 8192\n");
printf(" TRACE_FAC_SUBSCRIPTION 16384\n");
printf(" TRACE_FAC_ALL 32767\n");
}
int main(int argc, char *argv[])
{
int trace_level = TRACE_LEVEL_ERROR;
int facility_mask = TRACE_FAC_ALL;
int ret, opt;
struct sample_client *ctx = &g_ctx;
/* parse commandline arguments */
while ((opt = getopt(argc, argv, "hd:f:lc:u:")) != -1) {
switch (opt) {
case 'h':
usage(argv[0]);
exit(EXIT_SUCCESS);
case 'd':
trace_level = atoi(optarg);
break;
case 'f':
facility_mask = atoi(optarg);
break;
case 'c':
strncpy(config_file, optarg, sizeof(config_file) );
break;
case 'l':
print_debug_flags();
exit(EXIT_SUCCESS);
case 'u':
strncpy(url, optarg, sizeof(url) );
break;
default: /* '?' */
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
ret = uaapplication_init(&g_app, trace_level, facility_mask, config_file);
if (ret != 0) {
fprintf(stderr, "uaapplication_init failed.\n");
return EXIT_FAILURE;
}
ret = sample_client_init(ctx, url);
if (ret != 0) {
TRACE_ERROR(TRACE_FAC_USERAPPLICATION, "%s: sample_client_init failed with errorcode=%i\n", __func__, ret);
return EXIT_FAILURE;
}
while (ua_shutdown_should_shutdown() == 0) {
if (!sample_client_check_state(ctx)) break;
}
ret = sample_client_get_result(ctx);
if (ret != 0) {
TRACE_ERROR(TRACE_FAC_USERAPPLICATION, "%s: sample_client failed with result=%i\n", __func__, ret);
}
sample_client_cleanup(ctx);
IPC_CLEAR(&g_ctx);
IPC_CLEAR(&g_app);
IPC_CLEAR(&g_appconfig);
if (ret == 0) return EXIT_SUCCESS;
else return EXIT_FAILURE;
}