Diff between 56de7139dafa18b7f95080fbf46d44ae506694fa and 5a8f0192299605a7c5e7ac52375239dba5c5316d

Changed Files

File Additions Deletions Status
obexd/client/map-event.c +110 -0 added
obexd/client/map-event.h +25 -0 modified
obexd/client/mns.c +1 -0 modified

Full Patch

diff --git a/obexd/client/map-event.c b/obexd/client/map-event.c
new file mode 100644
index 0000000..76dfb84
--- /dev/null
+++ b/obexd/client/map-event.c
@@ -0,0 +1,110 @@
+/*
+ *
+ *  OBEX
+ *
+ *  Copyright (C) 2013  BMW Car IT GmbH. 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 as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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 <glib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "log.h"
+#include "map-event.h"
+
+#include <gdbus/gdbus.h>
+#include "transfer.h"
+#include "session.h"
+
+static GSList *handlers;
+
+struct mns_handler {
+	int mas_id;
+	struct obc_session *session;
+	map_event_cb cb;
+	void *user_data;
+};
+
+static struct mns_handler *find_handler(int mas_id, const char *device)
+{
+	GSList *list;
+
+	for (list = handlers; list; list = list->next) {
+		struct mns_handler *handler = list->data;
+
+		if (mas_id != handler->mas_id)
+			continue;
+
+		if (g_str_equal(device,
+				obc_session_get_destination(handler->session)))
+			return handler;
+	}
+
+	return NULL;
+}
+
+bool map_register_event_handler(struct obc_session *session,
+					int mas_id, map_event_cb cb,
+					void *user_data)
+{
+	struct mns_handler *handler;
+
+	handler = find_handler(mas_id, obc_session_get_destination(session));
+	if (handler != NULL)
+		return FALSE;
+
+	handler = g_new0(struct mns_handler, 1);
+	handler->mas_id = mas_id;
+	handler->session = session;
+	handler->cb = cb;
+	handler->user_data = user_data;
+
+	handlers = g_slist_prepend(handlers, handler);
+	DBG("Handler %p for %s:%d registered", handler,
+			obc_session_get_destination(session), mas_id);
+
+	return TRUE;
+}
+
+void map_unregister_event_handler(struct obc_session *session, int mas_id)
+{
+	struct mns_handler *handler;
+
+	handler = find_handler(mas_id, obc_session_get_destination(session));
+	if (handler == NULL)
+		return;
+
+	handlers = g_slist_remove(handlers, handler);
+	DBG("Handler %p for %s:%d unregistered", handler,
+			obc_session_get_destination(session), mas_id);
+}
+
+void map_dispatch_event(int mas_id, const char *device,
+						struct map_event *event)
+{
+	struct mns_handler *handler;
+
+	handler = find_handler(mas_id, device);
+	if (handler)
+		handler->cb(event, handler->user_data);
+}
diff --git a/obexd/client/map-event.h b/obexd/client/map-event.h
index 749f1e0..d77b477 100644
--- a/obexd/client/map-event.h
+++ b/obexd/client/map-event.h
@@ -21,6 +21,8 @@
  *
  */
 
+struct obc_session;
+
 enum map_event_type {
 	MAP_ET_NEW_MESSAGE,
 	MAP_ET_DELIVERY_SUCCESS,
@@ -40,3 +42,26 @@ struct map_event {
 	char *old_folder;
 	char *msg_type;
 };
+
+/* Handle notification in map client.
+ *
+ * event: Event report.
+ *
+ * Callback shall be called for every received event.
+ */
+typedef void (*map_event_cb) (struct map_event *event, void *user_data);
+
+/* Registers client notification handler callback for events that are
+ * addressed to the given mas instance id for the given device.
+ */
+bool map_register_event_handler(struct obc_session *session, int mas_id,
+					map_event_cb cb, void *user_data);
+
+/* Unregisters client notification handler callback.
+ */
+void map_unregister_event_handler(struct obc_session *session, int mas_id);
+
+/* Dispatch notification to a registered notification handler callback.
+ */
+void map_dispatch_event(int mas_id, const char *device,
+						struct map_event *event);
diff --git a/obexd/client/mns.c b/obexd/client/mns.c
index f564cdd..423fc6a 100644
--- a/obexd/client/mns.c
+++ b/obexd/client/mns.c
@@ -30,6 +30,7 @@
 #include <glib.h>
 #include <fcntl.h>
 #include <inttypes.h>
+#include <stdbool.h>
 
 #include <gobex/gobex.h>
 #include <gobex/gobex-apparam.h>