1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-02-15 04:42:06 +00:00

demo/miracle-wfdctl: maintain DBus interfaces by .vala files instead of generate from .xml which have only sync methods

This commit is contained in:
Derek Dai 2017-03-31 00:13:49 +08:00
parent 2da1f70ccd
commit 0edc5dd733
No known key found for this signature in database
GPG key ID: E109CC97553EF009
8 changed files with 279 additions and 208 deletions

View file

@ -3,16 +3,6 @@ if(NOT VALAC)
message(FATAL_ERROR "valac not found")
endif()
find_program(VALA_DBUS_BINDING_TOOL vala-dbus-binding-tool)
if(NOT VALA_DBUS_BINDING_TOOL)
message(FATAL_ERROR "vala-dbus-binding-tool not found")
endif()
find_program(GLIB_COMPILE_RESOURCES glib-compile-resources)
if(NOT GLIB_COMPILE_RESOURCES)
message(FATAL_ERROR "glib-compile-resources not found")
endif()
find_library(READLINE REQUIRED)
pkg_check_modules(GIO2 REQUIRED gio-2.0)
pkg_check_modules(GDK3 REQUIRED gdk-3.0)
@ -34,20 +24,6 @@ endif()
set(RES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/res)
set(DBUS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dbus)
add_custom_command(OUTPUT org-freedesktop-networkmanager.vala
org-freedesktop-miracle-wifi.vala
org-freedesktop-miracle-wfd.vala
COMMAND ${VALA_DBUS_BINDING_TOOL}
--gdbus
--no-synced
--rename-namespace=org:Org
--rename-namespace=freedesktop:Freedesktop
--rename-namespace=miracle:Miracle
--rename-namespace=wifi:Wifi
--rename-namespace=wfd:Wfd
--api-path=${DBUS_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(OUTPUT wfdctl.c
wfdctl.h
org-freedesktop-networkmanager.c
@ -58,25 +34,16 @@ add_custom_command(OUTPUT wfdctl.c
--pkg=gdk-3.0
${CMAKE_CURRENT_SOURCE_DIR}/wfdctl.vala
${CMAKE_CURRENT_SOURCE_DIR}/sigint.vapi
org-freedesktop-networkmanager.vala
org-freedesktop-miracle-wifi.vala
org-freedesktop-miracle-wfd.vala
${CMAKE_CURRENT_SOURCE_DIR}/org-freedesktop-networkmanager.vala
${CMAKE_CURRENT_SOURCE_DIR}/org-freedesktop-miracle-wifi.vala
${CMAKE_CURRENT_SOURCE_DIR}/org-freedesktop-miracle-wfd.vala
${VALA_EXTRA_OPTIONS}
DEPENDS wfdctl.vala
${CMAKE_CURRENT_BINARY_DIR}/org-freedesktop-networkmanager.vala
${CMAKE_CURRENT_BINARY_DIR}/org-freedesktop-miracle-wifi.vala
${CMAKE_CURRENT_BINARY_DIR}/org-freedesktop-miracle-wfd.vala
${CMAKE_CURRENT_SOURCE_DIR}/org-freedesktop-networkmanager.vala
${CMAKE_CURRENT_SOURCE_DIR}/org-freedesktop-miracle-wifi.vala
${CMAKE_CURRENT_SOURCE_DIR}/org-freedesktop-miracle-wfd.vala
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(OUTPUT wfdctl-res.c
COMMAND ${GLIB_COMPILE_RESOURCES}
--generate-source
--target=${CMAKE_CURRENT_BINARY_DIR}/wfdctl-res.c
${RES_DIR}/wfdctl-res.xml
DEPENDS ${RES_DIR}/wfdctl.ui
${RES_DIR}/wfdctl-res.xml
WORKING_DIRECTORY ${RES_DIR})
include_directories(${GIO2_INCLUDE_DIRS}
${GDK3_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR})
@ -88,7 +55,6 @@ set(CMAKE_C_FLAGS "-Wno-deprecated-declarations ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-Wno-unused-but-set-variable ${CMAKE_C_FLAGS}")
add_executable(miracle-wfdctl wfdctl
wfdctl-res.c
sigint.c
org-freedesktop-networkmanager.c
org-freedesktop-miracle-wifi.c

View file

@ -1,50 +0,0 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.50.3 -->
<node>
<interface name="org.freedesktop.NetworkManager.Device">
<method name="Reapply">
<arg type="a{sa{sv}}" name="connection" direction="in"/>
<arg type="t" name="version_id" direction="in"/>
<arg type="u" name="flags" direction="in"/>
</method>
<method name="GetAppliedConnection">
<arg type="u" name="flags" direction="in"/>
<arg type="a{sa{sv}}" name="connection" direction="out"/>
<arg type="t" name="version_id" direction="out"/>
</method>
<method name="Disconnect"/>
<method name="Delete"/>
<signal name="StateChanged">
<arg type="u" name="new_state"/>
<arg type="u" name="old_state"/>
<arg type="u" name="reason"/>
</signal>
<property type="s" name="Udi" access="readonly"/>
<property type="s" name="Interface" access="readonly"/>
<property type="s" name="IpInterface" access="readonly"/>
<property type="s" name="Driver" access="readonly"/>
<property type="s" name="DriverVersion" access="readonly"/>
<property type="s" name="FirmwareVersion" access="readonly"/>
<property type="u" name="Capabilities" access="readonly"/>
<property type="u" name="Ip4Address" access="readonly"/>
<property type="u" name="State" access="readonly"/>
<property type="(uu)" name="StateReason" access="readonly"/>
<property type="o" name="ActiveConnection" access="readonly"/>
<property type="o" name="Ip4Config" access="readonly"/>
<property type="o" name="Dhcp4Config" access="readonly"/>
<property type="o" name="Ip6Config" access="readonly"/>
<property type="o" name="Dhcp6Config" access="readonly"/>
<property type="b" name="Managed" access="readwrite"/>
<property type="b" name="Autoconnect" access="readwrite"/>
<property type="b" name="FirmwareMissing" access="readonly"/>
<property type="b" name="NmPluginMissing" access="readonly"/>
<property type="u" name="DeviceType" access="readonly"/>
<property type="ao" name="AvailableConnections" access="readonly"/>
<property type="s" name="PhysicalPortId" access="readonly"/>
<property type="u" name="Mtu" access="readonly"/>
<property type="u" name="Metered" access="readonly"/>
<property type="aa{sv}" name="LldpNeighbors" access="readonly"/>
<property type="b" name="Real" access="readonly"/>
</interface>
</node>

View file

@ -1,36 +0,0 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.miracle.wfd.Session">
<method name="Resume">
</method>
<method name="Pause">
</method>
<method name="Teardown">
</method>
<property name="Sink" type="o" access="readonly">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="Url" type="s" access="readonly">
</property>
<property name="State" type="i" access="readonly">
</property>
</interface>
<interface name="org.freedesktop.miracle.wfd.Sink">
<method name="StartSession">
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
<arg type="u" direction="in"/>
<arg type="u" direction="in"/>
<arg type="u" direction="in"/>
<arg type="u" direction="in"/>
<arg type="s" direction="in"/>
<arg type="o" direction="out"/>
</method>
<property name="Session" type="o" access="readonly">
</property>
<property name="Peer" type="o" access="readonly">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
</interface>
</node>

View file

@ -1,63 +0,0 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.miracle.wifi.Peer">
<method name="Connect">
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
</method>
<method name="Disconnect">
</method>
<property name="Link" type="o" access="readonly">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="P2PMac" type="s" access="readonly">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="FriendlyName" type="s" access="readonly">
</property>
<property name="Connected" type="b" access="readonly">
</property>
<property name="Interface" type="s" access="readonly">
</property>
<property name="LocalAddress" type="s" access="readonly">
</property>
<property name="RemoteAddress" type="s" access="readonly">
</property>
<property name="WfdSubelements" type="s" access="readonly">
</property>
<signal name="ProvisionDiscovery">
<arg type="s"/>
<arg type="s"/>
</signal>
<signal name="GoNegRequest">
<arg type="s"/>
<arg type="s"/>
</signal>
<signal name="FormationFailure">
<arg type="s"/>
</signal>
</interface>
<interface name="org.freedesktop.miracle.wifi.Link">
<method name="Manage">
</method>
<method name="Unmanage">
</method>
<property name="InterfaceIndex" type="u" access="readonly">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="MACAddress" type="s" access="readonly">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="InterfaceName" type="s" access="readonly">
</property>
<property name="FriendlyName" type="s" access="readwrite">
</property>
<property name="Managed" type="b" access="readonly">
</property>
<property name="P2PScanning" type="b" access="readwrite">
</property>
<property name="WfdSubelements" type="s" access="readwrite">
</property>
</interface>
</node>

View file

@ -0,0 +1,50 @@
/* Generated by vala-dbus-binding-tool 0.4.0. Do not modify! */
/* Generated with: /usr/bin/vala-dbus-binding-tool --gdbus --no-synced --rename-namespace=org:Org --rename-namespace=freedesktop:Freedesktop --rename-namespace=miracle:Miracle --rename-namespace=wifi:Wifi --rename-namespace=wfd:Wfd --api-path=/home/derekdai/Projects/miraclecast/demo/dbus */
using GLib;
namespace Org {
namespace Freedesktop {
namespace Miracle {
namespace Wfd {
[DBus (name = "org.freedesktop.miracle.wfd.Sink", timeout = 120000)]
public interface Sink : GLib.Object {
[DBus (name = "StartSession")]
public abstract async GLib.ObjectPath start_session(string param0, string param1, uint param2, uint param3, uint param4, uint param5, string param6) throws DBusError, IOError;
[DBus (name = "Session")]
public abstract GLib.ObjectPath session { owned get; }
[DBus (name = "Peer")]
public abstract GLib.ObjectPath peer { owned get; }
}
[DBus (name = "org.freedesktop.miracle.wfd.Session", timeout = 120000)]
public interface Session : GLib.Object {
[DBus (name = "Resume")]
public abstract async void resume() throws DBusError, IOError;
[DBus (name = "Pause")]
public abstract async void pause() throws DBusError, IOError;
[DBus (name = "Teardown")]
public abstract async void teardown() throws DBusError, IOError;
[DBus (name = "Sink")]
public abstract GLib.ObjectPath sink { owned get; }
[DBus (name = "Url")]
public abstract string url { owned get; }
[DBus (name = "State")]
public abstract int state { get; }
}
}
}
}
}

View file

@ -0,0 +1,89 @@
/* Generated by vala-dbus-binding-tool 0.4.0. Do not modify! */
/* Generated with: /usr/bin/vala-dbus-binding-tool --gdbus --no-synced --rename-namespace=org:Org --rename-namespace=freedesktop:Freedesktop --rename-namespace=miracle:Miracle --rename-namespace=wifi:Wifi --rename-namespace=wfd:Wfd --api-path=/home/derekdai/Projects/miraclecast/demo/dbus */
using GLib;
namespace Org {
namespace Freedesktop {
namespace Miracle {
namespace Wifi {
[DBus (name = "org.freedesktop.miracle.wifi.Peer", timeout = 120000)]
public interface Peer : GLib.Object {
[DBus (name = "Connect")]
public abstract async void connect(string param0, string param1) throws DBusError, IOError;
[DBus (name = "Disconnect")]
public abstract async void disconnect() throws DBusError, IOError;
[DBus (name = "Link")]
public abstract GLib.ObjectPath link { owned get; }
[DBus (name = "P2PMac")]
public abstract string p2_p_mac { owned get; }
[DBus (name = "FriendlyName")]
public abstract string friendly_name { owned get; }
[DBus (name = "Connected")]
public abstract bool connected { get; }
[DBus (name = "Interface")]
public abstract string interface { owned get; }
[DBus (name = "LocalAddress")]
public abstract string local_address { owned get; }
[DBus (name = "RemoteAddress")]
public abstract string remote_address { owned get; }
[DBus (name = "WfdSubelements")]
public abstract string wfd_subelements { owned get; }
[DBus (name = "ProvisionDiscovery")]
public signal void provision_discovery(string param0, string param1);
[DBus (name = "GoNegRequest")]
public signal void go_neg_request(string param0, string param1);
[DBus (name = "FormationFailure")]
public signal void formation_failure(string param0);
}
[DBus (name = "org.freedesktop.miracle.wifi.Link", timeout = 120000)]
public interface Link : GLib.Object {
[DBus (name = "Manage")]
public abstract async void manage() throws DBusError, IOError;
[DBus (name = "Unmanage")]
public abstract async void unmanage() throws DBusError, IOError;
[DBus (name = "InterfaceIndex")]
public abstract uint interface_index { get; }
[DBus (name = "MACAddress")]
public abstract string m_a_c_address { owned get; }
[DBus (name = "InterfaceName")]
public abstract string interface_name { owned get; }
[DBus (name = "FriendlyName")]
public abstract string friendly_name { owned get; set; }
[DBus (name = "Managed")]
public abstract bool managed { get; }
[DBus (name = "P2PScanning")]
public abstract bool p2_p_scanning { get; set; }
[DBus (name = "WfdSubelements")]
public abstract string wfd_subelements { owned get; set; }
}
}
}
}
}

View file

@ -0,0 +1,114 @@
/* Generated by vala-dbus-binding-tool 0.4.0. Do not modify! */
/* Generated with: /usr/bin/vala-dbus-binding-tool --gdbus --no-synced --rename-namespace=org:Org --rename-namespace=freedesktop:Freedesktop --rename-namespace=miracle:Miracle --rename-namespace=wifi:Wifi --rename-namespace=wfd:Wfd --api-path=/home/derekdai/Projects/miraclecast/demo/dbus */
using GLib;
namespace Org {
namespace Freedesktop {
namespace NetworkManager {
[DBus (name = "org.freedesktop.NetworkManager.Device", timeout = 120000)]
public interface Device : GLib.Object {
[DBus (name = "Reapply")]
public abstract async void reapply(GLib.HashTable<string, GLib.HashTable<string, GLib.Variant>> connection, uint64 version_id, uint flags) throws DBusError, IOError;
[DBus (name = "GetAppliedConnection")]
public abstract async void get_applied_connection(uint flags, out GLib.HashTable<string, GLib.HashTable<string, GLib.Variant>> connection, out uint64 version_id) throws DBusError, IOError;
[DBus (name = "Disconnect")]
public abstract async void disconnect() throws DBusError, IOError;
[DBus (name = "Delete")]
public abstract async void delete() throws DBusError, IOError;
[DBus (name = "StateChanged")]
public signal void state_changed(uint new_state, uint old_state, uint reason);
[DBus (name = "Udi")]
public abstract string udi { owned get; }
[DBus (name = "Interface")]
public abstract string interface { owned get; }
[DBus (name = "IpInterface")]
public abstract string ip_interface { owned get; }
[DBus (name = "Driver")]
public abstract string driver { owned get; }
[DBus (name = "DriverVersion")]
public abstract string driver_version { owned get; }
[DBus (name = "FirmwareVersion")]
public abstract string firmware_version { owned get; }
[DBus (name = "Capabilities")]
public abstract uint capabilities { get; }
[DBus (name = "Ip4Address")]
public abstract uint ip4_address { get; }
[DBus (name = "State")]
public abstract uint state { get; }
[DBus (name = "StateReason")]
public abstract DeviceStateReasonStruct state_reason { owned get; }
[DBus (name = "ActiveConnection")]
public abstract GLib.ObjectPath active_connection { owned get; }
[DBus (name = "Ip4Config")]
public abstract GLib.ObjectPath ip4_config { owned get; }
[DBus (name = "Dhcp4Config")]
public abstract GLib.ObjectPath dhcp4_config { owned get; }
[DBus (name = "Ip6Config")]
public abstract GLib.ObjectPath ip6_config { owned get; }
[DBus (name = "Dhcp6Config")]
public abstract GLib.ObjectPath dhcp6_config { owned get; }
[DBus (name = "Managed")]
public abstract bool managed { get; set; }
[DBus (name = "Autoconnect")]
public abstract bool autoconnect { get; set; }
[DBus (name = "FirmwareMissing")]
public abstract bool firmware_missing { get; }
[DBus (name = "NmPluginMissing")]
public abstract bool nm_plugin_missing { get; }
[DBus (name = "DeviceType")]
public abstract uint device_type { get; }
[DBus (name = "AvailableConnections")]
public abstract GLib.ObjectPath[] available_connections { owned get; }
[DBus (name = "PhysicalPortId")]
public abstract string physical_port_id { owned get; }
[DBus (name = "Mtu")]
public abstract uint mtu { get; }
[DBus (name = "Metered")]
public abstract uint metered { get; }
[DBus (name = "LldpNeighbors")]
public abstract GLib.HashTable<string, GLib.Variant>[] lldp_neighbors { owned get; }
[DBus (name = "Real")]
public abstract bool real { get; }
public struct DeviceStateReasonStruct {
public uint attr1;
public uint attr2;
}
}
}
}
}

View file

@ -40,6 +40,7 @@ errordomain WfdCtlError
NO_SUCH_NIC,
TIMEOUT,
MONITOR_GONE,
FORMATION_ERROR,
}
private void print(string format, ...)
@ -323,7 +324,7 @@ private class WfdCtl : GLib.Application
if(!l.managed) {
info("wifid is acquiring ownership of %s...", opt_iface);
l.manage();
yield l.manage();
yield wait_prop_changed(l as DBusProxy, "Managed");
}
}
@ -380,9 +381,14 @@ private class WfdCtl : GLib.Application
info("forming P2P group with %s (%s)...", p.p2_p_mac, p.friendly_name);
p.connect("auto", "");
ulong id = p.formation_failure.connect((r) => {
info("failed to form P2P group: %s", r);
});
yield p.connect("auto", "");
yield wait_prop_changed(p as DBusProxy, "Connected", 20);
(p as Object).disconnect(id);
info("P2P group formed");
}
@ -449,7 +455,7 @@ private class WfdCtl : GLib.Application
info("establishing display session...");
Sink sink = find_sink_by_mac(opt_peer_mac);
string path = sink.start_session(opt_authority,
string path = yield sink.start_session(opt_authority,
@"x://$(opt_display)",
g.x,
g.y,
@ -495,7 +501,7 @@ private class WfdCtl : GLib.Application
if(l.managed) {
info("wifid is releasing ownership of %s...", opt_iface);
l.unmanage();
yield l.unmanage();
yield wait_prop_changed(l as DBusProxy, "Managed");
}
@ -520,26 +526,17 @@ private class WfdCtl : GLib.Application
quit();
print("Bye");
}
public void stop_wireless_display()
{
info("tearing down wireless display...");
try {
if(null != curr_session) {
curr_session.teardown();
}
else {
release_wnic_ownership.begin(() => {
quit();
print("Bye");
});
}
if(null != curr_session) {
curr_session.teardown.begin(quit);
}
catch(Error e) {
warning("%s", e.message);
else {
release_wnic_ownership.begin(quit);
}
}
@ -667,7 +664,7 @@ private class WfdCtl : GLib.Application
private async void wait_prop_changed(DBusProxy o,
string name,
uint timeout = 0) throws WfdCtlError
uint timeout = 1) throws WfdCtlError
{
ulong prop_changed_id = o.g_properties_changed.connect((props) => {
string k;
@ -726,5 +723,9 @@ int main(string[]? argv)
return 1;
}
return app.run(argv);
int r = app.run(argv);
print("Bye");
return r;
}