Skip to content

Commit

Permalink
Merge pull request #437 from iain-anderson/v3-api-tweaks
Browse files Browse the repository at this point in the history
refactor: V3 name changes
  • Loading branch information
iain-anderson authored Jan 17, 2023
2 parents de537f5 + d9d33c5 commit 60c7205
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 90 deletions.
4 changes: 2 additions & 2 deletions src/c/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ iot_data_t *edgex_config_defaults (const iot_data_t *driverconf, const char *svc
iot_data_string_map_add (result, "Device/DevicesDir", iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (result, "Device/EventQLength", iot_data_alloc_ui32 (0));

iot_data_string_map_add (result, EX_MQ_TYPE, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (result, EX_BUS_TYPE, iot_data_alloc_string ("", IOT_DATA_REF));
edgex_mqtt_config_defaults (result, svcname);
// NB redis-streams uses a subset of the mqtt options

Expand Down Expand Up @@ -758,7 +758,7 @@ static JSON_Value *edgex_device_config_toJson (devsdk_service_t *svc)

json_object_set_value (obj, DYN_NAME, wval);

const char *mqtype = iot_data_string_map_get_string (svc->config.sdkconf, EX_MQ_TYPE);
const char *mqtype = iot_data_string_map_get_string (svc->config.sdkconf, EX_BUS_TYPE);
if (strcmp (mqtype, "mqtt") == 0)
{
JSON_Value *mqval = edgex_mqtt_config_json (svc->config.sdkconf);
Expand Down
2 changes: 1 addition & 1 deletion src/c/consul.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "api.h"
#include "iot/base64.h"

#define CONF_PREFIX "edgex/devices/2.0/"
#define CONF_PREFIX "edgex/v3/"

typedef struct consul_impl_t
{
Expand Down
91 changes: 46 additions & 45 deletions src/c/data-mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,52 @@ void edgex_mqtt_config_defaults (iot_data_t *allconf, const char *svcname)
char *reqt = malloc (sizeof (DEFAULTREQTOPIC) + strlen (svcname));
sprintf (reqt, DEFAULTREQTOPIC, svcname);

iot_data_string_map_add (allconf, EX_MQ_PROTOCOL, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_MQ_HOST, iot_data_alloc_string ("localhost", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_MQ_PORT, iot_data_alloc_ui16 (0));
iot_data_string_map_add (allconf, EX_MQ_TOPIC, iot_data_alloc_string (DEFAULTPUBTOPIC, IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_MQ_AUTHMODE, iot_data_alloc_string ("none", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_MQ_SECRETNAME, iot_data_alloc_string ("", IOT_DATA_REF));

iot_data_string_map_add (allconf, EX_MQ_CLIENTID, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_MQ_QOS, iot_data_alloc_ui16 (0));
iot_data_string_map_add (allconf, EX_MQ_KEEPALIVE, iot_data_alloc_ui16 (60));
iot_data_string_map_add (allconf, EX_MQ_RETAINED, iot_data_alloc_bool (false));
iot_data_string_map_add (allconf, EX_MQ_CERTFILE, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_MQ_KEYFILE, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_MQ_SKIPVERIFY, iot_data_alloc_bool (false));

iot_data_string_map_add (allconf, EX_MQ_TOPIC_CMDREQ, iot_data_alloc_string (reqt, IOT_DATA_TAKE));
iot_data_string_map_add (allconf, EX_MQ_TOPIC_CMDRESP, iot_data_alloc_string (DEFAULTRESPTOPIC, IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_DISABLED, iot_data_alloc_bool (false));
iot_data_string_map_add (allconf, EX_BUS_PROTOCOL, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_HOST, iot_data_alloc_string ("localhost", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_PORT, iot_data_alloc_ui16 (0));
iot_data_string_map_add (allconf, EX_BUS_TOPIC, iot_data_alloc_string (DEFAULTPUBTOPIC, IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_AUTHMODE, iot_data_alloc_string ("none", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_SECRETNAME, iot_data_alloc_string ("", IOT_DATA_REF));

iot_data_string_map_add (allconf, EX_BUS_CLIENTID, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_QOS, iot_data_alloc_ui16 (0));
iot_data_string_map_add (allconf, EX_BUS_KEEPALIVE, iot_data_alloc_ui16 (60));
iot_data_string_map_add (allconf, EX_BUS_RETAINED, iot_data_alloc_bool (false));
iot_data_string_map_add (allconf, EX_BUS_CERTFILE, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_KEYFILE, iot_data_alloc_string ("", IOT_DATA_REF));
iot_data_string_map_add (allconf, EX_BUS_SKIPVERIFY, iot_data_alloc_bool (false));

iot_data_string_map_add (allconf, EX_BUS_TOPIC_CMDREQ, iot_data_alloc_string (reqt, IOT_DATA_TAKE));
iot_data_string_map_add (allconf, EX_BUS_TOPIC_CMDRESP, iot_data_alloc_string (DEFAULTRESPTOPIC, IOT_DATA_REF));
}

JSON_Value *edgex_mqtt_config_json (const iot_data_t *allconf)
{
JSON_Value *mqval = json_value_init_object ();
JSON_Object *mqobj = json_value_get_object (mqval);
json_object_set_string (mqobj, "Protocol", iot_data_string_map_get_string (allconf, EX_MQ_PROTOCOL));
json_object_set_string (mqobj, "Host", iot_data_string_map_get_string (allconf, EX_MQ_HOST));
json_object_set_uint (mqobj, "Port", iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_PORT)));
json_object_set_string (mqobj, "Topic", iot_data_string_map_get_string (allconf, EX_MQ_TOPIC));
json_object_set_string (mqobj, "AuthMode", iot_data_string_map_get_string (allconf, EX_MQ_AUTHMODE));
json_object_set_string (mqobj, "SecretName", iot_data_string_map_get_string (allconf, EX_MQ_SECRETNAME));
json_object_set_string (mqobj, "Protocol", iot_data_string_map_get_string (allconf, EX_BUS_PROTOCOL));
json_object_set_string (mqobj, "Host", iot_data_string_map_get_string (allconf, EX_BUS_HOST));
json_object_set_uint (mqobj, "Port", iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_PORT)));
json_object_set_string (mqobj, "Topic", iot_data_string_map_get_string (allconf, EX_BUS_TOPIC));
json_object_set_string (mqobj, "AuthMode", iot_data_string_map_get_string (allconf, EX_BUS_AUTHMODE));
json_object_set_string (mqobj, "SecretName", iot_data_string_map_get_string (allconf, EX_BUS_SECRETNAME));

JSON_Value *optval = json_value_init_object ();
JSON_Object *optobj = json_value_get_object (optval);
json_object_set_string (optobj, "ClientId", iot_data_string_map_get_string (allconf, EX_MQ_CLIENTID));
json_object_set_number (optobj, "Qos", iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_QOS)));
json_object_set_number (optobj, "KeepAlive", iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_KEEPALIVE)));
json_object_set_boolean (optobj, "Retained", iot_data_bool (iot_data_string_map_get (allconf, EX_MQ_RETAINED)));
json_object_set_string (optobj, "CertFile", iot_data_string_map_get_string (allconf, EX_MQ_CERTFILE));
json_object_set_string (optobj, "KeyFile", iot_data_string_map_get_string (allconf, EX_MQ_KEYFILE));
json_object_set_boolean (optobj, "SkipCertVerify", iot_data_bool (iot_data_string_map_get (allconf, EX_MQ_SKIPVERIFY)));
json_object_set_string (optobj, "ClientId", iot_data_string_map_get_string (allconf, EX_BUS_CLIENTID));
json_object_set_number (optobj, "Qos", iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_QOS)));
json_object_set_number (optobj, "KeepAlive", iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_KEEPALIVE)));
json_object_set_boolean (optobj, "Retained", iot_data_bool (iot_data_string_map_get (allconf, EX_BUS_RETAINED)));
json_object_set_string (optobj, "CertFile", iot_data_string_map_get_string (allconf, EX_BUS_CERTFILE));
json_object_set_string (optobj, "KeyFile", iot_data_string_map_get_string (allconf, EX_BUS_KEYFILE));
json_object_set_boolean (optobj, "SkipCertVerify", iot_data_bool (iot_data_string_map_get (allconf, EX_BUS_SKIPVERIFY)));
json_object_set_value (mqobj, "Optional", optval);

