Browse Source

Merge pull request #29 from bboozzoo/bboozzzoo/sms

sms send support
bboozzoo/snappy
Maciej Borzecki 7 years ago
committed by GitHub
parent
commit
1ee1fc76e8
6 changed files with 135 additions and 1 deletions
  1. +2
    -0
      meson.build
  2. +3
    -0
      src/mconnect/packethandlers-proxy.vala
  3. +44
    -0
      src/mconnect/telephony-proxy.vala
  4. +33
    -1
      src/mconnect/telephony.vala
  5. +25
    -0
      src/mconnectctl/main.vala
  6. +28
    -0
      src/mconnectctl/telephony-iface.vala

+ 2
- 0
meson.build View File

@ -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',
@ -73,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,


+ 3
- 0
src/mconnect/packethandlers-proxy.vala View File

@ -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());


+ 44
- 0
src/mconnect/telephony-proxy.vala View File

@ -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 <maciek.borzecki (at] gmail.com>
*/
[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);
}
}

+ 33
- 1
src/mconnect/telephony.vala View File

@ -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));
}
}

+ 25
- 0
src/mconnectctl/main.vala View File

@ -74,6 +74,8 @@ namespace Mconnect {
share-url <path> <url> Share URL with device
share-text <path> <text> Share text with device
share-file <path> <file> Share file with device
send-sms <number> <message> 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<string>(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


+ 28
- 0
src/mconnectctl/telephony-iface.vala View File

@ -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 <maciek.borzecki (at] gmail.com>
*/
namespace Mconnect {
[DBus (name = "org.mconnect.Device.Telephony")]
public interface TelephonyIface : Object {
public abstract void send_sms(string number,
string message) throws IOError;
}
}

Loading…
Cancel
Save