+ svc_free(svc);
+ return NULL;
+}
+
+/*
+ * Creates a new service
+ */
+struct afb_svc *afb_svc_create_v2(
+ struct afb_apiset *apiset,
+ int share_session,
+ int (*start)(struct afb_service service),
+ void (*on_event)(struct afb_service service, const char *event, struct json_object *object),
+ struct afb_ditf *ditf
+)
+{
+ int rc;
+ struct afb_svc *svc;
+
+ /* allocates the svc handler */
+ svc = afb_svc_alloc(apiset, share_session);
+ if (svc == NULL)
+ goto error;
+ svc->ditf = ditf;
+
+ /* initialises the listener if needed */
+ if (on_event) {
+ svc->on_event_v2 = on_event;
+ svc->listener = afb_evt_listener_create(&evt_itf_v2, svc);
+ if (svc->listener == NULL)
+ goto error;
+ }
+
+ /* initialises the svc now */
+ rc = start(to_afb_service_v2(svc));
+ if (rc < 0)
+ goto error;
+
+ return svc;
+
+error:
+ svc_free(svc);