5edc6cbb0b75ec44f3831c85bc8d6b43429dda3b
[profile/ivi/audiomanager.git] / AudioManagerDaemon / src / main.cpp
1 /**
2 * Copyright (C) 2011, BMW AG
3 *
4 * GeniviAudioMananger AudioManagerDaemon
5 *
6 * \file main.cpp
7 *
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (christian.ei.mueller@bmw.de)
10 *
11 * \section License
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2011, BMW AG Christian Mueller  Christian.ei.mueller@bmw.de
14 *
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
22 *
23 */
24
25 /**
26  * Please make sure to have read the documentation on genivi.org!
27  */
28
29 //todo: add debug commandline option to allow to use other than memory database
30 //todo: make real daemon out of it- systemd conform
31 //todo: versioning of PluginInterfaces on linux level (.symver stuff)
32 //todo: all communication like all plugins loaded etc...
33 //todo: seperate documentation of test from normal project
34 //todo: check the startup sequence. Dbus shall be activated last...
35 //todo: there is a bug in the visible flags of sinks and sources. fix it.
36 //todo: check namespace handling. no use.. in headers
37 //todo: make sure that iterators have a fixed end to prevent crashed while adding vectors while iterating on critical vectors
38 //todo: make sure all configurations are tested
39
40 #include <config.h>
41 #include <SocketHandler.h>
42 #ifdef WITH_DBUS_WRAPPER
43 #include <dbus/DBusWrapper.h>
44 #endif
45 #include "DatabaseHandler.h"
46 #include "DatabaseObserver.h"
47 #include "RoutingReceiver.h"
48 #include "CommandReceiver.h"
49 #include "ControlReceiver.h"
50 #include "ControlSender.h"
51 #include "CommandSender.h"
52 #include "RoutingSender.h"
53
54 #include <dlt/dlt.h>
55
56 DLT_DECLARE_CONTEXT(DLT_CONTEXT)
57
58 using namespace am;
59
60 int main(int argc, char *argv[])
61 {
62         DLT_REGISTER_APP("AudioManagerDeamon","AudioManagerDeamon");
63         DLT_REGISTER_CONTEXT(DLT_CONTEXT,"Main","Main Context");
64         DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("The AudioManager is started "));
65
66         std::vector<std::string> listCommandPluginDirs;
67         listCommandPluginDirs.push_back(std::string(DEFAULT_PLUGIN_COMMAND_DIR)); //change this to be modified by the commandline!
68
69         std::vector<std::string> listRoutingPluginDirs;
70         listRoutingPluginDirs.push_back(std::string(DEFAULT_PLUGIN_ROUTING_DIR)); //change this to be modified by the commandline!
71
72         //Instantiate all classes. Keep in same order !
73 #ifdef WITH_SOCKETHANDLER_LOOP
74         SocketHandler iSocketHandler;
75 #endif
76
77 #ifdef WITH_DBUS_WRAPPER
78 #ifdef WITH_SOCKETHANDLER_LOOP
79         DBusWrapper iDBusWrapper(&iSocketHandler);
80 #else /*WITH_SOCKETHANDLER_LOOP*/
81         DBusWrapper iDBusWrapper;
82 #endif /*WITH_SOCKETHANDLER_LOOP*/
83 #endif /*WITH_DBUS_WRAPPER */
84
85         DatabaseHandler iDatabaseHandler(std::string(":memory:"));
86         RoutingSender iRoutingSender(listRoutingPluginDirs);
87         CommandSender iCommandSender(listCommandPluginDirs);
88         ControlSender iControlSender(std::string(CONTROLLER_PLUGIN));
89         DatabaseObserver iObserver(&iCommandSender, &iRoutingSender);
90
91 #ifdef WITH_DBUS_WRAPPER
92 #ifdef WITH_SOCKETHANDLER_LOOP
93         CommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iSocketHandler,&iDBusWrapper);
94         RoutingReceiver iRoutingReceiver(&iDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler,&iDBusWrapper);
95         ControlReceiver iControlReceiver(&iDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler);
96 #else /*WITH_SOCKETHANDLER_LOOP */
97         CommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iDBusWrapper);
98         RoutingReceiver iRoutingReceiver(&iDatabaseHandler,&iRoutingSender,&iControlSender,&iDBusWrapper);
99         ControlReceiver iControlReceiver(&iDatabaseHandler,&iRoutingSender,&iCommandSender);
100 #endif /*WITH_SOCKETHANDLER_LOOP*/
101 #else /*WITH_DBUS_WRAPPER*/
102         CommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iSocketHandler);
103         RoutingReceiver iRoutingReceiver(&iDatabaseHandler,&iRoutingSender,&iControlSender,&iSocketHandler);
104         ControlReceiver iControlReceiver(&iDatabaseHandler,&iRoutingSender,&iCommandSender,&iSocketHandler);
105 #endif /*WITH_DBUS_WRAPPER*/
106
107         //since the plugins have been loaded by the *Senders before, we can tell the Controller this:
108         iControlSender.hookAllPluginsLoaded();
109
110         //the controller should startup the interfaces - this is just for testing
111         iCommandSender.startupInterface(&iCommandReceiver);
112         iRoutingSender.startupRoutingInterface(&iRoutingReceiver);
113
114 #ifdef WITH_SOCKETHANDLER_LOOP
115         iSocketHandler.start_listenting();
116 #endif /*WITH_SOCKETHANDLER_LOOP*/
117
118 #ifdef WITH_DBUS_WRAPPER
119 #ifdef WITH_SIMPLEDBUS_LOOP
120         iDBusWrapper.dbusMainLoop();
121 #endif/*WITH_SIMPLEDBUS_LOOP*/
122 #endif /*WITH_DBUS_WRAPPER*/
123
124 }
125
126
127
128