Browse Source

device, devicemanager: add DBus intefaces, hide methods from the bus

bboozzoo/dbus-support-interfaces
Maciek Borzecki 8 years ago
parent
commit
bdcd3cf442
2 changed files with 30 additions and 0 deletions
  1. +14
    -0
      src/mconnect/device.vala
  2. +16
    -0
      src/mconnect/devicemanager.vala

+ 14
- 0
src/mconnect/device.vala View File

@ -21,11 +21,16 @@
/** /**
* General device wrapper. * General device wrapper.
*/ */
[DBus (name = "org.mconnect.Device")]
class Device : Object { class Device : Object {
[DBus (visible = false)]
public signal void paired(bool pair); public signal void paired(bool pair);
[DBus (visible = false)]
public signal void connected(); public signal void connected();
[DBus (visible = false)]
public signal void disconnected(); public signal void disconnected();
[DBus (visible = false)]
public signal void message(Packet pkt); public signal void message(Packet pkt);
public string device_id { get; private set; default = ""; } public string device_id { get; private set; default = ""; }
@ -33,6 +38,7 @@ class Device : Object {
public string device_type { get; private set; default = ""; } public string device_type { get; private set; default = ""; }
public uint protocol_version {get; private set; default = 5; } public uint protocol_version {get; private set; default = 5; }
public uint tcp_port {get; private set; default = 1714; } public uint tcp_port {get; private set; default = 1714; }
[DBus (visible = false)]
public InetAddress host { get; private set; default = null; } public InetAddress host { get; private set; default = null; }
public bool is_paired { get; private set; default = false; } public bool is_paired { get; private set; default = false; }
@ -108,10 +114,12 @@ class Device : Object {
/** /**
* Generates a unique string for this device * Generates a unique string for this device
*/ */
[DBus (visible = false)]
public string to_unique_string() { public string to_unique_string() {
return this.to_string().replace(" ", "-"); return this.to_string().replace(" ", "-");
} }
[DBus (visible = false)]
public string to_string() { public string to_string() {
return "%s-%s-%s-%u".printf(this.device_id, this.device_name, return "%s-%s-%s-%u".printf(this.device_id, this.device_name,
this.device_type, this.protocol_version); this.device_type, this.protocol_version);
@ -123,6 +131,7 @@ class Device : Object {
* @cache: device cache * @cache: device cache
* @name: group name * @name: group name
*/ */
[DBus (visible = false)]
public void to_cache(KeyFile cache, string name) { public void to_cache(KeyFile cache, string name) {
cache.set_string(name, "deviceId", this.device_id); cache.set_string(name, "deviceId", this.device_id);
cache.set_string(name, "deviceName", this.device_name); cache.set_string(name, "deviceName", this.device_name);
@ -150,6 +159,7 @@ class Device : Object {
* *
* @param expect_response se to true if expecting a response * @param expect_response se to true if expecting a response
*/ */
[DBus (visible = false)]
public async void pair(bool expect_response = true) { public async void pair(bool expect_response = true) {
if (this.host != null) { if (this.host != null) {
debug("start pairing"); debug("start pairing");
@ -164,6 +174,7 @@ class Device : Object {
} }
} }
[DBus (visible = false)]
public void pair_if_needed() { public void pair_if_needed() {
if (is_paired == false && _pair_in_progress == false) if (is_paired == false && _pair_in_progress == false)
this.pair.begin(); this.pair.begin();
@ -175,6 +186,7 @@ class Device : Object {
* Activate device. Triggers sending of #paired signal after * Activate device. Triggers sending of #paired signal after
* successfuly opening a connection. * successfuly opening a connection.
*/ */
[DBus (visible = false)]
public void activate() { public void activate() {
assert(_channel == null); assert(_channel == null);
@ -197,6 +209,7 @@ class Device : Object {
* *
* Deactivate device * Deactivate device
*/ */
[DBus (visible = false)]
public void deactivate() { public void deactivate() {
if (_channel != null) if (_channel != null)
_channel.close.begin((c) => { _channel.close.begin((c) => {
@ -214,6 +227,7 @@ class Device : Object {
* *
* @param dev device * @param dev device
*/ */
[DBus (visible = false)]
public void activate_from_device(Device dev) { public void activate_from_device(Device dev) {
if (host == null) { if (host == null) {
host = dev.host; host = dev.host;


+ 16
- 0
src/mconnect/devicemanager.vala View File

@ -19,12 +19,27 @@
*/ */
using Gee; using Gee;
[DBus (name = "org.mconnect.DeviceManager")]
class DeviceManager : GLib.Object class DeviceManager : GLib.Object
{ {
public const string DEVICES_CACHE_FILE = "devices"; public const string DEVICES_CACHE_FILE = "devices";
private HashMap<string, Device> devices; private HashMap<string, Device> devices;
/**
* DBus wrapper for devices
*/
private struct DeviceWrapper {
ObjectPath object_path;
Device device;
DeviceWrapper (string path, Device device) {
this.object_path = new ObjectPath(path);
this.device = device;
}
}
public DeviceManager() { public DeviceManager() {
debug("device manager.."); debug("device manager..");
@ -101,6 +116,7 @@ class DeviceManager : GLib.Object
} }
} }
[DBus (visible = false)]
public void found_device(Device dev) { public void found_device(Device dev) {
debug("found device: %s", dev.to_string()); debug("found device: %s", dev.to_string());


Loading…
Cancel
Save