From ae6db2ce253b2c95afa92c65fbad07c1d8635adf Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sat, 21 Oct 2017 22:24:27 +0200 Subject: [PATCH 1/3] telephony: add support for SMS requests --- src/mconnect/telephony.vala | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/mconnect/telephony.vala b/src/mconnect/telephony.vala index 9f2a9c1..12c4eff 100644 --- a/src/mconnect/telephony.vala +++ b/src/mconnect/telephony.vala @@ -21,7 +21,8 @@ using Mconn; class TelephonyHandler : Object, PacketHandlerInterface { - private const string TELEPHONY = "kdeconnect.telephony"; + public const string TELEPHONY = "kdeconnect.telephony"; + public const string SMS_REQUEST = "kdeconnect.sms.request"; public string get_pkt_type() { return TELEPHONY; @@ -94,4 +95,35 @@ class TelephonyHandler : Object, PacketHandlerInterface { } } + + /** + * make_sms_packet: + * @number: recipient's number + * @message: message + * + * @return allocated packet + */ + private Packet make_sms_packet(string number, string message) { + var builder = new Json.Builder(); + builder.begin_object(); + builder.set_member_name("sendSms"); + builder.add_boolean_value(true); + builder.set_member_name("phoneNumber"); + builder.add_string_value(number); + builder.set_member_name("messageBody"); + builder.add_string_value(message); + builder.end_object(); + + return new Packet(SMS_REQUEST, + builder.get_root().get_object()); + } + + /** + * send_sms: + * + * Reques to send an SMS to @number with message @message. + */ + public void send_sms(Device dev, string number, string message) { + dev.send(make_sms_packet(number, message)); + } } \ No newline at end of file From a7a6ca01fdbd1215c2e85c837f777608f5923da3 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sat, 21 Oct 2017 22:25:30 +0200 Subject: [PATCH 2/3] telephony-proxy: export sending SMS over DBus --- meson.build | 1 + src/mconnect/packethandlers-proxy.vala | 3 ++ src/mconnect/telephony-proxy.vala | 44 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/mconnect/telephony-proxy.vala diff --git a/meson.build b/meson.build index fff5416..20aa50c 100644 --- a/meson.build +++ b/meson.build @@ -39,6 +39,7 @@ mconnect_src = [ 'src/mconnect/battery.vala', 'src/mconnect/battery-proxy.vala', 'src/mconnect/telephony.vala', + 'src/mconnect/telephony-proxy.vala', 'src/mconnect/mousepad.vala', 'src/mconnect/ping.vala', 'src/mconnect/ping-proxy.vala', diff --git a/src/mconnect/packethandlers-proxy.vala b/src/mconnect/packethandlers-proxy.vala index a153906..cc450b1 100644 --- a/src/mconnect/packethandlers-proxy.vala +++ b/src/mconnect/packethandlers-proxy.vala @@ -35,6 +35,9 @@ class PacketHandlersProxy : Object { case ShareHandler.SHARE: { return new ShareHandlerProxy.for_device_handler(dev, iface); } + case TelephonyHandler.TELEPHONY: { + return new TelephonyHandlerProxy.for_device_handler(dev, iface); + } default: warning("cannot register bus handler for %s", iface.get_pkt_type()); diff --git a/src/mconnect/telephony-proxy.vala b/src/mconnect/telephony-proxy.vala new file mode 100644 index 0000000..817edba --- /dev/null +++ b/src/mconnect/telephony-proxy.vala @@ -0,0 +1,44 @@ +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * AUTHORS + * Maciek Borzecki + */ + +[DBus (name = "org.mconnect.Device.Telephony")] +class TelephonyHandlerProxy : Object, PacketHandlerInterfaceProxy { + + private Device device = null; + private TelephonyHandler telephony = null; + + public TelephonyHandlerProxy.for_device_handler(Device dev, + PacketHandlerInterface iface) { + this.device = dev; + this.telephony = (TelephonyHandler) iface; + } + + [DBus (visible = false)] + public void bus_register(DBusConnection conn, string path) throws IOError { + conn.register_object(path, this); + } + + [DBus (visible = false)] + public void bus_unregister(DBusConnection conn) throws IOError { + // conn.unregister_object(this); + } + + public void send_sms(string number, string message) { + this.telephony.send_sms(this.device, number, message); + } +} \ No newline at end of file From 8adf3f4f55789c08171ac5a0b26fee7f2d94bee2 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sat, 21 Oct 2017 22:26:16 +0200 Subject: [PATCH 3/3] mconnectctl: add send-sms command --- meson.build | 1 + src/mconnectctl/main.vala | 25 +++++++++++++++++++++++++ src/mconnectctl/telephony-iface.vala | 28 ++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 src/mconnectctl/telephony-iface.vala diff --git a/meson.build b/meson.build index 20aa50c..6b8d02f 100644 --- a/meson.build +++ b/meson.build @@ -74,6 +74,7 @@ mconnectctl_src = [ 'src/mconnectctl/device-manager-iface.vala', 'src/mconnectctl/device-iface.vala', 'src/mconnectctl/share-iface.vala', + 'src/mconnectctl/telephony-iface.vala', ] executable('mconnectctl', mconnectctl_src, dependencies : [glib_dep, gobject_dep, diff --git a/src/mconnectctl/main.vala b/src/mconnectctl/main.vala index ff9582e..4c24c70 100644 --- a/src/mconnectctl/main.vala +++ b/src/mconnectctl/main.vala @@ -74,6 +74,8 @@ namespace Mconnect { share-url Share URL with device share-text Share text with device share-file Share file with device + + send-sms Send SMS """ ); opt_context.set_help_enabled(true); @@ -99,6 +101,7 @@ namespace Mconnect { Command("share-url", 2, cl.cmd_share_url), Command("share-text", 2, cl.cmd_share_text), Command("share-file", 2, cl.cmd_share_file), + Command("send-sms", 3, cl.cmd_send_sms), }; handle_command(remaining, commands); @@ -204,6 +207,17 @@ namespace Mconnect { }); } + private int cmd_send_sms(string[] args) { + return checked_dbus_call(() => { + var dp = args[0]; + var number = args[1]; + var message = args[2]; + var telephony = get_telephony(new ObjectPath(dp)); + telephony.send_sms(number, message); + return 0; + }); + } + private void print_sorted_caps(string[] caps, string format) { qsort_with_data(caps, sizeof(string), (a, b) => GLib.strcmp(a, b)); @@ -323,6 +337,17 @@ namespace Mconnect { return get_mconnect_obj_proxy(path); } + /** + * get_telephony: + * + * Obtain DBus interface to Telephony of given device + * + * @return interface or null + */ + private TelephonyIface? get_telephony(ObjectPath path) throws IOError { + return get_mconnect_obj_proxy(path); + } + /** * print_paths: * @objs: object paths diff --git a/src/mconnectctl/telephony-iface.vala b/src/mconnectctl/telephony-iface.vala new file mode 100644 index 0000000..680b6ce --- /dev/null +++ b/src/mconnectctl/telephony-iface.vala @@ -0,0 +1,28 @@ +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * AUTHORS + * Maciek Borzecki + */ + +namespace Mconnect { + + [DBus (name = "org.mconnect.Device.Telephony")] + public interface TelephonyIface : Object { + + public abstract void send_sms(string number, + string message) throws IOError; + } + +} \ No newline at end of file