Enlightenment CVS committal

Author  : rephorm
Project : e17
Module  : proto

Dir     : e17/proto/e_dbus/src/lib/notification


Modified Files:
        E_Notification_Daemon.h daemon.c 


Log Message:
implement more of the daemon side

===================================================================
RCS file: /cvs/e/e17/proto/e_dbus/src/lib/notification/E_Notification_Daemon.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- E_Notification_Daemon.h     11 Jul 2007 00:46:13 -0000      1.1
+++ E_Notification_Daemon.h     11 Jul 2007 00:48:49 -0000      1.2
@@ -1,40 +1,56 @@
 #ifndef E_NOTIFICATION_DAEMON_H
 #define E_NOTIFICATION_DAEMON_H
 
-/* daemon events */
-extern int E_NOTIFICATION_EVENT_NOTIFY;
-extern int E_NOTIFICATION_EVENT_CLOSE;
+#define E_NOTIFICATION_DAEMON_VERSION "0.9"
 
+#include <E_Notify.h>
 
-typedef struct E_Notification_Context E_Notification_Daemon;
 
-/* daemon events */
-typedef struct E_Notification_Event_Daemon E_Notification_Event_Daemon;
-typedef struct E_Notification_Event_Daemon E_Notification_Event_Notify;
-typedef struct E_Notification_Event_Daemon E_Notification_Event_Close;
+typedef struct E_Notification_Daemon E_Notification_Daemon;
+
+/* daemon callbacks */
+typedef int (*E_Notification_Daemon_Callback_Notify) (E_Notification_Daemon 
*daemon, E_Notification *notification);
+typedef void (*E_Notification_Daemon_Callback_Close_Notification) 
(E_Notification_Daemon *daemon, int notification_id);
 
 /* gui */
 typedef struct E_Notification_View E_Notification_View;
 
-struct E_Notification_Context
+struct E_Notification_Daemon
 {
   E_DBus_Connection *conn;
-};
+  E_DBus_Interface *iface;
+  E_DBus_Object *obj;
 
-/* daemon event data */
-struct E_Notification_Event_Daemon
-{
-  E_Notification *notification;
+  char *name;
+  char *vendor;
+
+  struct 
+  {
+    E_Notification_Daemon_Callback_Notify notify;
+    E_Notification_Daemon_Callback_Close_Notification close_notification;
+  } func;
+  void *data;
+
+  int state;
 };
 
 /* daemon */
-E_Notification_Daemon *e_notification_daemon_add(DBusConnection *conn);
+E_Notification_Daemon *e_notification_daemon_add(const char *name, const char 
*vendor);
 void e_notification_daemon_free(E_Notification_Daemon *d);
 void e_notification_daemon_close(E_Notification_Daemon *d,
                                  E_Notification *n, unsigned int reason);
 void e_notification_daemon_action_invoke(E_Notification_Daemon *d,
                                  E_Notification *n, const char *action_id);
 
+void  e_notification_daemon_data_set(E_Notification_Daemon *daemon, void 
*data);
+void *e_notification_daemon_data_get(E_Notification_Daemon *daemon);
+
+void e_notification_daemon_callback_notify_set(E_Notification_Daemon *daemon, 
E_Notification_Daemon_Callback_Notify func);
+void 
e_notification_daemon_callback_close_notification_set(E_Notification_Daemon 
*daemon, E_Notification_Daemon_Callback_Close_Notification func);
+
+
+void e_notification_daemon_signal_notification_closed(E_Notification_Daemon 
*daemon, unsigned int id, E_Notification_Closed_Reason reason);
+void e_notification_daemon_signal_action_invoked(E_Notification_Daemon 
*daemon, unsigned int notification_id, const char *action_id);
 
 /***** gui *****/
 E_Notification_View *e_notification_view_add(E_Notification_Daemon *d, 
E_Notification *n);
===================================================================
RCS file: /cvs/e/e17/proto/e_dbus/src/lib/notification/daemon.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- daemon.c    11 Jul 2007 00:46:13 -0000      1.1
+++ daemon.c    11 Jul 2007 00:48:49 -0000      1.2
@@ -1,20 +1,213 @@
 #include "E_Notify.h"
 #include "E_Notification_Daemon.h"
 #include "e_notify_private.h"
