Browse Source

discovereddevice: split device that was found through discovery process from Device

bboozzoo/dbus-support-interfaces
Maciek Borzecki 8 years ago
parent
commit
4b2153c9f7
6 changed files with 84 additions and 20 deletions
  1. +1
    -0
      Makefile.am
  2. +2
    -2
      src/mconnect/application.vala
  3. +9
    -13
      src/mconnect/device.vala
  4. +8
    -2
      src/mconnect/devicemanager.vala
  5. +61
    -0
      src/mconnect/discovereddevice.vala
  6. +3
    -3
      src/mconnect/discovery.vala

+ 1
- 0
Makefile.am View File

@ -56,6 +56,7 @@ mconnect_SOURCES = \
src/mconnect/discovery.vala \ src/mconnect/discovery.vala \
src/mconnect/packet.vala \ src/mconnect/packet.vala \
src/mconnect/device.vala \ src/mconnect/device.vala \
src/mconnect/discovereddevice.vala \
src/mconnect/device-proxy.vala \ src/mconnect/device-proxy.vala \
src/mconnect/devicemanager.vala \ src/mconnect/devicemanager.vala \
src/mconnect/devicemanager-proxy.vala \ src/mconnect/devicemanager-proxy.vala \


+ 2
- 2
src/mconnect/application.vala View File

@ -60,8 +60,8 @@ namespace Mconn {
Notify.init("mconnect"); Notify.init("mconnect");
discovery.device_found.connect((disc, dev) => {
manager.handle_new_device(dev);
discovery.device_found.connect((disc, discdev) => {
manager.handle_discovered_device(discdev);
}); });
try { try {


+ 9
- 13
src/mconnect/device.vala View File

@ -57,19 +57,15 @@ class Device : Object {
* @param pkt identity packet * @param pkt identity packet
* @param host source host that the packet came from * @param host source host that the packet came from
*/ */
public Device.from_identity(Packet pkt, InetAddress host) {
debug("got packet: %s", pkt.to_string());
var body = pkt.body;
this.host = host;
this.device_name = body.get_string_member("deviceName");
this.device_id = body.get_string_member("deviceId");
this.device_type = body.get_string_member("deviceType");
this.protocol_version = (int) body.get_int_member("protocolVersion");
this.tcp_port = (uint) body.get_int_member("tcpPort");
debug("added new device: %s", this.to_string());
public Device.from_discovered_device(DiscoveredDevice disc) {
this.host = disc.host;
this.device_name = disc.device_name;
this.device_id = disc.device_id;
this.device_type = disc.device_type;
this.protocol_version = disc.protocol_version;
this.tcp_port = disc.tcp_port;
debug("new device: %s", this.to_string());
} }
/** /**


+ 8
- 2
src/mconnect/devicemanager.vala View File

@ -99,9 +99,15 @@ class DeviceManager : GLib.Object
} }
} }
public void handle_new_device(Device new_dev) {
debug("found device: %s", new_dev.to_string());
public void handle_discovered_device(DiscoveredDevice discovered_dev) {
debug("found device: %s", discovered_dev.to_string());
var new_dev = new Device.from_discovered_device(discovered_dev);
handle_new_device(new_dev);
}
public void handle_new_device(Device new_dev) {
var is_new = false; var is_new = false;
string unique = new_dev.to_unique_string(); string unique = new_dev.to_unique_string();
debug("device key: %s", unique); debug("device key: %s", unique);


+ 61
- 0
src/mconnect/discovereddevice.vala View File

@ -0,0 +1,61 @@
/* ex:ts=4:sw=4:sts=4:et */
/* -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/**
* 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>
*/
/**
* Newly discovered device wrapper.
*/
class DiscoveredDevice : Object {
public string device_id { get; private set; default = ""; }
public string device_name { get; private set; default = ""; }
public string device_type { get; private set; default = ""; }
public uint protocol_version {get; private set; default = 5; }
public uint tcp_port {get; private set; default = 1714; }
public InetAddress host { get; private set; default = null; }
/**
* Constructs DiscoveredDevice based on identity packet.
*
* @param pkt identity packet
* @param host source host that the packet came from
*/
public DiscoveredDevice.from_identity(Packet pkt, InetAddress host) {
debug("got packet: %s", pkt.to_string());
var body = pkt.body;
this.host = host;
this.device_name = body.get_string_member("deviceName");
this.device_id = body.get_string_member("deviceId");
this.device_type = body.get_string_member("deviceType");
this.protocol_version = (int) body.get_int_member("protocolVersion");
this.tcp_port = (uint) body.get_int_member("tcpPort");
debug("discovered new device: %s", this.to_string());
}
public string to_string() {
return "discovered-%s-%s-%s-%u".printf(this.device_id,
this.device_name,
this.device_type,
this.protocol_version);
}
}

+ 3
- 3
src/mconnect/discovery.vala View File

@ -22,10 +22,10 @@ class Discovery : GLib.Object
{ {
private Socket socket = null; private Socket socket = null;
public signal void device_found(Device dev);
public signal void device_found(DiscoveredDevice dev);
public Discovery() { public Discovery() {
}
}
~Discovery() { ~Discovery() {
debug("cleaning up discovery..."); debug("cleaning up discovery...");
@ -91,7 +91,7 @@ class Discovery : GLib.Object
return; return;
} }
var dev = new Device.from_identity(pkt, host);
var dev = new DiscoveredDevice.from_identity(pkt, host);
message("connection from device: \'%s\', responds at: %s:%u", message("connection from device: \'%s\', responds at: %s:%u",
dev.device_name, host.to_string(), dev.tcp_port); dev.device_name, host.to_string(), dev.tcp_port);


Loading…
Cancel
Save