update on dbus
[profile/ivi/audiomanager.git] / AudioManagerDaemon / CommandHandler.cpp
1 /*
2  * CommandHandler.cpp
3  *
4  *  Created on: Jul 27, 2011
5  *      Author: christian
6  */
7
8 #include "CommandHandler.h"
9 #include "audioManagerIncludes.h"
10
11 const char* commandPluginDirectories[] = { "/home/christian/workspace/gitserver/build/plugins/command"};
12 uint commandPluginDirectoriesCount = sizeof(commandPluginDirectories) / sizeof(commandPluginDirectories[0]);
13
14 CommandHandler::CommandHandler(AudioManagerCore* core) :m_core(core) {
15         // TODO Auto-generated constructor stub
16
17 }
18
19 CommandHandler::~CommandHandler() {
20         // TODO Auto-generated destructor stub
21 }
22
23 void CommandHandler::registerReceiver(CommandReceiveInterface *iface) {
24         m_receiver=iface;
25 }
26
27 void CommandHandler::loadPlugins(){
28         std::list<std::string> sharedLibraryNameList;
29
30         for (uint dirIndex = 0; dirIndex < commandPluginDirectoriesCount; ++dirIndex) {
31         const char* directoryName = commandPluginDirectories[dirIndex];
32         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Searching for Command in"),DLT_STRING(directoryName));
33         std::list<std::string> newList=m_core->getSharedLibrariesFromDirectory(directoryName);
34         sharedLibraryNameList.insert(sharedLibraryNameList.end(),newList.begin(),newList.end());
35     }
36
37
38     // iterate all communicator plugins and start them
39     std::list<std::string>::iterator iter = sharedLibraryNameList.begin();
40     std::list<std::string>::iterator iterEnd = sharedLibraryNameList.end();
41
42     for (; iter != iterEnd; ++iter)
43     {
44         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Loading Command plugin"),DLT_STRING(iter->c_str()));
45
46         CommandSendInterface* (*createFunc)();
47         createFunc = getCreateFunction<CommandSendInterface*()>(*iter);
48
49         if (!createFunc) {
50             DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Entry point of Communicator not found"));
51             continue;
52         }
53
54         CommandSendInterface* CommandPlugin = createFunc();
55
56
57         if (!CommandPlugin) {
58                 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("RoutingPlugin initialization failed. Entry Function not callable"));
59             continue;
60         }
61
62
63         CommandPlugin->startupInterface(m_receiver,m_core->returnDbusHandler());
64                 DLT_LOG( AudioManager, DLT_LOG_INFO, DLT_STRING("Registered Routing Plugin"));
65         m_interfaceList.push_back(CommandPlugin);
66     }
67 }
68
69
70