From 723bbf4b424a5cc31652325e346979bcc09bf8fe Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 22 Oct 2013 15:48:21 +0100 Subject: [PATCH 16/16] WiP, doesn't work: Python and JavaScript CMs For some reason get_parameters() doesn't bind, and neither does get_parameters_array(). I don't know why not. :-( --- examples/cm/js/cm.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ examples/cm/python/cm.py | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 examples/cm/js/cm.js create mode 100644 examples/cm/python/cm.py diff --git a/examples/cm/js/cm.js b/examples/cm/js/cm.js new file mode 100644 index 0000000..a8aa314 --- /dev/null +++ b/examples/cm/js/cm.js @@ -0,0 +1,65 @@ +#!/usr/bin/env gjs + +/* + * Copyright (c) 2013 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * 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 + */ + +const Mainloop = imports.mainloop; +const Lang = imports.lang; + +const GLib = imports.gi.GLib; +const Tp = imports.gi.TelepathyGLib; + +const ExampleProtocol = new Lang.Class({ + Name: 'ExampleProtocol', + Extends: Tp.BaseProtocol, + + _init: function (args) { + this.parent(args); + }, + + vfunc_get_parameters_array: function () { + return [ + new Tp.CMParamSpec('account', GLib.VariantType.STRING, + Tp.ConnMgrParamFlags.REQUIRED, null, + Tp.cm_param_filter_string_nonempty, null), + ]; + }, +}); + +const ExampleConnectionManager = new Lang.Class({ + Name: 'ExampleConnectionManager', + Extends: Tp.BaseConnectionManager, + + _init: function () { + this.parent(); + this.add_protocol(new ExampleProtocol({ name: 'example' })); + }, + + vfunc_dup_cm_dbus_name: function () { + return "example_js_cm"; + }, +}); + +function main () { + bus_daemon = Tp.DBusDaemon.dup(); + cm = new ExampleConnectionManager(); + cm.register(); + Mainloop.run('example'); +} + +main(); diff --git a/examples/cm/python/cm.py b/examples/cm/python/cm.py new file mode 100644 index 0000000..c153837 --- /dev/null +++ b/examples/cm/python/cm.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# encoding: utf-8 + +# Copyright © 2013 Collabora Ltd. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# 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 + +import sys +from gi.repository import GLib +from gi.repository import TelepathyGLib as Tp + +def cm_param_spec(**kwargs): + spec = CMParamSpec() + for k in kwargs: + setattr(spec, k, kwargs[k]) + +class ExampleProtocol(Tp.BaseProtocol, object): + def __init__(self, name): + super(ExampleProtocol, self).__init__(name=name) + + def do_dup_parameters_array(self): + return [ + Tp.CMParamSpec('account', GLib.VariantType.STRING, + Tp.ConnMgrParamFlags.REQUIRED, None, + Tp.cm_param_filter_string_nonempty, None), + ] + +class ExampleConnectionManager(Tp.BaseConnectionManager): + def __init__(self): + super(ExampleConnectionManager, self).__init__() + self.add_protocol(ExampleProtocol('example')) + + def do_dup_cm_dbus_name(self): + return "example_python_cm" + +if __name__ == '__main__': + bus_daemon = Tp.DBusDaemon.dup() + + cm = ExampleConnectionManager() + cm.register() + + while True: + GLib.main_context_default().iteration(True) -- 1.8.4.rc3