|
Line 0
Link Here
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2021 Robin Westermann <waked@seath.de> |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 |
| 7 |
* of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
namespace Clocks { |
| 20 |
|
| 21 |
[SingleInstance] |
| 22 |
public class Waked : GLib.Object { |
| 23 |
[DBus (name = "de.seath.Waked")] |
| 24 |
internal interface WakedProxy : GLib.Object { |
| 25 |
public async abstract void add (string id, uint64 time) throws GLib.Error; |
| 26 |
public async abstract void update (string id, uint64 time) throws GLib.Error; |
| 27 |
public async abstract void remove (string id) throws GLib.Error; |
| 28 |
} |
| 29 |
|
| 30 |
static Waked instance; |
| 31 |
private WakedProxy _waked_proxy; |
| 32 |
|
| 33 |
public static Waked get_default () { |
| 34 |
if (instance == null) { |
| 35 |
instance = new Waked (); |
| 36 |
} |
| 37 |
|
| 38 |
return instance; |
| 39 |
} |
| 40 |
|
| 41 |
async WakedProxy get_proxy () throws GLib.IOError { |
| 42 |
if (_waked_proxy == null) { |
| 43 |
_waked_proxy = |
| 44 |
yield Bus.get_proxy<WakedProxy> ( |
| 45 |
BusType.SYSTEM, |
| 46 |
"de.seath.Waked", |
| 47 |
"/de/seath/Waked/Alarm"); |
| 48 |
} |
| 49 |
|
| 50 |
return _waked_proxy; |
| 51 |
} |
| 52 |
|
| 53 |
public async void update_timer (string id, GLib.DateTime time) { |
| 54 |
try { |
| 55 |
var waked_proxy = yield get_proxy (); |
| 56 |
|
| 57 |
yield waked_proxy.update (id, time.to_unix ()); |
| 58 |
|
| 59 |
} catch (GLib.Error e) { |
| 60 |
stderr.printf ("%s\n", e.message); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
public async void remove_timer (string id) { |
| 65 |
try { |
| 66 |
var waked_proxy = yield get_proxy (); |
| 67 |
|
| 68 |
yield waked_proxy.remove (id); |
| 69 |
|
| 70 |
} catch (GLib.Error e) { |
| 71 |
stderr.printf ("%s\n", e.message); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
} // namespace Clocks |