Introduce afb_request
[src/app-framework-binder.git] / include / afb / afb-binding-v1.h
index 4fbe8f9..bafb876 100644 (file)
 
 #pragma once
 
-struct afb_binding_interface;
+struct json_object;
+
+#include "afb-req.h"
+#include "afb-event.h"
+#include "afb-service-common.h"
+#include "afb-daemon-common.h"
+
+#include "afb-req-v1.h"
+#include "afb-session-v1.h"
+#include "afb-service-v1.h"
+#include "afb-daemon-v1.h"
+
+struct afb_binding_v1;
+struct afb_binding_interface_v1;
 
 /*
  * Function for registering the binding
@@ -38,52 +51,36 @@ struct afb_binding_interface;
  * 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.
  */
-extern const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *interface);
+extern const struct afb_binding_v1 *afbBindingV1Register (const struct afb_binding_interface_v1 *interface);
 
 /*
- * Enum for Session/Token/Assurance middleware.
- * This enumeration is valid for bindings of type 1
+ * When a binding have an exported implementation of the
+ * function 'afbBindingV1ServiceInit', defined below,
+ * the framework calls it for initialising the service after
+ * registration of all bindings.
+ *
+ * The object 'service' should be recorded. It has functions that
+ * allows the binding to call features with its own personality.
+ *
+ * The function should return 0 in case of success or, else, should return
+ * a negative value.
  */
-enum afb_session_v1
-{
-       AFB_SESSION_NONE = 0,   /* nothing required */
-       AFB_SESSION_CREATE = 1, /* Obsolete */
-       AFB_SESSION_CLOSE = 2,  /* After token authentification, closes the session at end */
-       AFB_SESSION_RENEW = 4,  /* After token authentification, refreshes the token at end */
-       AFB_SESSION_CHECK = 8,  /* Requires token authentification */
-
-       AFB_SESSION_LOA_GE = 16, /* check that the LOA is greater or equal to the given value */
-       AFB_SESSION_LOA_LE = 32, /* check that the LOA is lesser or equal to the given value */
-       AFB_SESSION_LOA_EQ = 48, /* check that the LOA is equal to the given value */
-
-       AFB_SESSION_LOA_SHIFT = 6, /* shift for LOA */
-       AFB_SESSION_LOA_MASK = 7,  /* mask for LOA */
-
-       AFB_SESSION_LOA_0 = 0,   /* value for LOA of 0 */
-       AFB_SESSION_LOA_1 = 64,  /* value for LOA of 1 */
-       AFB_SESSION_LOA_2 = 128, /* value for LOA of 2 */
-       AFB_SESSION_LOA_3 = 192, /* value for LOA of 3 */
-       AFB_SESSION_LOA_4 = 256, /* value for LOA of 4 */
-
-       AFB_SESSION_LOA_LE_0 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_0, /* check LOA <= 0 */
-       AFB_SESSION_LOA_LE_1 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_1, /* check LOA <= 1 */
-       AFB_SESSION_LOA_LE_2 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_2, /* check LOA <= 2 */
-       AFB_SESSION_LOA_LE_3 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_3, /* check LOA <= 3 */
-
-       AFB_SESSION_LOA_GE_0 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_0, /* check LOA >= 0 */
-       AFB_SESSION_LOA_GE_1 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_1, /* check LOA >= 1 */
-       AFB_SESSION_LOA_GE_2 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_2, /* check LOA >= 2 */
-       AFB_SESSION_LOA_GE_3 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_3, /* check LOA >= 3 */
-
-       AFB_SESSION_LOA_EQ_0 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_0, /* check LOA == 0 */
-       AFB_SESSION_LOA_EQ_1 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_1, /* check LOA == 1 */
-       AFB_SESSION_LOA_EQ_2 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_2, /* check LOA == 2 */
-       AFB_SESSION_LOA_EQ_3 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_3  /* check LOA == 3 */
-};
+extern int afbBindingV1ServiceInit(struct afb_service service);
+
+/*
+ * When a binding have an implementation of the function 'afbBindingV1ServiceEvent',
+ * defined below, the framework calls that function for any broadcasted event or for
+ * events that the service subscribed to in its name.
+ *
+ * It receive the 'event' name and its related data in 'object' (be aware that 'object'
+ * might be NULL).
+ */
+extern void afbBindingV1ServiceEvent(const char *event, struct json_object *object);
+
 
 /*
  * Description of one verb of the API provided by the binding
@@ -92,7 +89,7 @@ enum afb_session_v1
 struct afb_verb_desc_v1
 {
        const char *name;                       /* name of the verb */
