Basic peer structure and attributes.
---
Makefile.am | 4 +-
include/dbus.h | 1 +
include/peer.h | 45 +++++++++++++++++
src/connman.h | 5 ++
src/main.c | 2 +
src/peer.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 205 insertions(+), 2 deletions(-)
create mode 100644 include/peer.h
create mode 100644 src/peer.c
diff --git a/Makefile.am b/Makefile.am
index b2778cc..c0f6c97 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/inotify.h include/peer.h
nodist_include_HEADERS = include/version.h
@@ -105,7 +105,7 @@ src_connmand_SOURCES = $(gdhcp_sources) $(gweb_sources) \
src/session.c src/tethering.c src/wpad.c src/wispr.c \
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/inotify.c src/firewall.c src/ipv6pd.c src/peer.c
src_connmand_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
@GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ @GNUTLS_LIBS@ \
diff --git a/include/dbus.h b/include/dbus.h
index 85e8ede..253a23b 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -46,6 +46,7 @@ extern "C" {
#define CONNMAN_TECHNOLOGY_INTERFACE CONNMAN_SERVICE ".Technology"
#define CONNMAN_SESSION_INTERFACE CONNMAN_SERVICE ".Session"
#define CONNMAN_NOTIFICATION_INTERFACE CONNMAN_SERVICE ".Notification"
+#define CONNMAN_PEER_INTERFACE CONNMAN_SERVICE ".Peer"
#define CONNMAN_PRIVILEGE_MODIFY 1
#define CONNMAN_PRIVILEGE_SECRET 2
diff --git a/include/peer.h b/include/peer.h
new file mode 100644
index 0000000..807c945
--- /dev/null
+++ b/include/peer.h
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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_PEER_H
+#define __CONNMAN_PEER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct connman_peer;
+
+struct connman_peer *connman_peer_create(const char *identifier);
+void connman_peer_destroy(struct connman_peer *peer);
+
+void connman_peer_set_name(struct connman_peer *peer, const char *name);
+
+int connman_peer_register(struct connman_peer *peer);
+void connman_peer_unregister(struct connman_peer *peer);
+
+struct connman_peer *connman_peer_get(const char *identifier);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_PEER_H */
diff --git a/src/connman.h b/src/connman.h
index 4366e19..f671173 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -771,6 +771,11 @@ void __connman_service_notify(struct connman_service
*service,
int __connman_service_counter_register(const char *counter);
void __connman_service_counter_unregister(const char *counter);
+#include <connman/peer.h>
+
+int __connman_peer_init(void);
+void __connman_peer_cleanup(void);
+
#include <connman/session.h>
typedef void (* service_iterate_cb) (struct connman_service *service,
diff --git a/src/main.c b/src/main.c
index 862a93e..4bd52b1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -650,6 +650,7 @@ int main(int argc, char *argv[])
__connman_notifier_init();
__connman_agent_init();
__connman_service_init();
+ __connman_peer_init();
__connman_provider_init();
__connman_network_init();
__connman_config_init();
@@ -723,6 +724,7 @@ int main(int argc, char *argv[])
__connman_device_cleanup();
__connman_network_cleanup();
__connman_service_cleanup();
+ __connman_peer_cleanup();
__connman_agent_cleanup();
__connman_ipconfig_cleanup();
__connman_notifier_cleanup();
diff --git a/src/peer.c b/src/peer.c
new file mode 100644
index 0000000..733ce0f
--- /dev/null
+++ b/src/peer.c
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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"
+
+static DBusConnection *connection = NULL;
+
+static GHashTable *peers_table = NULL;
+
+struct connman_peer {
+ char *identifier;
+ char *name;
+ char *path;
+};
+
+static void peer_free(gpointer data)
+{
+ struct connman_peer *peer = data;
+ connman_peer_destroy(peer);
+}
+
+struct connman_peer *connman_peer_create(const char *identifier)
+{
+ struct connman_peer *peer;
+
+ peer = g_malloc0(sizeof(struct connman_peer));
+ peer->identifier = g_strdup_printf("peer_%s", identifier);
+
+ return peer;
+}
+
+void connman_peer_destroy(struct connman_peer *peer)
+{
+ if (!peer)
+ return;
+
+ if (peer->path) {
+ g_dbus_unregister_interface(connection, peer->path,
+ CONNMAN_PEER_INTERFACE);
+ g_free(peer->path);
+ }
+
+ g_free(peer->identifier);
+ g_free(peer->name);
+
+ g_free(peer);
+}
+
+void connman_peer_set_name(struct connman_peer *peer, const char *name)
+{
+ g_free(peer->name);
+ peer->name = g_strdup(name);
+}
+
+static const GDBusMethodTable peer_methods[] = {
+ { GDBUS_ASYNC_METHOD("Connect", NULL, NULL, NULL) },
+ { GDBUS_METHOD("Disconnect", NULL, NULL, NULL) },
+ { },
+};
+
+static const GDBusSignalTable peer_signals[] = {
+ { GDBUS_SIGNAL("PropertyChanged",
+ GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+ { },
+};
+
+int connman_peer_register(struct connman_peer *peer)
+{
+ DBG("peer %p", peer);
+
+ if (peer->path)
+ return -EALREADY;
+
+ peer->path = g_strdup_printf("%s/peer/%s", CONNMAN_PATH,
+ peer->identifier);
+ DBG("path %s", peer->path);
+
+ g_hash_table_insert(peers_table, peer->identifier, peer);
+
+ g_dbus_register_interface(connection, peer->path,
+ CONNMAN_PEER_INTERFACE,
+ peer_methods, peer_signals,
+ NULL, peer, NULL);
+ return 0;
+}
+
+void connman_peer_unregister(struct connman_peer *peer)
+{
+ DBG("peer %p", peer);
+
+ if (peer->path)
+ g_hash_table_remove(peers_table, peer->identifier);
+ else
+ connman_peer_destroy(peer);
+}
+
+struct connman_peer *connman_peer_get(const char *identifier)
+{
+ char *ident = g_strdup_printf("peer_%s", identifier);
+ struct connman_peer *peer;
+
+ peer = g_hash_table_lookup(peers_table, ident);
+ g_free(ident);
+
+ return peer;
+}
+
+int __connman_peer_init(void)
+{
+ DBG("");
+
+ connection = connman_dbus_get_connection();
+
+ peers_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+ NULL, peer_free);
+ return 0;
+}
+
+void __connman_peer_cleanup(void)
+{
+ DBG("");
+
+ g_hash_table_destroy(peers_table);
+ dbus_connection_unref(connection);
+}
--
1.8.3.2
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman