2 * Copyright (C) 2015, 2016 "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"
34 #include "afb-msg-json.h"
36 #include "afb-api-so.h"
37 #include "afb-context.h"
39 #include "afb-subcall.h"
42 static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/";
49 * The path given are of the form
50 * system:/org/agl/afb/api/...
52 * user:/org/agl/afb/api/...
56 struct sd_bus *sdbus; /* the bus */
57 char *path; /* path of the object for the API */
58 char *name; /* name/interface of the object */
59 char *api; /* api name of the interface */
62 struct sd_bus_slot *slot_broadcast;
63 struct sd_bus_slot *slot_event;
64 struct dbus_event *events;
65 struct dbus_memo *memos;
68 struct sd_bus_slot *slot_call;
69 struct afb_evt_listener *listener; /* listener for broadcasted events */
70 struct destination *destinations;
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_req req; /* the request handle */
220 struct afb_context *context; /* the context of the query */
221 uint64_t msgid; /* the message identifier */
226 struct dbus_event *next;
227 struct afb_event event;
232 /* allocates and init the memorizing data */
233 static struct dbus_memo *api_dbus_client_memo_make(struct api_dbus *api, struct afb_req req, struct afb_context *context)
235 struct dbus_memo *memo;
237 memo = malloc(sizeof *memo);
241 memo->context = context;
244 memo->next = api->client.memos;
245 api->client.memos = memo;
250 /* free and release the memorizing data */
251 static void api_dbus_client_memo_destroy(struct dbus_memo *memo)
253 struct dbus_memo **prv;
255 prv = &memo->api->client.memos;
256 while (*prv != NULL) {
264 afb_req_unref(memo->req);
268 /* search a memorized request */
269 static struct dbus_memo *api_dbus_client_memo_search(struct api_dbus *api, uint64_t msgid)
271 struct dbus_memo *memo;
273 memo = api->client.memos;
274 while (memo != NULL && memo->msgid != msgid)
280 /* callback when received answer */
281 static int api_dbus_client_on_reply(sd_bus_message *message, void *userdata, sd_bus_error *ret_error)
284 struct dbus_memo *memo;
285 const char *first, *second;
289 /* retrieve the recorded data */
293 rc = sd_bus_message_read(message, "yssu", &type, &first, &second, &flags);
295 /* failing to have the answer */
296 afb_req_fail(memo->req, "error", "dbus error");
298 /* report the answer */
299 memo->context->flags = (unsigned)flags;
302 afb_req_success(memo->req, json_tokener_parse(first), *second ? second : NULL);
305 afb_req_fail(memo->req, first, *second ? second : NULL);
308 afb_req_send(memo->req, first, strlen(first));
311 afb_req_fail(memo->req, "error", "dbus link broken");
315 api_dbus_client_memo_destroy(memo);
319 /* on call, propagate it to the dbus service */
320 static void api_dbus_client_call(struct api_dbus *api, struct afb_req req, struct afb_context *context, const char *verb, size_t lenverb)
324 char *method = strndupa(verb, lenverb);
325 struct dbus_memo *memo;
326 struct sd_bus_message *msg;
328 /* create the recording data */
329 memo = api_dbus_client_memo_make(api, req, context);
331 afb_req_fail(req, "error", "out of memory");
335 /* creates the message */
337 rc = sd_bus_message_new_method_call(api->sdbus, &msg, api->name, api->path, api->name, method);
341 rc = sd_bus_message_append(msg, "ssu",
342 afb_req_raw(req, &size),
343 ctxClientGetUuid(context->session),
344 (uint32_t)context->flags);
349 rc = sd_bus_call_async(api->sdbus, NULL, msg, api_dbus_client_on_reply, memo, (uint64_t)-1);
353 rc = sd_bus_message_get_cookie(msg, &memo->msgid);
358 /* if there was an error report it directly */
360 afb_req_fail(req, "error", "dbus error");
361 api_dbus_client_memo_destroy(memo);
363 sd_bus_message_unref(msg);
366 static int api_dbus_service_start(struct api_dbus *api, int share_session, int onneed)
368 /* not an error when onneed */
372 /* already started: it is an error */
373 ERROR("The Dbus binding %s is not a startable service", api->name);
377 /* receives broadcasted events */
378 static int api_dbus_client_on_broadcast_event(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
380 struct json_object *object;
381 const char *event, *data;
382 int rc = sd_bus_message_read(m, "ss", &event, &data);
384 ERROR("unreadable broadcasted event");
386 object = json_tokener_parse(data);
387 afb_evt_broadcast(event, object);
392 /* search the event */
393 static struct dbus_event *api_dbus_client_event_search(struct api_dbus *api, int id, const char *name)
395 struct dbus_event *ev;
397 ev = api->client.events;
398 while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_name(ev->event), name)))
405 static void api_dbus_client_event_create(struct api_dbus *api, int id, const char *name)
407 struct dbus_event *ev;
409 /* check conflicts */
410 ev = api_dbus_client_event_search(api, id, name);
416 /* no conflict, try to add it */
417 ev = malloc(sizeof *ev);
419 ev->event = afb_evt_create_event(name);
420 if (ev->event.closure == NULL)
425 ev->next = api->client.events;
426 api->client.events = ev;
430 ERROR("can't create event %s, out of memory", name);
433 /* removes an event */
434 static void api_dbus_client_event_drop(struct api_dbus *api, int id, const char *name)
436 struct dbus_event *ev, **prv;
438 /* retrieves the event */
439 ev = api_dbus_client_event_search(api, id, name);
441 ERROR("event %s not found", name);
445 /* decrease the reference count */
449 /* unlinks the event */
450 prv = &api->client.events;
455 /* destroys the event */
456 afb_event_drop(ev->event);
461 static void api_dbus_client_event_push(struct api_dbus *api, int id, const char *name, const char *data)
463 struct json_object *object;
464 struct dbus_event *ev;
466 /* retrieves the event */
467 ev = api_dbus_client_event_search(api, id, name);
469 ERROR("event %s not found", name);
473 /* destroys the event */
474 object = json_tokener_parse(data);
475 afb_event_push(ev->event, object);
478 /* subscribes an event */
479 static void api_dbus_client_event_subscribe(struct api_dbus *api, int id, const char *name, uint64_t msgid)
482 struct dbus_event *ev;
483 struct dbus_memo *memo;
485 /* retrieves the event */
486 ev = api_dbus_client_event_search(api, id, name);
488 ERROR("event %s not found", name);
492 /* retrieves the memo */
493 memo = api_dbus_client_memo_search(api, msgid);
495 ERROR("message not found");
499 /* subscribe the request to the event */
500 rc = afb_req_subscribe(memo->req, ev->event);
502 ERROR("can't subscribe: %m");
505 /* unsubscribes an event */
506 static void api_dbus_client_event_unsubscribe(struct api_dbus *api, int id, const char *name, uint64_t msgid)
509 struct dbus_event *ev;
510 struct dbus_memo *memo;
512 /* retrieves the event */
513 ev = api_dbus_client_event_search(api, id, name);
515 ERROR("event %s not found", name);
519 /* retrieves the memo */
520 memo = api_dbus_client_memo_search(api, msgid);
522 ERROR("message not found");
526 /* unsubscribe the request from the event */
527 rc = afb_req_unsubscribe(memo->req, ev->event);
529 ERROR("can't unsubscribe: %m");
532 /* receives calls for event */
533 static int api_dbus_client_on_manage_event(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
535 const char *eventname, *data;
539 struct api_dbus *api;
542 /* check if expected message */
544 if (0 != strcmp(api->name, sd_bus_message_get_interface(m)))
545 return 0; /* not the expected interface */
546 if (0 != strcmp("event", sd_bus_message_get_member(m)))
547 return 0; /* not the expected member */
548 if (sd_bus_message_get_expect_reply(m))
549 return 0; /* not the expected type of message */
551 /* reads the message */
552 rc = sd_bus_message_read(m, "yisst", &order, &eventid, &eventname, &data, &msgid);
554 ERROR("unreadable event");
558 /* what is the order ? */
559 switch ((char)order) {
560 case '+': /* creates the event */
561 api_dbus_client_event_create(api, eventid, eventname);
563 case '-': /* drops the event */
564 api_dbus_client_event_drop(api, eventid, eventname);
566 case '!': /* pushs the event */
567 api_dbus_client_event_push(api, eventid, eventname, data);
569 case 'S': /* subscribe event for a request */
570 api_dbus_client_event_subscribe(api, eventid, eventname, msgid);
572 case 'U': /* unsubscribe event for a request */
573 api_dbus_client_event_unsubscribe(api, eventid, eventname, msgid);
576 /* unexpected order */
577 ERROR("unexpected order '%c' received", (char)order);
583 /* adds a afb-dbus-service client api */
584 int afb_api_dbus_add_client(const char *path)
587 struct api_dbus *api;
588 struct afb_api afb_api;
591 /* create the dbus client api */
592 api = make_api_dbus(path);
596 /* connect to broadcasted events */
597 rc = asprintf(&match, "type='signal',path='%s',interface='%s',member='broadcast'", api->path, api->name);
600 ERROR("out of memory");
603 rc = sd_bus_add_match(api->sdbus, &api->client.slot_broadcast, match, api_dbus_client_on_broadcast_event, api);
607 ERROR("can't add dbus match %s for %s", api->path, api->name);
611 /* connect to event management */
612 rc = sd_bus_add_object(api->sdbus, &api->client.slot_event, api->path, api_dbus_client_on_manage_event, api);
615 ERROR("can't add dbus object %s for %s", api->path, api->name);
619 /* record it as an API */
620 afb_api.closure = api;
621 afb_api.call = (void*)api_dbus_client_call;
622 afb_api.service_start = (void*)api_dbus_service_start;
623 if (afb_apis_add(api->api, afb_api) < 0)
629 destroy_api_dbus(api);
634 /******************* event structures for server part **********************************/
636 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid);
637 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid);
638 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object);
639 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object);
641 /* the interface for events broadcasting */
642 static const struct afb_evt_itf evt_broadcast_itf = {
643 .broadcast = afb_api_dbus_server_event_broadcast,
646 /* the interface for events pushing */
647 static const struct afb_evt_itf evt_push_itf = {
648 .push = afb_api_dbus_server_event_push,
649 .add = afb_api_dbus_server_event_add,
650 .remove = afb_api_dbus_server_event_remove
653 /******************* destination description part for server *****************************/
657 /* link to next different destination */
658 struct destination *next;
660 /* the server dbus-api */
661 struct api_dbus *api;
663 /* count of references */
666 /* the destination */
670 static struct destination *afb_api_dbus_server_destination_get(struct api_dbus *api, const char *sender)
672 struct destination *destination;
674 /* searchs for an existing destination */
675 destination = api->server.destinations;
676 while (destination != NULL) {
677 if (0 == strcmp(destination->name, sender)) {
678 destination->refcount++;
681 destination = destination->next;
684 /* not found, create it */
685 destination = malloc(strlen(sender) + sizeof *destination);
686 if (destination == NULL)
689 destination->api = api;
690 destination->refcount = 1;
691 strcpy(destination->name, sender);
692 destination->next = api->server.destinations;
693 api->server.destinations = destination;
698 static void afb_api_dbus_server_destination_unref(struct destination *destination)
700 if (!--destination->refcount) {
701 struct destination **prv;
703 prv = &destination->api->server.destinations;
704 while(*prv != destination)
706 *prv = destination->next;
713 /* link to next different destination */
714 struct destination *destination;
716 /* the listener of events */
717 struct afb_evt_listener *listener;
720 static void afb_api_dbus_server_listener_free(struct listener *listener)
722 afb_evt_listener_unref(listener->listener);
723 afb_api_dbus_server_destination_unref(listener->destination);
727 static struct listener *afb_api_dbus_server_listerner_get(struct api_dbus *api, const char *sender, struct AFB_clientCtx *session)
730 struct listener *listener;
731 struct destination *destination;
733 /* get the destination */
734 destination = afb_api_dbus_server_destination_get(api, sender);
735 if (destination == NULL)
738 /* retrieves the stored listener */
739 listener = ctxClientCookieGet(session, destination);
740 if (listener != NULL) {
742 afb_api_dbus_server_destination_unref(destination);
746 /* creates the listener */
747 listener = malloc(sizeof *listener);
748 if (listener == NULL)
751 listener->destination = destination;
752 listener->listener = afb_evt_listener_create(&evt_push_itf, destination);
753 if (listener->listener != NULL) {
754 rc = ctxClientCookieSet(session, destination, listener, (void*)afb_api_dbus_server_listener_free);
757 afb_evt_listener_unref(listener->listener);
761 afb_api_dbus_server_destination_unref(destination);
765 /******************* dbus request part for server *****************/
768 * structure for a dbus request
771 struct afb_context context; /* the context, should be THE FIRST */
772 sd_bus_message *message; /* the incoming request message */
773 const char *request; /* the readen request as string */
774 struct json_object *json; /* the readen request as object */
775 struct listener *listener; /* the listener for events */
776 int refcount; /* reference count of the request */
779 /* increment the reference count of the request */
780 static void dbus_req_addref(struct dbus_req *dreq)
785 /* decrement the reference count of the request and free/release it on falling to null */
786 static void dbus_req_unref(struct dbus_req *dreq)
788 if (dreq == NULL || --dreq->refcount)
791 afb_context_disconnect(&dreq->context);
792 json_object_put(dreq->json);
793 sd_bus_message_unref(dreq->message);
797 /* get the object of the request */
798 static struct json_object *dbus_req_json(struct dbus_req *dreq)
800 if (dreq->json == NULL) {
801 dreq->json = json_tokener_parse(dreq->request);
802 if (dreq->json == NULL) {
803 /* lazy error detection of json request. Is it to improve? */
804 dreq->json = json_object_new_string(dreq->request);
810 /* get the argument of the request of 'name' */
811 static struct afb_arg dbus_req_get(struct dbus_req *dreq, const char *name)
813 return afb_msg_json_get_arg(dbus_req_json(dreq), name);
816 static void dbus_req_reply(struct dbus_req *dreq, uint8_t type, const char *first, const char *second)
819 rc = sd_bus_reply_method_return(dreq->message,
820 "yssu", type, first ? : "", second ? : "", (uint32_t)dreq->context.flags);
822 ERROR("sending the reply failed");
825 static void dbus_req_success(struct dbus_req *dreq, struct json_object *obj, const char *info)
827 dbus_req_reply(dreq, RETOK, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN), info);
830 static void dbus_req_fail(struct dbus_req *dreq, const char *status, const char *info)
832 dbus_req_reply(dreq, RETERR, status, info);
835 static const char *dbus_req_raw(struct dbus_req *dreq, size_t *size)
838 *size = strlen(dreq->request);
839 return dreq->request;
842 static void dbus_req_send(struct dbus_req *dreq, const char *buffer, size_t size)
844 /* TODO: how to put sized buffer as strings? things aren't clear here!!! */
845 dbus_req_reply(dreq, RETRAW, buffer, "");
848 static void afb_api_dbus_server_event_send(struct destination *destination, char order, const char *event, int eventid, const char *data, uint64_t msgid);
850 static int dbus_req_subscribe(struct dbus_req *dreq, struct afb_event event)
855 rc = afb_evt_add_watch(dreq->listener->listener, event);
856 sd_bus_message_get_cookie(dreq->message, &msgid);
857 afb_api_dbus_server_event_send(dreq->listener->destination, 'S', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
861 static int dbus_req_unsubscribe(struct dbus_req *dreq, struct afb_event event)
866 sd_bus_message_get_cookie(dreq->message, &msgid);
867 afb_api_dbus_server_event_send(dreq->listener->destination, 'U', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
868 rc = afb_evt_remove_watch(dreq->listener->listener, event);
872 static void dbus_req_subcall(struct dbus_req *dreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure);
874 const struct afb_req_itf afb_api_dbus_req_itf = {
875 .json = (void*)dbus_req_json,
876 .get = (void*)dbus_req_get,
877 .success = (void*)dbus_req_success,
878 .fail = (void*)dbus_req_fail,
879 .raw = (void*)dbus_req_raw,
880 .send = (void*)dbus_req_send,
881 .context_get = (void*)afb_context_get,
882 .context_set = (void*)afb_context_set,
883 .addref = (void*)dbus_req_addref,
884 .unref = (void*)dbus_req_unref,
885 .session_close = (void*)afb_context_close,
886 .session_set_LOA = (void*)afb_context_change_loa,
887 .subscribe = (void*)dbus_req_subscribe,
888 .unsubscribe = (void*)dbus_req_unsubscribe,
889 .subcall = (void*)dbus_req_subcall
892 static void dbus_req_subcall(struct dbus_req *dreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure)
894 afb_subcall(&dreq->context, api, verb, args, callback, closure, (struct afb_req){ .itf = &afb_api_dbus_req_itf, .closure = dreq });
897 /******************* server part **********************************/
899 static void afb_api_dbus_server_event_send(struct destination *destination, char order, const char *event, int eventid, const char *data, uint64_t msgid)
902 struct api_dbus *api;
903 struct sd_bus_message *msg;
905 api = destination->api;
908 rc = sd_bus_message_new_method_call(api->sdbus, &msg, destination->name, api->path, api->name, "event");
912 rc = sd_bus_message_append(msg, "yisst", (uint8_t)order, (int32_t)eventid, event, data, msgid);
916 rc = sd_bus_send(api->sdbus, msg, NULL); /* NULL for cookie implies no expected reply */
921 ERROR("error while send event %c%s(%d) to %s", order, event, eventid, destination->name);
923 sd_bus_message_unref(msg);
926 static void afb_api_dbus_server_event_add(void *closure, const char *event, int eventid)
928 afb_api_dbus_server_event_send(closure, '+', event, eventid, "", 0);
931 static void afb_api_dbus_server_event_remove(void *closure, const char *event, int eventid)
933 afb_api_dbus_server_event_send(closure, '-', event, eventid, "", 0);
936 static void afb_api_dbus_server_event_push(void *closure, const char *event, int eventid, struct json_object *object)
938 const char *data = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
939 afb_api_dbus_server_event_send(closure, '!', event, eventid, data, 0);
942 static void afb_api_dbus_server_event_broadcast(void *closure, const char *event, int eventid, struct json_object *object)
945 struct api_dbus *api;
948 rc = sd_bus_emit_signal(api->sdbus, api->path, api->name, "broadcast",
949 "ss", event, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN));
951 ERROR("error while broadcasting event %s", event);
952 json_object_put(object);
955 /* called when the object for the service is called */
956 static int api_dbus_server_on_object_called(sd_bus_message *message, void *userdata, sd_bus_error *ret_error)
961 struct dbus_req *dreq;
962 struct api_dbus *api = userdata;
965 struct AFB_clientCtx *session;
966 struct listener *listener;
968 /* check the interface */
969 if (strcmp(sd_bus_message_get_interface(message), api->name) != 0)
973 method = sd_bus_message_get_member(message);
975 /* create the request */
976 dreq = calloc(1 , sizeof *dreq);
981 rc = sd_bus_message_read(message, "ssu", &dreq->request, &uuid, &flags);
983 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_SIGNATURE, "invalid signature");
987 /* connect to the context */
988 if (afb_context_connect(&dreq->context, uuid, NULL) < 0)
990 session = dreq->context.session;
992 /* get the listener */
993 listener = afb_api_dbus_server_listerner_get(api, sd_bus_message_get_sender(message), session);
994 if (listener == NULL)
997 /* fulfill the request and emit it */
998 dreq->context.flags = flags;
999 dreq->message = sd_bus_message_ref(message);
1001 dreq->listener = listener;
1003 areq.itf = &afb_api_dbus_req_itf;
1004 areq.closure = dreq;
1005 afb_apis_call_(areq, &dreq->context, api->api, method);
1006 dbus_req_unref(dreq);
1010 sd_bus_reply_method_errorf(message, SD_BUS_ERROR_NO_MEMORY, "out of memory");
1016 /* create the service */
1017 int afb_api_dbus_add_server(const char *path)
1020 struct api_dbus *api;
1022 /* get the dbus api object connected */
1023 api = make_api_dbus(path);
1027 /* request the service object name */
1028 rc = sd_bus_request_name(api->sdbus, api->name, 0);
1031 ERROR("can't register name %s", api->name);
1035 /* connect the service to the dbus object */
1036 rc = sd_bus_add_object(api->sdbus, &api->server.slot_call, api->path, api_dbus_server_on_object_called, api);
1039 ERROR("can't add dbus object %s for %s", api->path, api->name);
1042 INFO("afb service over dbus installed, name %s, path %s", api->name, api->path);
1044 api->server.listener = afb_evt_listener_create(&evt_broadcast_itf, api);
1047 sd_bus_release_name(api->sdbus, api->name);
1049 destroy_api_dbus(api);