[GnomeMeeting-devel-list] Re: Gnomemeeting remote control through DBUS



Le dim, 15/08/2004 à 01:33 +0200, PUYDT Julien a écrit :
> * a patch against gm's cvs.

Here it is.

Snark
diff -urN gnomemeeting/configure.in gnomemeeting.patched/configure.in
--- gnomemeeting/configure.in	2004-08-14 11:58:16.000000000 +0200
+++ gnomemeeting.patched/configure.in	2004-08-15 00:37:34.000000000 +0200
@@ -79,7 +79,7 @@
 PKG_CHECK_MODULES(GNOMEMEETING, gtk+-2.0 >= 2.0.6 gthread-2.0 >= 2.0.6 esound >= 0.2.28 libxml-2.0 >= 2.5.0)
 GNOMEMEETING_CFLAGS="$GNOMEMEETING_CFLAGS -DDISABLE_GNOME"
 else
-PKG_CHECK_MODULES(GNOMEMEETING, gtk+-2.0 >= 2.2.0 gthread-2.0 >= 2.2.0 esound >= 0.2.28 gconf-2.0 >= 2.2.0 libxml-2.0 >= 2.6.0 libgnome-2.0 >= 2.2.0 libgnomeui-2.0 >= 2.2.0 gnome-vfs-2.0 >= 2.2.0 libebook-1.0 >= 0.0.94)
+PKG_CHECK_MODULES(GNOMEMEETING, gtk+-2.0 >= 2.2.0 gthread-2.0 >= 2.2.0 esound >= 0.2.28 gconf-2.0 >= 2.2.0 libxml-2.0 >= 2.6.0 libgnome-2.0 >= 2.2.0 libgnomeui-2.0 >= 2.2.0 gnome-vfs-2.0 >= 2.2.0 libebook-1.0 >= 0.0.94 dbus-1 >= 0.21 dbus-glib-1 >= 0.21)
 fi
 
 PWLIB_REC_VERSION="1.8.1"
