/*
 * Created by jiaqiang.ye@lnxall.com
 *
 * Simple OPC-UA remote TAG implementation, for LC
 *
 * 2024/05/21
 */

#ifndef OPCUA_REMOTE_TAG_H
#define OPCUA_REMOTE_TAG_H 1
#ifdef __cplusplus
extern "C" {
#endif

#define SERVER_CERT_CERT "/app/cert/server_cert.der"
#define SERVER_CERT_KEY  "/app/cert/server_key.pem"

#define CLIENT_CERT_CERT "/app/cert/client_cert.der"
#define CLIENT_CERT_KEY  "/app/cert/client_key.pem"

struct cli_opcua_option {
	const char * uaurl;
	const char * username;
	const char * passwd;
};

void lc_opcua_option_default(struct cli_opcua_option * loo);

static inline void lc_opcua_option_setname(struct cli_opcua_option * loo,
	const char * uaurl)
{
	if (uaurl != NULL)
		loo->uaurl = uaurl;
}

static inline void lc_option_option_setuser(struct cli_opcua_option * loo,
	const char * username, const char * passwd)
{
	if (username != NULL)
		loo->username = username;

	if (passwd != NULL)
		loo->passwd = passwd;
}

/*
 * @return value
 * 0, if OPC-UA Client connection is not closed, return zero (0)
 * 1, if OPC-UA Client connection is closed, return one (1)
 */
int lc_client_closed(UA_Client * uacli, int * errorp);

void lc_client_free(UA_Client * uacli);

UA_Client * lc_connect_opcua(const struct cli_opcua_option * loo);

#ifdef __cplusplus
};
#endif
#endif
