From b60e110190c81a6deaba139c020d93771883a62c Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Fri, 26 Mar 2010 18:17:29 +0000 Subject: [PATCH] Try to make things async --- README | 4 +- zavai/gsm.vala | 189 ++++++++++++++++++++++++++++++------------------- 2 files changed, 120 insertions(+), 73 deletions(-) diff --git a/README b/README index 12d0788..bf02346 100644 --- a/README +++ b/README @@ -186,8 +186,8 @@ using vala-dbus-binding-tool: mkdir /tmp/foo vala-dbus-binding-tool --directory=/tmp/foo --api-path=/tmp/api.xml - - + Async and D-Bus: + http://git.gnome.org/browse/vala/tree/tests/dbus/async.test * Features to add: - if GPS time is more than 1 minute and less than 1 hour different than the diff --git a/zavai/gsm.vala b/zavai/gsm.vala index 8da0c0d..34d0fa9 100644 --- a/zavai/gsm.vala +++ b/zavai/gsm.vala @@ -23,13 +23,91 @@ using GLib; namespace zavai { namespace gsm { +[DBus (name = "org.freesmartphone.GSM.Device")] +public interface FSO_GSM_Device : Object { + public abstract async int test_int (int i, out int j) throws DBus.Error; + public abstract async string test_string (string s, out string t) throws DBus.Error; + public abstract async void set_sim_buffers_sms(bool sim_buffers_sms) throws DBus.Error; + public abstract async void set_r_t_c() throws DBus.Error; + public abstract async void cancel_command() throws DBus.Error; + public abstract async void set_antenna_power(bool power) throws DBus.Error; + public abstract async GLib.HashTable get_info() throws DBus.Error; + public abstract async void set_microphone_muted(bool muted) throws DBus.Error; + public signal void keypad_event(string name, bool pressed); + public abstract async int get_speaker_volume() throws DBus.Error; + public abstract async int get_r_t_c() throws DBus.Error; + public abstract async void set_speaker_volume(int modem_volume) throws DBus.Error; + public abstract async GLib.HashTable get_features() throws DBus.Error; + public abstract async bool get_microphone_muted() throws DBus.Error; + public abstract async bool get_antenna_power() throws DBus.Error; + public abstract async void get_power_status(out string param0, out int param1) throws DBus.Error; + public abstract async bool get_sim_buffers_sms() throws DBus.Error; +} + +[DBus (name = "org.freesmartphone.GSM.SIM")] +public interface FSO_GSM_SIM : GLib.Object { + //public abstract async SIMParam0Struct[] retrieve_phonebook(string category) throws DBus.Error; + public abstract async void send_auth_code(string code) throws DBus.Error; + public abstract async string get_issuer() throws DBus.Error; + public abstract async void change_auth_code(string old_pin, string new_pin) throws DBus.Error; + public signal void auth_status(string status); + public abstract async string send_generic_sim_command(string command) throws DBus.Error; + public abstract async string[] list_phonebooks() throws DBus.Error; + public abstract async void set_service_center_number(string number) throws DBus.Error; + public abstract async GLib.HashTable get_provider_list() throws DBus.Error; + //public abstract async SIMParam0Struct2[] get_home_zones() throws DBus.Error; + public signal void ready_status(bool status); + public abstract async void retrieve_entry(string category, int index, out string param0, out string param1) throws DBus.Error; + public abstract async void delete_message(int index) throws DBus.Error; + public abstract async void send_restricted_sim_command(int command, int fileid, int p1, int p2, int p3, string data, out int param0, out int param1, out string param2) throws DBus.Error; + public abstract async GLib.HashTable get_messagebook_info() throws DBus.Error; + public abstract async bool get_sim_ready() throws DBus.Error; + public abstract async GLib.HashTable get_phonebook_info(string category) throws DBus.Error; + public signal void memory_full(); + public abstract async GLib.HashTable get_sim_info() throws DBus.Error; + public abstract async void set_auth_code_required(bool required, string pin) throws DBus.Error; + public abstract async string get_auth_status() throws DBus.Error; + public abstract async void send_stored_message(int index, out int param0, out string param1) throws DBus.Error; + public abstract async int store_message(string number, string contents, GLib.HashTable properties) throws DBus.Error; + public abstract async bool get_auth_code_required() throws DBus.Error; + public signal void incoming_stored_message(int index); + public abstract async void retrieve_message(int index, out string param0, out string param1, out string param2, out GLib.HashTable param3) throws DBus.Error; + public abstract async void store_entry(string category, int index, string name, string number) throws DBus.Error; + public abstract async void unlock(string puk, string new_pin) throws DBus.Error; + public abstract async string get_service_center_number() throws DBus.Error; + //public abstract async SIMParam0Struct23[] retrieve_messagebook(string category) throws DBus.Error; + public abstract async void delete_entry(string category, int index) throws DBus.Error; +} + +[DBus (name = "org.freesmartphone.GSM.Network")] +public interface FSO_GSM_Network : GLib.Object { + public signal void status(GLib.HashTable status); + public signal void signal_strength(int strength); + //public abstract async NetworkParam0Struct[] list_providers() throws DBus.Error; + public abstract async GLib.HashTable get_call_forwarding(string reason) throws DBus.Error; + public signal void time_zone_report(int timezone); + public abstract async void unregister() throws DBus.Error; + public abstract async void set_calling_identification(string status) throws DBus.Error; + public abstract async void register_() throws DBus.Error; + public abstract async void send_ussd_request(string request) throws DBus.Error; + public abstract async void disable_call_forwarding(string reason, string class_) throws DBus.Error; + public signal void incoming_ussd(string mode, string message_); + public abstract async int get_signal_strength() throws DBus.Error; + public abstract async void enable_call_forwarding(string reason, string class_, string number, int timeout) throws DBus.Error; + public abstract async string get_calling_identification() throws DBus.Error; + public abstract async void register_with_provider(string operator_code) throws DBus.Error; + public signal void cipher_status(string gsm, string gprs); + public abstract async GLib.HashTable get_status() throws DBus.Error; + public abstract async void get_country_code(out string param0, out string param1) throws DBus.Error; +} + // Isolate here the insane loops we need to go through to turn on the bloody // gsm protected class GSMActivator : Object { - public dynamic DBus.Object device; - public dynamic DBus.Object network; - public dynamic DBus.Object sim; + public FSO_GSM_Device device; + public FSO_GSM_Network network; + public FSO_GSM_SIM sim; public signal void status_changed(string message); @@ -40,95 +118,64 @@ protected class GSMActivator : Object sim = null; } - public void begin() + public async void start() { if (device == null) { - device = zavai.registry.sbus.get_object( + device = (FSO_GSM_Device)zavai.registry.sbus.get_object( "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device", "org.freesmartphone.GSM.Device"); - network = zavai.registry.sbus.get_object( + network = (FSO_GSM_Network)zavai.registry.sbus.get_object( "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device", "org.freesmartphone.GSM.Network"); - sim = zavai.registry.sbus.get_object( + sim = (FSO_GSM_SIM)zavai.registry.sbus.get_object( "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device", "org.freesmartphone.GSM.SIM"); } status_changed("Turning on antenna"); - device.SetAntennaPower(true, on_antenna_power); - } - - protected void on_antenna_power(Error e) - { - if (e != null) + while (true) { - zavai.log.warning("on_antenna_power: " + e.message); - if (e.message.str("current status is 'enabling'") != null - || e.message.str("current status is 'unknown'") != null) - { - status_changed("Waiting for ogsmd to settle"); - zavai.log.info("trying again after 2 seconds"); - Timeout.add(2 * 1000, () => { - device.SetAntennaPower(true, on_antenna_power); - return false; - }); - } else { - status_changed("Checking if PIN is required"); - sim.GetAuthStatus(on_auth_status); + try { + yield device.set_antenna_power(true); + break; + } catch (Error e) { + zavai.log.warning("SetAntennaPower: " + e.message); + if (e.message.str("current status is 'enabling'") != null + || e.message.str("current status is 'unknown'") != null) + { + status_changed("Waiting for ogsmd to settle"); + zavai.log.info("trying again after 2 seconds"); + Timeout.add(2 * 1000, () => { + start.callback(); + return false; + }); + yield; + } else { + status_changed("Checking if PIN is required"); + string status = yield sim.get_auth_status(); + zavai.log.info("on_auth_status: " + status); + if (status == "READY") + status_changed("PIN ok"); + else if (status == "SIM PIN") + { + status_changed("Sending PIN"); + yield sim.send_auth_code(zavai.config.sim_pin); + status_changed("PIN OK"); + } + else + zavai.log.debug("Unknown status: " + status); + } } - return; } zavai.log.warning("on_antenna_power ok"); status_changed("Registering with network"); - network.Register(on_network_register); - } - - protected void on_network_register(Error e) - { - if (e != null) - { - zavai.log.warning("on_network_register: " + e.message); - return; - } + yield network.register_(); status_changed("Registered with network"); } - - protected void on_auth_status(string status, Error e) - { - if (e != null) - { - zavai.log.warning("on_auth_status: " + e.message); - return; - } - zavai.log.info("on_auth_status: " + status); - if (status == "READY") - { - status_changed("PIN ok"); - device.SetAntennaPower(true, on_antenna_power); - } - else if (status == "SIM PIN") - { - status_changed("Sending PIN"); - sim.SendAuthCode(zavai.config.sim_pin, on_auth_code); - } - else - zavai.log.debug("Unknown status: " + status); - } - - protected void on_auth_code(Error e) - { - if (e != null) - { - zavai.log.warning("on_auth_code: " + e.message); - return; - } - status_changed("Registering with network"); - network.Register(on_network_register); - } } public class GSM: zavai.ScriptMonitorService @@ -178,7 +225,7 @@ public class GSM: zavai.ScriptMonitorService if (name == "org.freesmartphone.ogsmd" && newOwner != "") { status_changed("ogpsd came online"); - activator.begin(); + activator.start.begin(); } } -- 2.39.5