diff -urN gnomemeeting/src/dbus_component.cpp gnomemeeting.patched/src/dbus_component.cpp
--- gnomemeeting/src/dbus_component.cpp	1970-01-01 01:00:00.000000000 +0100
+++ gnomemeeting.patched/src/dbus_component.cpp	2004-08-15 00:42:17.000000000 +0200
@@ -0,0 +1,339 @@
+#include "dbus_component.h"
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus-glib.h>
+
+#include "gnomemeeting.h"
+#include "endpoint.h"
+
+/* declaration of the DBUS helper functions */
+
+
+static DBusHandlerResult filter_func(DBusConnection *connection,
+				     DBusMessage *message,
+				     void *user_data);
+
+
+
+static DBusHandlerResult path_message_func (DBusConnection *connection,
+					    DBusMessage *message,
+					    void *user_data);
+
+
+static void handle_call_address_message (DBusConnection *connection,
+					 DBusMessage *message);
+
+
+static void handle_get_state_message (DBusConnection *connection,
+				      DBusMessage *message);
+
+
+static void handle_end_call_message (DBusConnection *connection,
+				     DBusMessage *message);
+
+
+/* definition of some helper DBUS-related data */
+
+#define OBJECT "/org/gnomemeeting/Endpoint"
+
+
+#define INTERFACE "org.gnomemeeting.CallService"
+
+
+#define SERVICE "org.gnomemeeting.CallService"
+
+
+static const char* broken_path[] = { "org", "gnomemeeting", "Endpoint", NULL };
+
+static DBusObjectPathVTable call_vtable = {
+  NULL,
+  path_message_func,
+  NULL,
+};
+
+
+/* declaration of the private part of the GObject */
+
+
+struct _DBusComponent
+{
+  GObject parent;
+
+  DBusConnection *connection;
+  gboolean is_first_instance;
+};
+
+
+struct _DBusComponentClass
+{
+  GObjectClass parent;
+};
+
+
+/* Implementation of the GObject */
+
+
+GType
+dbus_component_get_type()
+{
+  static GType my_type = 0; 
+  
+  if (!my_type) {
+    static const GTypeInfo my_info = {
+      sizeof (DBusComponentClass),
+      NULL,
+      NULL,
+      (GClassInitFunc) dbus_component_class_init,
+      NULL,
+      NULL,
+      sizeof(DBusComponent),
+      0,
+      (GInstanceInitFunc) dbus_component_init
+    };
+    my_type = g_type_register_static (G_TYPE_OBJECT ,
+				      "DBusComponent", &my_info, 
+				      (GTypeFlags)0);
+  }
+  
+  return my_type;
+}
+
+
+DBusComponent*
+dbus_component_new()
+{
+  DBusComponent *result = NULL;
+  gboolean ok = TRUE;
+
+  result = DBUS_COMPONENT (g_object_new (DBUS_COMPONENT_TYPE, NULL));
+
+  result->connection = dbus_bus_get_with_g_main (DBUS_BUS_SESSION, NULL);
+
+  ok = (result->connection != NULL);
+
+  if (ok)
+    ok = dbus_connection_add_filter (result->connection, 
+				     filter_func,
+				     result, NULL);
+
+  if (ok)
+    ok = dbus_connection_register_object_path (result->connection, broken_path,
+					       &call_vtable, NULL);
+
+  if (!ok) 
+    result->is_first_instance = FALSE;
+
+  if (ok)
+    ok = (dbus_bus_acquire_service (result->connection, 
+				    SERVICE, 0, NULL) >= 0);
+
+  return result;
+}
+
+
+void
+dbus_component_dispose (GObject *object)
+{
+  DBusComponent *self =NULL;
+  GObjectClass *parent_class = NULL;
+
+  g_return_if_fail (IS_DBUS_COMPONENT (object));
+
+  self = DBUS_COMPONENT (object);
+
+  if (self->connection != NULL) {
+    dbus_connection_disconnect (self->connection);
+    dbus_connection_unref (self->connection);
+    self->connection = NULL;
+  }
+  
+  parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (DBUS_COMPONENT_GET_CLASS (self)));
+
+  parent_class->dispose (G_OBJECT(self));
+}
+
+
+void
+dbus_component_finalize (GObject *object)
+{
+  DBusComponent *self =NULL;
+  GObjectClass *parent_class = NULL;
+
+  g_return_if_fail (IS_DBUS_COMPONENT (object));
+
+  self = DBUS_COMPONENT (object);
+
+  parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (DBUS_COMPONENT_GET_CLASS (self)));
+
+  parent_class->finalize (G_OBJECT(self));
+}
+
+
+void
+dbus_component_init (DBusComponent *self)
+{
+  self->connection = NULL;
+  self->is_first_instance = FALSE;
+}
+
+
+void dbus_component_class_init (DBusComponentClass *klass)
+{
+  GObjectClass *object_klass = G_OBJECT_CLASS (klass);
+      
+  object_klass->dispose = dbus_component_dispose;
+
+  object_klass->finalize = dbus_component_finalize;
+}
+
+
+gboolean
+dbus_component_is_first_instance (DBusComponent *object)
+{
+  g_return_val_if_fail (object != NULL, FALSE);
+
+  return object->is_first_instance;
+}
+
+
+void
+dbus_component_call_address (DBusComponent *object, 
+			     gchar *address)
+{
+  DBusMessage *message = NULL;
+
+  g_return_if_fail (object != NULL);
+  
+  message = dbus_message_new_method_call (SERVICE, OBJECT, INTERFACE, "Call");
+
+  dbus_message_set_no_reply (message, TRUE);
+  
+  if (dbus_message_append_args (message,
+				DBUS_TYPE_STRING, address,
+				DBUS_TYPE_INVALID)) {
+    
+    (void)dbus_connection_send (object->connection, message, NULL);
+    dbus_connection_flush (object->connection);
+  }
+}
+
+
+/* implementation of the internal helpers */
+
+
+static DBusHandlerResult
+filter_func(DBusConnection *connection,
+            DBusMessage *message,
+            void *user_data)
+{
+  DBusComponent *object = NULL;
+
+  g_return_val_if_fail (user_data != NULL,
+			DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
+  object = DBUS_COMPONENT (user_data);
+
+  g_return_val_if_fail (object->connection == connection,
+			DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
+  if (dbus_message_is_signal (message,
+                              DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
+                              "Disconnected"))
+    {
+      dbus_connection_disconnect (object->connection);
+      object->connection = NULL;
+      object->is_first_instance = FALSE;
+
+      return DBUS_HANDLER_RESULT_HANDLED;
+    }
+
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+
+static DBusHandlerResult
+path_message_func (DBusConnection *connection,
+                   DBusMessage *message,
+                   void *user_data)
+{
+  DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+  if (dbus_message_is_method_call (message,
+                                   SERVICE,
+                                   "Call")) {
+    handle_call_address_message (connection, message);
+    result = DBUS_HANDLER_RESULT_HANDLED;
+  }
+  else if (dbus_message_is_method_call (message,
+					SERVICE,
+					"GetState")) {
+    handle_get_state_message (connection, message);
+    result = DBUS_HANDLER_RESULT_HANDLED;
+  }
+  else if (dbus_message_is_method_call (message,
+					SERVICE,
+					"EndCall")) {
+    handle_end_call_message (connection, message);
+    result = DBUS_HANDLER_RESULT_HANDLED;
+  }
+  
+  return result;
+}
+
+
+static void
+handle_call_address_message (DBusConnection *connection,
+			     DBusMessage *message)
+{
+  gchar *address = NULL;
+
+  if (dbus_message_get_args (message, NULL,
+			     DBUS_TYPE_STRING, &address,
+			     DBUS_TYPE_INVALID)) {
+    GnomeMeeting::Process ()->Connect (address); /* FIXME! */
+  }
+}
+
+
+static void
+handle_get_state_message (DBusConnection *connection,
+			  DBusMessage *message)
+{
+  DBusMessage *reply = NULL;
+  gchar *state = NULL;
+  GMH323EndPoint *ep = NULL;
+
+  ep = GnomeMeeting::Process ()->Endpoint ();
+  
+  reply = dbus_message_new_method_return (message);
+
+  switch (ep->GetCallingState ()) {
+  case GMH323EndPoint::Standby:
+    state = "Standby";
+    break;
+  case GMH323EndPoint::Calling:
+    state = "Calling";
+    break;
+  case GMH323EndPoint::Connected:
+    state  = "Connected";
+    break;
+  case GMH323EndPoint::Called:
+    state = "Called";
+    break;
+  default:
+    state = "Bogus";
+  }
+
+  if (dbus_message_append_args (reply,
+				DBUS_TYPE_STRING, state,
+				DBUS_TYPE_INVALID)) {
+    (void)dbus_connection_send (connection, reply, NULL);
+    dbus_connection_flush (connection);
+  }
+}
+
+static void
+handle_end_call_message (DBusConnection *connection,
+			 DBusMessage *message)
+{
+  GnomeMeeting::Process ()->Disconnect ();
+}
diff -urN gnomemeeting/src/dbus_component.h gnomemeeting.patched/src/dbus_component.h
--- gnomemeeting/src/dbus_component.h	1970-01-01 01:00:00.000000000 +0100
+++ gnomemeeting.patched/src/dbus_component.h	2004-08-15 00:41:40.000000000 +0200
@@ -0,0 +1,62 @@
+#ifndef _DBUS_COMPONENT_H_
+#define _DBUS_COMPONENT_H_
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+
+#define DBUS_COMPONENT_TYPE dbus_component_get_type ()
+
+
+#define DBUS_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+                             DBUS_COMPONENT_TYPE, DBusComponent))
+
+
+#define DBUS_COMPONENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
+                                     DBUS_COMPONENT_TYPE, DBusComponentClass))
+
+
+#define IS_DBUS_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+			        DBUS_COMPONENT_TYPE))
+
+
+#define DBUS_COMPONENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                       DBUS_COMPONENT_TYPE, \
+                                       DBusComponentClass)) 
+
+
+typedef struct _DBusComponent DBusComponent;
+
+
+typedef struct _DBusComponentClass DBusComponentClass;
+
+
+GType dbus_component_get_type();
+
+
+DBusComponent* dbus_component_new();
+
+
+void dbus_component_dispose (DBusComponent *self);
+
+
+void dbus_component_finalize (DBusComponent *self);
+
+
+void dbus_component_init (DBusComponent *self);
+
+
+void dbus_component_class_init (DBusComponentClass *klass);
+
+
+gboolean dbus_component_is_first_instance (DBusComponent *object);
+
+
+void dbus_component_call_address (GObject *, gchar *);
+
+
+G_END_DECLS
+
+#endif
diff -urN gnomemeeting/src/gnomemeeting.cpp gnomemeeting.patched/src/gnomemeeting.cpp
--- gnomemeeting/src/gnomemeeting.cpp	2004-08-12 20:21:39.000000000 +0200
+++ gnomemeeting.patched/src/gnomemeeting.cpp	2004-08-15 00:43:05.000000000 +0200
@@ -54,6 +54,7 @@
 #include "main_window.h"
 #include "toolbar.h"
 #include "misc.h"
