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 CAmTelnetServer.h
19 * For further information see http://www.genivi.org/.
23 #ifndef TELNETSERVER_H_
24 #define TELNETSERVER_H_
28 #include "shared/CAmSocketHandler.h"
29 #include "CAmTelnetMenuHelper.h"
34 class CAmDatabaseHandler;
35 class CAmCommandSender;
36 class CAmRoutingSender;
37 class CAmControlSender;
38 class CAmCommandReceiver;
39 class CAmRoutingReceiver;
40 class CAmControlReceiver;
42 class CAmTelnetMenuHelper;
45 * Implements a telnetserver that can be used to connect to the audiomanager, retrieve some information and use it. For debugginp purposes.
46 * For example, launch a telnet session on port 6060:
47 * \code telnet localhost 6060 \endcode
48 * more details can be found at the README
53 CAmTelnetServer(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, CAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, unsigned int servPort, unsigned int maxConnections);
55 void connectSocket(const pollfd pfd, const sh_pollHandle_t handle, void* userData);
56 void disconnectClient(int filedescriptor);
57 void receiveData(const pollfd pfd, const sh_pollHandle_t handle, void* userData);
58 bool dispatchData(const sh_pollHandle_t handle, void* userData);
59 bool check(const sh_pollHandle_t handle, void* userData);
60 TAmShPollFired<CAmTelnetServer> telnetConnectFiredCB;
61 TAmShPollFired<CAmTelnetServer> telnetReceiveFiredCB;
62 TAmShPollDispatch<CAmTelnetServer> telnetDispatchCB;
63 TAmShPollCheck<CAmTelnetServer> telnetCheckCB;
66 typedef void (*CommandPrototype)(std::vector<std::string>& msg, int filedescriptor);
67 typedef std::map<std::string, CommandPrototype> mMapCommand_t;
69 void sliceCommand(const std::string& string, std::string& command, std::queue<std::string>& msg);
70 mMapCommand_t createCommandMap();
74 sh_pollHandle_t handle;
77 static CAmTelnetServer* mpInstance;
78 CAmSocketHandler *mpSocketHandler;
79 CAmCommandSender *mpCommandSender;
80 CAmCommandReceiver *mpCommandReceiver;
81 CAmRoutingSender *mpRoutingSender;
82 CAmRoutingReceiver *mpRoutingReceiver;
83 CAmControlSender *mpControlSender;
84 CAmControlReceiver *mpControlReceiver;
85 CAmDatabaseHandler *mpDatabasehandler;
87 sh_pollHandle_t mConnecthandle;
88 std::queue<std::string> mListMessages;
89 std::vector<connection_s> mListConnections;
91 unsigned int mServerPort;
92 unsigned int mMaxConnections;
93 CAmTelnetMenuHelper mTelnetMenuHelper;
98 #endif /* TELNETSERVER_H_ */