2 * Copyright (C) 2012, BMW AG
4 * This file is part of GENIVI Project AudioManager.
6 * Contributions are licensed to the GENIVI Alliance under one or more
7 * Contribution License Agreements.
10 * This Source Code Form is subject to the terms of the
11 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
12 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
16 * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012
18 * \file CAmTelnetMenuHelper.h
19 * For further information see http://www.genivi.org/.
24 #ifndef CAMTELNETMENUHELPER_H_
25 #define CAMTELNETMENUHELPER_H_
34 #include <sys/socket.h>
35 #include "audiomanagertypes.h"
40 class CAmTelnetServer;
41 class IAmDatabaseHandler;
42 class CAmCommandSender;
43 class CAmRoutingSender;
44 class CAmControlSender;
45 class CAmCommandReceiver;
46 class CAmRoutingReceiver;
47 class CAmControlReceiver;
50 class CAmSocketHandler;
53 * helper class for CAmTelnetServer
55 class CAmTelnetMenuHelper
61 eRootState = 0, eListState, eInfoState, eGetState, eSetState
64 CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, IAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer);
66 ~CAmTelnetMenuHelper();
68 void newSocketConnection(int filedescriptor);
70 void socketConnectionsClosed(int filedescriptor);
72 void enterCmdQueue(std::queue<std::string> &CmdQueue, int &filedescriptor);
76 void createCommandMaps();
77 void sendError(int & filedescriptor, std::string error_string);
78 void sendTelnetLine(int & filedescriptor, std::stringstream &line);
79 void sendCurrentCmdPrompt(int &filedescriptor);
82 static void oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
83 void oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
84 static void exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
85 void exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
86 static void helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
87 void helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
90 static void rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
91 void rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
92 static void rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
93 void rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
94 static void rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
95 void rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
96 static void rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
97 void rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
100 static void listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
101 void listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
102 static void listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
103 void listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
104 static void listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor);
105 void listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
106 static void listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor);
107 void listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
108 static void listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
109 void listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
110 static void listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
111 void listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
112 static void listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
113 void listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
114 static void listMainConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
115 void listMainConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
116 static void listMainSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
117 void listMainSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
118 static void listMainSinksCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
119 void listMainSinksCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
122 static void setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
123 void setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
124 static void setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor);
125 void setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
126 static void setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor);
127 void setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
128 static void setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor);
129 void setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
130 static void setSinkSoundProperty(std::queue<std::string> & CmdQueue, int & filedescriptor);
131 void setSinkSoundPropertyExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
132 static void setSinkVolume(std::queue<std::string> & CmdQueue, int & filedescriptor);
133 void setSinkVolumeExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
134 static void setVolumeStep(std::queue<std::string> & CmdQueue, int & filedescriptor);
135 void setVolumeStepExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
136 static void setSinkMuteState(std::queue<std::string> & CmdQueue, int & filedescriptor);
137 void setSinkMuteStateExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
138 static void setSourceSoundProperty(std::queue<std::string> & CmdQueue, int & filedescriptor);
139 void setSourceSoundPropertyExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
142 static void getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
143 void getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
144 static void getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
145 void getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
146 static void getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
147 void getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
150 static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
151 void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
152 static void infoDumpCommand(std::queue<std::string>& CmdQueue, int& filedescriptor);
153 void infoDumpCommandExec(std::queue<std::string>& CmdQueue, int& filedescriptor);
157 typedef void (*pCommandPrototype)(std::queue<std::string>& msg, int & filedescriptor);
159 struct sCommandPrototypeInfo
162 pCommandPrototype CommandPrototype;
164 // default contructor to set NULL
165 sCommandPrototypeInfo() :
166 info(""), CommandPrototype(NULL)
170 // a small contructor
171 sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) :
172 info(MyInfo), CommandPrototype(MyCommandPrototype)
177 typedef std::map<std::string, sCommandPrototypeInfo> tCommandMap;
178 std::map<int, EMainState> mCurrentMainStateMap; //!< int filedescriptor of socket connection; EMainState state of current telnet session
180 static CAmTelnetMenuHelper* instance;
181 CAmTelnetServer *mpTelenetServer;
182 CAmSocketHandler *mpSocketHandler;
183 CAmCommandSender *mpCommandSender;
184 CAmCommandReceiver *mpCommandReceiver;
185 CAmRoutingSender *mpRoutingSender;
186 CAmRoutingReceiver *mpRoutingReceiver;
187 CAmControlSender *mpControlSender;
188 CAmControlReceiver *mpControlReceiver;
189 IAmDatabaseHandler *mpDatabasehandler;
192 tCommandMap mRootCommands;
193 tCommandMap mListCommands;
194 tCommandMap mGetCommands;
195 tCommandMap mSetCommands;
196 tCommandMap mInfoCommands;
199 // class CAmTelnetMenuHelper
202 #endif // CAMTELNETMENUHELPER_H_