Refer to LGPL by it's (not so) new name.
[profile/ivi/rygel.git] / src / rygel / rygel-main.vala
1 /*
2  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
3  * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
4  *
5  * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21
22 using GUPnP;
23 using GConf;
24 using CStuff;
25 using Gee;
26
27 public class Rygel.Main : Object {
28     private PluginLoader plugin_loader;
29     private MediaServerFactory ms_factory;
30     private ArrayList<MediaServer> media_servers;
31
32     private MainLoop main_loop;
33
34     private int exit_code;
35
36     public Main () throws GLib.Error {
37         this.media_servers = new ArrayList<MediaServer> ();
38         this.plugin_loader = new PluginLoader ();
39         this.ms_factory = new MediaServerFactory ();
40         this.main_loop = new GLib.MainLoop (null, false);
41
42         this.exit_code = 0;
43
44         this.plugin_loader.plugin_available += this.on_plugin_loaded;
45
46         Utils.on_application_exit (this.application_exit_cb);
47     }
48
49     public int run () {
50         this.plugin_loader.load_plugins ();
51
52         this.main_loop.run ();
53
54         return this.exit_code;
55     }
56
57     public void exit (int exit_code) {
58         this.exit_code = exit_code;
59         this.main_loop.quit ();
60     }
61
62     private void application_exit_cb () {
63         this.exit (0);
64     }
65
66     private void on_plugin_loaded (PluginLoader plugin_loader,
67                                    Plugin       plugin) {
68         try {
69             var server = this.ms_factory.create_media_server (plugin);
70
71             /* Make our device available */
72             server.available = true;
73
74             media_servers.add (server);
75         } catch (GLib.Error error) {
76             warning ("Failed to create MediaServer for %s. Reason: %s\n",
77                      plugin.name,
78                      error.message);
79         }
80     }
81
82     public static int main (string[] args) {
83         Main main;
84
85         // initialize gstreamer
86         Gst.init (ref args);
87
88         try {
89             main = new Main ();
90         } catch (GLib.Error err) {
91             error ("%s", err.message);
92
93             return -1;
94         }
95
96         int exit_code = main.run ();
97
98         return exit_code;
99     }
100 }
101