+static int service_start(struct api_so_desc *desc, int share_session, int onneed)
+{
+ int (*init)(struct afb_service service);
+ void (*onevent)(const char *event, struct json_object *object);
+
+ /* check state */
+ if (desc->service != NULL) {
+ /* not an error when onneed */
+ if (onneed != 0)
+ return 0;
+
+ /* already started: it is an error */
+ ERROR("Service %s already started", desc->plugin->v1.prefix);
+ return -1;
+ }
+
+ /* get the initialisation */
+ init = dlsym(desc->handle, plugin_service_init_function_v1);
+ if (init == NULL) {
+ /* not an error when onneed */
+ if (onneed != 0)
+ return 0;
+
+ /* no initialisation method */
+ ERROR("Binding %s is not a service", desc->plugin->v1.prefix);
+ return -1;
+ }
+
+ /* get the event handler if any */
+ onevent = dlsym(desc->handle, plugin_service_event_function_v1);
+ desc->service = afb_svc_create(share_session, init, onevent);
+ if (desc->service == NULL) {
+ /* starting error */
+ ERROR("Starting service %s failed", desc->plugin->v1.prefix);
+ return -1;
+ }
+
+ return 0;
+}
+