3 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
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.
21 #include <dbus/dbus.h>
24 #include <libgdbus/dbus-system.h>
25 #include "fd_handler.h"
28 /* -1 is a default timeout value, it's converted to 25*1000 internally. */
29 #define DBUS_REPLY_TIMEOUT (-1)
31 int set_dbus_connection(const char *bus)
33 static DBusConnection *conn;
41 dbus_error_init(&err);
43 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
45 if (dbus_error_is_set(&err)) {
46 _E("dbus_bus_get error(%s, %s)", err.name, err.message);
47 dbus_error_free(&err);
49 _E("dbus_bus_get error");
55 dbus_error_init(&err);
57 ret = dbus_bus_request_name(conn, bus,
58 DBUS_NAME_FLAG_REPLACE_EXISTING | DBUS_NAME_FLAG_DO_NOT_QUEUE,
60 if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
61 if (dbus_error_is_set(&err)) {
62 _E("Failed to request dbus name (%s, %s, %s)", bus, err.name, err.message);
63 dbus_error_free(&err);
65 _E("Failed to request dbus name (%s)", bus);