-       enum afb_session_v1 session;            /* authorisation and session requirements of the verb */
+       enum afb_session_flags_v1 session;      /* authorisation and session requirements of the verb */
        void (*callback)(struct afb_req req);   /* callback function implementing the verb */
        const char *info;                       /* textual description of the verb */
 };
@@ -107,3 +104,103 @@ struct afb_binding_desc_v1
        const struct afb_verb_desc_v1 *verbs;   /* array of descriptions of verbs terminated by a NULL name */
 };
 
+/*
+ * Definition of the type+versions of the binding.
+ * The definition uses hashes.
+ */
+enum  afb_binding_type_v1
+{
+       AFB_BINDING_VERSION_1 = 123456789
+};
+
+/*
+ * Description of a binding
+ */
+struct afb_binding_v1
+{
+       enum afb_binding_type_v1 type; /* type of the binding */
+       union {
+               struct afb_binding_desc_v1 v1;   /* description of the binding of type 1 */
+       };
+};
+
+/*
+ * config mode
+ */
+enum afb_mode_v1
+{
+       AFB_MODE_LOCAL = 0,     /* run locally */
+       AFB_MODE_REMOTE,        /* run remotely */
+       AFB_MODE_GLOBAL         /* run either remotely or locally (DONT USE! reserved for future) */
+};
+
+/*
+ * Interface between the daemon and the binding.
+ */
+struct afb_binding_interface_v1
+{
+       struct afb_daemon daemon;       /* access to the daemon facilies */
+       int verbosity;                  /* level of verbosity */
+       enum afb_mode_v1 mode;          /* run mode (local or remote) */
+};
+
+/*
+ * Macros for logging messages
+ */
+#if defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DATA)
+
+# define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
+       do{ \
+               if(itf->verbosity>=vlevel) {\
+                       if (llevel <= AFB_VERBOSITY_LEVEL_ERROR) \
+                               afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
+                       else \
+                               afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,NULL,NULL); \
+               } \
+       }while(0)
+# define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
+       do{ \
+               if(itf->verbosity>=vlevel) \
+                       afb_req_verbose(req,llevel,__FILE__,__LINE__,NULL,NULL); \
+       }while(0)
+
+#elif defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
+
+# define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
+       do{ \
+               if(itf->verbosity>=vlevel) \
+                       afb_daemon_verbose2_v1(itf->daemon,llevel,NULL,0,NULL,__VA_ARGS__); \
+       }while(0)
+# define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
+       do{ \
+               if(itf->verbosity>=vlevel) \
+                       afb_req_verbose(req,llevel,NULL,0,NULL,__VA_ARGS__); \
+       }while(0)
+
+#else
+
+# define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
+       do{ \
+               if(itf->verbosity>=vlevel) \
+                       afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
+       }while(0)
+# define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
+       do{ \
+               if(itf->verbosity>=vlevel) \
+                       afb_req_verbose(req,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
+       }while(0)
+
+#endif
+
+# include "afb-verbosity.h"
+# define AFB_ERROR_V1(itf,...)       _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
+# define AFB_WARNING_V1(itf,...)     _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
+# define AFB_NOTICE_V1(itf,...)      _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
+# define AFB_INFO_V1(itf,...)        _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
+# define AFB_DEBUG_V1(itf,...)       _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)
+# define AFB_REQ_ERROR_V1(itf,...)   _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
+# define AFB_REQ_WARNING_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
+# define AFB_REQ_NOTICE_V1(itf,...)  _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
+# define AFB_REQ_INFO_V1(itf,...)    _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
+# define AFB_REQ_DEBUG_V1(itf,...)   _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)
+