summaryrefslogtreecommitdiff
path: root/AudioManagerDaemon
diff options
context:
space:
mode:
authorFrank Herchet <frank.fh.herchet@bmw.de>2012-02-09 10:27:43 +0100
committerFrank Herchet <frank.fh.herchet@bmw.de>2012-02-09 10:27:43 +0100
commit40ade5d852e6d4c781f33a20d8e4340d59ec07a8 (patch)
tree514b5f6ae01f9ba831548b28859b37724c3faae1 /AudioManagerDaemon
parent3a11cd051607c19d91a0eb8118fac87e937de929 (diff)
downloadaudiomanager-40ade5d852e6d4c781f33a20d8e4340d59ec07a8.tar.gz
* remove duplicate current command prompt
* remove debug output of TelnetServer.h * fix compile error in main.cpp * remove unused methods in TelnetServer.h
Diffstat (limited to 'AudioManagerDaemon')
-rw-r--r--AudioManagerDaemon/include/TelnetServer.h11
-rw-r--r--AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp58
-rw-r--r--AudioManagerDaemon/src/TelnetServer.cpp173
-rw-r--r--AudioManagerDaemon/src/main.cpp2
4 files changed, 36 insertions, 208 deletions
diff --git a/AudioManagerDaemon/include/TelnetServer.h b/AudioManagerDaemon/include/TelnetServer.h
index 1fe1ee9..03617a5 100644
--- a/AudioManagerDaemon/include/TelnetServer.h
+++ b/AudioManagerDaemon/include/TelnetServer.h
@@ -56,6 +56,7 @@ public:
Router *iRouter,
unsigned int servPort,
unsigned int maxConnections);
+
virtual ~TelnetServer();
void connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void* userData);
void disconnectClient(int filedescriptor);
@@ -71,15 +72,6 @@ private:
typedef void (*CommandPrototype)(std::vector<std::string>& msg,int filedescriptor);
typedef std::map<std::string,CommandPrototype> mMapCommand_t;
- static void listCommand(std::vector<std::string>& msg,int filedescriptor);
- void listCommandShadow(std::vector<std::string>& msg,int filedescriptor);
-
- static void dbCommand(std::vector<std::string>& msg,int filedescriptor);
- void dbCommandShadow(std::vector<std::string>& msg,int filedescriptor);
-
- static void helpCommand(std::vector<std::string>& msg,int filedescriptor);
- void helpCommandShadow(std::vector<std::string>& msg,int filedescriptor);
-
void sliceCommand(const std::string& string,std::string& command,std::queue<std::string>& msg);
mMapCommand_t createCommandMap();
struct connection_s
@@ -104,7 +96,6 @@ private:
int mConnectFD;
unsigned int mServerPort;
unsigned int mMaxConnections;
- mMapCommand_t mMapCommands;
CAmTelnetMenuHelper mTelnetMenuHelper;
};
diff --git a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp
index f283ccf..f901fa8 100644
--- a/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp
+++ b/AudioManagerDaemon/src/CAmTelnetMenuHelper.cpp
@@ -24,6 +24,10 @@
#include "CAmTelnetMenuHelper.h"
#include <dlt/dlt.h>
+#include <cassert>
+
+#define DEBUG_ON false
+
using namespace am;
DLT_IMPORT_CONTEXT(AudioManager)
@@ -291,7 +295,7 @@ void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQu
it = mCurrentMainStateMap.find(filedescriptor);
if( it != mCurrentMainStateMap.end())
{
- std::cout << "old state: " << it->second;
+ if(DEBUG_ON)std::cout << "old state: " << it->second;
switch(it->second)
{
case eRootState:
@@ -313,8 +317,8 @@ void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQu
it->second = eRootState;
break;
}
- std::cout << "new state: " << it->second << std::endl;
- enterCmdQueue(CmdQueue,filedescriptor);
+ if(DEBUG_ON)std::cout << "new state: " << it->second << std::endl;
+ //enterCmdQueue(CmdQueue,filedescriptor);
}
}
@@ -342,9 +346,18 @@ void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string> & CmdQueue, in
it = mCurrentMainStateMap.find(filedescriptor);
if( it != mCurrentMainStateMap.end())
{
- std::cout << "removing client connection " << filedescriptor << std::endl;
- mTelenetServer->disconnectClient(filedescriptor);
- mCurrentMainStateMap.erase(it);
+ 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";
+ }
}
}
@@ -415,7 +428,7 @@ void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string> & CmdQueue, in
break;
}
sendTelnetLine(filedescriptor,line);
- enterCmdQueue(CmdQueue,filedescriptor);
+ //enterCmdQueue(CmdQueue,filedescriptor);
}
}
@@ -435,7 +448,7 @@ void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string> & CmdQueue,
if( it != mCurrentMainStateMap.end())
{
it->second = eGetState;
- enterCmdQueue(CmdQueue,filedescriptor);
+ //enterCmdQueue(CmdQueue,filedescriptor);
}
}
@@ -455,7 +468,7 @@ void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string> & CmdQueue,
if( it != mCurrentMainStateMap.end())
{
it->second = eSetState;
- enterCmdQueue(CmdQueue,filedescriptor);
+ //enterCmdQueue(CmdQueue,filedescriptor);
}
}
@@ -475,7 +488,7 @@ void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string> & CmdQueue
if( it != mCurrentMainStateMap.end())
{
it->second = eListState;
- enterCmdQueue(CmdQueue,filedescriptor);
+ //enterCmdQueue(CmdQueue,filedescriptor);
}
}
@@ -495,7 +508,7 @@ void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string> & CmdQueue
if( it != mCurrentMainStateMap.end())
{
it->second = eInfoState;
- enterCmdQueue(CmdQueue,filedescriptor);
+ //enterCmdQueue(CmdQueue,filedescriptor);
}
}
@@ -532,9 +545,6 @@ void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string> & C
sendTelnetLine(filedescriptor,line);
it++;
}
-
- if(!CmdQueue.empty())
- enterCmdQueue(CmdQueue,filedescriptor);
}
/****************************************************************************/
@@ -569,9 +579,6 @@ void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string> & CmdQu
sendTelnetLine(filedescriptor,line);
it++;
}
-
- if(!CmdQueue.empty())
- enterCmdQueue(CmdQueue,filedescriptor);
}
/****************************************************************************/
@@ -606,9 +613,6 @@ void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string> & CmdQue
sendTelnetLine(filedescriptor,line);
it++;
}
-
- if(!CmdQueue.empty())
- enterCmdQueue(CmdQueue,filedescriptor);
}
/****************************************************************************/
@@ -641,9 +645,6 @@ void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string> & CmdQueue
sendTelnetLine(filedescriptor,line);
it++;
}
-
- if(!CmdQueue.empty())
- enterCmdQueue(CmdQueue,filedescriptor);
}
/****************************************************************************/
@@ -767,9 +768,6 @@ void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> &
<< "Routing: " << mRoutingSender->getInterfaceVersion();
sendTelnetLine(filedescriptor,line);
-
- if(!CmdQueue.empty())
- enterCmdQueue(CmdQueue,filedescriptor);
}
/****************************************************************************/
@@ -792,9 +790,6 @@ void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string>
sendTelnetLine(filedescriptor,line);
- if(!CmdQueue.empty())
- enterCmdQueue(CmdQueue,filedescriptor);
-
}
/****************************************************************************/
@@ -823,9 +818,6 @@ void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string
line << "Type: " << it->type << " Value: " << it->value;
sendTelnetLine(filedescriptor,line);
}
-
- if(!CmdQueue.empty())
- enterCmdQueue(CmdQueue,filedescriptor);
}
/****************************************************************************/
@@ -867,7 +859,7 @@ void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string> & CmdQue
return;
}
- std::cout << "setRoutingCommandExec(sourceID: " << sourceID << ",sinkID: " << sinkID << ")" << std::endl;
+ if(DEBUG_ON)std::cout << "setRoutingCommandExec(sourceID: " << sourceID << ",sinkID: " << sinkID << ")" << std::endl;
rError = mRouter->getRoute(true,sourceID,sinkID,routingList);
diff --git a/AudioManagerDaemon/src/TelnetServer.cpp b/AudioManagerDaemon/src/TelnetServer.cpp
index 752f0ee..8b51af3 100644
--- a/AudioManagerDaemon/src/TelnetServer.cpp
+++ b/AudioManagerDaemon/src/TelnetServer.cpp
@@ -68,7 +68,6 @@ TelnetServer::TelnetServer(SocketHandler *iSocketHandler, CommandSender *iComman
mConnectFD(NULL),
mServerPort(servPort),
mMaxConnections(maxConnections),
- mMapCommands(createCommandMap()),
mTelnetMenuHelper(iSocketHandler,iCommandSender,iCommandReceiver,iRoutingSender,iRoutingReceiver,iControlSender,iControlReceiver,iDatabasehandler,iRouter)
{
assert(mSocketHandler!=NULL);
@@ -79,6 +78,7 @@ TelnetServer::TelnetServer(SocketHandler *iSocketHandler, CommandSender *iComman
assert(mRoutingSender!=NULL);
assert(mRoutingReceiver!=NULL);
assert(mDatabasehandler!=NULL);
+ assert(mRouter!=NULL);
assert(servPort!=0);
assert(mMaxConnections!=0);
@@ -101,20 +101,21 @@ TelnetServer::TelnetServer(SocketHandler *iSocketHandler, CommandSender *iComman
{
DLT_LOG(AudioManager, DLT_LOG_ERROR, DLT_STRING("TelnetServer::TelnetServerk cannot listen "),DLT_INT(errno));
}
- DLT_LOG(AudioManager, DLT_LOG_INFO, DLT_STRING("TelnetServer::TelnetServerk started listening on port"),DLT_INT(mServerPort));
+ 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;
- std::cout << "TN: " << "mConnectFD: " << mConnectFD << std::endl;
- mSocketHandler->addFDPoll(mConnectFD, events, NULL, &telnetConnectFiredCB, NULL, NULL, NULL, mConnecthandle);
+ 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)
@@ -135,32 +136,26 @@ void TelnetServer::connectSocket(const pollfd pfd, const sh_pollHandle_t handle,
//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);
- std::cout << "New client connection, fd = " << connection.filedescriptor << "; pollhandle = " << connection.handle << std::endl;
mListConnections.push_back(connection);
}
void TelnetServer::disconnectClient(int filedescriptor)
{
-
std::vector<connection_s>::iterator iter = mListConnections.begin();
-
- std::cout << "Looking for filedescriptor " << filedescriptor << "..." << std::endl;
while(iter != mListConnections.end())
{
- std::cout << "fd = " << iter->filedescriptor << "; pollhandle = " << iter->handle << std::endl;
if( filedescriptor == iter->filedescriptor )
{
- std::cout << "fd = " << filedescriptor << " found, pollhandle = " << iter->handle << std::endl;
if( E_OK == mSocketHandler->removeFDPoll(iter->handle))
{
- std::cout << "Removing connection, fd = " << iter->filedescriptor << "; pollhandle = " << iter->handle << std::endl;
mListConnections.erase(iter);
close(filedescriptor);
}
else
{
- std::cout << "Error removing FDPoll ("<< iter->handle << "), can't close telnet session!" << std::endl;
+ // TODO: Handle error
}
+
break;
}
iter++;
@@ -183,9 +178,7 @@ void TelnetServer::receiveData(const pollfd pollfd, const sh_pollHandle_t handle
bool TelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData)
{
- std::cout << "TelnetServer::dispatchData -> handle: " << handle << " userData: " << userData << std::endl;
std::vector<connection_s>::iterator iterator=mListConnections.begin();
- std::cout << "mListConnections: " << mListConnections.size() << std::endl;
for(;iterator!=mListConnections.end();++iterator)
{
if(iterator->handle==handle) break;
@@ -202,8 +195,6 @@ bool TelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData)
mTelnetMenuHelper.enterCmdQueue(MsgQueue,iterator->filedescriptor);
- std::cout << "<<" << std::endl;
-
// must return false to stop endless polling
return false;
@@ -234,67 +225,6 @@ bool TelnetServer::check(const sh_pollHandle_t handle, void *userData)
return false;
}
-void TelnetServer::listCommand(std::vector<std::string>& msg, int filedescriptor)
-{
- instance->listCommandShadow(msg, filedescriptor);
-}
-
-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
- {
- output = "did not recognize parameter: " + msg.front() + "\n";
- }
- send(filedescriptor, output.c_str(), output.size(), 0);
-}
-
void am::TelnetServer::sliceCommand(const std::string & string, std::string & command, std::queue<std::string> & MsgQueue)
{
std::stringstream stream(string);
@@ -304,13 +234,11 @@ void am::TelnetServer::sliceCommand(const std::string & string, std::string & co
bool endOfStream = false;
int c = 0;
- std::cout << "Size of mMsgList: " << mMsgList.size() << std::endl;
while(!endOfStream)
{
cmd = *begin;
MsgQueue.push(cmd);
- std::cout << "(" << c << ")" << "Cmd: " << cmd << "--" << std::endl;
begin++;
if(begin == end )
@@ -327,87 +255,4 @@ void am::TelnetServer::sliceCommand(const std::string & string, std::string & co
*/
}
-void am::TelnetServer::dbCommandShadow(std::vector<std::string> & msg, int filedescriptor)
-{
- std::string output;
- std::string minorDBCmd;
-
- if(msg.empty())
- {
- output+="No second parameter given after db, please enter\n";
- }
- else
- {
- minorDBCmd = msg.front();
-
- msg.erase(msg.begin());
-
- if(minorDBCmd.compare("list")==0)
- {
- minorDBCmd = msg.front();
- msg.erase(msg.begin());
- if(minorDBCmd.compare("connections") == 0)
- {
- std::vector<am_Connection_s> listConnections;
- //std::vector<am_Connection_s>::iterator iter = listConnections.begin();
- unsigned int i = 0;
- mDatabasehandler->getListConnections(listConnections);
- output += "ID \tSourceID \tSinkID \tdelay\n";
- if(listConnections.size() > 0)
- {
- for(; i < listConnections.size(); i++)
- {
-
- output += listConnections[i].connectionID+"\t ";
- output += listConnections[i].sourceID+"\t ";
- output += listConnections[i].sinkID+"\t ";
- output += listConnections[i].delay+"\n ";
- }
- }
- else
- {
- output += "No active connections!\n";
- }
-
-
- }
- else
- {
- output+="Unknown db list command!\n";
- }
-
- }
- else
- {
- output+="Unknown db command\n";
- }
-
- }
- send(filedescriptor,output.c_str(),output.size(),0);
- output = ">";
- send(filedescriptor,output.c_str(),output.size(),0);
-}
-
-void am::TelnetServer::dbCommand(std::vector<std::string> & msg, int filedescriptor)
-{
- instance->dbCommandShadow(msg,filedescriptor);
-}
-
-void am::TelnetServer::helpCommandShadow(std::vector<std::string> & msg, int filedescriptor)
-{
-}
-
-void am::TelnetServer::helpCommand(std::vector<std::string> & msg, int filedescriptor)
-{
- instance->helpCommandShadow(msg,filedescriptor);
-}
-
-TelnetServer::mMapCommand_t TelnetServer::createCommandMap()
-{
- mMapCommand_t commands;
- commands.insert(std::make_pair("help",&TelnetServer::helpCommand));
- commands.insert(std::make_pair("list",&TelnetServer::listCommand));
- commands.insert(std::make_pair("db",&TelnetServer::dbCommand));
- return commands;
-}
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp
index d483925..575fc73 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);