* changes that follow the review comments from Thomas G.
[profile/ivi/genivi/genivi-audio-manager.git] / AudioManagerDaemon / include / CAmTelnetMenuHelper.h
1 /**
2  * Copyright (C) 2012, BMW AG
3  *
4  * This file is part of GENIVI Project AudioManager.
5  *
6  * Contributions are licensed to the GENIVI Alliance under one or more
7  * Contribution License Agreements.
8  *
9  * \copyright
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/.
13  *
14  *
15  * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012
16  * \author Frank Herchet, frank.fh.herchet@bmw.de BMW 2012
17  *
18  * \file CAmTelnetMenuHelper.h
19  * For further information see http://www.genivi.org/.
20  *
21  */
22
23 // Local header
24 #ifndef CAMTELNETMENUHELPER_H_
25 #define CAMTELNETMENUHELPER_H_
26
27 // Standard header
28 #include <iostream>
29 #include <queue>
30 #include <map>
31 #include <string>
32 #include <sstream>
33 #include <vector>
34 #include <sys/socket.h>
35 #include "audiomanagertypes.h"
36
37 namespace am
38 {
39
40 class CAmTelnetServer;
41 class CAmDatabaseHandler;
42 class CAmCommandSender;
43 class CAmRoutingSender;
44 class CAmControlSender;
45 class CAmCommandReceiver;
46 class CAmRoutingReceiver;
47 class CAmControlReceiver;
48
49 class CAmRouter;
50 class CAmSocketHandler;
51
52 /**
53  * helper class for CAmTelnetServer
54  */
55 class CAmTelnetMenuHelper
56 {
57 public:
58
59     enum EMainState
60     {
61         eRootState = 0, eListState, eInfoState, eGetState, eSetState
62     };
63
64     CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, CAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer);
65
66     ~CAmTelnetMenuHelper();
67
68     void newSocketConnection(int filedescriptor);
69
70     void socketConnectionsClosed(int filedescriptor);
71
72     void enterCmdQueue(std::queue<std::string> &CmdQueue, int &filedescriptor);
73
74 private:
75
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);
80
81     // COMMON commands
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);
88
89     // ROOT commands
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);
98
99     // LIST commands
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);
120
121     // SET commands
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);
140
141     // GET commands
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);
148
149     // INFO commands
150     static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
151     void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
152
153 private:
154
155     typedef void (*pCommandPrototype)(std::queue<std::string>& msg, int & filedescriptor);
156
157     struct sCommandPrototypeInfo
158     {
159         std::string info;
160         pCommandPrototype CommandPrototype;
161
162         // default contructor to set NULL
163         sCommandPrototypeInfo() :
164                 info(""), CommandPrototype(NULL)
165         {
166         }
167
168         // a small contructor
169         sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) :
170                 info(MyInfo), CommandPrototype(MyCommandPrototype)
171         {
172         }
173     };
174
175     typedef std::map<std::string, sCommandPrototypeInfo> tCommandMap;
176     std::map<int, EMainState> mCurrentMainStateMap; //!< int filedescriptor of socket connection; EMainState state of current telnet session
177
178     static CAmTelnetMenuHelper* instance;
179     CAmTelnetServer *mpTelenetServer;
180     CAmSocketHandler *mpSocketHandler;
181     CAmCommandSender *mpCommandSender;
182     CAmCommandReceiver *mpCommandReceiver;
183     CAmRoutingSender *mpRoutingSender;
184     CAmRoutingReceiver *mpRoutingReceiver;
185     CAmControlSender *mpControlSender;
186     CAmControlReceiver *mpControlReceiver;
187     CAmDatabaseHandler *mpDatabasehandler;
188     CAmRouter *mpRouter;
189
190     tCommandMap mRootCommands;
191     tCommandMap mListCommands;
192     tCommandMap mGetCommands;
193     tCommandMap mSetCommands;
194     tCommandMap mInfoCommands;
195
196 };
197 // class CAmTelnetMenuHelper
198 }// namespace am
199
200 #endif // CAMTELNETMENUHELPER_H_