aboutsummaryrefslogtreecommitdiffstats
path: root/binding/iiodevices-binding.c
diff options
context:
space:
mode:
Diffstat (limited to 'binding/iiodevices-binding.c')
-rw-r--r--binding/iiodevices-binding.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/binding/iiodevices-binding.c b/binding/iiodevices-binding.c
index 487af26..306124c 100644
--- a/binding/iiodevices-binding.c
+++ b/binding/iiodevices-binding.c
@@ -28,7 +28,7 @@
#include <limits.h>
#include <json-c/json.h>
-#define AFB_BINDING_VERSION 2
+#define AFB_BINDING_VERSION 3
#include <afb/afb-binding.h>
#include <iio.h>
@@ -51,17 +51,17 @@ struct client_sub {
uint64_t u_period;
enum iio_elements iioelts;
struct iio_device *dev;
- struct afb_event *event;
+ afb_event_t *event;
struct iio_info *infos;
json_object *jobject;
struct client_sub *next;
};
-/*gather all afb_event*/
+/*gather all afb_event_t*/
struct event
{
struct event *next;
- struct afb_event event;
+ afb_event_t event;
char tag[PATH_MAX];
};
@@ -81,8 +81,8 @@ static struct iio_info iio_infos[] = {
{ "16-006b", "compass", "anglvel"}
};
-/*get event by afb_event*/
-static struct event *event_get_event(const struct afb_event *event)
+/*get event by afb_event_t*/
+static struct event *event_get_event(const afb_event_t *event)
{
struct event *e = events;
while(&e->event != event) {
@@ -101,7 +101,7 @@ static struct event *event_get(const char *tag)
}
/* creates the event of tag */
-static struct afb_event* event_add(const char *tag)
+static afb_event_t* event_add(const char *tag)
{
struct event *e;
@@ -115,7 +115,7 @@ static struct afb_event* event_add(const char *tag)
strncpy(e->tag, tag, PATH_MAX);
/* make the event */
- e->event = afb_daemon_make_event(tag);
+ e->event = afb_api_make_event(afbBindingV3root, tag);
if (!afb_event_is_valid(e->event)) { free(e); return NULL; }
/* link */
@@ -125,7 +125,7 @@ static struct afb_event* event_add(const char *tag)
}
/* deletes the event of event */
-static int event_del(struct afb_event *event)
+static int event_del(afb_event_t *event)
{
struct event *e, **p;
@@ -150,7 +150,7 @@ int init_context()
ctx = iio_create_local_context();
if(!ctx)
{
- AFB_ERROR("cannot create local iio context");
+ AFB_API_ERROR(afbBindingV3root, "cannot create local iio context");
return -1;
}
return 0;
@@ -160,14 +160,14 @@ int init_context()
static void init_dev(struct client_sub *client)
{
if(!client) {
- AFB_ERROR("client is null");
+ AFB_API_ERROR(afbBindingV3root, "client is null");
return;
}
- AFB_DEBUG("iio_context_find_device %s", client->infos->dev_name);
+ AFB_API_DEBUG(afbBindingV3root, "iio_context_find_device %s", client->infos->dev_name);
client->dev = iio_context_find_device(ctx, client->infos->dev_name);
if(!client->dev) {
- AFB_ERROR("No %s device found", client->infos->dev_name);
+ AFB_API_ERROR(afbBindingV3root, "No %s device found", client->infos->dev_name);
return;
}
}
@@ -176,7 +176,7 @@ static void init_dev(struct client_sub *client)
static int read_infos(struct client_sub* client)
{
if(!client || !client->channels || !client->channels->chn) {
- AFB_ERROR("client or client->channels or client->channels->chn is null");
+ AFB_API_ERROR(afbBindingV3root, "client or client->channels or client->channels->chn is null");
return -1;
}
json_object *jobject = NULL;
@@ -190,7 +190,7 @@ static int read_infos(struct client_sub* client)
for(int i = 0; i < iio_channel_get_attrs_count(channel->chn); i++) {
const char *id_attr = iio_channel_get_attr(channel->chn, i);
if(!id_attr) {
- AFB_ERROR("cannot get attr from channel %d", i);
+ AFB_API_ERROR(afbBindingV3root, "cannot get attr from channel %d", i);
return -1;
}
if(strcasecmp(id_attr, "raw")) { //do not take raw infos
@@ -208,7 +208,7 @@ static int read_infos(struct client_sub* client)
strncpy(keyfirst, id_attr, size);
set_channel_name(keyfirst, client->channels->iioelts);
if(!json_object_object_get_ex(client->jobject, keyfirst, &jobject)) {
- AFB_WARNING("cannot find %s keyfirst in json object",
+ AFB_API_WARNING(afbBindingV3root, "cannot find %s keyfirst in json object",
keyfirst);
}
}
@@ -240,7 +240,7 @@ static int read_infos(struct client_sub* client)
static void close_fd(struct client_sub *client)
{
if(!client) {
- AFB_ERROR("client is null pointer");
+ AFB_API_ERROR(afbBindingV3root, "client is null pointer");
return;
}
@@ -252,14 +252,14 @@ static void close_fd(struct client_sub *client)
static void deinit_channels(struct client_sub *client)
{
if(!client->channels) {
- AFB_ERROR("client->channels is null pointer");
+ AFB_API_ERROR(afbBindingV3root, "client->channels is null pointer");
return;
}
struct channels *it_chn = client->channels;
while(it_chn) {
struct channels *tmp = it_chn->next;
- AFB_DEBUG("free it_chn=%s", it_chn->name);
+ AFB_API_DEBUG(afbBindingV3root, "free it_chn=%s", it_chn->name);
free(it_chn);
it_chn = tmp;
}
@@ -270,7 +270,7 @@ static void deinit_channels(struct client_sub *client)
static struct client_sub* looking_for_previous(struct client_sub *client)
{
if(!client || !clients) {
- AFB_ERROR("client or clients is null pointer");
+ AFB_API_ERROR(afbBindingV3root, "client or clients is null pointer");
return NULL;
}
struct client_sub* prev = clients;
@@ -284,7 +284,7 @@ static struct client_sub* looking_for_previous(struct client_sub *client)
static void deinit_client_sub(struct client_sub *client)
{
if(!client) {
- AFB_ERROR("client is null pointer");
+ AFB_API_ERROR(afbBindingV3root, "client is null pointer");
return;
}
@@ -295,12 +295,12 @@ static void deinit_client_sub(struct client_sub *client)
else {
prev_client = looking_for_previous(client);
if(!prev_client) {
- AFB_ERROR("cannot find previous client");
+ AFB_API_ERROR(afbBindingV3root, "cannot find previous client");
exit(-1);
}
prev_client->next = client->next;
}
- AFB_DEBUG("free client for %s", client->infos->id);
+ AFB_API_DEBUG(afbBindingV3root, "free client for %s", client->infos->id);
free(client);
}
@@ -308,7 +308,7 @@ static void deinit_client_sub(struct client_sub *client)
static void desallocate_channels(sd_event_source* src,
struct client_sub *client)
{
- afb_event_drop(*client->event);
+ afb_event_unref(*client->event);
if(src) {
sd_event_source_set_enabled(src, SD_EVENT_OFF);
sd_event_source_unref(src);
@@ -323,7 +323,7 @@ static void desallocate_channels(sd_event_source* src,
static int read_data(struct client_sub *client, sd_event_source* src)
{
if(!client) {
- AFB_ERROR("client is null");
+ AFB_API_ERROR(afbBindingV3root, "client is null");
return -1;
}
@@ -331,13 +331,13 @@ static int read_data(struct client_sub *client, sd_event_source* src)
struct channels *channel = client->channels;
while(channel) { //iterate on client channels
if(!channel->chn) {
- AFB_ERROR("chn is null for cl_chn=%s", channel->name);
+ AFB_API_ERROR(afbBindingV3root, "chn is null for cl_chn=%s", channel->name);
return -1;
}
iio_channel_attr_read(channel->chn, "raw", val, 10);
int data = (int)strtol(val, NULL, 10);
- AFB_DEBUG("read_data: %s %d", iio_channel_get_id(channel->chn), data);
+ AFB_API_DEBUG(afbBindingV3root, "read_data: %s %d", iio_channel_get_id(channel->chn), data);
json_object *value = json_object_new_int(data);
json_object_object_add(client->jobject, channel->name, value);
@@ -346,7 +346,7 @@ static int read_data(struct client_sub *client, sd_event_source* src)
/*if no more subscribers -> desallocate*/
int nb_subscribers = afb_event_push(*client->event, json_object_get(client->jobject));
- AFB_DEBUG("nb_subscribers for %s is %d", afb_event_name(*client->event), nb_subscribers);
+ AFB_API_DEBUG(afbBindingV3root, "nb_subscribers for %s is %d", afb_event_name(*client->event), nb_subscribers);
if(nb_subscribers <= 0)
desallocate_channels(src, client);
return 0;
@@ -367,7 +367,7 @@ static int read_data_timer(sd_event_source* src, uint64_t usec, void *userdata)
/*set next time to trigger*/
uint64_t usecs;
- sd_event_now(afb_daemon_get_event_loop(), CLOCK_MONOTONIC, &usecs);
+ sd_event_now(afb_api_get_event_loop(afbBindingV3root), CLOCK_MONOTONIC, &usecs);
usecs += client->u_period;
sd_event_source_set_time(src, usecs);
@@ -380,11 +380,11 @@ static int read_data_timer(sd_event_source* src, uint64_t usec, void *userdata)
static void init_event_io(struct client_sub *client)
{
if(!client) {
- AFB_ERROR("client is null");
+ AFB_API_ERROR(afbBindingV3root, "client is null");
return;
}
if(!client->channels) {
- AFB_ERROR("channel is null");
+ AFB_API_ERROR(afbBindingV3root, "channel is null");
return;
}
read_infos(client); //get unchanged infos
@@ -395,14 +395,14 @@ static void init_event_io(struct client_sub *client)
IIODEVICE"%s/%s", iio_device_get_id(client->dev),
iio_channel_attr_get_filename(client->channels->chn, "raw"));
if((client->fd = open(filename, O_RDONLY)) < 0) {
- AFB_ERROR("cannot open %s file", filename);
+ AFB_API_ERROR(afbBindingV3root, "cannot open %s file", filename);
return;
}
- sd_event_add_io(afb_daemon_get_event_loop(), &source, client->fd, EPOLLIN, read_data_push, client);
+ sd_event_add_io(afb_api_get_event_loop(afbBindingV3root), &source, client->fd, EPOLLIN, read_data_push, client);
}
else { //frequency specified
- sd_event_add_time(afb_daemon_get_event_loop(), &source, CLOCK_MONOTONIC, 0, 1, read_data_timer, client);
+ sd_event_add_time(afb_api_get_event_loop(afbBindingV3root), &source, CLOCK_MONOTONIC, 0, 1, read_data_timer, client);
sd_event_source_set_enabled(source, SD_EVENT_ON);
}
}
@@ -413,7 +413,7 @@ static struct channels* set_channel(
{
prev_chn->next = malloc(sizeof(struct channels));
if(!prev_chn->next) {
- AFB_ERROR("alloc failed for channels");
+ AFB_API_ERROR(afbBindingV3root, "alloc failed for channels");
return NULL;
}
@@ -426,7 +426,7 @@ static struct channels* set_channel(
set_channel_name(chn->name, i);
if(!(chn->chn = iio_device_find_channel(client->dev, chn->name, false))) {
- AFB_ERROR("cannot find %s channel", chn->name);
+ AFB_API_ERROR(afbBindingV3root, "cannot find %s channel", chn->name);
free(chn);
prev_chn->next = NULL;
return prev_chn;
@@ -438,10 +438,10 @@ static struct channels* set_channel(
static void init_channel(struct client_sub* client, const unsigned int iioelts)
{
if(!client) {
- AFB_ERROR("client is null");
+ AFB_API_ERROR(afbBindingV3root, "client is null");
return;
}
- AFB_DEBUG("size of channels=%d", get_iio_nb(iioelts));
+ AFB_API_DEBUG(afbBindingV3root, "size of channels=%d", get_iio_nb(iioelts));
/*looking for the last channel: could be the first*/
struct channels pre_index;
@@ -477,7 +477,7 @@ static struct client_sub* is_new_client_sub_needed(struct iio_info* infos,
struct client_sub *it_client = clients;
while(it_client) {
if(it_client->infos == infos && u_period == it_client->u_period) {
- AFB_DEBUG("a client is matching");
+ AFB_API_DEBUG(afbBindingV3root, "a client is matching");
*rest_iioelts = ~it_client->iioelts & *rest_iioelts;
it_client->iioelts |= *rest_iioelts;
return it_client;
@@ -493,7 +493,7 @@ static struct client_sub *add_new_client(struct iio_info *infos,
{
struct client_sub *client = malloc(sizeof(struct client_sub));
if(!client) {
- AFB_ERROR("cannot allocate client");
+ AFB_API_ERROR(afbBindingV3root, "cannot allocate client");
return NULL;
}
//initialise client
@@ -503,7 +503,7 @@ static struct client_sub *add_new_client(struct iio_info *infos,
}
else {
if(!last_client) {
- AFB_ERROR("last_client should not be null");
+ AFB_API_ERROR(afbBindingV3root, "last_client should not be null");
return NULL;
}
last_client->next = client;
@@ -512,7 +512,7 @@ static struct client_sub *add_new_client(struct iio_info *infos,
char event_name[100];
sprintf(event_name, "%s%d", infos->id, client->index);
- AFB_DEBUG("add_new_client with event_name=%s", event_name);
+ AFB_API_DEBUG(afbBindingV3root, "add_new_client with event_name=%s", event_name);
client->channels = NULL;
client->jobject = json_object_new_object();
@@ -529,7 +529,7 @@ static struct client_sub *add_new_client(struct iio_info *infos,
}
/*subscribe verb*/
-static void subscribe(struct afb_req request)
+static void subscribe(afb_req_t request)
{
init_context();
const char *value = afb_req_value(request, "event");
@@ -545,7 +545,7 @@ static void subscribe(struct afb_req request)
return;
}
- AFB_INFO("subscription with: value=%s, s_iioelts=%s, freq=%s",
+ AFB_API_INFO(afbBindingV3root, "subscription with: value=%s, s_iioelts=%s, freq=%s",
value, s_iioelts, freq);
bool found = false;
@@ -600,7 +600,7 @@ static void subscribe(struct afb_req request)
}
/*unsubscribe verb*/
-static void unsubscribe(struct afb_req request)
+static void unsubscribe(afb_req_t request)
{
init_context();
const char *value = afb_req_value(request, "event");
@@ -617,7 +617,7 @@ static void unsubscribe(struct afb_req request)
struct client_sub *client
= (struct client_sub *)afb_req_context_get(request);
if(!client) {
- AFB_ERROR("cannot find %s event, it seems that there was \
+ AFB_API_ERROR(afbBindingV3root, "cannot find %s event, it seems that there was \
no subscription", value);
afb_req_fail_f(request, "failed", "cannot find %s event, it seems that there was \
no subscription", value);
@@ -638,14 +638,14 @@ static void unsubscribe(struct afb_req request)
}
/*list of api verbs*/
-const afb_verb_v2 verbs[] = {
+const afb_verb_t verbs[] = {
{ .verb = "subscribe", .session = AFB_SESSION_NONE, .callback = subscribe, .info = "Subscribe for an event" },
{ .verb = "unsubscribe", .session = AFB_SESSION_NONE, .callback = unsubscribe, .info = "Unsubscribe for an event" },
{ .verb=NULL }
};
/*binding configuration*/
-const afb_binding_v2 afbBindingV2 = {
+const afb_binding_t afbBindingExport = {
.info = "iio devices service",
.api = "iiodevices",
.verbs = verbs