* change includes in 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 class Router;
53 class SocketHandler;
54
55 class CAmTelnetMenuHelper
56 {
57 public:
58
59     enum EMainState
60     {
61         eRootState = 0, eListState, eInfoState, eGetState, eSetState
62     };
63
64     CAmTelnetMenuHelper(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter);
65
66     ~CAmTelnetMenuHelper();
67
68     void setTelnetServer(TelnetServer* iTelnetServer);
69
70     void newSocketConnection(int filedescriptor);
71
72     void socketConnectionsClosed(int filedescriptor);
73
74     void enterCmdQueue(std::queue<std::string> &CmdQueue, int &filedescriptor);
75
76 private:
77
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);
82
83     // COMMON commands
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);
90
91     // ROOT commands
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);
100
101     // LIST commands
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);
116
117     // SET commands
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);
128
129     // GET commands
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);
136
137     // INFO commands
138     static void infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor);
139     void infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor);
140
141 private:
142
143     typedef void (*pCommandPrototype)(std::queue<std::string>& msg, int & filedescriptor);
144
145     struct sCommandPrototypeInfo
146     {
147         std::string info;
148         pCommandPrototype CommandPrototype;
149
150         // default contructor to set NULL
151         sCommandPrototypeInfo() :
152                 info(""), CommandPrototype(NULL)
153         {
154         }
155
156         // a small contructor
157         sCommandPrototypeInfo(std::string MyInfo, pCommandPrototype MyCommandPrototype) :
158                 info(MyInfo), CommandPrototype(MyCommandPrototype)
159         {
160         }
161     };
162
163     typedef std::map<std::string, sCommandPrototypeInfo> tCommandMap;
164
165     // int filedescriptor of socket connection; EMainState state of current telnet session
166     std::map<int, EMainState> mCurrentMainStateMap;
167
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;
178     Router *mRouter;
179
180     tCommandMap mRootCommands;
181     tCommandMap mListCommands;
182     tCommandMap mGetCommands;
183     tCommandMap mSetCommands;
184     tCommandMap mInfoCommands;
185
186 };
187 // class CAmTelnetMenuHelper
188 }// namespace am
189
190 #endif // CAMTELNETMENUHELPER_H_