It currently provides the machine type (chassis) only. But then it will
be possible to integrate further with setting the dynamic hostname when
relevant, i.e. when dhcp clients got one and if the AllowHostnameUpdates
key from main.conf is set to true.
---
Makefile.am | 4 +-
include/machine.h | 35 +++++++++++++++
src/connman.h | 5 +++
src/machine.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/main.c | 2 +
5 files changed, 169 insertions(+), 2 deletions(-)
create mode 100644 include/machine.h
create mode 100644 src/machine.c
diff --git a/Makefile.am b/Makefile.am
index a7f3ed3..a574170 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,7 @@ include_HEADERS = include/log.h include/plugin.h \
include/device.h include/network.h include/inet.h \
include/storage.h include/provision.h \
include/session.h include/ipaddress.h include/agent.h \
- include/inotify.h include/peer.h
+ include/inotify.h include/peer.h include/machine.h
nodist_include_HEADERS = include/version.h
@@ -106,7 +106,7 @@ src_connmand_SOURCES = $(gdhcp_sources) $(gweb_sources) \
src/stats.c src/iptables.c src/dnsproxy.c src/6to4.c \
src/ippool.c src/bridge.c src/nat.c src/ipaddress.c \
src/inotify.c src/firewall.c src/ipv6pd.c src/peer.c \
- src/peer_service.c
+ src/peer_service.c src/machine.c
src_connmand_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
@GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ @GNUTLS_LIBS@ \
diff --git a/include/machine.h b/include/machine.h
new file mode 100644
index 0000000..c8d8735
--- /dev/null
+++ b/include/machine.h
@@ -0,0 +1,35 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __CONNMAN_MACHINE_H
+#define __CONNMAN_MACHINE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *connman_machine_get_type(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_MACHINE_H */
diff --git a/src/connman.h b/src/connman.h
index daad623..79ad41d 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -1029,3 +1029,8 @@ int __connman_nfacct_disable(struct nfacct_context *ctx,
void *user_data);
void __connman_nfacct_cleanup(void);
+
+#include <machine.h>
+
+int __connman_machine_init(void);
+void __connman_machine_cleanup(void);
diff --git a/src/machine.c b/src/machine.c
new file mode 100644
index 0000000..14ea366
--- /dev/null
+++ b/src/machine.c
@@ -0,0 +1,125 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <gdbus.h>
+
+#include "connman.h"
+
+#define DEFAULT_MACHINE_TYPE "laptop"
+
+#define HOSTNAMED_SERVICE "org.freedesktop.hostname1"
+#define HOSTNAMED_INTERFACE HOSTNAMED_SERVICE
+#define HOSTNAMED_PATH "/org/freedesktop/hostname1"
+
+static GDBusClient *hostnamed_client = NULL;
+static GDBusProxy *hostnamed_proxy = NULL;
+static char *machine_type = NULL;
+
+const char *connman_machine_get_type(void)
+{
+ if (machine_type)
+ return machine_type;
+
+ return DEFAULT_MACHINE_TYPE;
+}
+
+static void machine_property_changed(GDBusProxy *proxy, const char *name,
+ DBusMessageIter *iter, void *user_data)
+{
+ DBG("Property %s", name);
+
+ if (g_str_equal(name, "Chassis")) {
+ const char *str;
+
+ if (!iter) {
+ g_dbus_proxy_refresh_property(proxy, name);
+ return;
+ }
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+ return;
+
+ dbus_message_iter_get_basic(iter, &str);
+ g_free(machine_type);
+ machine_type = g_strdup(str);
+
+ DBG("Machine type set to %s", machine_type);
+ }
+}
+
+int __connman_machine_init(void)
+{
+ DBusConnection *connection;
+ int err = -EIO;
+
+ DBG("");
+
+ connection = connman_dbus_get_connection();
+
+ hostnamed_client = g_dbus_client_new(connection, HOSTNAMED_SERVICE,
+ HOSTNAMED_PATH);
+ if (!hostnamed_client)
+ goto error;
+
+ hostnamed_proxy = g_dbus_proxy_new(hostnamed_client, HOSTNAMED_PATH,
+ HOSTNAMED_INTERFACE);
+ if (!hostnamed_proxy)
+ goto error;
+
+ g_dbus_proxy_set_property_watch(hostnamed_proxy,
+ machine_property_changed, NULL);
+
+ dbus_connection_unref(connection);
+
+ return 0;
+error:
+ if (hostnamed_client) {
+ g_dbus_client_unref(hostnamed_client);
+ hostnamed_client = NULL;
+ }
+
+ dbus_connection_unref(connection);
+
+ return err;
+}
+
+void __connman_machine_cleanup(void)
+{
+ DBG("");
+
+ if (hostnamed_proxy) {
+ g_dbus_proxy_unref(hostnamed_proxy);
+ hostnamed_proxy = NULL;
+ }
+
+ if (hostnamed_client) {
+ g_dbus_client_unref(hostnamed_client);
+ hostnamed_client = NULL;
+ }
+
+ g_free(machine_type);
+ machine_type = NULL;
+}
diff --git a/src/main.c b/src/main.c
index c401bc4..21d1e06 100644
--- a/src/main.c
+++ b/src/main.c
@@ -679,6 +679,7 @@ int main(int argc, char *argv[])
__connman_wpad_init();
__connman_wispr_init();
__connman_rfkill_init();
+ __connman_machine_init();
g_free(option_config);
g_free(option_device);
@@ -690,6 +691,7 @@ int main(int argc, char *argv[])
g_source_remove(signal);
+ __connman_machine_cleanup();
__connman_rfkill_cleanup();
__connman_wispr_cleanup();
__connman_wpad_cleanup();
--
1.8.5.5
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman