summaryrefslogtreecommitdiff
path: root/AudioManagerDaemon/src
diff options
context:
space:
mode:
authorchristian mueller <christian.ei.mueller@bmw.de>2012-02-09 12:54:59 +0100
committerchristian mueller <christian.ei.mueller@bmw.de>2012-02-09 12:54:59 +0100
commitd4627908f2f405b7b184bd47b2216adf5d4df486 (patch)
treed24ed57e508f35e66ccd58198451bbec5bd5f338 /AudioManagerDaemon/src
parent84b90467e8e9dcaafaf75738f4bf9840365424b9 (diff)
parent40ade5d852e6d4c781f33a20d8e4340d59ec07a8 (diff)
downloadaudiomanager-d4627908f2f405b7b184bd47b2216adf5d4df486.tar.gz
Merge branch 'telnetserver'
Diffstat (limited to 'AudioManagerDaemon/src')
-rw-r--r--AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp1194
-rw-r--r--AudioManagerDaemon/src/CommandSender.cpp21
-rw-r--r--AudioManagerDaemon/src/TelnetServer.cpp350
-rw-r--r--AudioManagerDaemon/src/main.cpp2
4 files changed, 1387 insertions, 180 deletions
diff --git a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp
new file mode 100644
index 0000000..f901fa8
--- /dev/null
+++ b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp
@@ -0,0 +1,1194 @@
+/**
+* Copyright (C) 2012, BMW AG
+*
+* GeniviAudioMananger AudioManagerDaemon
+*
+* \file CAmTelnetMenuHelper.cpp
+*
+* \date 24-Jan-2012
+* \author Frank Herchet (frank.fh.herchet@bmw.de)
+*
+* \section License
+* GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
+* Copyright (C) 2012, BMW AG Frank Herchet frank.fh.herchet@bmw.de
+*
+* 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.
+* 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.
+* 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>.
+* 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.
+* 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.
+* 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.
+* 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.
+*
+*/
+
+#include "CAmTelnetMenuHelper.h"
+#include <dlt/dlt.h>
+#include <cassert>
+
+#define DEBUG_ON false
+
+using namespace am;
+
+DLT_IMPORT_CONTEXT(AudioManager)
+
+CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL;
+
+/****************************************************************************/
+CAmTelnetMenuHelper::CAmTelnetMenuHelper(SocketHandler *iSocketHandler,
+ CommandSender *iCommandSender,
+ CommandReceiver *iCommandReceiver,
+ RoutingSender *iRoutingSender,
+ RoutingReceiver *iRoutingReceiver,
+ ControlSender *iControlSender,
+ ControlReceiver *iControlReceiver,
+ DatabaseHandler *iDatabasehandler,
+ Router *iRouter)
+/****************************************************************************/
+: mTelenetServer(NULL)
+, mSocketHandler(iSocketHandler)
+, mCommandSender(iCommandSender)
+, mCommandReceiver(iCommandReceiver)
+, mRoutingSender(iRoutingSender)
+, mRoutingReceiver(iRoutingReceiver)
+, mControlSender(iControlSender)
+, mControlReceiver(iControlReceiver)
+, mDatabasehandler(iDatabasehandler)
+, mRouter(iRouter)
+{
+ instance = this;
+ createCommandMaps();
+}
+
+/****************************************************************************/
+CAmTelnetMenuHelper::~CAmTelnetMenuHelper()
+/****************************************************************************/
+{
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::createCommandMaps()
+/****************************************************************************/
+{
+ // ROOT commands
+
+ mRootCommands.clear();
+
+ mRootCommands.insert(std::make_pair("help",sCommandPrototypeInfo("show all possible commands",&CAmTelnetMenuHelper::helpCommand)));
+ mRootCommands.insert(std::make_pair("list",sCommandPrototypeInfo("Go into 'list'-submenu",&CAmTelnetMenuHelper::rootListCommand)));
+ mRootCommands.insert(std::make_pair("info",sCommandPrototypeInfo("Go into 'info'-submenu",&CAmTelnetMenuHelper::rootInfoCommand)));
+ mRootCommands.insert(std::make_pair("set",sCommandPrototypeInfo("Go into 'set'-submenu",&CAmTelnetMenuHelper::rootSetCommand)));
+ mRootCommands.insert(std::make_pair("get",sCommandPrototypeInfo("Go into 'get'-submenu",&CAmTelnetMenuHelper::rootGetCommand)));
+ mRootCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("quit telnet session",&CAmTelnetMenuHelper::exitCommand)));
+
+ // List commands
+ mListCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
+ mListCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("list all connections",&CAmTelnetMenuHelper::listConnectionsCommand)));
+ mListCommands.insert(std::make_pair("sources",sCommandPrototypeInfo("list all available sources",&CAmTelnetMenuHelper::listSourcesCommand)));
+ mListCommands.insert(std::make_pair("sinks",sCommandPrototypeInfo("list all available sinks",&CAmTelnetMenuHelper::listSinksCommands)));
+ mListCommands.insert(std::make_pair("crfaders",sCommandPrototypeInfo("list all crossfaders",&CAmTelnetMenuHelper::listCrossfaders)));
+ mListCommands.insert(std::make_pair("domains",sCommandPrototypeInfo("list all domains",&CAmTelnetMenuHelper::listDomainsCommand)));
+ mListCommands.insert(std::make_pair("gws",sCommandPrototypeInfo("list all gateways",&CAmTelnetMenuHelper::listGatewaysCommand)));
+ mListCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
+ mListCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
+
+ // Set commands
+ mSetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
+ mSetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
+ mSetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
+ mSetCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink",&CAmTelnetMenuHelper::setConnection)));
+ mSetCommands.insert(std::make_pair("routing",sCommandPrototypeInfo("use 'routing sourceId sinkId' to get all\n\t possible routes between a sourceID and a sinkID",&CAmTelnetMenuHelper::setRoutingCommand)));
+
+ // Get commands
+ mGetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
+ mGetCommands.insert(std::make_pair("routing",sCommandPrototypeInfo("show current routing",&CAmTelnetMenuHelper::getRoutingCommand)));
+ mGetCommands.insert(std::make_pair("sendv",sCommandPrototypeInfo("show senderversion",&CAmTelnetMenuHelper::getSenderversionCommand)));
+ mGetCommands.insert(std::make_pair("recv",sCommandPrototypeInfo("show receiverversion ",&CAmTelnetMenuHelper::getReceiverversionCommand)));
+ mGetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
+ mGetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
+
+ // Info comands
+ mInfoCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
+ mInfoCommands.insert(std::make_pair("sysprop",sCommandPrototypeInfo("show all systemproperties",&CAmTelnetMenuHelper::infoSystempropertiesCommand)));
+ mInfoCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
+ mInfoCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setTelnetServer(TelnetServer* iTelnetServer)
+/****************************************************************************/
+{
+ mTelenetServer = iTelnetServer;
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor)
+/****************************************************************************/
+{
+ EMainState state = eRootState;
+ std::map<int,EMainState>::iterator it;
+ std::stringstream welcome;
+
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ // socket connection already exists, delete entry and go back to root state
+ mCurrentMainStateMap.erase(it);
+ }
+
+ it = mCurrentMainStateMap.begin();
+
+ // insert new socket connection
+ mCurrentMainStateMap.insert(it,std::make_pair<int,EMainState>(filedescriptor,state));
+
+ // Send welcome message
+ welcome << "Welcome to GENIVI AudioManager " << DAEMONVERSION << "\n>";
+ send(filedescriptor,welcome.str().c_str(),welcome.str().size(),0);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ mCurrentMainStateMap.erase(it);
+ }
+ else
+ {
+ // connection not found
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::enterCmdQueue(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ std::string cmd;
+ tCommandMap::iterator cmditer;
+
+ // find current filedescriptor to get the current state of the telnet session
+ it = mCurrentMainStateMap.find(filedescriptor);
+ while(!CmdQueue.empty())
+ {
+ cmd = CmdQueue.front();
+
+ // Now remove the first command, it's stored in 'cmd'
+ CmdQueue.pop();
+ // telnet session found. depending on the current state, different commands are available
+ switch(it->second)
+ {
+ case eRootState:
+ cmditer = mRootCommands.find(cmd);
+ if(mRootCommands.end() != cmditer)
+ cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
+ else
+ sendError(filedescriptor,"Command not found\n");
+ break;
+ case eListState:
+ cmditer = mListCommands.find(cmd);
+ if(mListCommands.end() != cmditer)
+ cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
+ else
+ sendError(filedescriptor,"Command not found\n");
+ break;
+ case eInfoState:
+ cmditer = mInfoCommands.find(cmd);
+ if(mInfoCommands.end() != cmditer)
+ cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
+ else
+ sendError(filedescriptor,"Command not found\n");
+ break;
+ case eGetState:
+ cmditer = mGetCommands.find(cmd);
+ if(mGetCommands.end() != cmditer)
+ cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
+ else
+ sendError(filedescriptor,"Command not found\n");
+ break;
+ case eSetState:
+ cmditer = mSetCommands.find(cmd);
+ if(mSetCommands.end() != cmditer)
+ cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
+ else
+ sendError(filedescriptor,"Command not found\n");
+ break;
+ default:
+ break;
+ }
+ }
+
+ sendCurrentCmdPrompt(filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::sendError(int & filedescriptor, std::string error_string)
+/****************************************************************************/
+{
+ send(filedescriptor,error_string.c_str(),error_string.size(),0);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::sendTelnetLine(int & filedescriptor, std::stringstream &line)
+/****************************************************************************/
+{
+ send(filedescriptor,line.str().c_str(),line.str().size(),0);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ std::stringstream outputstream;
+ outputstream << std::endl;
+
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ switch(it->second)
+ {
+ case eRootState:
+ outputstream << "\\>";
+ break;
+ case eListState:
+ outputstream << "\\List>";
+ break;
+ case eGetState:
+ outputstream << "\\Get>";
+ break;
+ case eSetState:
+ outputstream << "\\Set>";
+ break;
+ case eInfoState:
+ outputstream << "\\Info>";
+ break;
+ default:
+ break;
+ }
+
+ send(filedescriptor,outputstream.str().c_str(),outputstream.str().size(),0);
+
+ }
+ else
+ {
+ // connection not found
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->exitCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ if(DEBUG_ON)std::cout << "old state: " << it->second;
+ switch(it->second)
+ {
+ case eRootState:
+ it->second = eRootState;
+ break;
+ case eListState:
+ it->second = eRootState;;
+ break;
+ case eGetState:
+ it->second = eRootState;;
+ break;
+ case eSetState:
+ it->second = eRootState;;
+ break;
+ case eInfoState:
+ it->second = eRootState;;
+ break;
+ default:
+ it->second = eRootState;
+ break;
+ }
+ if(DEBUG_ON)std::cout << "new state: " << it->second << std::endl;
+ //enterCmdQueue(CmdQueue,filedescriptor);
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->oneStepBackCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ std::stringstream line;
+ std::stringstream output;
+
+ // Sending a last message to the client
+ output << "Your wish is my command ... bye!" << std::endl;
+ sendTelnetLine(filedescriptor,output);
+
+
+ tCommandMap::iterator iter;
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ if(DEBUG_ON)std::cout << "removing client connection " << filedescriptor << std::endl;
+
+ if(NULL != mTelenetServer)
+ {
+ mTelenetServer->disconnectClient(filedescriptor);
+ mCurrentMainStateMap.erase(it);
+ }
+ else
+ {
+ // ASSERT mTelenetServer == NULL
+ if(DEBUG_ON)std::cout << "mTelenetServer";
+ }
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->helpCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ std::stringstream line;
+ tCommandMap::iterator cmdIter;
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ line << "###################################################" << std::endl;
+ line << "###### The following commands are supported: ######"<< std::endl;
+ line << "###################################################" << std::endl << std::endl;
+ switch(it->second)
+ {
+ case eRootState:
+
+ cmdIter = mRootCommands.begin();
+ while(cmdIter != mRootCommands.end())
+ {
+ line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
+ cmdIter++;
+ }
+ break;
+ case eListState:
+ cmdIter = mListCommands.begin();
+ while(cmdIter != mListCommands.end())
+ {
+ line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
+ cmdIter++;
+ }
+ break;
+ case eGetState:
+ cmdIter = mGetCommands.begin();
+ while(cmdIter != mGetCommands.end())
+ {
+ line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
+ cmdIter++;
+ }
+ break;
+ case eSetState:
+ cmdIter = mSetCommands.begin();
+ while(cmdIter != mSetCommands.end())
+ {
+ line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
+ cmdIter++;
+ }
+ break;
+ case eInfoState:
+ cmdIter = mInfoCommands.begin();
+ while(cmdIter != mInfoCommands.end())
+ {
+ line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
+ cmdIter++;
+ }
+ break;
+ default:
+ break;
+ }
+ sendTelnetLine(filedescriptor,line);
+ //enterCmdQueue(CmdQueue,filedescriptor);
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->rootGetCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ it->second = eGetState;
+ //enterCmdQueue(CmdQueue,filedescriptor);
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->rootSetCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ it->second = eSetState;
+ //enterCmdQueue(CmdQueue,filedescriptor);
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->rootListCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ it->second = eListState;
+ //enterCmdQueue(CmdQueue,filedescriptor);
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->rootInfoCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::map<int,EMainState>::iterator it;
+ it = mCurrentMainStateMap.find(filedescriptor);
+ if( it != mCurrentMainStateMap.end())
+ {
+ it->second = eInfoState;
+ //enterCmdQueue(CmdQueue,filedescriptor);
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->listConnectionsCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_Connection_s> listConnections;
+ std::vector<am_Connection_s>::iterator it;
+ std::stringstream line;
+
+ mDatabasehandler->getListConnections(listConnections);
+
+ line << "Current connections: " << listConnections.size();
+
+ sendTelnetLine(filedescriptor,line);
+
+ while(it != listConnections.end())
+ {
+ line.clear();
+ line << "\tID: " << it->connectionID
+ << "\tSrcID: " << it->sourceID
+ << "\tSinkID: " << it->sinkID
+ << "\tFormat: " << it->connectionFormat
+ << "\tdelay: " << it->delay;
+
+ sendTelnetLine(filedescriptor,line);
+ it++;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->listSourcesCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_Source_s> listSources;
+ std::vector<am_Source_s>::iterator it;
+ std::stringstream line;
+
+ mDatabasehandler->getListSources(listSources);
+
+ line << "Current sources: " << listSources.size();
+ sendTelnetLine(filedescriptor,line);
+
+ while(it != listSources.end())
+ {
+ line.clear();
+ line << "\tID: " << it->sourceID
+ << "\tDomainID: " << it->domainID
+ << "\tName: " << it->name
+ << "\tState: " << it->sourceState
+ << "\tVolume: " << it->volume;
+
+ sendTelnetLine(filedescriptor,line);
+ it++;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->listSinksCommandsExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_Sink_s> listSinks;
+ std::vector<am_Sink_s>::iterator it;
+ std::stringstream line;
+
+ mDatabasehandler->getListSinks(listSinks);
+
+ line << "Current sinks: " << listSinks.size();
+ sendTelnetLine(filedescriptor,line);
+
+ while(it != listSinks.end())
+ {
+ line.clear();
+ line << "\tID: " << it->sinkID
+ << "\tDomainID: " << it->domainID
+ << "\tName: " << it->name
+ << "\tAvailable: " << it->available.availability
+ << "\tVolume: " << it->volume;
+
+ sendTelnetLine(filedescriptor,line);
+ it++;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->listCrossfadersExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_Crossfader_s> listCrossfaders;
+ std::vector<am_Crossfader_s>::iterator it;
+ std::stringstream line;
+
+ mDatabasehandler->getListCrossfaders(listCrossfaders);
+
+ line << "Current crossfaders: " << listCrossfaders.size();
+ sendTelnetLine(filedescriptor,line);
+
+ while(it != listCrossfaders.end())
+ {
+ line.clear();
+ line << "\tID: " << it->crossfaderID
+ << "\tName: " << it->name
+ << "\tSourceID: " << it->sourceID;
+
+ sendTelnetLine(filedescriptor,line);
+ it++;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->listDomainsCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_Domain_s> listDomains;
+ std::vector<am_Domain_s>::iterator it;
+ std::stringstream line;
+
+ mDatabasehandler->getListDomains(listDomains);
+
+ line << "Current domains: " << listDomains.size();
+ sendTelnetLine(filedescriptor,line);
+
+ while(it != listDomains.end())
+ {
+ line.clear();
+ line << "\tID: " << it->domainID
+ << "\tName: " << it->name
+ << "\tBusname: " << it->busname
+ << "\tNodename: " << it->nodename
+ << "\tState: " << it->state;
+
+ sendTelnetLine(filedescriptor,line);
+ it++;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->listGatewaysCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_Gateway_s> listGateways;
+ std::vector<am_Gateway_s>::iterator it;
+ std::stringstream line;
+
+ mDatabasehandler->getListGateways(listGateways);
+
+ line << "Current gateways: " << listGateways.size();
+ sendTelnetLine(filedescriptor,line);
+
+ while(it != listGateways.end())
+ {
+ line.clear();
+ line << "\tID: " << it->gatewayID
+ << "\tName: " << it->name
+ << "\tSourceID: " << it->sourceID
+ << "\tSinkID: " << it->sinkID;
+
+ sendTelnetLine(filedescriptor,line);
+ it++;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->getRoutingCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_Gateway_s> listGateways;
+ std::vector<am_Gateway_s>::iterator it;
+ std::stringstream line;
+
+ /*
+ mRouter->getRoute()
+
+ line << "Current gateways: " << listGateways.size();
+ sendTelnetLine(filedescriptor,line);
+
+ while(it != listGateways.end())
+ {
+ line.clear();
+ line << "\tID: " << it->gatewayID
+ << "\tName: " << it->name
+ << "\tSourceID: " << it->sourceID
+ << "\tSinkID: " << it->sinkID;
+
+ sendTelnetLine(filedescriptor,line);
+ it++;
+ }
+ */
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->getSenderversionCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::stringstream line;
+
+ line << "Sender versions:" << std::endl
+ << "Ctrl: " << mControlSender->getInterfaceVersion() << " | "
+ << "Cmd: " << mCommandSender->getInterfaceVersion() << " | "
+ << "Routing: " << mRoutingSender->getInterfaceVersion();
+
+ sendTelnetLine(filedescriptor,line);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->getReceiverversionCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::stringstream line;
+
+ line << "Receiver versions:" << std::endl
+ << "Ctrl: " << mControlReceiver->getInterfaceVersion() << " | "
+ << "Cmd: " << mCommandReceiver->getInterfaceVersion() << " | "
+ << "Routing: " << mRoutingReceiver->getInterfaceVersion();
+
+ sendTelnetLine(filedescriptor,line);
+
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->infoSystempropertiesCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<am_SystemProperty_s> listSystemProperties;
+ std::vector<am_SystemProperty_s>::iterator it;
+ std::stringstream line;
+
+ mDatabasehandler->getListSystemProperties(listSystemProperties);
+
+ line << "Systemproperties: ";
+ sendTelnetLine(filedescriptor,line);
+
+ for(it = listSystemProperties.begin(); it < listSystemProperties.end(); it++ )
+ {
+ line.clear();
+ line << "Type: " << it->type << " Value: " << it->value;
+ sendTelnetLine(filedescriptor,line);
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->setRoutingCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::stringstream output;
+ std::vector<am_Route_s> routingList;
+
+ am_sourceID_t sourceID = 0;
+ am_sinkID_t sinkID = 0;
+
+ bool error = false;
+ am_Error_e rError = E_OK;
+
+
+ if(CmdQueue.size() >= 2)
+ {
+ std::istringstream istream_sourceID(CmdQueue.front());
+ CmdQueue.pop();
+ std::istringstream istream_sinkID(CmdQueue.front());
+ CmdQueue.pop();
+
+ if(!(istream_sourceID >> sourceID))
+ error = true;
+ if(!(istream_sinkID >> sinkID))
+ error = true;
+
+ if(error)
+ {
+ sendError(filedescriptor,"Error parsing sourcID and sinkID");
+ return;
+ }
+
+ if(DEBUG_ON)std::cout << "setRoutingCommandExec(sourceID: " << sourceID << ",sinkID: " << sinkID << ")" << std::endl;
+
+ rError = mRouter->getRoute(true,sourceID,sinkID,routingList);
+
+ if(E_OK == rError)
+ {
+ std::vector<am_Route_s>::iterator rlIter = routingList.begin();
+ for(int rlCnt = 1;rlIter < routingList.end();rlIter++)
+ {
+ output << "#" << rlCnt << " ";
+
+ std::vector<am_RoutingElement_s>::iterator reIter = rlIter->route.begin();
+ for(;reIter < rlIter->route.end();reIter++)
+ {
+ reIter->connectionFormat;
+ reIter->domainID;
+ output << ">(" << reIter->sourceID << ")->--[D:"<< reIter->domainID <<"F:"<< reIter->connectionFormat <<"]-->-(" << reIter->sinkID<< ")" << std::endl;
+ }
+
+ rlCnt++;
+ }
+
+ sendTelnetLine(filedescriptor,output);
+ }
+ else
+ {
+ sendError(filedescriptor,"Error getting route");
+ }
+
+ }
+ else
+ {
+ CmdQueue.pop();
+ output << "Not enough arguments to set routing. Please enter sourceID and sinkID after command" << std::endl;
+ return;
+ }
+
+
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->setConnectionExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::stringstream output;
+
+ am_sourceID_t sourceID = 0;
+ am_sinkID_t sinkID = 0;
+ am_mainConnectionID_t connID = 0;
+
+ bool error = false;
+ am_Error_e rError = E_OK;
+
+ if(CmdQueue.size() >= 2)
+ {
+ std::istringstream istream_sourceID(CmdQueue.front());
+ CmdQueue.pop();
+
+ std::istringstream istream_sinkID(CmdQueue.front());
+ CmdQueue.pop();
+
+ if(!(istream_sourceID >> sourceID))
+ error = true;
+
+ if(!(istream_sinkID >> sinkID))
+ error = true;
+
+ if(error)
+ {
+ sendError(filedescriptor,"Error parsing sinkID and/or sourceID");
+ return;
+ }
+
+ // Try to set up connection
+ rError = mCommandReceiver->connect(sourceID,sinkID,connID);
+
+ if(E_OK == rError)
+ {
+ output << "ConnID: " << connID << "Src: " << sourceID << " ---> Sink: " << sinkID << std::endl;
+ sendTelnetLine(filedescriptor,output);
+ }
+ else
+ {
+ sendError(filedescriptor,"Error connecting sourceID and sinkID");
+ }
+
+ }
+ else
+ {
+ CmdQueue.pop();
+ sendError(filedescriptor,"Not enough arguments to set routing. Please enter sourceID and sinkID after command");
+ return;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->setConnectionExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::stringstream output;
+
+ am_mainConnectionID_t connID = 0;
+
+ bool error = false;
+ am_Error_e rError = E_OK;
+
+ if(CmdQueue.size() >= 1)
+ {
+ std::istringstream istream_connID(CmdQueue.front());
+ CmdQueue.pop();
+
+ if(!(istream_connID >> connID))
+ error = true;
+
+ if(error)
+ {
+ sendError(filedescriptor,"Error parsing connID");
+ return;
+ }
+
+ // Try to disconnect connection id
+ rError = mCommandReceiver->disconnect(connID);
+
+ if(E_OK == rError)
+ {
+ output << "ConnID " << connID << " closed successfully! " << std::endl;
+ sendTelnetLine(filedescriptor,output);
+ }
+ else
+ {
+ sendError(filedescriptor,"Error connecting sourceID and sinkID");
+ }
+ }
+ else
+ {
+ sendError(filedescriptor,"Not enough arguments to disconnect a Main Connection, please enter 'connection ID' after command");
+ return;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->setConnectionExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::stringstream output;
+ am_sinkID_t sourceID;
+ am_MainSoundProperty_s soundProperty;
+ unsigned int tmpType = 0;
+ bool error = false;
+
+ if(CmdQueue.size() >= 3)
+ {
+ std::istringstream istream_sourceID(CmdQueue.front());
+ CmdQueue.pop();
+
+ std::istringstream istream_type(CmdQueue.front());
+ CmdQueue.pop();
+
+ std::istringstream istream_value(CmdQueue.front());
+ CmdQueue.pop();
+
+ if(!(istream_type >> tmpType))
+ error = true;
+
+ if(tmpType < MSP_MAX)
+ soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
+ else
+ error = true;
+
+ if(!(istream_value >> soundProperty.value))
+ error = true;
+
+ if(!(istream_sourceID >> sourceID))
+ error = true;
+
+ if(error)
+ {
+ sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'");
+ return;
+ }
+
+ if(E_OK == mCommandReceiver->setMainSourceSoundProperty(soundProperty,sourceID))
+ {
+ output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
+ sendTelnetLine(filedescriptor,output);
+ }
+ else
+ {
+ sendError(filedescriptor,"Error setMainSourceSoundProperty");
+ }
+ }
+ else
+ {
+ sendError(filedescriptor,"Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
+ return;
+ }
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->setConnectionExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::stringstream output;
+ am_sinkID_t sinkID;
+ am_MainSoundProperty_s soundProperty;
+ unsigned int tmpType = 0;
+ bool error = false;
+
+ if(CmdQueue.size() >= 3)
+ {
+ std::istringstream istream_sinkID(CmdQueue.front());
+ CmdQueue.pop();
+
+ std::istringstream istream_type(CmdQueue.front());
+ CmdQueue.pop();
+
+ std::istringstream istream_value(CmdQueue.front());
+ CmdQueue.pop();
+
+ if(!(istream_type >> tmpType))
+ error = true;
+
+ if(tmpType < MSP_MAX)
+ soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
+ else
+ error = true;
+
+ if(!(istream_value >> soundProperty.value))
+ error = true;
+
+ if(!(istream_sinkID >> sinkID))
+ error = true;
+
+ if(error)
+ {
+ sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'");
+ return;
+ }
+
+ if(E_OK == mCommandReceiver->setMainSinkSoundProperty(soundProperty,sinkID))
+ {
+ output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
+ sendTelnetLine(filedescriptor,output);
+ }
+ else
+ {
+ sendError(filedescriptor,"Error setMainSinkSoundProperty");
+ }
+ }
+ else
+ {
+ sendError(filedescriptor,"Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command");
+ return;
+ }
+}
+
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ instance->listPluginsCommandExec(CmdQueue,filedescriptor);
+}
+
+/****************************************************************************/
+void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
+/****************************************************************************/
+{
+ std::vector<std::string> PlugInNames;
+ std::vector<std::string>::iterator iter;
+ std::stringstream output;
+ am_Error_e rError = E_OK;
+
+
+ rError = mCommandSender->getListPlugins(PlugInNames);
+
+ output << "CommandSender Plugins loaded: " << PlugInNames.size() << std::endl;
+
+ for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
+ {
+ output << iter->c_str() << std::endl;
+ }
+
+ rError = mRoutingSender->getListPlugins(PlugInNames);
+
+ output << std::endl << "RoutingSender Plugins loaded: " << PlugInNames.size() << std::endl;
+
+ for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
+ {
+ output << iter->c_str() << std::endl;
+ }
+
+ sendTelnetLine(filedescriptor,output);
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AudioManagerDaemon/src/CommandSender.cpp b/AudioManagerDaemon/src/CommandSender.cpp
index 7a5b75e..810eec4 100644
--- a/AudioManagerDaemon/src/CommandSender.cpp
+++ b/AudioManagerDaemon/src/CommandSender.cpp
@@ -27,10 +27,13 @@
#include <dirent.h>
#include "PluginTemplate.h"
#include "DLTWrapper.h"
+
using namespace am;
#define REQUIRED_INTERFACE_VERSION 1
+DLT_IMPORT_CONTEXT(AudioManager)
+
//!< macro to call all interfaces
#define CALL_ALL_INTERFACES(...) \
std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin(); \
@@ -42,7 +45,8 @@ using namespace am;
CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirectories) :
mListInterfaces(), //
- mListLibraryHandles()
+ mListLibraryHandles(),
+ mListLibraryNames()
{
std::vector<std::string> sharedLibraryNameList;
std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin();
@@ -52,12 +56,12 @@ CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirecto
for (; dirIter < dirIterEnd; ++dirIter)
{
const char* directoryName = dirIter->c_str();
- logInfo("Searching for CommandPlugins in",directoryName);
+ logInfo("Searching for CommandPlugins in" , *dirIter);
DIR *directory = opendir(directoryName);
if (!directory)
{
- logInfo("Error opening directory ",directoryName);
+ logError("Error opening directory ",*dirIter);
continue;
}
@@ -86,14 +90,14 @@ CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirecto
for (; iter < iterEnd; ++iter)
{
- logInfo("Loading CommandSender plugin",*iter);
+ logInfo("Loading CommandSender plugin", *iter);
CommandSendInterface* (*createFunc)();
void* tempLibHandle = NULL;
createFunc = getCreateFunction<CommandSendInterface*()>(*iter, tempLibHandle);
if (!createFunc)
{
- logInfo("Entry point of CommandPlugin not found",*iter);
+ logInfo("Entry point of CommandPlugin not found", *iter);
continue;
}
@@ -114,6 +118,7 @@ CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirecto
mListInterfaces.push_back(commander);
mListLibraryHandles.push_back(tempLibHandle);
+ mListLibraryNames.push_back(iter->c_str());
}
}
@@ -236,6 +241,12 @@ void CommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainC
CALL_ALL_INTERFACES(cbTimingInformationChanged(mainConnection,time))
}
+am_Error_e am::CommandSender::getListPlugins(std::vector<std::string> & interfaces) const
+{
+ interfaces = mListLibraryNames;
+ return E_OK;
+}
+
void CommandSender::unloadLibraries(void)
{
std::vector<void*>::iterator iterator = mListLibraryHandles.begin();
diff --git a/AudioManagerDaemon/src/TelnetServer.cpp b/AudioManagerDaemon/src/TelnetServer.cpp
index 38e8453..8b51af3 100644
--- a/AudioManagerDaemon/src/TelnetServer.cpp
+++ b/AudioManagerDaemon/src/TelnetServer.cpp
@@ -23,12 +23,14 @@
*/
#include "TelnetServer.h"
-#include <cassert>
+#include "CAmTelnetMenuHelper.h"
+#include <assert.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <string.h>
#include <netdb.h>
+#include <dlt/dlt.h>
#include <config.h>
#include <errno.h>
#include <sstream>
@@ -40,217 +42,217 @@
using namespace am;
+DLT_IMPORT_CONTEXT(AudioManager)
+
TelnetServer* TelnetServer::instance = NULL;
#define PRINT_BOOL(var) var ? output+="true\t\t" : output+="false\t\t";
-TelnetServer::TelnetServer(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, unsigned int servPort, unsigned int maxConnections) :
- telnetConnectFiredCB(this, &TelnetServer::connectSocket), //
- telnetReceiveFiredCB(this, &TelnetServer::receiveData), //
- telnetDispatchCB(this, &TelnetServer::dispatchData), //
- telnetCheckCB(this, &TelnetServer::check), //
- mSocketHandler(iSocketHandler), //
- mCommandSender(iCommandSender), //
- mCommandReceiver(iCommandReceiver), //
- mRoutingSender(iRoutingSender), //
- mRoutingReceiver(iRoutingReceiver), //
- mControlSender(iControlSender), //
- mControlReceiver(iControlReceiver), //
- mDatabasehandler(iDatabasehandler), //
- mConnecthandle(), //
- msgList(), //
- mListConnections(), //
- mConnectFD(NULL), //
- mServerPort(servPort), //
- mMaxConnections(maxConnections), //
- mMapCommands(createCommandMap())
+TelnetServer::TelnetServer(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter, unsigned int servPort, unsigned int maxConnections)
+ :telnetConnectFiredCB(this,&TelnetServer::connectSocket),
+ telnetReceiveFiredCB(this,&TelnetServer::receiveData),
+ telnetDispatchCB(this,&TelnetServer::dispatchData),
+ telnetCheckCB(this,&TelnetServer::check),
+ mSocketHandler(iSocketHandler),
+ mCommandSender(iCommandSender),
+ mCommandReceiver(iCommandReceiver),
+ mRoutingSender(iRoutingSender),
+ mRoutingReceiver(iRoutingReceiver),
+ mControlSender(iControlSender),
+ mControlReceiver(iControlReceiver),
+ mDatabasehandler(iDatabasehandler),
+ mRouter(iRouter),
+ mConnecthandle(),
+ mMsgList(),
+ mListConnections(),
+ mConnectFD(NULL),
+ mServerPort(servPort),
+ mMaxConnections(maxConnections),
+ mTelnetMenuHelper(iSocketHandler,iCommandSender,iCommandReceiver,iRoutingSender,iRoutingReceiver,iControlSender,iControlReceiver,iDatabasehandler,iRouter)
{
- assert(mSocketHandler!=NULL);
- assert(mCommandReceiver!=NULL);
- assert(mCommandSender!=NULL);
- assert(mControlSender!=NULL);
- assert(mControlReceiver!=NULL);
- assert(mRoutingSender!=NULL);
- assert(mRoutingReceiver!=NULL);
- assert(mDatabasehandler!=NULL);
- assert(servPort!=0);
- assert(mMaxConnections!=0);
-
- instance = this;
-
- int yes = 1;
- struct sockaddr_in servAddr;
-
- //setup the port Listener
- mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
- memset(&servAddr, 0, sizeof(servAddr));
- servAddr.sin_family = AF_INET;
- servAddr.sin_addr.s_addr = INADDR_ANY;
- servAddr.sin_port = htons(servPort);
- bind(mConnectFD, (struct sockaddr *) &servAddr, sizeof(servAddr));
-
- int a = 1;
- ioctl(mConnectFD, FIONBIO, (char *) &a);
- setsockopt(mConnectFD, SOL_SOCKET, SO_KEEPALIVE, (char *) &a, sizeof(a));
-
- short events = 0;
- events |= POLLIN;
- mSocketHandler->addFDPoll(mConnectFD, events, NULL, &telnetConnectFiredCB, NULL, NULL, NULL, mConnecthandle);
+ assert(mSocketHandler!=NULL);
+ assert(mCommandReceiver!=NULL);
+ assert(mCommandSender!=NULL);
+ assert(mControlSender!=NULL);
+ assert(mControlReceiver!=NULL);
+ assert(mRoutingSender!=NULL);
+ assert(mRoutingReceiver!=NULL);
+ assert(mDatabasehandler!=NULL);
+ assert(mRouter!=NULL);
+ assert(servPort!=0);
+ assert(mMaxConnections!=0);
+
+ instance = this;
+ mTelnetMenuHelper.setTelnetServer(this);
+
+ int yes = 1;
+ struct sockaddr_in servAddr;
+
+ //setup the port Listener
+ mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
+ memset(&servAddr, 0, sizeof(servAddr));
+ servAddr.sin_family = AF_INET;
+ servAddr.sin_addr.s_addr = INADDR_ANY;
+ servAddr.sin_port = htons(servPort);
+ bind(mConnectFD, (struct sockaddr *) &servAddr, sizeof(servAddr));
+
+ if (listen(mConnectFD,mMaxConnections) < 0)
+ {
+ DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("TelnetServer::TelnetServerk cannot listen "),DLT_INT(errno));
+ }
+ else
+ DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("TelnetServer::TelnetServer started listening on port"),DLT_INT(mServerPort));
+
+ int a=1;
+ ioctl (mConnectFD, FIONBIO, (char *) &a); // should we use the posix call fcntl(mConnectFD, F_SETFL, O_NONBLOCK)
+ setsockopt (mConnectFD, SOL_SOCKET, SO_KEEPALIVE, (char *) &a, sizeof (a));
+
+ short events = 0;
+ events |= POLLIN;
+ mSocketHandler->addFDPoll(mConnectFD, events, NULL, &telnetConnectFiredCB, NULL, NULL, NULL, mConnecthandle);
}
TelnetServer::~TelnetServer()
{
+ mTelnetMenuHelper.setTelnetServer(NULL);
}
void TelnetServer::connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void *userData)
{
- (void) handle;
- (void) userData;
- //first, accept the connection, create a new filedescriptor
- struct sockaddr answer;
- socklen_t len = sizeof(answer);
- connection_s connection;
- connection.filedescriptor = accept(pfd.fd, (struct sockaddr*) &answer, &len);
-
- mListConnections.push_back(connection);
-
- //set the correct event:
- short event = 0;
- event |= POLLIN;
-
- //aded the filedescriptor to the sockethandler and register the callbacks for receiving the data
- mSocketHandler->addFDPoll(mListConnections.back().filedescriptor, event, NULL, &telnetReceiveFiredCB, &telnetCheckCB, &telnetDispatchCB, NULL, mListConnections.back().handle);
+ //first, accept the connection, create a new filedescriptor
+ struct sockaddr answer;
+ socklen_t len=sizeof(answer);
+ connection_s connection;
+ connection.handle = 0;
+ connection.filedescriptor = accept(pfd.fd, (struct sockaddr*)&answer, &len);
+
+ // Notiy menuhelper
+ mTelnetMenuHelper.newSocketConnection(connection.filedescriptor);
+
+ //set the correct event:
+ short event = 0;
+ event |=POLLIN;
+
+ //aded the filedescriptor to the sockethandler and register the callbacks for receiving the data
+ mSocketHandler->addFDPoll(connection.filedescriptor,event,NULL,&telnetReceiveFiredCB,&telnetCheckCB,&telnetDispatchCB,NULL,connection.handle);
+ mListConnections.push_back(connection);
+}
+
+void TelnetServer::disconnectClient(int filedescriptor)
+{
+ std::vector<connection_s>::iterator iter = mListConnections.begin();
+ while(iter != mListConnections.end())
+ {
+ if( filedescriptor == iter->filedescriptor )
+ {
+ if( E_OK == mSocketHandler->removeFDPoll(iter->handle))
+ {
+ mListConnections.erase(iter);
+ close(filedescriptor);
+ }
+ else
+ {
+ // TODO: Handle error
+ }
+
+ break;
+ }
+ iter++;
+ }
}
void TelnetServer::receiveData(const pollfd pollfd, const sh_pollHandle_t handle, void *userData)
{
- (void)handle;
- (void)userData;
- //initialize buffer
- char buffer[100];
- //read until buffer is full or no more data is there
- int read = recv(pollfd.fd, buffer, 100, NULL);
- if (read > 1)
- {
- //read the message and store it in a queue - its a telnet connection so data will be sent on enter !
- std::string msg = std::string(buffer, read);
- msgList.push(msg);
- }
+ //initialize buffer
+ char buffer[100];
+ //read until buffer is full or no more data is there
+ int read=recv(pollfd.fd,buffer,100,NULL);
+ if (read>1)
+ {
+ //read the message and store it in a queue - its a telnet connection so data will be sent on enter !
+ std::string msg=std::string(buffer,read);
+ mMsgList.push(msg);
+ }
}
bool TelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData)
{
- (void)handle;
- (void)userData;
- std::vector<connection_s>::iterator iterator = mListConnections.begin();
- for (; iterator != mListConnections.end(); ++iterator)
- {
- if (iterator->handle == handle) break;
- }
- if (iterator == mListConnections.end()) return false;
-
- std::string command;
- std::vector<std::string> msg;
- sliceCommand(msgList.front(), command, msg);
- msgList.pop();
- mMapCommand_t::iterator commandIter = mMapCommands.find(command);
- if (commandIter == mMapCommands.end())
- {
- send(iterator->filedescriptor, "Command not found!\n", 20, 0);
- }
- else
- {
- (*commandIter).second(msg, iterator->filedescriptor);
- }
+ std::vector<connection_s>::iterator iterator=mListConnections.begin();
+ for(;iterator!=mListConnections.end();++iterator)
+ {
+ if(iterator->handle==handle) break;
+ }
+ //if (iterator==mListConnections.end()) return false;
- //remove the message from the queue and return false if there is no more message to read.
- if (msgList.size() != 0) return true;
- return false;
+ std::string command;
+ std::queue<std::string> MsgQueue;
+ if(!mMsgList.empty())
+ {
+ sliceCommand(mMsgList.front(),command,MsgQueue);
+ mMsgList.pop();
+ }
+
+ mTelnetMenuHelper.enterCmdQueue(MsgQueue,iterator->filedescriptor);
+
+ // must return false to stop endless polling
+ return false;
+
+ /*
+ mMsgList.pop();
+ mMapCommand_t::iterator commandIter=mMapCommands.find(command);
+ if (commandIter==mMapCommands.end())
+ {
+ send(iterator->filedescriptor,"Command not found!\n",20,0);
+ }
+ else
+ {
+ commandIter->second(msg,iterator->filedescriptor);
+ //(*commandIter).second(msg,iterator->filedescriptor);
+ }
+
+ //remove the message from the queue and return false if there is no more message to read.
+ if (mMsgList.size()!=0) return true;
+ return false;
+ */
}
bool TelnetServer::check(const sh_pollHandle_t handle, void *userData)
{
(void)handle;
(void)userData;
- if (msgList.size() != 0) return true;
+ if (mMsgList.size() != 0) return true;
return false;
}
-void TelnetServer::listCommand(std::vector<std::string>& msg, int filedescriptor)
+void am::TelnetServer::sliceCommand(const std::string & string, std::string & command, std::queue<std::string> & MsgQueue)
{
- instance->listCommandShadow(msg, filedescriptor);
-}
+ std::stringstream stream(string);
+ std::istream_iterator<std::string> begin(stream);
+ std::istream_iterator<std::string> end;
+ std::string cmd;
+ bool endOfStream = false;
-void TelnetServer::listCommandShadow(std::vector<std::string> & msg, int filedescriptor)
-{
- std::string output;
- if (msg.empty())
- {
- output += "No second parameter given after list, please enter\n";
- }
- else if (msg.front().compare("plugins") == 0)
- {
- std::vector<std::string> plugins;
- mRoutingSender->getListPlugins(plugins);
- std::vector<std::string>::iterator it = plugins.begin();
- output = "\n\nrouting plugins:\n-------------------------\n";
- for (; it != plugins.end(); ++it)
- {
- output += *it + "\n";
- }
- }
- else if (msg.front().compare("domains") == 0)
- {
- output = "domainID\t\tdomainName\t\tbusName\t\tnodeName\t\tearly\t\tstate\t\tcomplete\n";
- output += "-------------------------------------------------------------------------------------\n";
- std::vector<am_Domain_s> domainList;
- mDatabasehandler->getListDomains(domainList);
- std::vector<am_Domain_s>::iterator it = domainList.begin();
- for (; it != domainList.end(); ++it)
- {
- output += it->domainID + "\t\t";
- output += it->name + "\t\t";
- output += it->busname + "\t\t";
- output += it->nodename + "\t\t";
- PRINT_BOOL(it->early);
- switch (it->state)
- {
- case DS_CONTROLLED:
- output += "DS_CONTROLLED\t\t";
- break;
- case DS_INDEPENDENT_STARTUP:
- output += "DS_INDEPENDENT_STARTUP\t\t";
- break;
- case DS_INDEPENDENT_RUNDOWN:
- output += "DS_INDEPENDENT_RUNDOWN\t\t";
- break;
- default:
- output += "undefined\t\t";
- break;
- }PRINT_BOOL(it->complete);
- }
- }
- else
+ int c = 0;
+
+ while(!endOfStream)
{
- output = "did not recognize parameter: " + msg.front() + "\n";
+ cmd = *begin;
+ MsgQueue.push(cmd);
+ begin++;
+
+ if(begin == end )
+ {
+ endOfStream = true;
+ }
+ c++;
}
- send(filedescriptor, output.c_str(), output.size(), 0);
-}
-void am::TelnetServer::sliceCommand(const std::string & string, std::string & command, std::vector<std::string> & msg)
-{
- std::stringstream stream(string);
- std::istream_iterator<std::string> begin(stream);
- std::istream_iterator<std::string> end;
+
+ /*
command = *begin++;
msg = std::vector<std::string>(begin, end);
+ */
}
-TelnetServer::mMapCommand_t TelnetServer::createCommandMap()
-{
- mMapCommand_t commands;
- commands.insert(std::make_pair("list", &TelnetServer::listCommand));
- return commands;
-}
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp
index 73e9baf..54c4639 100644
--- a/AudioManagerDaemon/src/main.cpp
+++ b/AudioManagerDaemon/src/main.cpp
@@ -278,7 +278,7 @@ int main(int argc, char *argv[])
RoutingReceiver iRoutingReceiver(&iDatabaseHandler, &iRoutingSender, &iControlSender, &iSocketHandler, &iDBusWrapper);
ControlReceiver iControlReceiver(&iDatabaseHandler, &iRoutingSender, &iCommandSender, &iSocketHandler, &iRouter);
#ifdef WITH_TELNET
- TelnetServer iTelnetServer(&iSocketHandler,&iCommandSender,&iCommandReceiver,&iRoutingSender,&iRoutingReceiver,&iControlSender,&iControlReceiver,&iDatabaseHandler,telnetport,maxConnections);
+ TelnetServer iTelnetServer(&iSocketHandler,&iCommandSender,&iCommandReceiver,&iRoutingSender,&iRoutingReceiver,&iControlSender,&iControlReceiver,&iDatabaseHandler,&iRouter,telnetport,maxConnections);
#endif
#else /*WITH_SOCKETHANDLER_LOOP */
CommandReceiver iCommandReceiver(&iDatabaseHandler,&iControlSender,&iDBusWrapper);