enable silent rules, if available
[fso-monitord.git] / src / phone.vala
blob12150f38ec76e8d7fd1478ca44d01192109a8ff7
1 /*
2 * File Name: phone.vala
3 * Creation Date: 06-02-2009
4 * Last Modified: 06-02-2009
6 * Authored by Frederik 'playya' Sdun <Frederik.Sdun@googlemail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 using GLib;
24 using DBus;
26 namespace FSO
28 public class Phone: System
30 public static string BUS_NAME = "org.freesmartphone.ophoned";
31 public static string IFACE = "org.freesmartphone.Phone";
32 public static string OBJ_PATH = "/org/freesmartphone/Phone";
33 private dynamic DBus.Object object;
34 public Phone( Logger l, DBus.Connection c )
36 base( l,c );
37 this.busname = BUS_NAME;
39 public override void run() throws GLib.Error
41 base.run();
42 this.object = this.con.get_object( BUS_NAME, OBJ_PATH, IFACE );
43 this.object.Incoming += this.incoming_call;
45 private void incoming_call( dynamic DBus.Object obj, DBus.ObjectPath call )
47 this.logger.log( "Phone" ).signal( "Incoming" ).name( "call" ).value( call ).end();
48 Call tmpobj = new Call( this.logger, this.con, call );
49 this.subsystems.prepend(tmpobj);
50 try
52 tmpobj.run();
54 catch (GLib.Error e)
56 debug( "running Call failed: %s", e.message );
59 public class Call: Subsystem
61 public static string IFACE = "org.freesmartphone.Phone.Call";
62 private string cur_status = null;
64 public Call( Logger l, DBus.Connection c, string name )
66 debug( "New call on: %s", name );
67 base( l,c,name );
68 this._IFACE = IFACE;
69 this._BUS_NAME = BUS_NAME;
70 this._OBJ_PATH = name;
71 this.run();
73 public override void run() throws GLib.Error
75 base.run();
76 this.object.Incoming += this.incoming_call;
77 this.object.Release += this.release_call;
78 this.object.Outgoing += this.outgoing_call;
79 this.object.Activated += this.activated_call;
80 try
82 this.object.GetStatus( this.get_status );
84 catch ( GLib.Error e )
86 debug( "Calling GetStatus:%s",e.message );
89 private void incoming_call( dynamic DBus.Object obj )
91 this.logger.log( "Phone.Call" ).log( "Incoming" ).end();
93 private void release_call( dynamic DBus.Object obj )
95 this.logger.log( "Phone.Call" ).log( "Release" ).end();
96 try
98 this.object.Remove();
100 catch ( GLib.Error e )
102 debug( "Removing Call Object: %s", e.message );
104 debug( "destroying Call Object %X",( uint )this );
105 this = null;
107 private void outgoing_call( dynamic DBus.Object obj )
109 this.logger.log( "Phone.Call" ).log( "Outgoing" ).end();
111 private void activated_call( dynamic DBus.Object obj )
113 this.logger.log( "Phone.Call" ).log( "Activated" ).end();
115 private void get_status( dynamic DBus.Object obj, string status, GLib.Error error )
117 if( error != null )
119 debug( "Can't get Callstatus: %s", error.message );
120 this.cur_status = "UNKNOWN";
122 else
124 this.cur_status = status;