diff options
author | Christian as GENIVI Maintainer <genivi-maint-audiomanager@genivi.org> | 2016-10-18 03:56:12 -0700 |
---|---|---|
committer | Christian as GENIVI Maintainer <genivi-maint-audiomanager@genivi.org> | 2016-10-18 03:56:12 -0700 |
commit | 196e133de35bfa7ffddd04ef69fdcb278380f51c (patch) | |
tree | 3cdca5e9d9859e197d7f51ddcd14e2c7f8ae024a /AudioManagerCore | |
parent | 1111f28e3693ee0f296819654a5c35fe147c395d (diff) | |
download | audiomanager-196e133de35bfa7ffddd04ef69fdcb278380f51c.tar.gz |
remove telnet server from Audiomanager
Signed-off-by: Christian as GENIVI Maintainer <genivi-maint-audiomanager@genivi.org>
Diffstat (limited to 'AudioManagerCore')
-rw-r--r-- | AudioManagerCore/include/CAmDatabaseHandlerMap.h | 1 | ||||
-rw-r--r-- | AudioManagerCore/include/CAmTelnetMenuHelper.h | 204 | ||||
-rw-r--r-- | AudioManagerCore/include/CAmTelnetServer.h | 100 | ||||
-rw-r--r-- | AudioManagerCore/src/CAmDatabaseObserver.cpp | 1 | ||||
-rw-r--r-- | AudioManagerCore/src/CAmTelnetMenuHelper.cpp | 1438 | ||||
-rwxr-xr-x | AudioManagerCore/src/CAmTelnetServer.cpp | 257 | ||||
-rw-r--r-- | AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp | 209 | ||||
-rw-r--r-- | AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h | 107 | ||||
-rw-r--r-- | AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt | 48 | ||||
-rw-r--r-- | AudioManagerCore/test/CMakeLists.txt | 4 |
10 files changed, 1 insertions, 2368 deletions
diff --git a/AudioManagerCore/include/CAmDatabaseHandlerMap.h b/AudioManagerCore/include/CAmDatabaseHandlerMap.h index 5de220e..38628a4 100644 --- a/AudioManagerCore/include/CAmDatabaseHandlerMap.h +++ b/AudioManagerCore/include/CAmDatabaseHandlerMap.h @@ -471,6 +471,7 @@ public: CAmDatabaseObserver *mpDatabaseObserver; //!< pointer to the Observer ListConnectionFormat mListConnectionFormat; //!< list of connection formats CAmMappedData mMappedData; //!< Internal structure encapsulating all the maps used in this class + #ifdef UNIT_TEST public: void setConnectionIDRange(const int16_t & min, const int16_t & max) diff --git a/AudioManagerCore/include/CAmTelnetMenuHelper.h b/AudioManagerCore/include/CAmTelnetMenuHelper.h deleted file mode 100644 index 7038cb3..0000000 --- a/AudioManagerCore/include/CAmTelnetMenuHelper.h +++ /dev/null @@ -1,204 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetMenuHelper.h - * For further information see http://www.genivi.org/. - * - */ - -// Local header -#ifndef CAMTELNETMENUHELPER_H_ -#define CAMTELNETMENUHELPER_H_ - -// Standard header -#include <iostream> -#include <queue> -#include <map> -#include <string> -#include <sstream> -#include <vector> -#include <sys/socket.h> -#include "audiomanagertypes.h" - -namespace am -{ - -class CAmTelnetServer; -class IAmDatabaseHandler; -class CAmCommandSender; -class CAmRoutingSender; -class CAmControlSender; -class CAmCommandReceiver; -class CAmRoutingReceiver; -class CAmControlReceiver; - -class CAmRouter; -class CAmSocketHandler; - -/** - * helper class for CAmTelnetServer - */ -class CAmTelnetMenuHelper -{ -public: - - enum EMainState - { - eRootState = 0, eListState, eInfoState, eGetState, eSetState - }; - - CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer); - - ~CAmTelnetMenuHelper(); - - void newSocketConnection(int filedescriptor); - - void socketConnectionsClosed(int filedescriptor); - - void enterCmdQueue(std::queue<std::string> &CmdQueue, int &filedescriptor); - -private: - - void createCommandMaps(); - void sendError(int & filedescriptor, std::string error_string); - void sendTelnetLine(int & filedescriptor, std::stringstream &line); - void sendCurrentCmdPrompt(int &filedescriptor); - - // COMMON commands - static void oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - - // ROOT commands - static void rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - - // LIST commands - static void listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listMainConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listMainConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listMainSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listMainSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void listMainSinksCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void listMainSinksCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - - // SET commands - static void setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setSinkSoundProperty(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setSinkSoundPropertyExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setSinkVolume(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setSinkVolumeExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setVolumeStep(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setVolumeStepExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setSinkMuteState(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setSinkMuteStateExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void setSourceSoundProperty(std::queue<std::string> & CmdQueue, int & filedescriptor); - void setSourceSoundPropertyExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - - // GET commands - static void getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - - // INFO commands - static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor); - void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor); - static void infoDumpCommand(std::queue<std::string>& CmdQueue, int& filedescriptor); - void infoDumpCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor); - -private: - - typedef void (*pCommandPrototype)(std::queue<std::string>& msg, int & filedescriptor); - - struct sCommandPrototypeInfo - { - std::string info; - pCommandPrototype CommandPrototype; - - // default contructor to set NULL - sCommandPrototypeInfo() : - info(""), CommandPrototype(NULL) - { - } - - // a small contructor - sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) : - info(MyInfo), CommandPrototype(MyCommandPrototype) - { - } - }; - - typedef std::map<std::string, sCommandPrototypeInfo> tCommandMap; - std::map<int, EMainState> mCurrentMainStateMap; //!< int filedescriptor of socket connection; EMainState state of current telnet session - - static CAmTelnetMenuHelper* instance; - CAmTelnetServer *mpTelenetServer; - CAmSocketHandler *mpSocketHandler; - CAmCommandSender *mpCommandSender; - CAmCommandReceiver *mpCommandReceiver; - CAmRoutingSender *mpRoutingSender; - CAmRoutingReceiver *mpRoutingReceiver; - CAmControlSender *mpControlSender; - CAmControlReceiver *mpControlReceiver; - IAmDatabaseHandler *mpDatabasehandler; - CAmRouter *mpRouter; - - tCommandMap mRootCommands; - tCommandMap mListCommands; - tCommandMap mGetCommands; - tCommandMap mSetCommands; - tCommandMap mInfoCommands; - -}; -// class CAmTelnetMenuHelper -}// namespace am - -#endif // CAMTELNETMENUHELPER_H_ diff --git a/AudioManagerCore/include/CAmTelnetServer.h b/AudioManagerCore/include/CAmTelnetServer.h deleted file mode 100644 index 0e4c510..0000000 --- a/AudioManagerCore/include/CAmTelnetServer.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetServer.h - * For further information see http://www.genivi.org/. - * - */ - -#ifndef TELNETSERVER_H_ -#define TELNETSERVER_H_ - -#include <queue> -#include <map> -#include "CAmSocketHandler.h" -#include "CAmTelnetMenuHelper.h" - -namespace am -{ - -class IAmDatabaseHandler; -class CAmCommandSender; -class CAmRoutingSender; -class CAmControlSender; -class CAmCommandReceiver; -class CAmRoutingReceiver; -class CAmControlReceiver; -class CAmRouter; -class CAmTelnetMenuHelper; - -/** - * Implements a telnetserver that can be used to connect to the audiomanager, retrieve some information and use it. For debugging purposes. - * For example, launch a telnet session on port 6060: - * \code telnet localhost 6060 \endcode - * more details can be found at the README - */ -class CAmTelnetServer -{ -public: - CAmTelnetServer(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, unsigned int servPort, unsigned int maxConnections); - ~CAmTelnetServer(); - void connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void* userData); - void disconnectClient(int filedescriptor); - void receiveData(const pollfd pfd, const sh_pollHandle_t handle, void* userData); - bool dispatchData(const sh_pollHandle_t handle, void* userData); - bool check(const sh_pollHandle_t handle, void* userData); - TAmShPollFired<CAmTelnetServer> telnetConnectFiredCB; - TAmShPollFired<CAmTelnetServer> telnetReceiveFiredCB; - TAmShPollDispatch<CAmTelnetServer> telnetDispatchCB; - TAmShPollCheck<CAmTelnetServer> telnetCheckCB; -private: - - typedef void (*CommandPrototype)(std::vector<std::string>& msg, int filedescriptor); - typedef std::map<std::string, CommandPrototype> mMapCommand_t; - - void sliceCommand(const std::string& string, std::string& command, std::queue<std::string>& msg); - mMapCommand_t createCommandMap(); - struct connection_s - { - int filedescriptor; - sh_pollHandle_t handle; - }; - - static CAmTelnetServer* mpInstance; - CAmSocketHandler *mpSocketHandler; - CAmCommandSender *mpCommandSender; - CAmCommandReceiver *mpCommandReceiver; - CAmRoutingSender *mpRoutingSender; - CAmRoutingReceiver *mpRoutingReceiver; - CAmControlSender *mpControlSender; - CAmControlReceiver *mpControlReceiver; - IAmDatabaseHandler *mpDatabasehandler; - CAmRouter *mpRouter; - sh_pollHandle_t mConnecthandle; - std::queue<std::string> mListMessages; - std::vector<connection_s> mListConnections; - int mConnectFD; - unsigned int mServerPort; - unsigned int mMaxConnections; - CAmTelnetMenuHelper mTelnetMenuHelper; - -}; - -} /* namespace am */ -#endif /* TELNETSERVER_H_ */ diff --git a/AudioManagerCore/src/CAmDatabaseObserver.cpp b/AudioManagerCore/src/CAmDatabaseObserver.cpp index acac639..d9ced92 100644 --- a/AudioManagerCore/src/CAmDatabaseObserver.cpp +++ b/AudioManagerCore/src/CAmDatabaseObserver.cpp @@ -29,7 +29,6 @@ #include <sys/ioctl.h> #include "CAmCommandSender.h" #include "CAmRoutingSender.h" -#include "CAmTelnetServer.h" #include "CAmDltWrapper.h" #include "CAmSerializer.h" diff --git a/AudioManagerCore/src/CAmTelnetMenuHelper.cpp b/AudioManagerCore/src/CAmTelnetMenuHelper.cpp deleted file mode 100644 index 2aae4f5..0000000 --- a/AudioManagerCore/src/CAmTelnetMenuHelper.cpp +++ /dev/null @@ -1,1438 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetMenuHelper.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmTelnetMenuHelper.h" -#include <cassert> -#include "audiomanagerconfig.h" -#include "CAmRouter.h" -#include "CAmTelnetServer.h" -#include "IAmDatabaseHandler.h" -#include "CAmControlSender.h" -#include "CAmCommandSender.h" -#include "CAmRoutingSender.h" -#include "CAmRoutingReceiver.h" -#include "CAmCommandReceiver.h" -#include "CAmControlReceiver.h" -#include "CAmDltWrapper.h" - -static const std::string COLOR_WELCOME("\033[1;33m\033[44m"); -static const std::string COLOR_HEAD("\033[1m\033[42m"); -static const std::string COLOR_DEFAULT("\033[0m"); - - -namespace am { - -CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL; - -/****************************************************************************/ -CAmTelnetMenuHelper::CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer) -/****************************************************************************/ -:mpTelenetServer(iTelnetServer), mpSocketHandler(iSocketHandler), mpCommandSender(iCommandSender), mpCommandReceiver(iCommandReceiver), mpRoutingSender(iRoutingSender), mpRoutingReceiver(iRoutingReceiver), mpControlSender(iControlSender), mpControlReceiver(iControlReceiver), mpDatabasehandler(iDatabasehandler), mpRouter(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("crfader", 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("mainconn", sCommandPrototypeInfo("list all main connections", &CAmTelnetMenuHelper::listMainConnectionsCommand))); - mListCommands.insert(std::make_pair("mainsinks", sCommandPrototypeInfo("list all main sinks", &CAmTelnetMenuHelper::listMainSinksCommand))); - mListCommands.insert(std::make_pair("mainsources", sCommandPrototypeInfo("list all main sources", &CAmTelnetMenuHelper::listMainSourcesCommand))); - 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))); - mSetCommands.insert(std::make_pair("disc", sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t this connection", &CAmTelnetMenuHelper::setDisconnectConnId))); - mSetCommands.insert(std::make_pair("sinkvolume", sCommandPrototypeInfo("use 'sinkvolume sinkID volume' to set \n\t absorption in db of sink", &CAmTelnetMenuHelper::setSinkVolume))); - mSetCommands.insert(std::make_pair("sinkvolstep", sCommandPrototypeInfo("use 'sinkvolstep sinkID volumestep' to increment \n\t or decrement volume", &CAmTelnetMenuHelper::setVolumeStep))); - mSetCommands.insert(std::make_pair("sinkprop", sCommandPrototypeInfo("use 'sinkprop type value' to set \n\t a specific sinksoundproperty", &CAmTelnetMenuHelper::setSinkSoundProperty))); - mSetCommands.insert(std::make_pair("sinkmute", sCommandPrototypeInfo("use 'sinkmute sinkid mutestate' to mute \n\t or unmute", &CAmTelnetMenuHelper::setSinkMuteState))); - mSetCommands.insert(std::make_pair("sourceprop", sCommandPrototypeInfo("use 'sourceprop type value' to set \n\t a specific sinksoundproperty", &CAmTelnetMenuHelper::setSourceSoundProperty))); - // 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("dump", sCommandPrototypeInfo("create a database dump of currently used data", &CAmTelnetMenuHelper::infoDumpCommand))); - 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::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(filedescriptor, state)); - // Send welcome message - welcome << COLOR_WELCOME << "Welcome to GENIVI AudioManager " << DAEMONVERSION << COLOR_DEFAULT << "\n>"; - assert(send(filedescriptor, welcome.str().c_str(), welcome.str().size(), 0)>=0); - logInfo("[TN] New connection: ", filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor) -/****************************************************************************/ -{ - std::map<int, EMainState>::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - mCurrentMainStateMap.erase(it); - } - else - { - logError("[TN] socketConnectionsClosed, fd not found, ", filedescriptor); - } -} - -/****************************************************************************/ -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) -/****************************************************************************/ -{ - assert(send(filedescriptor, error_string.c_str(), error_string.size(), 0)>=0); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::sendTelnetLine(int& filedescriptor, std::stringstream& line) -/****************************************************************************/ -{ - assert(send(filedescriptor, line.str().c_str(), line.str().size(), 0)>=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; - } - assert(send(filedescriptor, outputstream.str().c_str(), outputstream.str().size(), 0)>=0); - } - else - { - logInfo("[TN] sendCurrentCmdPrompt, fd not found: ", filedescriptor); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::exitCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->exitCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map<int, EMainState>::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - 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; - } - logInfo("[TN] oneStepBackCommandExec, state: ", it->second); - } - -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->oneStepBackCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map<int, EMainState>::iterator it; - std::stringstream line; - std::stringstream output; - // Sending a last message to the client - output << "bye!" << COLOR_DEFAULT << std::endl; - sendTelnetLine(filedescriptor, output); - tCommandMap::iterator iter; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - if (NULL != mpTelenetServer) - { - logInfo("[TN] exitCommandExec, removing fd ", filedescriptor); - mpTelenetServer->disconnectClient(filedescriptor); - mCurrentMainStateMap.erase(it); - } - else - { - logError("[TN] exitCommandExec, mpTelenetServer == NULL, fd ", filedescriptor); - } - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::helpCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->helpCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map<int, EMainState>::iterator it; - std::stringstream line; - tCommandMap::iterator cmdIter; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl; - line << COLOR_HEAD << "###### The following commands are supported: ######" << COLOR_DEFAULT << std::endl; - line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl << std::endl; - switch (it->second) - { - case eRootState: - cmdIter = mRootCommands.begin(); - while (cmdIter != mRootCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eListState: - cmdIter = mListCommands.begin(); - while (cmdIter != mListCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eGetState: - cmdIter = mGetCommands.begin(); - while (cmdIter != mGetCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eSetState: - cmdIter = mSetCommands.begin(); - while (cmdIter != mSetCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - case eInfoState: - cmdIter = mInfoCommands.begin(); - while (cmdIter != mInfoCommands.end()) - { - line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl; - cmdIter++; - } - break; - default: - break; - } - - sendTelnetLine(filedescriptor, line); - } - -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootGetCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map<int, EMainState>::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eGetState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootSetCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map<int, EMainState>::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eSetState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootListCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map<int, EMainState>::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eListState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->rootInfoCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::map<int, EMainState>::iterator it; - it = mCurrentMainStateMap.find(filedescriptor); - if (it != mCurrentMainStateMap.end()) - { - it->second = eInfoState; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listConnectionsCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listConnectionsCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Connection_s > listConnections; - if (E_OK == mpDatabasehandler->getListConnections(listConnections)) - { - std::stringstream output; - output << "\tConnections: " << listConnections.size() << std::endl; - for (std::vector<am_Connection_s>::iterator iter(listConnections.begin()); iter < listConnections.end(); iter++) - { - output << "\tID: " << iter->connectionID << "\tSrcID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << "\tFormat: " << iter->connectionFormat << "\tdelay: " << iter->delay << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListConnections"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listSourcesCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Source_s > listSources; - if (E_OK == mpDatabasehandler->getListSources(listSources)) - { - std::stringstream output; - output << "\tSources: " << listSources.size() << std::endl; - for (std::vector<am_Source_s>::iterator iter(listSources.begin()); iter < listSources.end(); iter++) - { - output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tDomainID: " << iter->domainID << "\tState: " << iter->sourceState << "\tVolume: " << iter->volume << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListSources"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listSinksCommandsExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Sink_s > listSinks; - if (E_OK == mpDatabasehandler->getListSinks(listSinks)) - { - std::stringstream output; - output << "\tSinks: " << listSinks.size() << std::endl; - for (std::vector<am_Sink_s>::iterator iter(listSinks.begin()); iter < listSinks.end(); iter++) - { - output << "\tID: " << iter->sinkID << "\tDomainID: " << iter->domainID << "\tName: " << iter->name << "\tAvailable: " << iter->available.availability << "\tVolume: " << iter->volume << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListSinks"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listCrossfadersExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Crossfader_s > listCrossfaders; - if (E_OK == mpDatabasehandler->getListCrossfaders(listCrossfaders)) - { - std::stringstream output; - output << "\tCrossfader: " << listCrossfaders.size() << std::endl; - for (std::vector<am_Crossfader_s>::iterator iter(listCrossfaders.begin()); iter < listCrossfaders.end(); iter++) - { - output << "\tID: " << iter->crossfaderID << "\tName: " << iter->name << "\tSinkA: " << iter->sinkID_A << "\tSinkB: " << iter->sinkID_B << "\tSourceID: " << iter->sourceID << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListCrossfaders"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listDomainsCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Domain_s > listDomains; - if (E_OK == mpDatabasehandler->getListDomains(listDomains)) - { - std::stringstream output; - output << "\tDomains: " << listDomains.size() << std::endl; - for (std::vector<am_Domain_s>::iterator iter(listDomains.begin()); iter < listDomains.end(); iter++) - { - output << "\tID: " << iter->domainID << "\tName: " << iter->name << "\tBusname: " << iter->busname << "\tNodename: " << iter->nodename << "\tState: " << static_cast<int>(iter->state) << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListDomains"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listGatewaysCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_Gateway_s > listGateways; - if (E_OK == mpDatabasehandler->getListGateways(listGateways)) - { - std::stringstream output; - output << "\tGateways: " << listGateways.size(); - for (std::vector<am_Gateway_s>::iterator iter(listGateways.begin()); iter < listGateways.end(); iter++) - { - output << "\tID: " << iter->gatewayID << "\tName: " << iter->name << "\tSourceID: " << iter->sourceID << "\tSinkID: " << iter->sinkID << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListGateways"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->getRoutingCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - (void) (filedescriptor); -//TODO: fill with function -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->getSenderversionCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::stringstream output; - std::string versionCommand; - std::string versionRouting; - std::string versionControl; - mpControlSender->getInterfaceVersion(versionControl); - mpRoutingSender->getInterfaceVersion(versionRouting); - mpCommandSender->getInterfaceVersion(versionCommand); - output << "\tSender versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; - sendTelnetLine(filedescriptor, output); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->getReceiverversionCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::stringstream output; - std::string versionCommand; - std::string versionRouting; - std::string versionControl; - mpControlReceiver->getInterfaceVersion(versionControl); - mpRoutingReceiver->getInterfaceVersion(versionRouting); - mpCommandReceiver->getInterfaceVersion(versionCommand); - output << "\tReceiver versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl; - sendTelnetLine(filedescriptor, output); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->infoSystempropertiesCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoDumpCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->infoDumpCommandExec(CmdQueue, filedescriptor); -} - - -/****************************************************************************/ -void CAmTelnetMenuHelper::setVolumeStep(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkVolumeExec(CmdQueue,filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setVolumeStepExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - int16_t volumestep = 0; - am_sinkID_t sinkID = 0; - bool error = false; - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_volumestep(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_volumestep >> volumestep)) - error = true; - - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing setVolumeStep 'sinkID' or 'volumestep'"); - return; - } - if (E_OK == mpCommandReceiver->volumeStep(sinkID,volumestep)) - { - std::stringstream output; - output << "SetSinkVolumeStep set: " << sinkID << "->" << volumestep << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error SetSinkVolumeStep"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set SetSinkVolumeStep, please enter 'sinkID' and 'volumestep' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkMuteState(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkMuteStateExec(CmdQueue,filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkMuteStateExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - u_int16_t tmp = 0; - am_MuteState_e MuteState = MS_UNKNOWN; - am_sinkID_t sinkID = 0; - bool error = false; - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_mutestate(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_mutestate >> tmp)) - error = true; - - if (!(istream_sinkID >> sinkID)) - error = true; - - if(tmp < MS_MAX) - { - MuteState = static_cast<am_MuteState_e>(tmp); - } - else - { - sendError(filedescriptor, "You tried to set an invalid am_MuteState_e"); - error = true; - } - - if (error) - { - sendError(filedescriptor, "Error parsing setSinkMuteState 'sinkID' or 'mutestate'"); - return; - } - if (E_OK == mpCommandReceiver->setSinkMuteState(sinkID,MuteState)) - { - std::stringstream output; - output << "setSinkMuteState set: " << sinkID << "->" << MuteState << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setSinkMuteState"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set setSinkMuteState, please enter 'sinkID' and 'mutestate' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSourceSoundProperty(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSourceSoundPropertiesExec(CmdQueue,filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSourceSoundPropertyExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - 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; - - am_MainSoundProperty_s soundProperty; - soundProperty.type = static_cast<am_CustomMainSoundPropertyType_t>(tmpType); - - if (!(istream_value >> soundProperty.value)) - error = true; - - am_sourceID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing setMainSourceSoundProperty 'type', 'value' or 'sourceID'"); - return; - } - if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID)) - { - std::stringstream output; - output << "setMainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setMainSourceSoundProperty"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set setMainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command"); - return; - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_SystemProperty_s > listSystemProperties; - if (E_OK == mpDatabasehandler->getListSystemProperties(listSystemProperties)) - { - std::stringstream output; - output << "\tSystemproperties: " << listSystemProperties.size() << std::endl; - std::vector<am_SystemProperty_s>::iterator it; - for (it = listSystemProperties.begin(); it < listSystemProperties.end(); it++) - { - output << "\tType: " << it->type << " Value: " << it->value << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListSystemProperties"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::infoDumpCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - - std::stringstream *pOutput = new std::stringstream(); - - mpDatabasehandler->dump(*pOutput); - - sendTelnetLine(filedescriptor, *pOutput); - - delete pOutput; -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setRoutingCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - bool error = false; - std::istringstream istream_sourceID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - am_sourceID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - am_sinkID_t sinkID = 0; - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing sourcID and sinkID"); - return; - } - std::vector < am_Route_s > routingList; - if (E_OK == mpRouter->getRoute(true, sourceID, sinkID, routingList)) - { - std::stringstream output; - 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++) - { - output << ">(" << reIter->sourceID << ")->--[D:" << reIter->domainID << "][F:" << reIter->connectionFormat << "]-->-(" << reIter->sinkID << ")" << std::endl; - } - rlCnt++; - } - - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error getting route"); - } - } - else - { - if (!CmdQueue.empty()) - CmdQueue.pop(); - - sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setConnection(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setConnectionExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setConnectionExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - 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(); - am_sourceID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - am_sinkID_t sinkID = 0; - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing sinkID and/or sourceID"); - return; - } -// Try to set up connection - am_mainConnectionID_t connID = 0; - rError = mpCommandReceiver->connect(sourceID, sinkID, connID); - if (E_OK == rError) - { - std::stringstream output; - output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error connecting sourceID and sinkID"); - } - } - else - { -// remove 1 element if list is not empty - if (!CmdQueue.empty()) - 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->setDisconnectConnIdExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - 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 = mpCommandReceiver->disconnect(connID); - if (E_OK == rError) - { - std::stringstream output; - output << "ConnID " << connID << " closed successfully! " << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error disconnecting connectionID"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to disconnect a Main Connection, please enter 'connectionID' 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) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 3) - { - bool error = false; - std::istringstream istream_sourceID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_type(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_value(CmdQueue.front()); - CmdQueue.pop(); - unsigned int tmpType = 0; - if (!(istream_type >> tmpType)) - error = true; - - am_MainSoundProperty_s soundProperty; - soundProperty.type = static_cast<am_CustomMainSoundPropertyType_t>(tmpType); - - if (!(istream_value >> soundProperty.value)) - error = true; - - am_sinkID_t sourceID = 0; - if (!(istream_sourceID >> sourceID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'"); - return; - } - if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID)) - { - std::stringstream output; - 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::setSinkSoundProperty(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkSoundPropertyExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkSoundPropertyExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - 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; - - am_MainSoundProperty_s soundProperty; - soundProperty.type = static_cast<am_CustomMainSoundPropertyType_t>(tmpType); - - if (!(istream_value >> soundProperty.value)) - error = true; - - am_sinkID_t sinkID = 0; - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'"); - return; - } - if (E_OK == mpCommandReceiver->setMainSinkSoundProperty(soundProperty, sinkID)) - { - std::stringstream output; - 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::setSinkVolume(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->setSinkVolumeExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::setSinkVolumeExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - if (CmdQueue.size() >= 2) - { - am_volume_t volume = 0; - am_sinkID_t sinkID = 0; - bool error = false; - std::istringstream istream_sinkID(CmdQueue.front()); - CmdQueue.pop(); - std::istringstream istream_volume(CmdQueue.front()); - CmdQueue.pop(); - if (!(istream_volume >> volume)) - error = true; - - if (!(istream_sinkID >> sinkID)) - error = true; - - if (error) - { - sendError(filedescriptor, "Error parsing SetSinkVolume 'sinkID' or 'volume'"); - return; - } - if (E_OK == mpCommandReceiver->setVolume(sinkID,volume)) - { - std::stringstream output; - output << "setVolume set: " << sinkID << "->" << volume << std::endl; - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "Error setVolume"); - } - } - else - { - sendError(filedescriptor, "Not enough arguments to set setVolume, please enter 'sinkID' and 'volume' 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) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < std::string > PlugInNames; - std::vector<std::string>::iterator iter; - std::stringstream output; - if (E_OK == mpCommandSender->getListPlugins(PlugInNames)) - { - output << "\tCommandSender Plugins loaded: " << PlugInNames.size() << std::endl; - for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++) - { - output << iter->c_str() << std::endl; - } - } - else - { - sendError(filedescriptor, "ERROR: mCommandSender->getListPlugins"); - } - if (E_OK == mpRoutingSender->getListPlugins(PlugInNames)) - { - output << std::endl << "\tRoutingSender Plugins loaded: " << PlugInNames.size() << std::endl; - for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++) - { - output << iter->c_str() << std::endl; - } - } - else - { - sendError(filedescriptor, "ERROR: mRoutingSender->getListPlugins"); - } - sendTelnetLine(filedescriptor, output); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSourcesCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listMainSourcesCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSourcesCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_SourceType_s > listMainSources; - if (E_OK == mpDatabasehandler->getListMainSources(listMainSources)) - { - std::stringstream output; - output << std::endl << "\tMainSources: " << listMainSources.size() << std::endl; - std::vector<am_SourceType_s>::iterator iter; - for (iter = listMainSources.begin(); iter < listMainSources.end(); iter++) - { - output << "\tID: " << iter->sourceID << "\tName: " << iter->name << "\tsourceClassID: " << iter->sourceClassID << "\tavailability: " << iter->availability.availability << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSources"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSinksCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listMainSinksCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainSinksCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector < am_SinkType_s > listMainSinks; - if (E_OK == mpDatabasehandler->getListMainSinks(listMainSinks)) - { - std::stringstream output; - output << std::endl << "\tMainSinks: " << listMainSinks.size() << std::endl; - std::vector<am_SinkType_s>::iterator iter; - for (iter = listMainSinks.begin(); iter < listMainSinks.end(); iter++) - { - output << "\tID: " << iter->sinkID << "\tsinkClassID: " << iter->sinkClassID << "\tName: " << iter->name << "\tAvailable: " << iter->availability.availability << "\tVolume: " << iter->volume << std::endl; - } - sendTelnetLine(filedescriptor, output); - } - else - { - sendError(filedescriptor, "ERROR: mDatabasehandler->getListMainSinks"); - } -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainConnectionsCommand(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - instance->listMainConnectionsCommandExec(CmdQueue, filedescriptor); -} - -/****************************************************************************/ -void CAmTelnetMenuHelper::listMainConnectionsCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor) -/****************************************************************************/ -{ - (void) (CmdQueue); - std::vector<am_MainConnection_s> listMainConnections; - - if(E_OK == mpDatabasehandler->getListMainConnections(listMainConnections)) - { - std::stringstream output; - output << std::endl << "\tMainConnections: " << listMainConnections.size() << std::endl; - - std::vector<am_MainConnection_s>::iterator iter; - for (iter = listMainConnections.begin(); iter < listMainConnections.end(); iter++) - { - output << "\tID: " << iter->mainConnectionID - << "\tState: " << iter->connectionState - << "\tDelay: " << iter->delay - << "\tsourceID: " << iter->sourceID - << "\tsinkID: " << iter->sinkID << std::endl; - - output << "ConnectionIDs: "; - std::vector<am_connectionID_t>::iterator list_connIDs_iter = iter->listConnectionID.begin(); - for(;list_connIDs_iter < iter->listConnectionID.end();list_connIDs_iter++) - { - output << *list_connIDs_iter << " "; - } - - output << std::endl; - } - sendTelnetLine(filedescriptor,output); - } - else - { - sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks"); - } -} -} - - - - - diff --git a/AudioManagerCore/src/CAmTelnetServer.cpp b/AudioManagerCore/src/CAmTelnetServer.cpp deleted file mode 100755 index 22f7b0e..0000000 --- a/AudioManagerCore/src/CAmTelnetServer.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * \file CAmTelnetServer.cpp - * For further information see http://www.genivi.org/. - * - */ - -#include "CAmTelnetServer.h" -#include <cassert> -#include <sys/socket.h> -#include <arpa/inet.h> -#include <sys/ioctl.h> -#include <string.h> -#include <netdb.h> -#include <audiomanagerconfig.h> -#include <errno.h> -#include <sstream> -#include <istream> -#include <iostream> -#include <iterator> -#include <unistd.h> -#include <stdexcept> -#include <cstdlib> -#include "CAmRoutingSender.h" -#include "CAmTelnetMenuHelper.h" -#include "CAmDltWrapper.h" - -namespace am -{ - -CAmTelnetServer* CAmTelnetServer::mpInstance = NULL; - -#define PRINT_BOOL(var) var ? output+="true\t\t" : output+="false\t\t"; - -CAmTelnetServer::CAmTelnetServer(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, unsigned int servPort, unsigned int maxConnections) : - telnetConnectFiredCB(this, &CAmTelnetServer::connectSocket), // - telnetReceiveFiredCB(this, &CAmTelnetServer::receiveData), // - telnetDispatchCB(this, &CAmTelnetServer::dispatchData), // - telnetCheckCB(this, &CAmTelnetServer::check), // - mpSocketHandler(iSocketHandler), // - mpCommandSender(iCommandSender), // - mpCommandReceiver(iCommandReceiver), // - mpRoutingSender(iRoutingSender), // - mpRoutingReceiver(iRoutingReceiver), // - mpControlSender(iControlSender), // - mpControlReceiver(iControlReceiver), // - mpDatabasehandler(iDatabasehandler), // - mpRouter(iRouter), // - mConnecthandle(), // - mListMessages(), // - mListConnections(), // - mConnectFD(0), // - mServerPort(servPort), // - mMaxConnections(maxConnections), // - mTelnetMenuHelper(iSocketHandler, iCommandSender, iCommandReceiver, iRoutingSender, iRoutingReceiver, iControlSender, iControlReceiver, iDatabasehandler, iRouter, this) -{ - assert(mpSocketHandler!=NULL); - assert(mpCommandReceiver!=NULL); - assert(mpCommandSender!=NULL); - assert(mpControlSender!=NULL); - assert(mpControlReceiver!=NULL); - assert(mpRoutingSender!=NULL); - assert(mpRoutingReceiver!=NULL); - assert(mpDatabasehandler!=NULL); - assert(mpRouter!=NULL); - assert(servPort!=0); - assert(mMaxConnections!=0); - - mpInstance = this; - //mTelnetMenuHelper.setTelnetServer(this); - - int yes = 1; - struct sockaddr_in servAddr; - - //setup the port Listener - mConnectFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - assert (mConnectFD>0); - assert(setsockopt(mConnectFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))==0); - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = INADDR_ANY; - servAddr.sin_port = htons(servPort); - if(bind(mConnectFD, (struct sockaddr *) &servAddr, sizeof(servAddr))!=0) - { - logError("CAmTelnetServer::CAmTelnetServer bind failed, error",errno); - throw std::runtime_error("CAmTelnetServer::CAmTelnetServer bind failed"); - } - - if (listen(mConnectFD, mMaxConnections) < 0) - { - logError("TelnetServer::TelnetServerk cannot listen ", errno); - throw std::runtime_error("CAmTelnetServer::CAmTelnetServer bind failed"); - } - else - logInfo("TelnetServer::TelnetServer started listening on port", mServerPort); - - int a = 1; - ioctl(mConnectFD, FIONBIO, (char *) &a); - setsockopt(mConnectFD, SOL_SOCKET, SO_KEEPALIVE, (char *) &a, sizeof(a)); - - short events = 0; - events |= POLLIN; - mpSocketHandler->addFDPoll(mConnectFD, events, NULL, &telnetConnectFiredCB, NULL, NULL, NULL, mConnecthandle); -} - -CAmTelnetServer::~CAmTelnetServer() -{ -} - -void CAmTelnetServer::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.handle = 0; - connection.filedescriptor = accept(pfd.fd, (struct sockaddr*) &answer, &len); - - assert(connection.filedescriptor>0); - - // Notiy menuhelper - mTelnetMenuHelper.newSocketConnection(connection.filedescriptor); - - //set the correct event: - short event = 0; - event |= POLLIN; - - //add the filedescriptor to the sockethandler and register the callbacks for receiving the data - mpSocketHandler->addFDPoll(connection.filedescriptor, event, NULL, &telnetReceiveFiredCB, &telnetCheckCB, &telnetDispatchCB, NULL, connection.handle); - mListConnections.push_back(connection); -} - -void CAmTelnetServer::disconnectClient(int filedescriptor) -{ - std::vector<connection_s>::iterator iter = mListConnections.begin(); - while (iter != mListConnections.end()) - { - if (filedescriptor == iter->filedescriptor) - { - if (E_OK == mpSocketHandler->removeFDPoll(iter->handle)) - { - mListConnections.erase(iter); - close(filedescriptor); - } - else - { - // TODO: Handle error - } - - break; - } - iter++; - } -} - -void CAmTelnetServer::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, 0); - 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); - mListMessages.push(msg); - } -} - -bool CAmTelnetServer::dispatchData(const sh_pollHandle_t handle, void *userData) -{ - (void) userData; - std::vector<connection_s>::iterator iterator = mListConnections.begin(); - for (; iterator != mListConnections.end(); ++iterator) - { - if (iterator->handle == handle) - break; - } - if (iterator==mListConnections.end()) - { - logError("CAmTelnetServer::dispatchData could not find handle !"); - return (false); - } - - std::string command; - std::queue<std::string> MsgQueue; - if (!mListMessages.empty()) - { - sliceCommand(mListMessages.front(), command, MsgQueue); - mListMessages.pop(); - mTelnetMenuHelper.enterCmdQueue(MsgQueue, iterator->filedescriptor); - } - else - { - logError("CAmTelnetServer::dispatchData Message queue was empty!"); - } - - // must return false to stop endless polling - return (false); -} - -bool CAmTelnetServer::check(const sh_pollHandle_t handle, void *userData) -{ - (void) handle; - (void) userData; - if (mListMessages.size() != 0) - return (true); - return (false); -} - -void am::CAmTelnetServer::sliceCommand(const std::string & string, std::string & command, std::queue<std::string> & MsgQueue) -{ - (void) command; - std::stringstream stream(string); - std::istream_iterator<std::string> begin(stream); - std::istream_iterator<std::string> end; - std::string cmd; - bool endOfStream = false; - - int c = 0; - - while (!endOfStream) - { - cmd = *begin; - MsgQueue.push(cmd); - begin++; - - if (begin == end) - { - endOfStream = true; - } - c++; - } -} -} - diff --git a/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp deleted file mode 100644 index d3f7a11..0000000 --- a/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#include <sys/socket.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <string> - -#include "CAmTelnetServerTest.h" -#include "CAmCommandReceiver.h" -#include "CAmRoutingReceiver.h" -#include "CAmControlReceiver.h" -#include "audiomanagerconfig.h" - - -using namespace testing; -using namespace am; -using namespace std; - - -static std::string controllerPlugin = std::string(CONTROLLER_PLUGIN_DIR); -static unsigned short servPort = 6060; -static int staticSocket = -1; -static CAmSocketHandler* mpSocketHandler = NULL; - -void* startSocketHandler(void* data) -{ - CAmEnvironment* Env = static_cast<CAmEnvironment*>(data); - Env->setSocketHandler(&Env->mSocketHandler); - Env->mSocketHandler.start_listenting(); - Env->setSocketHandler(NULL); - return (NULL); -} - -CAmEnvironment::CAmEnvironment() -: mlistRoutingPluginDirs() -, mlistCommandPluginDirs() -, mSocketHandler() -, mDatabasehandler() -, mRoutingSender(mlistRoutingPluginDirs) -, mCommandSender(mlistRoutingPluginDirs) -, mRouter(&mDatabasehandler,&mControlSender) -, mpCommandReceiver(NULL) -, mpRoutingReceiver(NULL) -, mpControlReceiver(NULL) -, mpTelnetServer(NULL) -, mSocketHandlerThread(0) -{ -} - -CAmEnvironment::~CAmEnvironment() -{ - usleep(500); - if(NULL != mpTelnetServer) - delete(mpTelnetServer); - if(NULL != mpControlReceiver) - delete(mpControlReceiver); - if(NULL != mpRoutingReceiver) - delete(mpRoutingReceiver); - if(NULL != mpCommandReceiver) - delete(mpCommandReceiver); -} - -void CAmEnvironment::SetUp() -{ - pthread_create(&mSocketHandlerThread, NULL, startSocketHandler, this); - sleep(1); -} - -void CAmEnvironment::TearDown() -{ - pthread_cancel(mSocketHandlerThread); -} - -void CAmEnvironment::setSocketHandler(CAmSocketHandler* pSocketHandler) -{ - mpSocketHandler = pSocketHandler; - - if(NULL != pSocketHandler) - { - mpCommandReceiver = new CAmCommandReceiver(&mDatabasehandler,&mControlSender,mpSocketHandler); - mpRoutingReceiver = new CAmRoutingReceiver(&mDatabasehandler,&mRoutingSender,&mControlSender,mpSocketHandler); - mpControlReceiver = new CAmControlReceiver(&mDatabasehandler,&mRoutingSender,&mCommandSender,mpSocketHandler,&mRouter); - - //startup all the Plugins and Interfaces - //mControlSender.startupController(mpControlReceiver); - //mCommandSender.startupInterfaces(mpCommandReceiver); - //mRoutingSender.startupInterfaces(mpRoutingReceiver); - - //when the routingInterface is done, all plugins are loaded: - //mControlSender.setControllerReady(); - - // Starting TelnetServer - mpTelnetServer = new CAmTelnetServer(mpSocketHandler,&mCommandSender,mpCommandReceiver,&mRoutingSender,mpRoutingReceiver,&mControlSender,mpControlReceiver,&mDatabasehandler,&mRouter,servPort,3); - } -} - -void CAmEnvironment::stopSocketHandler() -{ - mpSocketHandler->stop_listening(); -} - -CAmTelnetServerTest::CAmTelnetServerTest() -{ - -} - -CAmTelnetServerTest::~CAmTelnetServerTest() -{ - -} - -void CAmTelnetServerTest::SetUp() -{ - -} - -void CAmTelnetServerTest::TearDown() -{ - -} - -void CAmTelnetServerTest::sendCmd(std::string & command ) -{ - ssize_t sizesent = send(staticSocket, command.c_str(), command.size(), 0); - ASSERT_EQ(static_cast<uint>(sizesent),command.size()); - - char buffer[1000]; - memset(buffer,0,sizeof(buffer)); - int read=recv(staticSocket,buffer,sizeof(buffer),0); - ASSERT_GT(read,1); -} - -TEST_F(CAmTelnetServerTest,connectTelnetServer) -{ - struct sockaddr_in servAddr; - - staticSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - ASSERT_GE(staticSocket,0); - - struct hostent *host = (struct hostent*) gethostbyname("localhost"); - if (host == 0) - { - std::cout << " ERROR: gethostbyname() failed\n" << std::endl; - return; - } - - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = inet_addr(inet_ntoa(*(struct in_addr*) (host->h_addr_list[0]))); - servAddr.sin_port = htons(servPort); - - int return_connect = connect(staticSocket, (struct sockaddr *) &servAddr, sizeof(servAddr)); - ASSERT_GE(return_connect,0); - - char buffer[1000]; - int read=recv(staticSocket,buffer,sizeof(buffer),0); - ASSERT_GT(read,1); -} - -TEST_F(CAmTelnetServerTest,sendCmdTelnetServer) -{ - std::string cmd("help"); - sendCmd(cmd); -} - -TEST_F(CAmTelnetServerTest,sendDumpCmdTelnetServer) -{ - std::string cmd1("info"); - std::string cmd3("dump"); - sendCmd(cmd1); - sendCmd(cmd3); -} - -TEST_F(CAmTelnetServerTest,closeTelnetServerConnection) -{ - std::string cmd("exit"); - mpSocketHandler->stop_listening(); - sendCmd(cmd); - close(staticSocket); - staticSocket = -1; -} - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - ::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new CAmEnvironment); - (void) env; - return RUN_ALL_TESTS(); -} diff --git a/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h b/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h deleted file mode 100644 index 02f98a3..0000000 --- a/AudioManagerCore/test/AmTelnetServerTest/CAmTelnetServerTest.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - * SPDX license identifier: MPL-2.0 - * - * Copyright (C) 2012, BMW AG - * - * This file is part of GENIVI Project AudioManager. - * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 - * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012 - * - * For further information see http://www.genivi.org/. - * - */ - -#ifndef CAMTELNETSERVERTEST_H_ -#define CAMTELNETSERVERTEST_H_ - -#include "gtest/gtest.h" -#include "CAmTelnetServer.h" -#include "CAmRoutingSender.h" -#include "CAmCommandSender.h" -#include "CAmControlSender.h" -#include "CAmRouter.h" -#include "audiomanagerconfig.h" -#include "CAmDatabaseHandlerMap.h" - - - - - -namespace am -{ - -class CAmSocketHandler; -class CAmRoutingSender; -class CAmCommandSender; -class CAmControlSender; -class CAmRouter; -class CAmCommandReceiver; -class CAmRoutingReceiver; -class CAmControlReceiver; -class CAmTelnetServer; - - -class CAmEnvironment : public ::testing::Environment -{ - public: - CAmEnvironment(); - - ~CAmEnvironment(); - // Override this to define how to set up the environment. - void SetUp(); - // Override this to define how to tear down the environment. - void TearDown(); - - void setSocketHandler(CAmSocketHandler* pSocketHandler); - - void stopSocketHandler(); - - std::vector<std::string> mlistRoutingPluginDirs; - std::vector<std::string> mlistCommandPluginDirs; - - CAmSocketHandler mSocketHandler; - CAmDatabaseHandlerMap mDatabasehandler; - CAmRoutingSender mRoutingSender; - CAmCommandSender mCommandSender; - CAmControlSender mControlSender; - CAmRouter mRouter; - - CAmCommandReceiver* mpCommandReceiver; - CAmRoutingReceiver* mpRoutingReceiver; - CAmControlReceiver* mpControlReceiver; - - CAmTelnetServer* mpTelnetServer; - - pthread_t mSocketHandlerThread; -}; - -class CAmTelnetServerTest : public ::testing::Test -{ - public: - CAmTelnetServerTest(); - ~CAmTelnetServerTest(); - - - void SetUp() ; - - void TearDown() ; - void sendCmd(std::string & command ); - //int mSocket; -}; - -} - - - - -#endif /* CAMTELNETSERVERTEST_H_ */ diff --git a/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt b/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt deleted file mode 100644 index 746edb5..0000000 --- a/AudioManagerCore/test/AmTelnetServerTest/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 2012, BMW AG -# -# This file is part of GENIVI Project AudioManager. -# -# Contributions are licensed to the GENIVI Alliance under one or more -# Contribution License Agreements. -# -# copyright -# This Source Code Form is subject to the terms of the -# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with -# this file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# author Christian Linke, christian.linke@bmw.de BMW 2011,2012 -# -# For further information see http://www.genivi.org/. -# - -cmake_minimum_required(VERSION 3.0) - -PROJECT(AmTelnetServerTest LANGUAGES CXX VERSION ${DAEMONVERSION}) - -INCLUDE_DIRECTORIES( - ${AUDIOMANAGER_CORE_INCLUDE} - ${GMOCK_INCLUDE_DIRS} - ${GTEST_INCLUDE_DIRS}) - -file(GLOB TELNET_SRCS_CXX - "*.cpp" -) - -ADD_EXECUTABLE(AmTelnetServerTest ${TELNET_SRCS_CXX}) - -TARGET_LINK_LIBRARIES(AmTelnetServerTest - ${GTEST_LIBRARIES} - ${GMOCK_LIBRARIES} - AudioManagerCore -) -#add_test(AmTelnetServerTest AmTelnetServerTest) - -ADD_DEPENDENCIES(AmTelnetServerTest AudioManagerCore) - -INSTALL(TARGETS AmTelnetServerTest - DESTINATION ${TEST_EXECUTABLE_INSTALL_PATH} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ - COMPONENT tests -) - - diff --git a/AudioManagerCore/test/CMakeLists.txt b/AudioManagerCore/test/CMakeLists.txt index 9dd9007..47658b4 100644 --- a/AudioManagerCore/test/CMakeLists.txt +++ b/AudioManagerCore/test/CMakeLists.txt @@ -29,7 +29,3 @@ add_subdirectory (AmRouterTest) add_subdirectory (AmRouterMapTest) add_subdirectory (AmRoutingInterfaceTest) -IF(WITH_TELNET) - add_subdirectory (AmTelnetServerTest) -ENDIF(WITH_TELNET) - |