The technology functions handle connman's technology features, such as scanning,
parsing, setting and receiving technology properties. With match_tech_name a
user can verify if any given technology exists on the system.
---
client/technology.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++
client/technology.h | 45 ++++++++++++++
2 files changed, 215 insertions(+)
create mode 100644 client/technology.c
create mode 100644 client/technology.h
diff --git a/client/technology.c b/client/technology.c
new file mode 100644
index 0000000..49561bb
--- /dev/null
+++ b/client/technology.c
@@ -0,0 +1,170 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2012 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
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "client/technology.h"
+#include "connman.h"
+
+void extract_properties(DBusMessageIter *dict)
+{
+ while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+ DBusMessageIter entry, value;
+ const char *key, *sdata;
+ dbus_bool_t bdata;
+
+ dbus_message_iter_recurse(dict, &entry);
+ dbus_message_iter_get_basic(&entry, &key);
+ printf("\t[%s] = ", key);
+
+ dbus_message_iter_next(&entry);
+
+ dbus_message_iter_recurse(&entry, &value);
+
+ if (dbus_message_iter_get_arg_type(&value) ==
+ DBUS_TYPE_BOOLEAN) {
+ dbus_message_iter_get_basic(&value, &bdata);
+ printf("%s\n", bdata ? "True" : "False");
+ } else if (dbus_message_iter_get_arg_type(&value) ==
+ DBUS_TYPE_STRING) {
+ dbus_message_iter_get_basic(&value, &sdata);
+ printf("%s\n", sdata);
+ }
+ dbus_message_iter_next(dict);
+ }
+}
+
+void match_tech_name(DBusMessage *message, char *tech_name,
+ struct tech_data *tech)
+{
+ DBusMessageIter iter, array;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_recurse(&iter, &array);
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
+ DBusMessageIter entry;
+ const char *path;
+ const char *name;
+
+ dbus_message_iter_recurse(&array, &entry);
+ dbus_message_iter_get_basic(&entry, &path);
+ tech->path = g_strdup(path);
+ name = strrchr(path, '/') + 1;
+ tech->name = g_strdup(name);
+ if (g_strcmp0(tech_name, tech->name) == 0) {
+ printf(" %-20s { %s } exists\n", tech->name,
+ tech->path);
+ break;
+ } else
+ dbus_message_iter_next(&array);
+ }
+
+}
+
+void extract_tech(DBusMessage *message)
+{
+ DBusMessageIter iter, array;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_recurse(&iter, &array);
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
+ DBusMessageIter entry, dict;
+
+ const char *path;
+
+ dbus_message_iter_recurse(&array, &entry);
+ dbus_message_iter_get_basic(&entry, &path);
+
+ printf(" { %s }\n", path);
+
+ dbus_message_iter_next(&entry);
+
+ dbus_message_iter_recurse(&entry, &dict);
+ extract_properties(&dict);
+
+ dbus_message_iter_next(&array);
+ }
+}
+
+int scan_technology(DBusConnection *connection, DBusMessage *message,
+ char *tech)
+{
+ DBusMessage *message_send;
+ struct tech_data technology;
+
+ match_tech_name(message, tech, &technology);
+ if (g_strcmp0(tech, technology.name) != 0) {
+ fprintf(stderr, "%s does not exist on the system\n", tech);
+ return -1;
+ }
+
+ message_send = dbus_message_new_method_call("net.connman",
+ technology.path,
+ "net.connman.Technology",
+ "Scan");
+ if (message_send == NULL)
+ return -1;
+
+ printf("Scanned for new services on %s.\n", technology.name);
+ dbus_connection_send(connection, message, NULL);
+ dbus_connection_flush(connection);
+ dbus_message_unref(message_send);
+ g_free((char *)technology.name);
+ g_free((char *)technology.path);
+
+ return 0;
+}
+
+int set_technology(DBusConnection *connection, DBusMessage *message, char *key,
+ char *tech, dbus_bool_t value)
+{
+ DBusMessage *message_send;
+ DBusMessageIter iter;
+ struct tech_data technology;
+
+ match_tech_name(message, tech, &technology);
+ if (g_strcmp0(tech, technology.name) != 0) {
+ fprintf(stderr, "%s does not exist on the system\n", tech);
+ return -1;
+ }
+
+ message_send = dbus_message_new_method_call("net.connman",
+ technology.path,
+
"net.connman.Technology",
+ "SetProperty");
+ if (message_send == NULL)
+ return -1;
+
+ dbus_message_iter_init_append(message_send, &iter);
+ connman_dbus_property_append_basic(&iter, (const char *) key,
+ DBUS_TYPE_BOOLEAN, &value);
+ dbus_connection_send(connection, message_send, NULL);
+ dbus_connection_flush(connection);
+ dbus_message_unref(message_send);
+ g_free((char *)technology.name);
+ g_free((char *)technology.path);
+
+ return 0;
+}
+
diff --git a/client/technology.h b/client/technology.h
new file mode 100644
index 0000000..6e1317d
--- /dev/null
+++ b/client/technology.h
@@ -0,0 +1,45 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2012 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 __CLIENT_TECHNOLOGY_H
+#define __CLIENT_TECHNOLOGY_H
+
+#include <dbus/dbus.h>
+
+struct tech_data {
+ const char *path;
+ const char *name;
+ dbus_bool_t powered;
+ dbus_bool_t connected;
+};
+
+void extract_properties(DBusMessageIter *dict);
+void match_tech_name(DBusMessage *message, char *tech_name,
+ struct tech_data *tech);
+void extract_tech(DBusMessage *message);
+int list_tech(DBusConnection *connection, char *function);
+int set_technology(DBusConnection *connection, DBusMessage *message, char *key,
+ char *tech, dbus_bool_t value);
+int scan_technology(DBusConnection *connection, DBusMessage *message,
+ char *tech);
+
+#endif
+
--
1.7.9.5
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman