+ free(svc);
+error:
+ return NULL;
+}
+
+/*
+ * Creates a new service
+ */
+struct afb_svc *afb_svc_create_v2(
+ int share_session,
+ void (*on_event)(const char *event, struct json_object *object),
+ int (*start)(const struct afb_binding_interface *interface, struct afb_service service),
+ const struct afb_binding_interface *interface)
+{
+ int rc;
+ struct afb_svc *svc;
+
+ /* allocates the svc handler */
+ svc = afb_svc_alloc(share_session, on_event);
+ if (svc == NULL)
+ goto error;
+
+ /* initialises the svc now */
+ rc = start(interface, (struct afb_service){ .itf = &service_itf, .closure = svc });
+ if (rc < 0)
+ goto error2;
+
+ return svc;
+