From 9fc78a4485da1b4de08b32358290592bea3325e2 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 25 Oct 2016 18:12:08 +0200 Subject: [PATCH] TMP --- src/cauchy-connection-manager.vala | 74 +++++++++++++++++++++++++++--- src/cauchy-protocol.vala | 20 +++++++- src/cauchy.c | 32 +++---------- src/tp-base.vapi | 2 + 4 files changed, 95 insertions(+), 33 deletions(-) diff --git a/src/cauchy-connection-manager.vala b/src/cauchy-connection-manager.vala index 07d7bea..ff51285 100644 --- a/src/cauchy-connection-manager.vala +++ b/src/cauchy-connection-manager.vala @@ -18,13 +18,75 @@ using TelepathyGLib; -[DBUS (name = "org.freedesktop.Telepathy.ConnectionManager.cauchy")] -public class Cauchy.ConnectionManager : BaseConnectionManager { - class construct { - cm_dbus_name = "cauchy"; +[DBus (name = "org.freedesktop.Telepathy.ConnectionManager")] +public class Cauchy.ConnectionManager : Object { + public struct CMParams { + string name; + ConnMgrParamFlags flags; + string signature; + Variant default_value; } - construct { - add_protocol(new Cauchy.Protocol()); + public unowned string + get_name() + throws TelepathyGLib.Error + { + return "cauchy"; + } + + public bool + has_protocol(string protocol) + throws TelepathyGLib.Error + { + return (protocol == "matrix"); + } + + public void + get_parameters(string protocol, + out CMParams[] parameters) + throws TelepathyGLib.Error + { + parameters = { + }; + + parameters += CMParams() { + name = "account", + flags = ConnMgrParamFlags.REQUIRED, + signature = "s", + default_value = new Variant.maybe(VariantType.STRING, null) + }; + } + + private void + on_bus_acquired(DBusConnection conn) + { + try { + conn.register_object( + "/org/freedesktop/Telepathy/ConnectionManager/cauchy", + this); + } catch (IOError e) { + stderr.printf("Could not register service: %s\n", e.message); + } + + try { + conn.register_object( + "/org/freedesktop/Telepathy/ConnectionManager/cauchy/matrix", + new Cauchy.Protocol()); + } catch (IOError e) { + stderr.printf("Could not register protocol: %s\n", e.message); + } + } + + public void + run() + { + Bus.own_name(BusType.SESSION, + "org.freedesktop.Telepathy.ConnectionManager.cauchy", + BusNameOwnerFlags.NONE, + on_bus_acquired, + () => {}, + () => stderr.printf("Could not acquire name.\n")); + + new MainLoop().run(); } } diff --git a/src/cauchy-protocol.vala b/src/cauchy-protocol.vala index b87dba0..c312dbc 100644 --- a/src/cauchy-protocol.vala +++ b/src/cauchy-protocol.vala @@ -18,4 +18,22 @@ using TelepathyGLib; -public class Cauchy.Protocol : BaseProtocol {} +[DBus (name = "org.freedesktop.Telepathy.Protocol")] +public class Cauchy.Protocol : Object { + public void + identify_account(HashTable parameters, + out string account_id) + throws TelepathyGLib.Error + { + throw new TelepathyGLib.Error.NOT_IMPLEMENTED( + "This feature is not implemented"); + } + + public void + normalize_contact(string contact_id, out string normalized_contact_id) + throws TelepathyGLib.Error + { + throw new TelepathyGLib.Error.NOT_IMPLEMENTED( + "This feature is meaningless on Matrix"); + } +} diff --git a/src/cauchy.c b/src/cauchy.c index 10482e5..c95bd65 100644 --- a/src/cauchy.c +++ b/src/cauchy.c @@ -20,37 +20,17 @@ #include -#include "cauchy-connection-manager.h" +#include "cauchy.h" #include "cauchy-debug.h" -static TpBaseConnectionManager * -_construct_cm(void) -{ - TpBaseConnectionManager *base_cm = TP_BASE_CONNECTION_MANAGER( - g_object_new(CAUCHY_TYPE_CONNECTION_MANAGER, NULL)); - - return base_cm; -} - int main(int argc, char **argv) { - TpDebugSender *debug_sender; - int result; + CauchyConnectionManager *cm; - g_type_init(); - tp_debug_divert_messages(g_getenv("CAUCHY_LOGFILE")); + cm = cauchy_connection_manager_new(); + cauchy_connection_manager_run(cm); + g_object_unref(cm); - cauchy_debug_init(); - - debug_sender = tp_debug_sender_dup(); - - result = tp_run_connection_manager( - "telepathy-cauchy", VERSION, - _construct_cm, - argc, argv); - - g_object_unref (debug_sender); - - return result; + return 0; } diff --git a/src/tp-base.vapi b/src/tp-base.vapi index 4fa8586..8ca776c 100644 --- a/src/tp-base.vapi +++ b/src/tp-base.vapi @@ -21,6 +21,8 @@ namespace TelepathyGLib { public abstract class BaseProtocol : GLib.Object { [CCode (has_construct_function = false)] public BaseProtocol(); + + public string name { get; construct; } } [CCode (cheader_filename = "telepathy-glib/telepathy-glib.h")]