2 * app - zavai main window
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 public interface Resource : Object {
27 * Shut down this resource.
29 * Normally one does nothing here, but it is important to give resources a
30 * chance to do cleanup when the program quits.
32 * This can be used for tasks like closing the tags on a GPX track,
33 * releasing a FSO resource, restoring mixer settings and so on.
35 public abstract void shutdown();
38 public abstract class Service : Object, Resource {
39 public string name { get; construct; }
43 get { return _started; }
44 set { _started = value; }
48 public signal void toggled(bool new_state);
50 protected Gee.HashMap<string, int> requests;
54 requests = new Gee.HashMap<string, int>(str_hash, str_equal);
55 zavai.registry.register(this);
58 public void shutdown()
63 /// Activate the service
64 protected virtual void start()
68 zavai.log.info("Service " + name + " started\n");
74 /// Deactivate the service
75 protected virtual void stop()
79 zavai.log.info("Service " + name + " stopped\n");
86 Request a resource using the given ID.
88 * If it is the first time the resource is requested, start it and
89 * return true. Else, take note of the request and return false.
91 * If a resource is requested multiple times with the same ID, it will
92 * need to be released multiple times with that ID.
94 public bool request(string id)
96 bool res = (requests.size == 0);
98 requests[id] = requests[id] + 1;
106 * Release a resource using the given ID.
108 * If after the call nothing is requesting the resource, stop it and
109 * return true. Else, take note of the release and return false.
111 * If a resource is requested multiple times with the same ID, it will
112 * need to be released multiple times with that ID.
114 public bool release(string id)
118 if (requests[id] > 1)
119 requests[id] = requests[id] - 1;
125 if (requests.size > 0)