JSON_Value *topicval = json_value_init_object ();
JSON_Object *topicobj = json_value_get_object (topicval);
json_object_set_string (topicobj, "CommandRequestTopic", iot_data_string_map_get_string (allconf, EX_MQ_TOPIC_CMDREQ));
json_object_set_string (topicobj, "CommandResponseTopicPrefix", iot_data_string_map_get_string (allconf, EX_MQ_TOPIC_CMDRESP));
json_object_set_string (topicobj, "CommandRequestTopic", iot_data_string_map_get_string (allconf, EX_BUS_TOPIC_CMDREQ));
json_object_set_string (topicobj, "CommandResponseTopicPrefix", iot_data_string_map_get_string (allconf, EX_BUS_TOPIC_CMDRESP));
json_object_set_value (mqobj, "Topics", topicval);

return mqval;
Expand Down Expand Up @@ -222,11 +223,11 @@ edgex_data_client_t *edgex_data_client_new_mqtt (devsdk_service_t *svc, const de
edgex_data_client_t *result = malloc (sizeof (edgex_data_client_t));
edc_mqtt_conninfo *cinfo = calloc (1, sizeof (edc_mqtt_conninfo));

const char *host = iot_data_string_map_get_string (allconf, EX_MQ_HOST);
const char *prot = iot_data_string_map_get_string (allconf, EX_MQ_PROTOCOL);
const char *certfile = iot_data_string_map_get_string (allconf, EX_MQ_CERTFILE);
const char *keyfile = iot_data_string_map_get_string (allconf, EX_MQ_KEYFILE);
uint16_t port = iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_PORT));
const char *host = iot_data_string_map_get_string (allconf, EX_BUS_HOST);
const char *prot = iot_data_string_map_get_string (allconf, EX_BUS_PROTOCOL);
const char *certfile = iot_data_string_map_get_string (allconf, EX_BUS_CERTFILE);
const char *keyfile = iot_data_string_map_get_string (allconf, EX_BUS_KEYFILE);
uint16_t port = iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_PORT));
if (*prot == '\0')
{
prot = "tcp";
Expand Down Expand Up @@ -255,14 +256,14 @@ edgex_data_client_t *edgex_data_client_new_mqtt (devsdk_service_t *svc, const de
result->mf = NULL;
result->address = cinfo;

cinfo->qos = iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_QOS));
cinfo->retained = iot_data_bool (iot_data_string_map_get (allconf, EX_MQ_RETAINED));
cinfo->topicbase = iot_data_string_map_get_string (allconf, EX_MQ_TOPIC);
cinfo->qos = iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_QOS));
cinfo->retained = iot_data_bool (iot_data_string_map_get (allconf, EX_BUS_RETAINED));
cinfo->topicbase = iot_data_string_map_get_string (allconf, EX_BUS_TOPIC);
cinfo->uri = uri;

