* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Authors: Xavier Claessens <xclaesse@gmail.com>
* Elliot Fairweather <elliot.fairweather@collabora.co.uk>
*/
#include <extensions/extensions.h>
-#include "empathy-tp-tube.h"
#include "empathy-tube-handler.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
gchar *channel;
guint handle_type;
guint handle;
+ TpChannel *tube;
} IdleData;
+static void
+tube_ready_destroy_notify (gpointer data)
+{
+ IdleData *idle_data = data;
+
+ g_object_unref (idle_data->tube);
+ g_free (idle_data->bus_name);
+ g_free (idle_data->connection);
+ g_free (idle_data->channel);
+ g_slice_free (IdleData, idle_data);
+}
+
+static void
+channel_ready_cb (TpChannel *channel,
+ const GError *error,
+ gpointer data)
+{
+ IdleData *idle_data = data;
+
+ if (error != NULL)
+ {
+ DEBUG ("channel has been invalidated: %s", error->message);
+ tube_ready_destroy_notify (data);
+ g_object_unref (channel);
+ return;
+ }
+
+ g_signal_emit (idle_data->thandler, signals[NEW_TUBE], 0, idle_data->tube);
+
+ g_object_unref (channel);
+}
+
+static void
+connection_ready_cb (TpConnection *connection,
+ const GError *error,
+ gpointer data)
+{
+ TpChannel *channel;
+ IdleData *idle_data = data;
+
+ if (error != NULL)
+ {
+ DEBUG ("connection has been invalidated: %s", error->message);
+ tube_ready_destroy_notify (data);
+ g_object_unref (connection);
+ return;
+ }
+
+ channel = tp_channel_new (connection, idle_data->channel,
+ TP_IFACE_CHANNEL_TYPE_TUBES, idle_data->handle_type,
+ idle_data->handle, NULL);
+ tp_channel_call_when_ready (channel, channel_ready_cb, idle_data);
+
+ g_object_unref (connection);
+}
+
static gboolean
tube_handler_handle_tube_idle_cb (gpointer data)
{
IdleData *idle_data = data;
TpConnection *connection;
- TpChannel *channel;
- EmpathyTpTube *tube;
static TpDBusDaemon *daemon = NULL;
DEBUG ("New tube to be handled");
connection = tp_connection_new (daemon, idle_data->bus_name,
idle_data->connection, NULL);
- channel = tp_channel_new (connection, idle_data->channel,
- TP_IFACE_CHANNEL_TYPE_TUBES, idle_data->handle_type,
- idle_data->handle, NULL);
- tp_channel_run_until_ready (channel, NULL, NULL);
-
- tube = empathy_tp_tube_new (channel);
- g_signal_emit (idle_data->thandler, signals[NEW_TUBE], 0, tube);
-
- g_object_unref (tube);
- g_object_unref (channel);
- g_object_unref (connection);
- g_free (idle_data->bus_name);
- g_free (idle_data->connection);
- g_free (idle_data->channel);
- g_slice_free (IdleData, idle_data);
+ tp_connection_call_when_ready (connection,
+ connection_ready_cb, idle_data);
return FALSE;
}
static void
tube_handler_handle_tube (EmpSvcTubeHandler *self,
- const gchar *bus_name,
- const gchar *connection,
- const gchar *channel,
- guint handle_type,
- guint handle,
- DBusGMethodInvocation *context)
+ const gchar *bus_name,
+ const gchar *connection,
+ const gchar *channel,
+ guint handle_type,
+ guint handle,
+ DBusGMethodInvocation *context)
{
EmpathyTubeHandler *thandler = EMPATHY_TUBE_HANDLER (self);
IdleData *data;
signals[NEW_TUBE] =
g_signal_new ("new-tube", G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, EMPATHY_TYPE_TP_TUBE);
+ G_TYPE_NONE, 1, TP_TYPE_CHANNEL);
}
static void
}
EmpathyTubeHandler *
-empathy_tube_handler_new (EmpathyTubeType type, const gchar *service)
+empathy_tube_handler_new (TpTubeType type,
+ const gchar *service)
{
EmpathyTubeHandler *thandler = NULL;
DBusGProxy *proxy;
gchar *object_path;
GError *error = NULL;
- g_return_val_if_fail (type <= EMPATHY_TYPE_DBUS_TUBE, NULL);
+ g_return_val_if_fail (type < NUM_TP_TUBE_TYPES, NULL);
g_return_val_if_fail (service != NULL, NULL);
bus_name = empathy_tube_handler_build_bus_name (type, service);
goto OUT;
}
+ DEBUG ("Creating tube handler %s", bus_name);
thandler = g_object_new (EMPATHY_TYPE_TUBE_HANDLER, NULL);
dbus_g_connection_register_g_object (tp_get_bus (), object_path,
G_OBJECT (thandler));
return thandler;
}
+static gchar *
+sanitize_service_name (const gchar *str)
+{
+ guint i;
+ gchar *result;
+
+ g_assert (str != NULL);
+ result = g_strdup (str);
+
+ for (i = 0; result[i] != '\0'; i++)
+ {
+ if (!g_ascii_isalnum (result[i]))
+ result[i] = '_';
+ }
+
+ return result;
+}
+
gchar *
-empathy_tube_handler_build_bus_name (EmpathyTubeType type,
+empathy_tube_handler_build_bus_name (TpTubeType type,
const gchar *service)
{
gchar *str = NULL;
const gchar *prefix = NULL;
+ gchar *service_escaped;
- g_return_val_if_fail (type <= EMPATHY_TYPE_DBUS_TUBE, NULL);
+ g_return_val_if_fail (type < NUM_TP_TUBE_TYPES, NULL);
g_return_val_if_fail (service != NULL, NULL);
- if (type == EMPATHY_TYPE_DBUS_TUBE)
+ if (type == TP_TUBE_TYPE_DBUS)
prefix = "org.gnome.Empathy.DTubeHandler.";
- else if (type == EMPATHY_TYPE_STREAM_TUBE)
+ else if (type == TP_TUBE_TYPE_STREAM)
prefix = "org.gnome.Empathy.StreamTubeHandler.";
else
g_return_val_if_reached (NULL);
- str = g_strconcat (prefix, service, NULL);
+ service_escaped = sanitize_service_name (service);
+ str = g_strconcat (prefix, service_escaped, NULL);
+ g_free (service_escaped);
return str;
}
gchar *
-empathy_tube_handler_build_object_path (EmpathyTubeType type,
+empathy_tube_handler_build_object_path (TpTubeType type,
const gchar *service)
{
gchar *bus_name;
gchar *str;
- g_return_val_if_fail (type <= EMPATHY_TYPE_DBUS_TUBE, NULL);
+ g_return_val_if_fail (type < NUM_TP_TUBE_TYPES, NULL);
g_return_val_if_fail (service != NULL, NULL);
bus_name = empathy_tube_handler_build_bus_name (type, service);
return str;
}
-