2 * Copyright (C) 2015, 2016, 2017 "IoT.bzh"
3 * Author José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #define NO_PLUGIN_VERBOSE_MACRO
26 #include <systemd/sd-bus.h>
27 #include <json-c/json.h>
29 #include <afb/afb-req-itf.h>
31 #include "afb-common.h"
33 #include "afb-session.h"
34 #include "afb-msg-json.h"
36 #include "afb-api-so.h"
37 #include "afb-context.h"
43 static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/";
50 * The path given are of the form
51 * system:/org/agl/afb/api/...
53 * user:/org/agl/afb/api/...
57 struct sd_bus *sdbus; /* the bus */
58 char *path; /* path of the object for the API */
59 char *name; /* name/interface of the object */
60 char *api; /* api name of the interface */
63 struct sd_bus_slot *slot_broadcast;
64 struct sd_bus_slot *slot_event;
65 struct dbus_event *events;
66 struct dbus_memo *memos;
69 struct sd_bus_slot *slot_call;
70 struct afb_evt_listener *listener; /* listener for broadcasted events */
71 struct origin *origins;
79 /******************* common part **********************************/
82 * create a structure api_dbus connected on either the system
83 * bus if 'system' is not null or on the user bus. The connection
84 * is established for either emiting/receiving on 'path' being of length
87 static struct api_dbus *make_api_dbus_3(int system, const char *path, size_t pathlen)
93 /* allocates the structure */
94 api = calloc(1, sizeof *api + 1 + pathlen + pathlen);
100 /* init the structure's strings */
102 /* path is copied after the struct */
103 api->path = (void*)(api+1);
104 strcpy(api->path, path);
106 /* api name is at the end of the path */
107 api->api = strrchr(api->path, '/');
108 if (api->api == NULL) {
113 if (!afb_apis_is_valid_api_name(api->api)) {
118 /* the name/interface is copied after the path */
119 api->name = &api->path[pathlen + 1];
120 strcpy(api->name, &path[1]);
121 ptr = strchr(api->name, '/');
124 ptr = strchr(ptr, '/');
128 sdbus = (system ? afb_common_get_system_bus : afb_common_get_user_bus)();
142 * create a structure api_dbus connected on either the system
143 * bus if 'system' is not null or on the user bus. The connection
144 * is established for either emiting/receiving on 'path'.
145 * If 'path' is not absolute, it is prefixed with DEFAULT_PATH_PREFIX.
147 static struct api_dbus *make_api_dbus_2(int system, const char *path)
152 /* check the length of the path */
159 /* if the path is absolute, creation now */
161 return make_api_dbus_3(system, path, len);
163 /* compute the path prefixed with DEFAULT_PATH_PREFIX */
164 assert(strlen(DEFAULT_PATH_PREFIX) > 0);
165 assert(DEFAULT_PATH_PREFIX[strlen(DEFAULT_PATH_PREFIX) - 1] == '/');
166 len += strlen(DEFAULT_PATH_PREFIX);
167 ptr = alloca(len + 1);
168 strcpy(stpcpy(ptr, DEFAULT_PATH_PREFIX), path);
170 /* creation for prefixed path */
171 return make_api_dbus_3(system, ptr, len);
175 * create a structure api_dbus connected either emiting/receiving
177 * The path can be prefixed with "system:" or "user:" to select
178 * either the user or the system D-Bus. If none is set then user's
180 * If remaining 'path' is not absolute, it is prefixed with
181 * DEFAULT_PATH_PREFIX.
183 static struct api_dbus *make_api_dbus(const char *path)
188 /* retrieves the prefix "scheme-like" part */
189 ptr = strchr(path, ':');
191 return make_api_dbus_2(0, path);
193 /* check the prefix part */
194 preflen = (size_t)(ptr - path);
195 if (strncmp(path, "system", preflen) == 0)
196 return make_api_dbus_2(1, ptr + 1);
198 if (strncmp(path, "user", preflen) == 0)
199 return make_api_dbus_2(0, ptr + 1);
201 /* TODO: connect to a foreign D-Bus? */
206 static void destroy_api_dbus(struct api_dbus *api)
211 /******************* client part **********************************/
214 * structure for recording query data
217 struct dbus_memo *next; /* the next memo */
218 struct api_dbus *api; /* the dbus api */
219 struct afb_xreq *xreq; /* the request */
220 uint64_t msgid; /* the message identifier */
225 struct dbus_event *next;
226 struct afb_event event;
231 /* allocates and init the memorizing data */
232 static struct dbus_memo *api_dbus_client_memo_make(struct api_dbus *api, struct afb_xreq *xreq)
234 struct dbus_memo *memo;
236 memo = malloc(sizeof *memo);
238 afb_xreq_addref(xreq);
242 memo->next = api->client.memos;
243 api->client.memos = memo;
248 /* free and release the memorizing data */
249 static void api_dbus_client_memo_destroy(struct dbus_memo *memo)
251 struct dbus_memo **prv;
253 prv = &memo->api->client.memos;
254 while (*prv != NULL) {
262 afb_xreq_unref(memo->xreq);
266 /* search a memorized request */
267 static struct dbus_memo *api_dbus_client_memo_search(struct api_dbus *api, uint64_t msgid)
269 struct dbus_memo *memo;
271 memo = api->client.memos;
272 while (memo != NULL && memo->msgid != msgid)
278 /* callback when received answer */
279 static int api_dbus_client_on_reply(sd_bus_message *message, void *userdata, sd_bus_error *ret_error)
282 struct dbus_memo *memo;
283 const char *first, *second;
287 /* retrieve the recorded data */
291 rc = sd_bus_message_read(message, "yssu", &type, &first, &second, &flags);
293 /* failing to have the answer */
294 afb_xreq_fail(memo->xreq, "error", "dbus error");
296 /* report the answer */
297 memo->xreq->context.flags = (unsigned)flags;
300 afb_xreq_success(memo->xreq, json_tokener_parse(first), *second ? second : NULL);
303 afb_xreq_fail(memo->xreq, first, *second ? second : NULL);
306 afb_xreq_fail(memo->xreq, "error", "dbus link broken");
310 api_dbus_client_memo_destroy(memo);
314 /* on call, propagate it to the dbus service */
315 static void api_dbus_client_call(void *closure, struct afb_xreq *xreq)
317 struct api_dbus *api = closure;
320 struct dbus_memo *memo;
321 struct sd_bus_message *msg;
323 /* create the recording data */
324 memo = api_dbus_client_memo_make(api, xreq);
326 afb_xreq_fail(xreq, "error", "out of memory");
330 /* creates the message */
332 rc = sd_bus_message_new_method_call(api->sdbus, &msg, api->name, api->path, api->name, xreq->verb);
336 rc = sd_bus_message_append(msg, "ssu",
337 afb_xreq_raw(xreq, &size),
338 afb_session_uuid(xreq->context.session),
339 (uint32_t)xreq->context.flags);
344 rc = sd_bus_call_async(api->sdbus, NULL, msg, api_dbus_client_on_reply, memo, (uint64_t)-1);
348 rc = sd_bus_message_get_cookie(msg, &memo->msgid);
353 /* if there was an error report it directly */
355 afb_xreq_fail(xreq, "error", "dbus error");
356 api_dbus_client_memo_destroy(memo);
358 sd_bus_message_unref(msg);
361 static int api_dbus_service_start(void *closure, int share_session, int onneed)
363 struct api_dbus *api = closure;
365 /* not an error when onneed */
369 /* already started: it is an error */
370 ERROR("The Dbus binding %s is not a startable service", api->name);
374 /* receives broadcasted events */
375 static int api_dbus_client_on_broadcast_event(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
377 struct json_object *object;
378 const char *event, *data;
379 int rc = sd_bus_message_read(m, "ss", &event, &data);
381 ERROR("unreadable broadcasted event");
383 object = json_tokener_parse(data);
384 afb_evt_broadcast(event, object);
389 /* search the event */
390 static struct dbus_event *api_dbus_client_event_search(struct api_dbus *api, int id, const char *name)
392 struct dbus_event *ev;
394 ev = api->client.events;
395 while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_name(ev->event), name)))
402 static void api_dbus_client_event_create(struct api_dbus *api, int id, const char *name)
404 struct dbus_event *ev;
406 /* check conflicts */
407 ev = api_dbus_client_event_search(api, id, name);
413 /* no conflict, try to add it */
414 ev = malloc(sizeof *ev);
416 ev->event = afb_evt_create_event(name);
417 if (ev->event.closure == NULL)
422 ev->next = api->client.events;
423 api->client.events = ev;
427 ERROR("can't create event %s, out of memory", name);
430 /* removes an event */
431 static void api_dbus_client_event_drop(struct api_dbus *api, int id, const char *name)
433 struct dbus_event *ev, **prv;
435 /* retrieves the event */
436 ev = api_dbus_client_event_search(api, id, name);
438 ERROR("event %s not found", name);
442 /* decrease the reference count */
446 /* unlinks the event */
447 prv = &api->client.events;
452 /* destroys the event */
453 afb_event_drop(ev->event);
458 static void api_dbus_client_event_push(struct api_dbus *api, int id, const char *name, const char *data)
460 struct json_object *object;
461 struct dbus_event *ev;
463 /* retrieves the event */
464 ev = api_dbus_client_event_search(api, id, name);
466 ERROR("event %s not found", name);
470 /* destroys the event */
471 object = json_tokener_parse(data);
472 afb_event_push(ev->event, object);
475 /* subscribes an event */
476 static void api_dbus_client_event_subscribe(struct api_dbus *api, int id, const char *name, uint64_t msgid)
479 struct dbus_event *ev;
480 struct dbus_memo *memo;
482 /* retrieves the event */
483 ev = api_dbus_client_event_search(api, id, name);
485 ERROR("event %s not found", name);
489 /* retrieves the memo */
490 memo = api_dbus_client_memo_search(api, msgid);
492 ERROR("message not found");
496 /* subscribe the request to the event */
497 rc = afb_xreq_subscribe(memo->xreq, ev->event);
499 ERROR("can't subscribe: %m");
502 /* unsubscribes an event */
503 static void api_dbus_client_event_unsubscribe(struct api_dbus *api, int id, const char *name, uint64_t msgid)
506 struct dbus_event *ev;
507 struct dbus_memo *memo;
509 /* retrieves the event */
510 ev = api_dbus_client_event_search(api, id, name);
512 ERROR("event %s not found", name);
516 /* retrieves the memo */
517 memo = api_dbus_client_memo_search(api, msgid);
519 ERROR("message not found");
523 /* unsubscribe the request from the event */
524 rc = afb_xreq_unsubscribe(memo->xreq, ev->event);
526 ERROR("can't unsubscribe: %m");
529 /* receives calls for event */
530 static int api_dbus_client_on_manage_event(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
532 const char *eventname, *data;
536 struct api_dbus *api;
539 /* check if expected message */
541 if (0 != strcmp(api->name, sd_bus_message_get_interface(m)))
542 return 0; /* not the expected interface */
543 if (0 != strcmp("event", sd_bus_message_get_member(m)))
544 return 0; /* not the expected member */
545 if (sd_bus_message_get_expect_reply(m))
546 return 0; /* not the expected type of message */
548 /* reads the message */
549 rc = sd_bus_message_read(m, "yisst", &order, &eventid, &eventname, &data, &msgid);
551 ERROR("unreadable event");
555 /* what is the order ? */
556 switch ((char)order) {
557 case '+': /* creates the event */
558 api_dbus_client_event_create(api, eventid, eventname);
560 case '-': /* drops the event */
561 api_dbus_client_event_drop(api, eventid, eventname);
563 case '!': /* pushs the event */
564 api_dbus_client_event_push(api, eventid, eventname, data);
566 case 'S': /* subscribe event for a request */
567 api_dbus_client_event_subscribe(api, eventid, eventname, msgid);
569 case 'U': /* unsubscribe event for a request */
570 api_dbus_client_event_unsubscribe(api, eventid, eventname, msgid);
573 /* unexpected order */
574 ERROR("unexpected order '%c' received", (char)order);
580 static struct afb_api_itf dbus_api_itf = {
581 .call = api_dbus_client_call,
582 .service_start = api_dbus_service_start
585 /* adds a afb-dbus-service client api */
586 int afb_api_dbus_add_client(const char *path)
589 struct api_dbus *api;
590 struct afb_api afb_api;
593 /* create the dbus client api */
594 api = make_api_dbus(path);
598 /* connect to broadcasted events */
599 rc = asprintf(&match, "type='signal',path='%s',interface='%s',member='broadcast'", api->path, api->name);
602 ERROR("out of memory");
605 rc = sd_bus_add_match(api->sdbus, &api->client.slot_broadcast, match, api_dbus_client_on_broadcast_event, api);
609 ERROR("can't add dbus match %s for %s", api->path, api->name);
613 /* connect to event management */
614 rc = sd_bus_add_object(api->sdbus, &api->client.slot_event, api->path, api_dbus_client_on_manage_event, api);
617 ERROR("can't add dbus object %s for %s", api->path, api->name);
621 /* record it as an API */
622 afb_api.closure = api;
623 afb_api.itf = &dbus_api_itf;
624 if (afb_apis_add(api->api, afb_api) < 0)
630 destroy_api_dbus(api);
635 /******************* event structures for server part **********************************/
637 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid);
638 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid);
639 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object);
640 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object);
642 /* the interface for events broadcasting */
643 static const struct afb_evt_itf evt_broadcast_itf = {
644 .broadcast = afb_api_dbus_server_event_broadcast,
647 /* the interface for events pushing */
648 static const struct afb_evt_itf evt_push_itf = {
649 .push = afb_api_dbus_server_event_push,
650 .add = afb_api_dbus_server_event_add,
651 .remove = afb_api_dbus_server_event_remove
654 /******************* origin description part for server *****************************/
658 /* link to next different origin */
661 /* the server dbus-api */
662 struct api_dbus *api;
664 /* count of references */
667 /* credentials of the origin */
668 struct afb_cred *cred;
674 /* get the credentials for the message */
675 static void init_origin_creds(struct origin *origin)
684 rc = sd_bus_get_name_creds(origin->api->sdbus, origin->name,
685 SD_BUS_CREDS_PID|SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_SELINUX_CONTEXT,
690 afb_cred_unref(origin->cred);
691 sd_bus_creds_get_uid(c, &uid);
692 sd_bus_creds_get_gid(c, &gid);
693 sd_bus_creds_get_pid(c, &pid);
694 sd_bus_creds_get_selinux_context(c, &context);
695 origin->cred = afb_cred_create(uid, gid, pid, context);
696 sd_bus_creds_unref(c);
700 static struct origin *afb_api_dbus_server_origin_get(struct api_dbus *api, const char *sender)
702 struct origin *origin;
704 /* searchs for an existing origin */
705 origin = api->server.origins;
706 while (origin != NULL) {
707 if (0 == strcmp(origin->name, sender)) {
711 origin = origin->next;
714 /* not found, create it */
715 origin = malloc(strlen(sender) + sizeof *origin);
720 origin->refcount = 1;
721 strcpy(origin->name, sender);
722 init_origin_creds(origin);
723 origin->next = api->server.origins;
724 api->server.origins = origin;
729 static void afb_api_dbus_server_origin_unref(struct origin *origin)
731 if (!--origin->refcount) {
734 prv = &origin->api->server.origins;
735 while(*prv != origin)
738 afb_cred_unref(origin->cred);
745 /* link to next different origin */
746 struct origin *origin;
748 /* the listener of events */
749 struct afb_evt_listener *listener;
752 static void afb_api_dbus_server_listener_free(struct listener *listener)
754 afb_evt_listener_unref(listener->listener);
755 afb_api_dbus_server_origin_unref(listener->origin);
759 static struct listener *afb_api_dbus_server_listener_get(struct api_dbus *api, const char *sender, struct afb_session *session)
762 struct listener *listener;
763 struct origin *origin;
766 origin = afb_api_dbus_server_origin_get(api, sender);
770 /* retrieves the stored listener */
771 listener = afb_session_get_cookie(session, origin);
772 if (listener != NULL) {
774 afb_api_dbus_server_origin_unref(origin);
778 /* creates the listener */
779 listener = malloc(sizeof *listener);
780 if (listener == NULL)
783 listener->origin = origin;
784 listener->listener = afb_evt_listener_create(&evt_push_itf, origin);
785 if (listener->listener != NULL) {
786 rc = afb_session_set_cookie(session, origin, listener, (void*)afb_api_dbus_server_listener_free);
789 afb_evt_listener_unref(listener->listener);
793 afb_api_dbus_server_origin_unref(origin);
797 /******************* dbus request part for server *****************/
800 * Structure for a dbus request
803 struct afb_xreq xreq; /**< the xreq of the request */
804 sd_bus_message *message; /**< the incoming request message */
805 const char *request; /**< the readen request as string */
806 struct json_object *json; /**< the readen request as object */
807 struct listener *listener; /**< the listener for events */
810 /* decrement the reference count of the request and free/release it on falling to null */
811 static void dbus_req_destroy(struct afb_xreq *xreq)
813 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
815 afb_context_disconnect(&dreq->xreq.context);
816 json_object_put(dreq->json);
817 sd_bus_message_unref(dreq->message);
821 /* get the object of the request */
822 static struct json_object *dbus_req_json(struct afb_xreq *xreq)
824 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
829 /* get the argument of the request of 'name' */
830 static void dbus_req_reply(struct dbus_req *dreq, uint8_t type, const char *first, const char *second)
833 rc = sd_bus_reply_method_return(dreq->message,
834 "yssu", type, first ? : "", second ? : "", (uint32_t)dreq->xreq.context.flags);
836 ERROR("sending the reply failed");
839 static void dbus_req_success(struct afb_xreq *xreq, struct json_object *obj, const char *info)
841 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
843 dbus_req_reply(dreq, RETOK, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN), info);
846 static void dbus_req_fail(struct afb_xreq *xreq, const char *status, const char *info)
848 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
850 dbus_req_reply(dreq, RETERR, status, info);
853 static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid);
855 static int dbus_req_subscribe(struct afb_xreq *xreq, struct afb_event event)
857 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
861 rc = afb_evt_add_watch(dreq->listener->listener, event);
862 sd_bus_message_get_cookie(dreq->message, &msgid);
863 afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
867 static int dbus_req_unsubscribe(struct afb_xreq *xreq, struct afb_event event)
869 struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
873 sd_bus_message_get_cookie(dreq->message, &msgid);
874 afb_api_dbus_server_event_send(dreq->listener->origin, 'U', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
875 rc = afb_evt_remove_watch(dreq->listener->listener, event);
879 const struct afb_xreq_query_itf afb_api_dbus_xreq_itf = {
880 .json = dbus_req_json,
881 .success = dbus_req_success,
882 .fail = dbus_req_fail,
883 .unref = dbus_req_destroy,
884 .subscribe = dbus_req_subscribe,
885 .unsubscribe = dbus_req_unsubscribe
888 /******************* server part **********************************/
890 static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid)
893 struct api_dbus *api;
894 struct sd_bus_message *msg;
899 rc = sd_bus_message_new_method_call(api->sdbus, &msg, origin->name, api->path, api->name, "event");
903 rc = sd_bus_message_append(msg, "yisst", (uint8_t)order, (int32_t)eventid, event, data, msgid);
907 rc = sd_bus_send(api->sdbus, msg, NULL); /* NULL for cookie implies no expected reply */
912 ERROR("error while send event %c%s(%d) to %s", order, event, eventid, origin->name);
914 sd_bus_message_unref(msg);
917 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid)
919 afb_api_dbus_server_event_send(closure, '+', event, eventid, "", 0);
922 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid)
924 afb_api_dbus_server_event_send(closure, '-', event, eventid, "", 0);
927 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object)
929 const char *data = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
930 afb_api_dbus_server_event_send(closure, '!', event, eventid, data, 0);
931 json_object_put(object);
934 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object)
937 struct api_dbus *api;
940 rc = sd_bus_emit_signal(api->sdbus, api->path, api->name, "broadcast",
941 "ss", event, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN));
943 ERROR("error while broadcasting event %s", event);
944 json_object_put(object);
947 /* called when the object for the service is called */
948 static int api_dbus_server_on_object_called(sd_bus_message *message, void *userdata, sd_bus_error *ret_error)
953 struct dbus_req *dreq;
954 struct api_dbus *api = userdata;
956 struct afb_session *session;
957 struct listener *listener;
959 /* check the interface */
960 if (strcmp(sd_bus_message_get_interface(message), api->name) != 0)
964 method = sd_bus_message_get_member(message);
966 /* create the request */
967 dreq = calloc(1 , sizeof *dreq);
972 rc = sd_bus_message_read(message, "ssu", &dreq->request, &uuid, &flags);
974 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_SIGNATURE, "invalid signature");
978 /* connect to the context */
979 afb_xreq_init(&dreq->xreq, &afb_api_dbus_xreq_itf);
980 if (afb_context_connect(&dreq->xreq.context, uuid, NULL) < 0)
982 session = dreq->xreq.context.session;
984 /* get the listener */
985 listener = afb_api_dbus_server_listener_get(api, sd_bus_message_get_sender(message), session);
986 if (listener == NULL)
989 /* fulfill the request and emit it */
990 dreq->xreq.context.flags = flags;
991 dreq->message = sd_bus_message_ref(message);
992 dreq->json = json_tokener_parse(dreq->request);
993 if (dreq->json == NULL && strcmp(dreq->request, "null")) {
994 /* lazy error detection of json request. Is it to improve? */
995 dreq->json = json_object_new_string(dreq->request);
997 dreq->listener = listener;
998 dreq->xreq.api = api->api;
999 dreq->xreq.verb = method;
1000 afb_apis_call(&dreq->xreq);
1001 afb_xreq_unref(&dreq->xreq);
1005 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NO_MEMORY, "out of memory");
1011 /* create the service */
1012 int afb_api_dbus_add_server(const char *path)
1015 struct api_dbus *api;
1017 /* get the dbus api object connected */
1018 api = make_api_dbus(path);
1022 /* request the service object name */
1023 rc = sd_bus_request_name(api->sdbus, api->name, 0);
1026 ERROR("can't register name %s", api->name);
1030 /* connect the service to the dbus object */
1031 rc = sd_bus_add_object(api->sdbus, &api->server.slot_call, api->path, api_dbus_server_on_object_called, api);
1034 ERROR("can't add dbus object %s for %s", api->path, api->name);
1037 INFO("afb service over dbus installed, name %s, path %s", api->name, api->path);
1039 api->server.listener = afb_evt_listener_create(&evt_broadcast_itf, api);
1042 sd_bus_release_name(api->sdbus, api->name);
1044 destroy_api_dbus(api);