5 * Copyright (C) 2014 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #define DEFAULT_MACHINE_TYPE "laptop"
33 #define HOSTNAMED_SERVICE "org.freedesktop.hostname1"
34 #define HOSTNAMED_INTERFACE HOSTNAMED_SERVICE
35 #define HOSTNAMED_PATH "/org/freedesktop/hostname1"
37 static GDBusClient *hostnamed_client = NULL;
38 static GDBusProxy *hostnamed_proxy = NULL;
39 static char *machine_type = NULL;
41 const char *connman_machine_get_type(void)
46 return DEFAULT_MACHINE_TYPE;
49 static void machine_property_changed(GDBusProxy *proxy, const char *name,
50 DBusMessageIter *iter, void *user_data)
52 DBG("Property %s", name);
54 if (g_str_equal(name, "Chassis")) {
58 g_dbus_proxy_refresh_property(proxy, name);
62 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
65 dbus_message_iter_get_basic(iter, &str);
67 machine_type = g_strdup(str);
69 DBG("Machine type set to %s", machine_type);
73 int __connman_machine_init(void)
75 DBusConnection *connection;
80 connection = connman_dbus_get_connection();
82 hostnamed_client = g_dbus_client_new(connection, HOSTNAMED_SERVICE,
84 if (!hostnamed_client)
87 hostnamed_proxy = g_dbus_proxy_new(hostnamed_client, HOSTNAMED_PATH,
92 g_dbus_proxy_set_property_watch(hostnamed_proxy,
93 machine_property_changed, NULL);
95 dbus_connection_unref(connection);
99 if (hostnamed_client) {
100 g_dbus_client_unref(hostnamed_client);
101 hostnamed_client = NULL;
104 dbus_connection_unref(connection);
109 void __connman_machine_cleanup(void)
113 if (hostnamed_proxy) {
114 g_dbus_proxy_unref(hostnamed_proxy);
115 hostnamed_proxy = NULL;
118 if (hostnamed_client) {
119 g_dbus_client_unref(hostnamed_client);
120 hostnamed_client = NULL;
123 g_free(machine_type);