* modify contructor of CAmTelnetMenuHelper
[profile/ivi/audiomanager.git] / AudioManagerDaemon / include / CAmTelnetMenuHelper.h
1 /**
2  * Copyright (C) 2012, BMW AG
3  *
4  * GeniviAudioMananger AudioManagerDaemon
5  *
6  * \file CAmTelnetMenuHelper.h
7  *
8  * \date 23-Jan-2012
9  * \author Frank Herchet (frank.fh.herchet@bmw.de)
10  *
11  * \section License
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
14  *
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.
22  *
23  */
24
25 // Local header
26 #ifndef CAMTELNETMENUHELPER_H_
27 #define CAMTELNETMENUHELPER_H_
28
29 // Standard header
30 #include <iostream>
31 #include <queue>
32 #include <map>
33 #include <string>
34 #include <sstream>
35 #include <vector>
36
37 // for sockets
38 #include <sys/socket.h>
39 #include <audiomanagertypes.h>
40
41 namespace am
42 {
43
44 class TelnetServer;
45 class DatabaseHandler;
46 class CommandSender;
47 class RoutingSender;
48 class ControlSender;
49 class CommandReceiver;
50 class RoutingReceiver;
51 class ControlReceiver;
52
53 class Router;
54 class SocketHandler;
55
56 class CAmTelnetMenuHelper
57 {
58 public:
59
60     enum EMainState
61     {
62         eRootState = 0, eListState, eInfoState, eGetState, eSetState
63     };
64
65     CAmTelnetMenuHelper(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter, TelnetServer *iTelnetServer);
66
67     ~CAmTelnetMenuHelper();
68
69     void setTelnetServer(TelnetServer* iTelnetServer);
70
71     void newSocketConnection(int filedescriptor);
72
73     void socketConnectionsClosed(int filedescriptor);
74
75     void enterCmdQueue(std::queue<std::string> &CmdQueue, int &filedescriptor);
76
77 private:
78
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);
83
84     // COMMON commands
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);
91
92     // ROOT commands
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);
101
102     // LIST commands
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);
117
118     // SET commands
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);
129
130     // GET commands
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);
137
138     // INFO commands
139     static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
140     void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
141
142 private:
143
144     typedef void (*pCommandPrototype)(std::queue<std::string>& msg, int & filedescriptor);
145
146     struct sCommandPrototypeInfo
147     {
148         std::string info;
149         pCommandPrototype CommandPrototype;
150
151         // default contructor to set NULL
152         sCommandPrototypeInfo() :
153                 info(""), CommandPrototype(NULL)
154         {
155         }
156
157         // a small contructor
158         sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) :
159                 info(MyInfo), CommandPrototype(MyCommandPrototype)
160         {
161         }
162     };
163
164     typedef std::map<std::string, sCommandPrototypeInfo> tCommandMap;
165
166     // int filedescriptor of socket connection; EMainState state of current telnet session
167     std::map<int, EMainState> mCurrentMainStateMap;
168
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;
179     Router *mRouter;
180
181     tCommandMap mRootCommands;
182     tCommandMap mListCommands;
183     tCommandMap mGetCommands;
184     tCommandMap mSetCommands;
185     tCommandMap mInfoCommands;
186
187 };
188 // class CAmTelnetMenuHelper
189 }// namespace am
190
191 #endif // CAMTELNETMENUHELPER_H_