- v = desc->plugin->apis;
- while (v->name && (strncasecmp(v->name, verb, lenverb) || v->name[lenverb]))
- v++;
- if (v->name)
- call_check(req, v);
- else
- afb_req_fail_f(req, "unknown-verb", "verb %.*s unknown within api %s", (int)lenverb, verb, desc->plugin->prefix);
+ struct api_so_desc *desc = closure;
+
+ /* 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->binding->v1.prefix);
+ return -1;
+ }
+
+ /* get the initialisation */
+ init = dlsym(desc->handle, binding_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->binding->v1.prefix);
+ return -1;
+ }
+
+ /* get the event handler if any */
+ onevent = dlsym(desc->handle, binding_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->binding->v1.prefix);
+ return -1;
+ }
+
+ return 0;