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
26 public interface Resource : Object {
28 * Shut down this resource.
30 * Normally one does nothing here, but it is important to give resources a
31 * chance to do cleanup when the program quits.
33 * This can be used for tasks like closing the tags on a GPX track,
34 * releasing a FSO resource, restoring mixer settings and so on.
36 public abstract void shutdown();
39 public abstract class Service : Object, Resource {
40 public string name { get; construct; }
44 get { return _started; }
45 set { _started = value; }
49 public signal void toggled(bool new_state);
51 protected HashMap<string, int> requests;
54 requests = new HashMap<string, int>(str_hash, str_equal);
57 public void shutdown()
62 /// Activate the service
63 protected virtual void start()
67 zavai.log.info("Service " + name + " started\n");
73 /// Deactivate the service
74 protected virtual void stop()
78 zavai.log.info("Service " + name + " stopped\n");
85 Request a resource using the given ID.
87 * If it is the first time the resource is requested, start it and
88 * return true. Else, take note of the request and return false.
90 * If a resource is requested multiple times with the same ID, it will
91 * need to be released multiple times with that ID.
93 public bool request(string id)
95 bool res = (requests.size == 0);
97 requests[id] = requests[id] + 1;
105 * Release a resource using the given ID.
107 * If after the call nothing is requesting the resource, stop it and
108 * return true. Else, take note of the release and return false.
110 * If a resource is requested multiple times with the same ID, it will
111 * need to be released multiple times with that ID.
113 public bool release(string id)
117 if (requests[id] > 1)
118 requests[id] = requests[id] - 1;
124 if (requests.size > 0)