create_opts.sendWhileDisconnected = 1;
rc = MQTTAsync_createWithOptions
(&cinfo->client, uri, iot_data_string_map_get_string (allconf, EX_MQ_CLIENTID), MQTTCLIENT_PERSISTENCE_NONE, NULL, &create_opts);
(&cinfo->client, uri, iot_data_string_map_get_string (allconf, EX_BUS_CLIENTID), MQTTCLIENT_PERSISTENCE_NONE, NULL, &create_opts);
if (rc != MQTTASYNC_SUCCESS)
{
iot_log_error (lc, "mqtt: failed to create client, return code %d", rc);
Expand All @@ -271,15 +272,15 @@ edgex_data_client_t *edgex_data_client_new_mqtt (devsdk_service_t *svc, const de
free (uri);
return NULL;
}
conn_opts.keepAliveInterval = iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_KEEPALIVE));
conn_opts.keepAliveInterval = iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_KEEPALIVE));
conn_opts.cleansession = 1;
conn_opts.automaticReconnect = 1;
conn_opts.onSuccess = edc_mqtt_onconnect;
conn_opts.onFailure = edc_mqtt_onconnectfail;
conn_opts.context = cinfo;
if (strcmp (iot_data_string_map_get_string (allconf, EX_MQ_AUTHMODE), "usernamepassword") == 0)
if (strcmp (iot_data_string_map_get_string (allconf, EX_BUS_AUTHMODE), "usernamepassword") == 0)
{
secrets = devsdk_get_secrets (svc, iot_data_string_map_get_string (allconf, EX_MQ_SECRETNAME));
secrets = devsdk_get_secrets (svc, iot_data_string_map_get_string (allconf, EX_BUS_SECRETNAME));
conn_opts.username = iot_data_string_map_get_string (secrets, "username");
conn_opts.password = iot_data_string_map_get_string (secrets, "password");
}
Expand All @@ -292,7 +293,7 @@ edgex_data_client_t *edgex_data_client_new_mqtt (devsdk_service_t *svc, const de
{
ssl_opts.keyStore = keyfile;
}
ssl_opts.verify = iot_data_string_map_get_bool (allconf, EX_MQ_SKIPVERIFY, false) ? 0 : 1;
ssl_opts.verify = iot_data_string_map_get_bool (allconf, EX_BUS_SKIPVERIFY, false) ? 0 : 1;

pthread_mutex_init (&cinfo->mtx, NULL);
pthread_cond_init (&cinfo->cond, NULL);
Expand Down
24 changes: 12 additions & 12 deletions src/c/data-redstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ JSON_Value *edgex_redstr_config_json (const iot_data_t *allconf)
{
JSON_Value *mqval = json_value_init_object ();
JSON_Object *mqobj = json_value_get_object (mqval);
json_object_set_string (mqobj, "Host", iot_data_string_map_get_string (allconf, EX_MQ_HOST));
json_object_set_uint (mqobj, "Port", iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_PORT)));
json_object_set_string (mqobj, "Topic", iot_data_string_map_get_string (allconf, EX_MQ_TOPIC));
json_object_set_string (mqobj, "Host", iot_data_string_map_get_string (allconf, EX_BUS_HOST));
json_object_set_uint (mqobj, "Port", iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_PORT)));
json_object_set_string (mqobj, "Topic", iot_data_string_map_get_string (allconf, EX_BUS_TOPIC));

