2 * Copyright (C) 2012, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file CAmTelnetMenuHelper.h
9 * \author Frank Herchet (frank.fh.herchet@bmw.de)
12 * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13 * Copyright (C) 2012, BMW AG Frank Herchet frank.fh.herchet@bmw.de
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 2.1, for more details.
17 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20 * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21 * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
26 #ifndef CAMTELNETMENUHELPER_H_
27 #define CAMTELNETMENUHELPER_H_
38 #include <sys/socket.h>
39 #include <audiomanagertypes.h>
45 class DatabaseHandler;
49 class CommandReceiver;
50 class RoutingReceiver;
51 class ControlReceiver;
55 class CAmTelnetMenuHelper
61 eRootState = 0, eListState, eInfoState, eGetState, eSetState
64 CAmTelnetMenuHelper(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter);
66 ~CAmTelnetMenuHelper();
68 void setTelnetServer(TelnetServer* iTelnetServer);
70 void newSocketConnection(int filedescriptor);
72 void socketConnectionsClosed(int filedescriptor);
74 void enterCmdQueue(std::queue<std::string> &CmdQueue, int &filedescriptor);
78 void createCommandMaps();
79 void sendError(int & filedescriptor, std::string error_string);
80 void sendTelnetLine(int & filedescriptor, std::stringstream &line);
81 void sendCurrentCmdPrompt(int &filedescriptor);
84 static void oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
85 void oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
86 static void exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
87 void exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
88 static void helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
89 void helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
92 static void rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
93 void rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
94 static void rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
95 void rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
96 static void rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
97 void rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
98 static void rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
99 void rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
102 static void listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
103 void listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
104 static void listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
105 void listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
106 static void listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor);
107 void listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
108 static void listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor);
109 void listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
110 static void listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
111 void listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
112 static void listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
113 void listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
114 static void listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
115 void listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
118 static void setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
119 void setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
120 static void setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor);
121 void setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
122 static void setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor);
123 void setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
124 static void setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor);
125 void setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
126 static void setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor);
127 void setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
130 static void getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
131 void getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
132 static void getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
133 void getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
134 static void getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
135 void getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
138 static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
139 void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
143 typedef void (*pCommandPrototype)(std::queue<std::string>& msg, int & filedescriptor);
145 struct sCommandPrototypeInfo
148 pCommandPrototype CommandPrototype;
150 // default contructor to set NULL
151 sCommandPrototypeInfo() :
152 info(""), CommandPrototype(NULL)
156 // a small contructor
157 sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) :
158 info(MyInfo), CommandPrototype(MyCommandPrototype)
163 typedef std::map<std::string, sCommandPrototypeInfo> tCommandMap;
165 // int filedescriptor of socket connection; EMainState state of current telnet session
166 std::map<int, EMainState> mCurrentMainStateMap;
168 static CAmTelnetMenuHelper* instance;
169 TelnetServer *mTelenetServer;
170 SocketHandler *mSocketHandler;
171 CommandSender *mCommandSender;
172 CommandReceiver *mCommandReceiver;
173 RoutingSender *mRoutingSender;
174 RoutingReceiver *mRoutingReceiver;
175 ControlSender *mControlSender;
176 ControlReceiver *mControlReceiver;
177 DatabaseHandler *mDatabasehandler;
180 tCommandMap mRootCommands;
181 tCommandMap mListCommands;
182 tCommandMap mGetCommands;
183 tCommandMap mSetCommands;
184 tCommandMap mInfoCommands;
187 // class CAmTelnetMenuHelper
190 #endif // CAMTELNETMENUHELPER_H_