+#include "dbus_component.h"
 
 #include "history-combo.h"
 #include "dialog.h"
@@ -151,6 +152,8 @@
     gtk_widget_destroy (gm);
   if (druid_window)
     gtk_widget_destroy (druid_window);
+  if (dbus_component)
+    g_object_unref (G_OBJECT (dbus_component));
   
   delete (rtp);
 }
@@ -433,6 +436,8 @@
   gw->docklet = gnomemeeting_tray_new ();
   gw->tray_popup_menu = gnomemeeting_tray_init_menu (gw->docklet);
 #endif
+  dbus_component = dbus_component_new ();
+
   gm_main_window_new (gw);
 
 
diff -urN gnomemeeting/src/gnomemeeting.h gnomemeeting.patched/src/gnomemeeting.h
--- gnomemeeting/src/gnomemeeting.h	2004-08-12 20:21:39.000000000 +0200
+++ gnomemeeting.patched/src/gnomemeeting.h	2004-08-15 00:42:49.000000000 +0200
@@ -41,7 +41,7 @@
 
 #include "common.h"
 #include "endpoint.h"
-
+#include "dbus_component.h"
 
 /**
  * COMMON NOTICE: The Application must be initialized with Init after its
@@ -196,6 +196,9 @@
   GtkWidget *druid_window;
   GtkWidget *prefs_window;
 
+  /* other things */
+  DBusComponent *dbus_component;
+
   static GnomeMeeting *GM;
 };
 
diff -urN gnomemeeting/src/Makefile.am gnomemeeting.patched/src/Makefile.am
--- gnomemeeting/src/Makefile.am	2004-06-04 18:49:48.000000000 +0200
+++ gnomemeeting.patched/src/Makefile.am	2004-08-15 00:37:34.000000000 +0200
@@ -57,8 +57,10 @@
 	lid.cpp			\
 	lid.h			\
 	addressbook_window.cpp	\
-	addressbook_window.h
-	
+	addressbook_window.h    \
+	dbus_component.h	\
+	dbus_component.cpp
+
 gnomemeeting_LDADD = \
 	@GNOMEMEETING_LIBS@ \
 	$(top_builddir)/lib/libgnomemeeting.la


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]