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;
56 class CAmTelnetMenuHelper
62 eRootState = 0, eListState, eInfoState, eGetState, eSetState
65 CAmTelnetMenuHelper(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter, TelnetServer *iTelnetServer);
67 ~CAmTelnetMenuHelper();
69 void setTelnetServer(TelnetServer* iTelnetServer);
71 void newSocketConnection(int filedescriptor);
73 void socketConnectionsClosed(int filedescriptor);
75 void enterCmdQueue(std::queue<std::string> &CmdQueue, int &filedescriptor);
79 void createCommandMaps();
80 void sendError(int & filedescriptor, std::string error_string);
81 void sendTelnetLine(int & filedescriptor, std::stringstream &line);
82 void sendCurrentCmdPrompt(int &filedescriptor);
85 static void oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
86 void oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
87 static void exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
88 void exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
89 static void helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
90 void helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
93 static void rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
94 void rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
95 static void rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
96 void rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
97 static void rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
98 void rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
99 static void rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
100 void rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
103 static void listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
104 void listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
105 static void listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
106 void listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
107 static void listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor);
108 void listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
109 static void listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor);
110 void listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
111 static void listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
112 void listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
113 static void listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
114 void listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
115 static void listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
116 void listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
119 static void setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
120 void setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
121 static void setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor);
122 void setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
123 static void setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor);
124 void setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
125 static void setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor);
126 void setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
127 static void setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor);
128 void setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
131 static void getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
132 void getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
133 static void getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
134 void getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
135 static void getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
136 void getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
139 static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
140 void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
144 typedef void (*pCommandPrototype)(std::queue<std::string>& msg, int & filedescriptor);
146 struct sCommandPrototypeInfo
149 pCommandPrototype CommandPrototype;
151 // default contructor to set NULL
152 sCommandPrototypeInfo() :
153 info(""), CommandPrototype(NULL)
157 // a small contructor
158 sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) :
159 info(MyInfo), CommandPrototype(MyCommandPrototype)
164 typedef std::map<std::string, sCommandPrototypeInfo> tCommandMap;
166 // int filedescriptor of socket connection; EMainState state of current telnet session
167 std::map<int, EMainState> mCurrentMainStateMap;
169 static CAmTelnetMenuHelper* instance;
170 TelnetServer *mTelenetServer;
171 SocketHandler *mSocketHandler;
172 CommandSender *mCommandSender;
173 CommandReceiver *mCommandReceiver;
174 RoutingSender *mRoutingSender;
175 RoutingReceiver *mRoutingReceiver;
176 ControlSender *mControlSender;
177 ControlReceiver *mControlReceiver;
178 DatabaseHandler *mDatabasehandler;
181 tCommandMap mRootCommands;
182 tCommandMap mListCommands;
183 tCommandMap mGetCommands;
184 tCommandMap mSetCommands;
185 tCommandMap mInfoCommands;
188 // class CAmTelnetMenuHelper
191 #endif // CAMTELNETMENUHELPER_H_