+#include <string.h>
+
+static int next_id = 0;
+
+DBusMessage *
+method_get_capabilities(E_DBus_Object *obj, DBusMessage *message)
+{
+  const char *capabilities[] = {
+    "body",
+    "actions",
+    NULL
+  };
+  return e_notify_marshal_get_capabilities_return(message, capabilities);
+}
+
+DBusMessage *
+method_notify(E_DBus_Object *obj, DBusMessage *message)
+{
+  E_Notification *n;
+  E_Notification_Daemon *daemon;
+  int id = -1;
+  
+  daemon = e_dbus_object_data_get(obj);
+  n = e_notify_unmarshal_notify(message, NULL);
+  if (daemon->func.notify)
+    id = daemon->func.notify(daemon, n);
+  else
+    return dbus_message_new_error(message, 
E_NOTIFICATION_INTERFACE".Unimplemented", "This functionality has not yet been 
implemented");
+
+  e_notification_unref(n);
+  return e_notify_marshal_notify_return(message, id);
+}
+
+DBusMessage *
+method_close_notification(E_DBus_Object *obj, DBusMessage *message)
+{
+  E_Notification_Daemon *daemon;
+  dbus_uint32_t id;
+
+  daemon = e_dbus_object_data_get(obj);
+  id = e_notify_unmarshal_close_notification(message, NULL);
+  if (daemon->func.close_notification)
+    daemon->func.close_notification(daemon, id);
+  return dbus_message_new_method_return(message);
+}
+
+DBusMessage *
+method_get_server_information(E_DBus_Object *obj, DBusMessage *message)
+{
+  E_Notification_Daemon *daemon;
+
+  daemon = e_dbus_object_data_get(obj);
+
+  return e_notify_marshal_get_server_information_return(message, daemon->name, 
daemon->vendor, E_NOTIFICATION_DAEMON_VERSION);
+}
+
 
 /**** daemon api ****/
+
+
+E_Notification_Daemon *
+e_notification_daemon_add(const char *name, const char *vendor)
+{
+  E_Notification_Daemon *daemon;
+
+  if (!e_dbus_init()) return NULL;
+  daemon = calloc(1, sizeof(E_Notification_Daemon));
+  if (daemon)
+    e_notification_daemon_bus_init(daemon);
+
+  if (!daemon || !daemon->conn)
+  {
+    if (daemon) free(daemon);
+    e_dbus_shutdown();
+    return NULL;
+  }
+
+  daemon->name = strdup(name);
+  daemon->vendor = strdup(vendor);
+
+  daemon->iface = e_dbus_interface_new(E_NOTIFICATION_INTERFACE);
+  e_dbus_interface_method_add(daemon->iface, "GetCapabilities", "", "as", 
method_get_capabilities);
+  e_dbus_interface_method_add(daemon->iface, "Notify", "susssasa{sv}i", "u", 
method_notify);
+  e_dbus_interface_method_add(daemon->iface, "CloseNotification", "u", "u", 
method_close_notification);
+  e_dbus_interface_method_add(daemon->iface, "GetServerInformation", "", 
"sss", method_get_server_information);
+
+  return daemon;
+}
+
+void
+e_notification_daemon_free(E_Notification_Daemon *daemon)
+{
+  if (daemon->obj) e_dbus_object_free(daemon->obj);
+  if (daemon->conn) e_dbus_connection_unref(daemon->conn);
+  if (daemon->name) free(daemon->name);
+  if (daemon->vendor) free(daemon->vendor);
+  if (daemon->iface) e_dbus_interface_unref(daemon->iface);
+  free(daemon);
+  e_dbus_shutdown();
+}
+
+void
+e_notification_daemon_data_set(E_Notification_Daemon *daemon, void *data)
+{
+  daemon->data = data;
+}
+
+void *
+e_notification_daemon_data_get(E_Notification_Daemon *daemon)
+{
+  return daemon->data;
+}
+
+void
+e_notification_daemon_callback_notify_set(E_Notification_Daemon *daemon, 
E_Notification_Daemon_Callback_Notify func)
+{
+  daemon->func.notify = func;
+}
+
+void
+e_notification_daemon_callback_close_notification_set(E_Notification_Daemon 
*daemon, E_Notification_Daemon_Callback_Close_Notification func)
+{
+  daemon->func.close_notification = func;
+}
+
+
+static void
+cb_request_name(void *data, DBusMessage *msg, DBusError *err)
+{
+  E_Notification_Daemon *daemon = data;
+  dbus_uint32_t ret;
+  DBusError new_err;
+
+  if (dbus_error_is_set(err))
+  {
+    printf("Error (request_name): %s\n", err->message);
+    dbus_error_free(err);
+    return;
+  }
+
+  printf("received response with signature: '%s'\n", 
dbus_message_get_signature(msg));
+  dbus_error_init(&new_err);
+  dbus_message_get_args(msg, &new_err, DBUS_TYPE_UINT32, &ret, 
DBUS_TYPE_INVALID);
+  if (dbus_error_is_set(&new_err))
+  {
+    printf("Error (req name unmarshal): %s\n", new_err.message);
+    dbus_error_free(&new_err);
+    return;
+  }
+
+  switch(ret)
+  {
+    case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
+    case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
+      e_notification_daemon_object_init(daemon);
+      break;
+    case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
+      //XXX mark daemon as queued?
+      break;
+    case DBUS_REQUEST_NAME_REPLY_EXISTS:
+      //XXX exit?
+      break;
+  }
+}
+
+int
+e_notification_daemon_bus_init(E_Notification_Daemon *daemon)
+{
+  daemon->conn = e_dbus_bus_get(DBUS_BUS_SESSION);
+  if (!daemon->conn) return 0;
+
+  // this blocks... make it async, and handle failure, etc
+  e_dbus_request_name(daemon->conn, E_NOTIFICATION_BUS_NAME, 
DBUS_NAME_FLAG_REPLACE_EXISTING, cb_request_name, daemon);
+}
+
+int
+e_notification_daemon_object_init(E_Notification_Daemon *daemon)
+{
+  E_DBus_Object *obj = NULL;
+  E_DBus_Interface *iface = NULL;
+
+  if (!daemon || !daemon->conn) return 0;
+  daemon->obj = e_dbus_object_add(daemon->conn, E_NOTIFICATION_PATH, daemon);
+  if (!daemon->obj) return 0;
+
+  e_dbus_object_interface_attach(daemon->obj, daemon->iface);
+
+  return 1;
+}
+
+
 void
-e_notification_signal_notification_closed(E_Notification_Daemon *daemon, 
unsigned int id, E_Notification_Closed_Reason reason)
+e_notification_daemon_signal_notification_closed(E_Notification_Daemon 
*daemon, unsigned int id, E_Notification_Closed_Reason reason)
 {
+  DBusMessage *msg = e_notify_marshal_notification_closed_signal(id, reason);
   e_dbus_message_send(daemon->conn, 
-                      e_notify_marshal_notification_closed_signal(id, reason),
+                      msg,
                       NULL, -1, NULL);
+  dbus_message_unref(msg);
 }
 
 void
-e_notification_signal_action_invoked(E_Notification_Daemon *daemon, unsigned 
int notification_id, const char *action_id)
+e_notification_daemon_signal_action_invoked(E_Notification_Daemon *daemon, 
unsigned int notification_id, const char *action_id)
 {
+  DBusMessage *msg = e_notify_marshal_action_invoked_signal(notification_id, 
action_id);
   e_dbus_message_send(daemon->conn, 
-                      e_notify_marshal_action_invoked_signal(notification_id, 
action_id),
+                      msg,
                       NULL, -1, NULL);
+  dbus_message_unref(msg);
 }



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to