JSON_Value *topicval = json_value_init_object ();
JSON_Object *topicobj = json_value_get_object (topicval);
json_object_set_string (topicobj, "CommandRequestTopic", iot_data_string_map_get_string (allconf, EX_MQ_TOPIC_CMDREQ));
json_object_set_string (topicobj, "CommandResponseTopicPrefix", iot_data_string_map_get_string (allconf, EX_MQ_TOPIC_CMDRESP));
json_object_set_string (topicobj, "CommandRequestTopic", iot_data_string_map_get_string (allconf, EX_BUS_TOPIC_CMDREQ));
json_object_set_string (topicobj, "CommandResponseTopicPrefix", iot_data_string_map_get_string (allconf, EX_BUS_TOPIC_CMDRESP));
json_object_set_value (mqobj, "Topics", topicval);

return mqval;
Expand Down Expand Up @@ -333,8 +333,8 @@ edgex_data_client_t *edgex_data_client_new_redstr (devsdk_service_t *svc, const
edc_redstr_conninfo *cinfo = calloc (1, sizeof (edc_redstr_conninfo));
pthread_mutex_init (&cinfo->mtx, NULL);

const char *host = iot_data_string_map_get_string (allconf, EX_MQ_HOST);
uint16_t port = iot_data_ui16 (iot_data_string_map_get (allconf, EX_MQ_PORT));
const char *host = iot_data_string_map_get_string (allconf, EX_BUS_HOST);
uint16_t port = iot_data_ui16 (iot_data_string_map_get (allconf, EX_BUS_PORT));
if (port == 0)
{
port = 6379;
Expand Down Expand Up @@ -373,10 +373,10 @@ edgex_data_client_t *edgex_data_client_new_redstr (devsdk_service_t *svc, const
return NULL;
}

if (strcmp (iot_data_string_map_get_string (allconf, EX_MQ_AUTHMODE), "usernamepassword") == 0)
if (strcmp (iot_data_string_map_get_string (allconf, EX_BUS_AUTHMODE), "usernamepassword") == 0)
{
bool auth = true;
iot_data_t *secrets = devsdk_get_secrets (svc, iot_data_string_map_get_string (allconf, EX_MQ_SECRETNAME));
iot_data_t *secrets = devsdk_get_secrets (svc, iot_data_string_map_get_string (allconf, EX_BUS_SECRETNAME));
const char *pass = iot_data_string_map_get_string (secrets, "password");
if (pass)
{
Expand All @@ -391,15 +391,15 @@ edgex_data_client_t *edgex_data_client_new_redstr (devsdk_service_t *svc, const
}
}

cmdtopic = iot_data_string_map_get_string (allconf, EX_MQ_TOPIC_CMDREQ);
cmdtopic = iot_data_string_map_get_string (allconf, EX_BUS_TOPIC_CMDREQ);
if (!edc_redis_subscribe (lc, cinfo->ctx_rd, cmdtopic))
{
edc_redstr_freefn (lc, cinfo);
return NULL;
}

reptopic = iot_data_string_map_get_string (allconf, EX_MQ_TOPIC_CMDRESP);
cinfo->topicbase = strdup (iot_data_string_map_get_string (allconf, EX_MQ_TOPIC));
reptopic = iot_data_string_map_get_string (allconf, EX_BUS_TOPIC_CMDRESP);
cinfo->topicbase = strdup (iot_data_string_map_get_string (allconf, EX_BUS_TOPIC));
cinfo->pubsub_topicbase = malloc (strlen (reptopic) + strlen (svc->name) + 2);
sprintf (cinfo->pubsub_topicbase, "%s.%s", reptopic, svc->name);
mettopic = svc->config.metrics.topic;
Expand Down
35 changes: 18 additions & 17 deletions src/c/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
#include "rest-server.h"
#include "iot/threadpool.h"

#define EX_MQ_TYPE "MessageQueue/Type"

#define EX_MQ_PROTOCOL "MessageQueue/Protocol"
#define EX_MQ_HOST "MessageQueue/Host"
#define EX_MQ_PORT "MessageQueue/Port"
#define EX_MQ_TOPIC "MessageQueue/PublishTopicPrefix"
#define EX_MQ_AUTHMODE "MessageQueue/AuthMode"
#define EX_MQ_SECRETNAME "MessageQueue/SecretName"
#define EX_MQ_CLIENTID "MessageQueue/Optional/ClientId"
#define EX_MQ_QOS "MessageQueue/Optional/Qos"
#define EX_MQ_KEEPALIVE "MessageQueue/Optional/KeepAlive"
#define EX_MQ_RETAINED "MessageQueue/Optional/Retained"
#define EX_MQ_CERTFILE "MessageQueue/Optional/CertFile"
#define EX_MQ_KEYFILE "MessageQueue/Optional/KeyFile"
#define EX_MQ_SKIPVERIFY "MessageQueue/Optional/SkipCertVerify"
#define EX_MQ_TOPIC_CMDREQ "MessageQueue/Topics/CommandRequestTopic"
#define EX_MQ_TOPIC_CMDRESP "MessageQueue/Topics/CommandResponseTopicPrefix"
#define EX_BUS_TYPE "MessageBus/Type"

#define EX_BUS_DISABLED "MessageBus/Disabled"
#define EX_BUS_PROTOCOL "MessageBus/Protocol"
#define EX_BUS_HOST "MessageBus/Host"
#define EX_BUS_PORT "MessageBus/Port"
#define EX_BUS_AUTHMODE "MessageBus/AuthMode"
#define EX_BUS_SECRETNAME "MessageBus/SecretName"
#define EX_BUS_CLIENTID "MessageBus/Optional/ClientId"
#define EX_BUS_QOS "MessageBus/Optional/Qos"
#define EX_BUS_KEEPALIVE "MessageBus/Optional/KeepAlive"
#define EX_BUS_RETAINED "MessageBus/Optional/Retained"
#define EX_BUS_CERTFILE "MessageBus/Optional/CertFile"
#define EX_BUS_KEYFILE "MessageBus/Optional/KeyFile"
#define EX_BUS_SKIPVERIFY "MessageBus/Optional/SkipCertVerify"
#define EX_BUS_TOPIC "MessageBus/Topics/PublishTopicPrefix"
#define EX_BUS_TOPIC_CMDREQ "MessageBus/Topics/CommandRequestTopic"
#define EX_BUS_TOPIC_CMDRESP "MessageBus/Topics/CommandResponseTopicPrefix"

typedef enum { JSON, CBOR} edgex_event_encoding;

Expand Down
4 changes: 2 additions & 2 deletions src/c/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,12 @@ static void edgex_device_v2impl (devsdk_service_t *svc, edgex_device *dev, const
bool pushv = false;
bool retv = true;
if (req->qparams && iot_data_string_map_get_string(req->qparams, DS_PUSH) &&
(strcmp(iot_data_string_map_get_string(req->qparams, DS_PUSH), "yes") == 0))
(strcmp(iot_data_string_map_get_string(req->qparams, DS_PUSH), "true") == 0))
{
pushv = true;
}
if (req->qparams && iot_data_string_map_get_string(req->qparams, DS_RETURN) &&
(strcmp(iot_data_string_map_get_string(req->qparams, DS_RETURN), "no") == 0))
(strcmp(iot_data_string_map_get_string(req->qparams, DS_RETURN), "false") == 0))
{
retv = false;
}
Expand Down
Loading

0 comments on commit 60c7205

Please sign in to comment.