Commit 7e872170 authored by Dimitris Lampridis's avatar Dimitris Lampridis

Merge branch 'fixes' into proposed_master

parents 2fd3ae9a 16200441
......@@ -92,6 +92,40 @@ Functions
examples. However, in a real application, users should always check the status code of every call
to a WRTD function, like in :numref:`lst-get_error`.
.. hint::
If you want to be sure that the buffer that you pass to :cpp:func:`wrtd_get_error`
is large enough, without having to resort to querying like in :numref:`lst-get_error`, you can
always allocate a buffer of :c:macro:`WRTD_ERR_MSG_BUF_SIZE`. WRTD guarantees that all error
messages shall not exceed this size.
.. doxygendefine:: WRTD_ERR_MSG_BUF_SIZE
.. code-block:: c
:caption: Retrieving the error message with a pre-defined buffer size
#include <libwrtd.h>
int main(void) {
wrtd_dev *wrtd;
wrtd_status status;
char err_msg[WRTD_ERR_MSG_BUF_SIZE];
status = wrtd_init(1, false, NULL, &wrtd);
status = wrtd_get_attr_bool(wrtd, WRTD_GLOBAL_REP_CAP_ID,
WRTD_ATTR_EVENT_LOG_EMPTY);
if (status != WRTD_SUCCESS) {
/* retrieve the error code and message */
wrtd_get_error(wrtd, &err_code, WRTD_ERR_MSG_BUF_SIZE, err_msg)
printf("ERROR: %d, %s\n", err_code, err_msg);
return status;
}
wrtd_close(wrtd);
return 0;
}
.. _api_init:
Initialisation API
......@@ -257,7 +291,7 @@ Functions
/* get the delay configured for "rule1" */
status = wrtd_get_attr_tstamp(wrtd, "rule1",
WRTD_ATTR_RULE_DELAY, &ts");
WRTD_ATTR_RULE_DELAY, &ts);
wrtd_close(wrtd);
}
......@@ -295,6 +329,7 @@ The Event Logging API provides functions for accessing the :ref:`event_log`.
int main(void) {
wrtd_dev *wrtd;
wrtd_status status;
char *log_msg;
int buf_size;
......@@ -332,6 +367,7 @@ The Event Logging API provides functions for accessing the :ref:`event_log`.
int main(void) {
wrtd_dev *wrtd;
wrtd_status status;
char log_msg[WRTD_LOG_ENTRY_SIZE];
status = wrtd_init(1, false, NULL, &wrtd);
......@@ -368,6 +404,7 @@ Configuration of an Alarm happens by setting the relevant :ref:`Attributes <attr
int i, count;
char rep_cap_id[16];
wrtd_dev *wrtd;
wrtd_status status;
status = wrtd_init(1, false, NULL, &wrtd);
......@@ -427,6 +464,7 @@ Configuration of a Rule happens by setting the relevant :ref:`Attributes <attrib
int i, count;
char rep_cap_id[16];
wrtd_dev *wrtd;
wrtd_status status;
status = wrtd_init(1, false, NULL, &wrtd);
......@@ -487,7 +525,7 @@ Configuration of a Rule happens by setting the relevant :ref:`Attributes <attrib
/* Enable rule */
status = wrtd_set_attr_bool(wrtd, "rule1",
WRTD_ATTR_RULE_ENABLED, True);
WRTD_ATTR_RULE_ENABLED, true);
wrtd_close(wrtd);
......@@ -516,6 +554,7 @@ relevant :ref:`Attributes <attribute>` via the :ref:`api_attr`.
int i, count, major, minor;
char rep_cap_id[16];
wrtd_dev *wrtd;
wrtd_status status;
status = wrtd_init(1, false, NULL, &wrtd);
......
......@@ -257,8 +257,8 @@ wrtd_status wrtd_get_error(wrtd_dev *wrtd,
if (wrtd == NULL)
return WRTD_ERROR_NOT_INITIALIZED;
char error_message[256];
memset(error_message, 0, 256);
char error_message[WRTD_ERR_MSG_BUF_SIZE];
memset(error_message, 0, WRTD_ERR_MSG_BUF_SIZE);
status = wrtd_error_message(wrtd, wrtd->err, error_message);
WRTD_RETURN_IF_ERROR(status);
......@@ -312,7 +312,8 @@ wrtd_status wrtd_get_error(wrtd_dev *wrtd,
* @param[in] wrtd Device token. Can be NULL to allow calling this function
* even when initialisation has failed.
* @param[in] err_code #wrtd_status error code to convert.
* @param[out] err_message Buffer of at least 256 bytes to store the resulting string.
* @param[out] err_message Buffer of at least #WRTD_ERR_MSG_BUF_SIZE bytes
* to store the resulting string.
* @return #wrtd_status
*/
wrtd_status wrtd_error_message(wrtd_dev *wrtd,
......@@ -332,71 +333,92 @@ wrtd_status wrtd_error_message(wrtd_dev *wrtd,
switch(err_code){
case WRTD_SUCCESS:
snprintf(err_message, 256, "WRTD_SUCCESS");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE, "WRTD_SUCCESS");
break;
case WRTD_ERROR_INVALID_ATTRIBUTE:
snprintf(err_message, 256, "WRTD_ERROR_INVALID_ATTRIBUTE");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_INVALID_ATTRIBUTE");
break;
case WRTD_ERROR_ATTR_NOT_WRITEABLE:
snprintf(err_message, 256, "WRTD_ERROR_ATTR_NOT_WRITEABLE");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_ATTR_NOT_WRITEABLE");
break;
case WRTD_ERROR_ATTR_NOT_READABLE:
snprintf(err_message, 256, "WRTD_ERROR_ATTR_NOT_READABLE");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_ATTR_NOT_READABLE");
break;
case WRTD_ERROR_INVALID_VALUE:
snprintf(err_message, 256, "WRTD_ERROR_INVALID_VALUE");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_INVALID_VALUE");
break;
case WRTD_ERROR_NOT_INITIALIZED:
snprintf(err_message, 256, "WRTD_ERROR_NOT_INITIALIZED");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_NOT_INITIALIZED");
break;
case WRTD_ERROR_UNKNOWN_CHANNEL_NAME:
snprintf(err_message, 256, "WRTD_ERROR_UNKNOWN_CHANNEL_NAME");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_UNKNOWN_CHANNEL_NAME");
break;
case WRTD_ERROR_OUT_OF_MEMORY:
snprintf(err_message, 256, "WRTD_ERROR_OUT_OF_MEMORY");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_OUT_OF_MEMORY");
break;
case WRTD_ERROR_NULL_POINTER:
snprintf(err_message, 256, "WRTD_ERROR_NULL_POINTER");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_NULL_POINTER");
break;
case WRTD_ERROR_UNEXPECTED_RESPONSE:
snprintf(err_message, 256, "WRTD_ERROR_UNEXPECTED_RESPONSE");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_UNEXPECTED_RESPONSE");
break;
case WRTD_ERROR_RESOURCE_UNKNOWN:
snprintf(err_message, 256, "WRTD_ERROR_RESOURCE_UNKNOWN");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_RESOURCE_UNKNOWN");
break;
case WRTD_ERROR_BADLY_FORMED_SELECTOR:
snprintf(err_message, 256, "WRTD_ERROR_BADLY_FORMED_SELECTOR");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_BADLY_FORMED_SELECTOR");
break;
case WRTD_ERROR_ALARM_EXISTS:
snprintf(err_message, 256, "WRTD_ERROR_ALARM_EXISTS");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_ALARM_EXISTS");
break;
case WRTD_ERROR_ALARM_DOES_NOT_EXIST:
snprintf(err_message, 256, "WRTD_ERROR_ALARM_DOES_NOT_EXIST");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_ALARM_DOES_NOT_EXIST");
break;
case WRTD_ERROR_VERSION_MISMATCH:
snprintf(err_message, 256, "WRTD_ERROR_VERSION_MISMATCH");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_VERSION_MISMATCH");
break;
case WRTD_ERROR_INTERNAL:
snprintf(err_message, 256, "WRTD_ERROR_INTERNAL");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_INTERNAL");
break;
case WRTD_ERROR_UNKNOWN_LOG_TYPE:
snprintf(err_message, 256, "WRTD_ERROR_UNKNOWN_LOG_TYPE");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_UNKNOWN_LOG_TYPE");
break;
case WRTD_ERROR_RESOURCE_ACTIVE:
snprintf(err_message, 256, "WRTD_ERROR_RESOURCE_ACTIVE");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_RESOURCE_ACTIVE");
break;
case WRTD_ERROR_ATTR_GLOBAL:
snprintf(err_message, 256, "WRTD_ERROR_ATTR_GLOBAL");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_ATTR_GLOBAL");
break;
case WRTD_ERROR_OUT_OF_RESOURCES:
snprintf(err_message, 256, "WRTD_ERROR_OUT_OF_RESOURCES");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_OUT_OF_RESOURCES");
break;
case WRTD_ERROR_RULE_EXISTS:
snprintf(err_message, 256, "WRTD_ERROR_RULE_EXISTS");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_RULE_EXISTS");
break;
case WRTD_ERROR_RULE_DOES_NOT_EXIST:
snprintf(err_message, 256, "WRTD_ERROR_RULE_DOES_NOT_EXIST");
snprintf(err_message, WRTD_ERR_MSG_BUF_SIZE,
"WRTD_ERROR_RULE_DOES_NOT_EXIST");
break;
default:
......@@ -834,7 +856,7 @@ wrtd_status wrtd_get_attr_string(wrtd_dev *wrtd,
}
/**
* Set an attribute of type `timestamp`.
* Set an attribute of type `timestamp` (#wrtd_tstamp).
*
* Modelled after the IVI-C SetAttribute family of functions.
*
......@@ -842,13 +864,15 @@ wrtd_status wrtd_get_attr_string(wrtd_dev *wrtd,
* @param[in] rep_cap_id ID (string) of concerned repeated capability.
* If it is a global attribute, use #WRTD_GLOBAL_REP_CAP_ID
* @param[in] id ID (#wrtd_attr) of concerned attribute.
* @param[in] value Value to write to the attribute.
* @param[in] value Value (#wrtd_tstamp) to write to the attribute.
* If the `ns` part is greater or equal to 1e9, the `seconds` part will be
* automatically increased and the `ns` part will be reduced accordingly.
* @return #wrtd_status
*/
wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
const char *rep_cap_id,
wrtd_attr id,
const wrtd_tstamp *value)
wrtd_tstamp *value)
{
wrtd_status status;
......@@ -865,6 +889,11 @@ wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
"parameter value", __func__);
}
while (value->ns >= 1e9) {
value->seconds++;
value->ns -= 1e9;
}
switch(id) {
case WRTD_ATTR_ALARM_TIME:
return wrtd_attr_set_alarm_time
......@@ -902,7 +931,7 @@ wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
}
/**
* Get an attribute of type `timestamp`.
* Get an attribute of type `timestamp` (#wrtd_tstamp).
*
* Modelled after the IVI-C GetAttribute family of functions.
*
......@@ -910,7 +939,7 @@ wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
* @param[in] rep_cap_id ID (string) of concerned repeated capability.
* If it is a global attribute, use #WRTD_GLOBAL_REP_CAP_ID
* @param[in] id ID (#wrtd_attr) of concerned attribute.
* @param[out] value Retrieved attribute value.
* @param[out] value Retrieved attribute value (#wrtd_tstamp).
* @return #wrtd_status
*/
wrtd_status wrtd_get_attr_tstamp(wrtd_dev *wrtd,
......
......@@ -236,6 +236,9 @@ typedef enum wrtd_attr {
/** Size (in characters, including null termination) of an event log enty. */
#define WRTD_LOG_ENTRY_SIZE 120
/** Size (in characters, including null termination) of minimum error message bugger. */
#define WRTD_ERR_MSG_BUF_SIZE 256
/* ------------------------------------------------------------------- */
/* Function prototypes for the official WRTD API. Documented in wrtd.c */
/* ------------------------------------------------------------------- */
......@@ -302,7 +305,7 @@ wrtd_status wrtd_get_attr_string(wrtd_dev *wrtd,
wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
const char *rep_cap_id,
wrtd_attr id,
const wrtd_tstamp *value);
wrtd_tstamp *value);
wrtd_status wrtd_get_attr_tstamp(wrtd_dev *wrtd,
const char *rep_cap_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment