aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-05-22 16:37:28 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-05-22 17:01:05 +0200
commit95c29ef579d6320a721f96d7146efd10f74a201b (patch)
tree2460427281fe724014033774a7786c857332cfb4 /include
parente9040472b72ff699964d89dda03ef07ce72b487b (diff)
Bindings V2: Remove explicit references to daemon/service
Usage shown that managing daemon interface and service interface wasn't obvious. This evolution hides the complexity by setting up an internal hidden variable. Change-Id: I667b1ee4e3a7b5ad29d712ee20ad5dd1878b97f3 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'include')
-rw-r--r--include/afb/afb-binding-v1.h25
-rw-r--r--include/afb/afb-binding-v2.h102
-rw-r--r--include/afb/afb-binding.h11
-rw-r--r--include/afb/afb-daemon-common.h48
-rw-r--r--include/afb/afb-daemon-v1.h (renamed from include/afb/afb-daemon-itf.h)50
-rw-r--r--include/afb/afb-daemon-v2.h118
-rw-r--r--include/afb/afb-service-common.h45
-rw-r--r--include/afb/afb-service-v1.h (renamed from include/afb/afb-service-itf.h)28
-rw-r--r--include/afb/afb-service-v2.h48
9 files changed, 373 insertions, 102 deletions
diff --git a/include/afb/afb-binding-v1.h b/include/afb/afb-binding-v1.h
index d9b33f1c..e6f322fb 100644
--- a/include/afb/afb-binding-v1.h
+++ b/include/afb/afb-binding-v1.h
@@ -17,10 +17,17 @@
#pragma once
+struct json_object;
+
+#include "afb-req-itf.h"
+#include "afb-event-itf.h"
+#include "afb-service-common.h"
+#include "afb-daemon-common.h"
+
#include "afb-session-v1.h"
+#include "afb-daemon-v1.h"
+#include "afb-daemon-v1.h"
-struct json_object;
-struct afb_service;
struct afb_binding_v1;
struct afb_binding_interface_v1;
@@ -43,7 +50,7 @@ struct afb_binding_interface_v1;
* Be aware that the given 'interface' is not fully functionnal
* because no provision is given to the name and description
* of the binding. Check the function 'afbBindingV1ServiceInit'
- * defined in the file <afb/afb-service-itf.h> because when
+ * defined in the file <afb/afb-service-v1.h> because when
* the function 'afbBindingV1ServiceInit' is called, the 'interface'
* is fully functionnal.
*/
@@ -206,6 +213,18 @@ struct afb_binding_interface_v1
# endif
+#define afb_daemon_get_event_loop afb_daemon_get_event_loop_v1
+#define afb_daemon_get_user_bus afb_daemon_get_user_bus_v1
+#define afb_daemon_get_system_bus afb_daemon_get_system_bus_v1
+#define afb_daemon_broadcast_event afb_daemon_broadcast_event_v1
+#define afb_daemon_make_event afb_daemon_make_event_v1
+#define afb_daemon_verbose afb_daemon_verbose_v1
+#define afb_daemon_rootdir_get_fd afb_daemon_rootdir_get_fd_v1
+#define afb_daemon_rootdir_open_locale afb_daemon_rootdir_open_locale_v1
+#define afb_daemon_queue_job afb_daemon_queue_job_v1
+
+#define afb_service_call afb_service_call_v1
+
#endif
diff --git a/include/afb/afb-binding-v2.h b/include/afb/afb-binding-v2.h
index 91d64693..6f8eb953 100644
--- a/include/afb/afb-binding-v2.h
+++ b/include/afb/afb-binding-v2.h
@@ -19,25 +19,17 @@
#include <stdint.h>
-#include "afb-session-v2.h"
+#include "afb-auth.h"
+#include "afb-req-itf.h"
+#include "afb-event-itf.h"
+#include "afb-service-common.h"
+#include "afb-daemon-common.h"
-struct afb_service;
-struct afb_daemon;
-struct afb_binding_v2;
+#include "afb-session-v2.h"
struct json_object;
/*
- * A binding V2 MUST have two exported symbols of name:
- *
- * - afbBindingV2
- * - afbBindingV2verbosity
- *
- */
-extern const struct afb_binding_v2 afbBindingV2;
-extern int afbBindingV2verbosity;
-
-/*
* Description of one verb of the API provided by the binding
* This enumeration is valid for bindings of type version 2
*/
@@ -57,31 +49,73 @@ struct afb_binding_v2
const char *api; /* api name for the binding */
const char *specification; /* textual specification of the binding */
const struct afb_verb_v2 *verbs; /* array of descriptions of verbs terminated by a NULL name */
- int (*preinit)(struct afb_daemon daemon);
- int (*init)(struct afb_service service);
- void (*onevent)(struct afb_service service, const char *event, struct json_object *object);
- unsigned concurrent: 1; /* allows concurrent requests to verbs */
+ int (*preinit)();
+ int (*init)();
+ void (*onevent)(const char *event, struct json_object *object);
+ unsigned noconcurrency: 1; /* avoids concurrent requests to verbs */
+};
+
+struct afb_binding_data_v2
+{
+ int verbosity; /* level of verbosity */
+ struct afb_daemon daemon; /* access to daemon APIs */
+ struct afb_service service; /* access to service APIs */
};
/*
+ * A binding V2 MUST have two exported symbols of name:
+ *
+ * - afbBindingV2
+ * - afbBindingV2data
+ *
+ */
+#if !defined(AFB_BINDING_MAIN_NAME_V2)
+extern const struct afb_binding_v2 afbBindingV2;
+#endif
+
+#if !defined(AFB_BINDING_DATA_NAME_V2)
+#define AFB_BINDING_DATA_NAME_V2 afbBindingV2data
+#endif
+
+#if AFB_BINDING_VERSION == 2
+struct afb_binding_data_v2 AFB_BINDING_DATA_NAME_V2 __attribute__ ((weak));
+#else
+extern struct afb_binding_data_v2 AFB_BINDING_DATA_NAME_V2;
+#endif
+
+#define afb_get_verbosity_v2() (AFB_BINDING_DATA_NAME_V2.verbosity)
+#define afb_get_daemon_v2() (AFB_BINDING_DATA_NAME_V2.daemon)
+#define afb_get_service_v2() (AFB_BINDING_DATA_NAME_V2.service)
+
+/*
* Macros for logging messages
*/
#if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
# if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
-# define AFB_ERROR_V2(daemon,...) do{if(afbBindingV2verbosity>=0)afb_daemon_verbose(daemon,3,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_WARNING_V2(daemon,...) do{if(afbBindingV2verbosity>=1)afb_daemon_verbose(daemon,4,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_NOTICE_V2(daemon,...) do{if(afbBindingV2verbosity>=1)afb_daemon_verbose(daemon,5,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_INFO_V2(daemon,...) do{if(afbBindingV2verbosity>=2)afb_daemon_verbose(daemon,6,__FILE__,__LINE__,__VA_ARGS__);}while(0)
-# define AFB_DEBUG_V2(daemon,...) do{if(afbBindingV2verbosity>=3)afb_daemon_verbose(daemon,7,__FILE__,__LINE__,__VA_ARGS__);}while(0)
+# define _AFB_LOGGING_V2_(vlevel,llevel,...) \
+ do{ \
+ if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
+ afb_daemon_verbose_v2(llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
+ }while(0)
# else
-# define AFB_ERROR_V2(daemon,...) do{if(afbBindingV2verbosity>=0)afb_daemon_verbose(daemon,3,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_WARNING_V2(daemon,...) do{if(afbBindingV2verbosity>=1)afb_daemon_verbose(daemon,4,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_NOTICE_V2(daemon,...) do{if(afbBindingV2verbosity>=1)afb_daemon_verbose(daemon,5,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_INFO_V2(daemon,...) do{if(afbBindingV2verbosity>=2)afb_daemon_verbose(daemon,6,NULL,0,__VA_ARGS__);}while(0)
-# define AFB_DEBUG_V2(daemon,...) do{if(afbBindingV2verbosity>=3)afb_daemon_verbose(daemon,7,NULL,0,__VA_ARGS__);}while(0)
+# define _AFB_LOGGING_V2_(vlevel,llevel,...) \
+ do{ \
+ if(afbBindingV2data.verbosity>=vlevel) \
+ afb_daemon_verbose_v2(llevel,NULL,0,NULL,__VA_ARGS__); \
+ }while(0)
# endif
+# define AFB_ERROR_V2(...) _AFB_LOGGING_V2_(0,3,__VA_ARGS__)
+# define AFB_WARNING_V2(...) _AFB_LOGGING_V2_(1,4,__VA_ARGS__)
+# define AFB_NOTICE_V2(...) _AFB_LOGGING_V2_(1,5,__VA_ARGS__)
+# define AFB_INFO_V2(...) _AFB_LOGGING_V2_(2,6,__VA_ARGS__)
+# define AFB_DEBUG_V2(...) _AFB_LOGGING_V2_(3,7,__VA_ARGS__)
#endif
+#include "afb-daemon-v2.h"
+#include "afb-service-v2.h"
+
+/***************************************************************************************************/
+
#if AFB_BINDING_VERSION == 2
# define afb_binding afb_binding_v2
@@ -110,4 +144,16 @@ struct afb_binding_v2
# endif
+#define afb_daemon_get_event_loop afb_daemon_get_event_loop_v2
+#define afb_daemon_get_user_bus afb_daemon_get_user_bus_v2
+#define afb_daemon_get_system_bus afb_daemon_get_system_bus_v2
+#define afb_daemon_broadcast_event afb_daemon_broadcast_event_v2
+#define afb_daemon_make_event afb_daemon_make_event_v2
+#define afb_daemon_verbose afb_daemon_verbose_v2
+#define afb_daemon_rootdir_get_fd afb_daemon_rootdir_get_fd_v2
+#define afb_daemon_rootdir_open_locale afb_daemon_rootdir_open_locale_v2
+#define afb_daemon_queue_job afb_daemon_queue_job_v2
+
+#define afb_service_call afb_service_call_v2
+
#endif
diff --git a/include/afb/afb-binding.h b/include/afb/afb-binding.h
index 5a6f9bc4..ac750c7a 100644
--- a/include/afb/afb-binding.h
+++ b/include/afb/afb-binding.h
@@ -40,15 +40,16 @@
#define AFB_BINDING_VERSION AFB_BINDING_DEFAULT_VERSION
#endif
+#if AFB_BINDING_VERSION != 0
+# if AFB_BINDING_VERSION < AFB_BINDING_LOWER_VERSION || AFB_BINDING_VERSION > AFB_BINDING_UPPER_VERSION
+# error "Unsupported binding version AFB_BINDING_VERSION " #AFB_BINDING_VERSION
+# endif
+#endif
+
/*
* Some function of the library are exported to afb-daemon.
*/
-#include "afb-auth.h"
-#include "afb-req-itf.h"
-#include "afb-event-itf.h"
-#include "afb-service-itf.h"
-#include "afb-daemon-itf.h"
#include "afb-binding-v1.h"
#include "afb-binding-v2.h"
diff --git a/include/afb/afb-daemon-common.h b/include/afb/afb-daemon-common.h
new file mode 100644
index 00000000..7b241492
--- /dev/null
+++ b/include/afb/afb-daemon-common.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+/* declaration of features of libsystemd */
+struct sd_event;
+struct sd_bus;
+
+/*
+ * Definition of the facilities provided by the daemon.
+ */
+struct afb_daemon_itf {
+ int (*event_broadcast)(void *closure, const char *name, struct json_object *object); /* broadcasts evant 'name' with 'object' */
+ struct sd_event *(*get_event_loop)(void *closure); /* gets the common systemd's event loop */
+ struct sd_bus *(*get_user_bus)(void *closure); /* gets the common systemd's user d-bus */
+ struct sd_bus *(*get_system_bus)(void *closure); /* gets the common systemd's system d-bus */
+ void (*vverbose_v1)(void*closure, int level, const char *file, int line, const char *fmt, va_list args);
+ struct afb_event (*event_make)(void *closure, const char *name); /* creates an event of 'name' */
+ int (*rootdir_get_fd)(void *closure);
+ int (*rootdir_open_locale)(void *closure, const char *filename, int flags, const char *locale);
+ int (*queue_job)(void *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout);
+ void (*vverbose_v2)(void*closure, int level, const char *file, int line, const char * func, const char *fmt, va_list args);
+};
+
+/*
+ * Structure for accessing daemon.
+ * See also: afb_daemon_get_event_sender, afb_daemon_get_event_loop, afb_daemon_get_user_bus, afb_daemon_get_system_bus
+ */
+struct afb_daemon {
+ const struct afb_daemon_itf *itf; /* the interfacing functions */
+ void *closure; /* the closure when calling these functions */
+};
+
diff --git a/include/afb/afb-daemon-itf.h b/include/afb/afb-daemon-v1.h
index 88ce27c9..84095e04 100644
--- a/include/afb/afb-daemon-itf.h
+++ b/include/afb/afb-daemon-v1.h
@@ -19,39 +19,11 @@
#include <stdarg.h>
-/* declaration of features of libsystemd */
-struct sd_event;
-struct sd_bus;
-
-/*
- * Definition of the facilities provided by the daemon.
- */
-struct afb_daemon_itf {
- int (*event_broadcast)(void *closure, const char *name, struct json_object *object); /* broadcasts evant 'name' with 'object' */
- struct sd_event *(*get_event_loop)(void *closure); /* gets the common systemd's event loop */
- struct sd_bus *(*get_user_bus)(void *closure); /* gets the common systemd's user d-bus */
- struct sd_bus *(*get_system_bus)(void *closure); /* gets the common systemd's system d-bus */
- void (*vverbose)(void*closure, int level, const char *file, int line, const char *fmt, va_list args);
- struct afb_event (*event_make)(void *closure, const char *name); /* creates an event of 'name' */
- int (*rootdir_get_fd)(void *closure);
- int (*rootdir_open_locale)(void *closure, const char *filename, int flags, const char *locale);
- int (*queue_job)(void *closure, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout);
-};
-
-/*
- * Structure for accessing daemon.
- * See also: afb_daemon_get_event_sender, afb_daemon_get_event_loop, afb_daemon_get_user_bus, afb_daemon_get_system_bus
- */
-struct afb_daemon {
- const struct afb_daemon_itf *itf; /* the interfacing functions */
- void *closure; /* the closure when calling these functions */
-};
-
/*
* Retrieves the common systemd's event loop of AFB
* 'daemon' MUST be the daemon given in interface when activating the binding.
*/
-static inline struct sd_event *afb_daemon_get_event_loop(struct afb_daemon daemon)
+static inline struct sd_event *afb_daemon_get_event_loop_v1(struct afb_daemon daemon)
{
return daemon.itf->get_event_loop(daemon.closure);
}
@@ -60,7 +32,7 @@ static inline struct sd_event *afb_daemon_get_event_loop(struct afb_daemon daemo
* Retrieves the common systemd's user/session d-bus of AFB
* 'daemon' MUST be the daemon given in interface when activating the binding.
*/
-static inline struct sd_bus *afb_daemon_get_user_bus(struct afb_daemon daemon)
+static inline struct sd_bus *afb_daemon_get_user_bus_v1(struct afb_daemon daemon)
{
return daemon.itf->get_user_bus(daemon.closure);
}
@@ -69,7 +41,7 @@ static inline struct sd_bus *afb_daemon_get_user_bus(struct afb_daemon daemon)
* Retrieves the common systemd's system d-bus of AFB
* 'daemon' MUST be the daemon given in interface when activating the binding.
*/
-static inline struct sd_bus *afb_daemon_get_system_bus(struct afb_daemon daemon)
+static inline struct sd_bus *afb_daemon_get_system_bus_v1(struct afb_daemon daemon)
{
return daemon.itf->get_system_bus(daemon.closure);
}
@@ -85,7 +57,7 @@ static inline struct sd_bus *afb_daemon_get_system_bus(struct afb_daemon daemon)
*
* Returns the count of clients that received the event.
*/
-static inline int afb_daemon_broadcast_event(struct afb_daemon daemon, const char *name, struct json_object *object)
+static inline int afb_daemon_broadcast_event_v1(struct afb_daemon daemon, const char *name, struct json_object *object)
{
return daemon.itf->event_broadcast(daemon.closure, name, object);
}
@@ -94,7 +66,7 @@ static inline int afb_daemon_broadcast_event(struct afb_daemon daemon, const cha
* Creates an event of 'name' and returns it.
* 'daemon' MUST be the daemon given in interface when activating the binding.
*/
-static inline struct afb_event afb_daemon_make_event(struct afb_daemon daemon, const char *name)
+static inline struct afb_event afb_daemon_make_event_v1(struct afb_daemon daemon, const char *name)
{
return daemon.itf->event_make(daemon.closure, name);
}
@@ -105,12 +77,12 @@ static inline struct afb_event afb_daemon_make_event(struct afb_daemon daemon, c
* 'file' and 'line' are indicators of position of the code in source files.
* 'daemon' MUST be the daemon given in interface when activating the binding.
*/
-static inline void afb_daemon_verbose(struct afb_daemon daemon, int level, const char *file, int line, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
-static inline void afb_daemon_verbose(struct afb_daemon daemon, int level, const char *file, int line, const char *fmt, ...)
+static inline void afb_daemon_verbose_v1(struct afb_daemon daemon, int level, const char *file, int line, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
+static inline void afb_daemon_verbose_v1(struct afb_daemon daemon, int level, const char *file, int line, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- daemon.itf->vverbose(daemon.closure, level, file, line, fmt, args);
+ daemon.itf->vverbose_v1(daemon.closure, level, file, line, fmt, args);
va_end(args);
}
@@ -118,7 +90,7 @@ static inline void afb_daemon_verbose(struct afb_daemon daemon, int level, const
* Get the root directory file descriptor. This file descriptor can
* be used with functions 'openat', 'fstatat', ...
*/
-static inline int afb_daemon_rootdir_get_fd(struct afb_daemon daemon)
+static inline int afb_daemon_rootdir_get_fd_v1(struct afb_daemon daemon)
{
return daemon.itf->rootdir_get_fd(daemon.closure);
}
@@ -128,7 +100,7 @@ static inline int afb_daemon_rootdir_get_fd(struct afb_daemon daemon)
* using the 'locale' definition (example: "jp,en-US") that can be NULL.
* Returns the file descriptor or -1 in case of error.
*/
-static inline int afb_daemon_rootdir_open_locale(struct afb_daemon daemon, const char *filename, int flags, const char *locale)
+static inline int afb_daemon_rootdir_open_locale_v1(struct afb_daemon daemon, const char *filename, int flags, const char *locale)
{
return daemon.itf->rootdir_open_locale(daemon.closure, filename, flags, locale);
}
@@ -146,7 +118,7 @@ static inline int afb_daemon_rootdir_open_locale(struct afb_daemon daemon, const
*
* Returns 0 in case of success or -1 in case of error.
*/
-static inline int afb_daemon_queue_job(struct afb_daemon daemon, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
+static inline int afb_daemon_queue_job_v1(struct afb_daemon daemon, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
{
return daemon.itf->queue_job(daemon.closure, callback, argument, group, timeout);
}
diff --git a/include/afb/afb-daemon-v2.h b/include/afb/afb-daemon-v2.h
new file mode 100644
index 00000000..3ecd763b
--- /dev/null
+++ b/include/afb/afb-daemon-v2.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <stdarg.h>
+
+/*
+ * Retrieves the common systemd's event loop of AFB
+ */
+static inline struct sd_event *afb_daemon_get_event_loop_v2()
+{
+ return afb_get_daemon_v2().itf->get_event_loop(afb_get_daemon_v2().closure);
+}
+
+/*
+ * Retrieves the common systemd's user/session d-bus of AFB
+ */
+static inline struct sd_bus *afb_daemon_get_user_bus_v2()
+{
+ return afb_get_daemon_v2().itf->get_user_bus(afb_get_daemon_v2().closure);
+}
+
+/*
+ * Retrieves the common systemd's system d-bus of AFB
+ */
+static inline struct sd_bus *afb_daemon_get_system_bus_v2()
+{
+ return afb_get_daemon_v2().itf->get_system_bus(afb_get_daemon_v2().closure);
+}
+
+/*
+ * Broadcasts widely the event of 'name' with the data 'object'.
+ * 'object' can be NULL.
+ *
+ * For convenience, the function calls 'json_object_put' for 'object'.
+ * Thus, in the case where 'object' should remain available after
+ * the function returns, the function 'json_object_get' shall be used.
+ *
+ * Returns the count of clients that received the event.
+ */
+static inline int afb_daemon_broadcast_event_v2(const char *name, struct json_object *object)
+{
+ return afb_get_daemon_v2().itf->event_broadcast(afb_get_daemon_v2().closure, name, object);
+}
+
+/*
+ * Creates an event of 'name' and returns it.
+ */
+static inline struct afb_event afb_daemon_make_event_v2(const char *name)
+{
+ return afb_get_daemon_v2().itf->event_make(afb_get_daemon_v2().closure, name);
+}
+
+/*
+ * Send a message described by 'fmt' and following parameters
+ * to the journal for the verbosity 'level'.
+ * 'file' and 'line' are indicators of position of the code in source files.
+ */
+static inline void afb_daemon_verbose_v2(int level, const char *file, int line, const char * func, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
+static inline void afb_daemon_verbose_v2(int level, const char *file, int line, const char * func, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ afb_get_daemon_v2().itf->vverbose_v2(afb_get_daemon_v2().closure, level, file, line, func, fmt, args);
+ va_end(args);
+}
+
+/*
+ * Get the root directory file descriptor. This file descriptor can
+ * be used with functions 'openat', 'fstatat', ...
+ */
+static inline int afb_daemon_rootdir_get_fd_v2()
+{
+ return afb_get_daemon_v2().itf->rootdir_get_fd(afb_get_daemon_v2().closure);
+}
+
+/*
+ * Opens 'filename' within the root directory with 'flags' (see function openat)
+ * using the 'locale' definition (example: "jp,en-US") that can be NULL.
+ * Returns the file descriptor or -1 in case of error.
+ */
+static inline int afb_daemon_rootdir_open_locale_v2(const char *filename, int flags, const char *locale)
+{
+ return afb_get_daemon_v2().itf->rootdir_open_locale(afb_get_daemon_v2().closure, filename, flags, locale);
+}
+
+/*
+ * Queue the job defined by 'callback' and 'argument' for being executed asynchronously
+ * in this thread (later) or in an other thread.
+ * If 'group' is not NUL, the jobs queued with a same value (as the pointer value 'group')
+ * are executed in sequence in the order of there submission.
+ * If 'timeout' is not 0, it represent the maximum execution time for the job in seconds.
+ * At first, the job is called with 0 as signum and the given argument.
+ * The job is executed with the monitoring of its time and some signals like SIGSEGV and
+ * SIGFPE. When a such signal is catched, the job is terminated and reexecuted but with
+ * signum being the signal number (SIGALRM when timeout expired).
+ *
+ * Returns 0 in case of success or -1 in case of error.
+ */
+static inline int afb_daemon_queue_job_v2(void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
+{
+ return afb_get_daemon_v2().itf->queue_job(afb_get_daemon_v2().closure, callback, argument, group, timeout);
+}
diff --git a/include/afb/afb-service-common.h b/include/afb/afb-service-common.h
new file mode 100644
index 00000000..76f8e4e4
--- /dev/null
+++ b/include/afb/afb-service-common.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+/* avoid inclusion of <json-c/json.h> */
+struct json_object;
+
+/*
+ * Interface for internal of services
+ * It records the functions to be called for the request.
+ * Don't use this structure directly.
+ * Use the helper functions documented below.
+ */
+struct afb_service_itf
+{
+ /* CAUTION: respect the order, add at the end */
+
+ void (*call)(void *closure, const char *api, const char *verb, struct json_object *args,
+ void (*callback)(void*, int, struct json_object*), void *callback_closure);
+};
+
+/*
+ * Object that encapsulate accesses to service items
+ */
+struct afb_service
+{
+ const struct afb_service_itf *itf;
+ void *closure;
+};
+
diff --git a/include/afb/afb-service-itf.h b/include/afb/afb-service-v1.h
index e2e61dc8..6e85a293 100644
--- a/include/afb/afb-service-itf.h
+++ b/include/afb/afb-service-v1.h
@@ -17,32 +17,6 @@
#pragma once
-/* avoid inclusion of <json-c/json.h> */
-struct json_object;
-
-/*
- * Interface for internal of services
- * It records the functions to be called for the request.
- * Don't use this structure directly.
- * Use the helper functions documented below.
- */
-struct afb_service_itf
-{
- /* CAUTION: respect the order, add at the end */
-
- void (*call)(void *closure, const char *api, const char *verb, struct json_object *args,
- void (*callback)(void*, int, struct json_object*), void *callback_closure);
-};
-
-/*
- * Object that encapsulate accesses to service items
- */
-struct afb_service
-{
- const struct afb_service_itf *itf;
- void *closure;
-};
-
/**
* Calls the 'verb' of the 'api' with the arguments 'args' and 'verb' in the name of the binding.
* The result of the call is delivered to the 'callback' function with the 'callback_closure'.
@@ -63,7 +37,7 @@ struct afb_service
*
* @see also 'afb_req_subcall'
*/
-static inline void afb_service_call(
+static inline void afb_service_call_v1(
struct afb_service service,
const char *api,
const char *verb,
diff --git a/include/afb/afb-service-v2.h b/include/afb/afb-service-v2.h
new file mode 100644
index 00000000..84da1209
--- /dev/null
+++ b/include/afb/afb-service-v2.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Author: José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+/**
+ * Calls the 'verb' of the 'api' with the arguments 'args' and 'verb' in the name of the binding.
+ * The result of the call is delivered to the 'callback' function with the 'callback_closure'.
+ *
+ * The 'callback' receives 3 arguments:
+ * 1. 'closure' the user defined closure pointer 'callback_closure',
+ * 2. 'iserror' a boolean status being true (not null) when an error occured,
+ * 2. 'result' the resulting data as a JSON object.
+ *
+ * @param api The api name of the method to call
+ * @param verb The verb name of the method to call
+ * @param args The arguments to pass to the method
+ * @param callback The to call on completion
+ * @param callback_closure The closure to pass to the callback
+ *
+ * @returns 0 in case of success or -1 in case of error.
+ *
+ * @see also 'afb_req_subcall'
+ */
+static inline void afb_service_call_v2(
+ const char *api,
+ const char *verb,
+ struct json_object *args,
+ void (*callback)(void*closure, int iserror, struct json_object *result),
+ void *callback_closure)
+{
+ afb_get_service_v2().itf->call(afb_get_service_v2().closure, api, verb, args, callback, callback_closure);
+}
+