2 * Copyright (C) 2012, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file CAmTelnetMenuHelper.cpp
9 * \author Frank Herchet (frank.fh.herchet@bmw.de)
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
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.
25 #include "CAmTelnetMenuHelper.h"
26 #include "TelnetServer.h"
27 #include "DatabaseHandler.h"
28 #include "ControlSender.h"
29 #include "CommandSender.h"
30 #include "RoutingSender.h"
31 #include "RoutingReceiver.h"
32 #include "CommandReceiver.h"
33 #include "ControlReceiver.h"
38 #define DEBUG_ON false
42 CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL;
44 /****************************************************************************/
45 CAmTelnetMenuHelper::CAmTelnetMenuHelper(SocketHandler *iSocketHandler, CommandSender *iCommandSender, CommandReceiver *iCommandReceiver, RoutingSender *iRoutingSender, RoutingReceiver *iRoutingReceiver, ControlSender *iControlSender, ControlReceiver *iControlReceiver, DatabaseHandler *iDatabasehandler, Router *iRouter, TelnetServer *iTelnetServer)
46 /****************************************************************************/
47 :mTelenetServer(iTelnetServer), mSocketHandler(iSocketHandler), mCommandSender(iCommandSender), mCommandReceiver(iCommandReceiver), mRoutingSender(iRoutingSender), mRoutingReceiver(iRoutingReceiver), mControlSender(iControlSender), mControlReceiver(iControlReceiver), mDatabasehandler(iDatabasehandler), mRouter(iRouter)
53 /****************************************************************************/
54 CAmTelnetMenuHelper::~CAmTelnetMenuHelper()
55 /****************************************************************************/
59 /****************************************************************************/
60 void CAmTelnetMenuHelper::createCommandMaps()
61 /****************************************************************************/
65 mRootCommands.clear();
67 mRootCommands.insert(std::make_pair("help", sCommandPrototypeInfo("show all possible commands", &CAmTelnetMenuHelper::helpCommand)));
68 mRootCommands.insert(std::make_pair("list", sCommandPrototypeInfo("Go into 'list'-submenu", &CAmTelnetMenuHelper::rootListCommand)));
69 mRootCommands.insert(std::make_pair("info", sCommandPrototypeInfo("Go into 'info'-submenu", &CAmTelnetMenuHelper::rootInfoCommand)));
70 mRootCommands.insert(std::make_pair("set", sCommandPrototypeInfo("Go into 'set'-submenu", &CAmTelnetMenuHelper::rootSetCommand)));
71 mRootCommands.insert(std::make_pair("get", sCommandPrototypeInfo("Go into 'get'-submenu", &CAmTelnetMenuHelper::rootGetCommand)));
72 mRootCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("quit telnet session", &CAmTelnetMenuHelper::exitCommand)));
75 mListCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
76 mListCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("list all connections", &CAmTelnetMenuHelper::listConnectionsCommand)));
77 mListCommands.insert(std::make_pair("sources", sCommandPrototypeInfo("list all available sources", &CAmTelnetMenuHelper::listSourcesCommand)));
78 mListCommands.insert(std::make_pair("sinks", sCommandPrototypeInfo("list all available sinks", &CAmTelnetMenuHelper::listSinksCommands)));
79 mListCommands.insert(std::make_pair("crfaders", sCommandPrototypeInfo("list all crossfaders", &CAmTelnetMenuHelper::listCrossfaders)));
80 mListCommands.insert(std::make_pair("domains", sCommandPrototypeInfo("list all domains", &CAmTelnetMenuHelper::listDomainsCommand)));
81 mListCommands.insert(std::make_pair("gws", sCommandPrototypeInfo("list all gateways", &CAmTelnetMenuHelper::listGatewaysCommand)));
82 mListCommands.insert(std::make_pair("mainconn", sCommandPrototypeInfo("list all main connections", &CAmTelnetMenuHelper::listMainConnectionsCommand)));
83 mListCommands.insert(std::make_pair("mainsinks", sCommandPrototypeInfo("list all main sinks", &CAmTelnetMenuHelper::listMainSinksCommand)));
84 mListCommands.insert(std::make_pair("mainsources", sCommandPrototypeInfo("list all main sources", &CAmTelnetMenuHelper::listMainSourcesCommand)));
85 mListCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
86 mListCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
89 mSetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
90 mSetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
91 mSetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
92 mSetCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink", &CAmTelnetMenuHelper::setConnection)));
93 mSetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("use 'routing sourceId sinkId' to get all\n\t possible routes between a sourceID and a sinkID", &CAmTelnetMenuHelper::setRoutingCommand)));
94 mSetCommands.insert(std::make_pair("disc", sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t this connection", &CAmTelnetMenuHelper::setDisconnectConnId)));
97 mGetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
98 mGetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("show current routing", &CAmTelnetMenuHelper::getRoutingCommand)));
99 mGetCommands.insert(std::make_pair("sendv", sCommandPrototypeInfo("show senderversion", &CAmTelnetMenuHelper::getSenderversionCommand)));
100 mGetCommands.insert(std::make_pair("recv", sCommandPrototypeInfo("show receiverversion ", &CAmTelnetMenuHelper::getReceiverversionCommand)));
101 mGetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
102 mGetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
105 mInfoCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
106 mInfoCommands.insert(std::make_pair("sysprop", sCommandPrototypeInfo("show all systemproperties", &CAmTelnetMenuHelper::infoSystempropertiesCommand)));
107 mInfoCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
108 mInfoCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
111 /****************************************************************************/
112 void CAmTelnetMenuHelper::setTelnetServer(TelnetServer* iTelnetServer)
113 /****************************************************************************/
115 mTelenetServer = iTelnetServer;
118 /****************************************************************************/
119 void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor)
120 /****************************************************************************/
122 EMainState state = eRootState;
123 std::map<int, EMainState>::iterator it;
124 std::stringstream welcome;
126 it = mCurrentMainStateMap.find(filedescriptor);
127 if (it != mCurrentMainStateMap.end())
129 // socket connection already exists, delete entry and go back to root state
130 mCurrentMainStateMap.erase(it);
133 it = mCurrentMainStateMap.begin();
135 // insert new socket connection
136 mCurrentMainStateMap.insert(it, std::make_pair<int, EMainState>(filedescriptor, state));
138 // Send welcome message
139 welcome << "Welcome to GENIVI AudioManager " << DAEMONVERSION << "\n>";
140 send(filedescriptor, welcome.str().c_str(), welcome.str().size(), 0);
143 /****************************************************************************/
144 void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor)
145 /****************************************************************************/
147 std::map<int, EMainState>::iterator it;
149 it = mCurrentMainStateMap.find(filedescriptor);
150 if (it != mCurrentMainStateMap.end())
152 mCurrentMainStateMap.erase(it);
156 // connection not found
160 /****************************************************************************/
161 void CAmTelnetMenuHelper::enterCmdQueue(std::queue<std::string> & CmdQueue, int & filedescriptor)
162 /****************************************************************************/
164 std::map<int, EMainState>::iterator it;
166 tCommandMap::iterator cmditer;
168 // find current filedescriptor to get the current state of the telnet session
169 it = mCurrentMainStateMap.find(filedescriptor);
170 while (!CmdQueue.empty())
172 cmd = CmdQueue.front();
174 // Now remove the first command, it's stored in 'cmd'
176 // telnet session found. depending on the current state, different commands are available
180 cmditer = mRootCommands.find(cmd);
181 if (mRootCommands.end() != cmditer)
182 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
184 sendError(filedescriptor, "Command not found\n");
187 cmditer = mListCommands.find(cmd);
188 if (mListCommands.end() != cmditer)
189 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
191 sendError(filedescriptor, "Command not found\n");
194 cmditer = mInfoCommands.find(cmd);
195 if (mInfoCommands.end() != cmditer)
196 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
198 sendError(filedescriptor, "Command not found\n");
201 cmditer = mGetCommands.find(cmd);
202 if (mGetCommands.end() != cmditer)
203 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
205 sendError(filedescriptor, "Command not found\n");
208 cmditer = mSetCommands.find(cmd);
209 if (mSetCommands.end() != cmditer)
210 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
212 sendError(filedescriptor, "Command not found\n");
219 sendCurrentCmdPrompt(filedescriptor);
222 /****************************************************************************/
223 void CAmTelnetMenuHelper::sendError(int & filedescriptor, std::string error_string)
224 /****************************************************************************/
226 send(filedescriptor, error_string.c_str(), error_string.size(), 0);
229 /****************************************************************************/
230 void CAmTelnetMenuHelper::sendTelnetLine(int & filedescriptor, std::stringstream &line)
231 /****************************************************************************/
233 send(filedescriptor, line.str().c_str(), line.str().size(), 0);
236 /****************************************************************************/
237 void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int & filedescriptor)
238 /****************************************************************************/
240 std::map<int, EMainState>::iterator it;
241 std::stringstream outputstream;
242 outputstream << std::endl;
244 it = mCurrentMainStateMap.find(filedescriptor);
245 if (it != mCurrentMainStateMap.end())
250 outputstream << "\\>";
253 outputstream << "\\List>";
256 outputstream << "\\Get>";
259 outputstream << "\\Set>";
262 outputstream << "\\Info>";
268 send(filedescriptor, outputstream.str().c_str(), outputstream.str().size(), 0);
273 // connection not found
277 /****************************************************************************/
278 void CAmTelnetMenuHelper::exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
279 /****************************************************************************/
281 instance->exitCommandExec(CmdQueue, filedescriptor);
284 /****************************************************************************/
285 void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
286 /****************************************************************************/
289 std::map<int, EMainState>::iterator it;
290 it = mCurrentMainStateMap.find(filedescriptor);
291 if (it != mCurrentMainStateMap.end())
294 std::cout << "old state: " << it->second;
298 it->second = eRootState;
301 it->second = eRootState;
305 it->second = eRootState;
309 it->second = eRootState;
313 it->second = eRootState;
317 it->second = eRootState;
321 std::cout << "new state: " << it->second << std::endl;
325 /****************************************************************************/
326 void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
327 /****************************************************************************/
329 instance->oneStepBackCommandExec(CmdQueue, filedescriptor);
332 /****************************************************************************/
333 void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
334 /****************************************************************************/
337 std::map<int, EMainState>::iterator it;
338 std::stringstream line;
339 std::stringstream output;
341 // Sending a last message to the client
342 output << "Your wish is my command ... bye!" << std::endl;
343 sendTelnetLine(filedescriptor, output);
345 tCommandMap::iterator iter;
346 it = mCurrentMainStateMap.find(filedescriptor);
347 if (it != mCurrentMainStateMap.end())
350 std::cout << "removing client connection " << filedescriptor << std::endl;
352 if (NULL != mTelenetServer)
354 mTelenetServer->disconnectClient(filedescriptor);
355 mCurrentMainStateMap.erase(it);
359 // ASSERT mTelenetServer == NULL
361 std::cout << "mTelenetServer";
366 /****************************************************************************/
367 void CAmTelnetMenuHelper::helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
368 /****************************************************************************/
370 instance->helpCommandExec(CmdQueue, filedescriptor);
373 /****************************************************************************/
374 void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
375 /****************************************************************************/
378 std::map<int, EMainState>::iterator it;
379 std::stringstream line;
380 tCommandMap::iterator cmdIter;
381 it = mCurrentMainStateMap.find(filedescriptor);
382 if (it != mCurrentMainStateMap.end())
384 line << "###################################################" << std::endl;
385 line << "###### The following commands are supported: ######" << std::endl;
386 line << "###################################################" << std::endl << std::endl;
391 cmdIter = mRootCommands.begin();
392 while (cmdIter != mRootCommands.end())
394 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
399 cmdIter = mListCommands.begin();
400 while (cmdIter != mListCommands.end())
402 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
407 cmdIter = mGetCommands.begin();
408 while (cmdIter != mGetCommands.end())
410 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
415 cmdIter = mSetCommands.begin();
416 while (cmdIter != mSetCommands.end())
418 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
423 cmdIter = mInfoCommands.begin();
424 while (cmdIter != mInfoCommands.end())
426 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
433 sendTelnetLine(filedescriptor, line);
437 /****************************************************************************/
438 void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
439 /****************************************************************************/
441 instance->rootGetCommandExec(CmdQueue, filedescriptor);
444 /****************************************************************************/
445 void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
446 /****************************************************************************/
449 std::map<int, EMainState>::iterator it;
450 it = mCurrentMainStateMap.find(filedescriptor);
451 if (it != mCurrentMainStateMap.end())
453 it->second = eGetState;
457 /****************************************************************************/
458 void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
459 /****************************************************************************/
461 instance->rootSetCommandExec(CmdQueue, filedescriptor);
464 /****************************************************************************/
465 void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
466 /****************************************************************************/
469 std::map<int, EMainState>::iterator it;
470 it = mCurrentMainStateMap.find(filedescriptor);
471 if (it != mCurrentMainStateMap.end())
473 it->second = eSetState;
477 /****************************************************************************/
478 void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
479 /****************************************************************************/
481 instance->rootListCommandExec(CmdQueue, filedescriptor);
484 /****************************************************************************/
485 void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
486 /****************************************************************************/
489 std::map<int, EMainState>::iterator it;
490 it = mCurrentMainStateMap.find(filedescriptor);
491 if (it != mCurrentMainStateMap.end())
493 it->second = eListState;
497 /****************************************************************************/
498 void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
499 /****************************************************************************/
501 instance->rootInfoCommandExec(CmdQueue, filedescriptor);
504 /****************************************************************************/
505 void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
506 /****************************************************************************/
509 std::map<int, EMainState>::iterator it;
510 it = mCurrentMainStateMap.find(filedescriptor);
511 if (it != mCurrentMainStateMap.end())
513 it->second = eInfoState;
517 /****************************************************************************/
518 void CAmTelnetMenuHelper::listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
519 /****************************************************************************/
521 instance->listConnectionsCommandExec(CmdQueue, filedescriptor);
524 /****************************************************************************/
525 void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
526 /****************************************************************************/
530 std::vector<am_Connection_s> listConnections;
531 if(E_OK == mDatabasehandler->getListConnections(listConnections))
533 std::stringstream output;
534 output << "\tConnections: " << listConnections.size() << std::endl;
535 for (std::vector<am_Connection_s>::iterator iter(listConnections.begin()); iter < listConnections.end(); iter++)
537 output << "\tID: " << iter->connectionID
538 << "\tSrcID: " << iter->sourceID
539 << "\tSinkID: " << iter->sinkID
540 << "\tFormat: " << iter->connectionFormat
541 << "\tdelay: " << iter->delay << std::endl;
543 sendTelnetLine(filedescriptor, output);
547 sendError(filedescriptor,"ERROR: mDatabasehandler->getListConnections");
551 /****************************************************************************/
552 void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
553 /****************************************************************************/
555 instance->listSourcesCommandExec(CmdQueue, filedescriptor);
558 /****************************************************************************/
559 void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
560 /****************************************************************************/
564 std::vector<am_Source_s> listSources;
565 if(E_OK == mDatabasehandler->getListSources(listSources))
567 std::stringstream output;
568 output << "\tSources: " << listSources.size() << std::endl;
569 for (std::vector<am_Source_s>::iterator iter(listSources.begin()); iter < listSources.end(); iter++)
571 output << "\tID: " << iter->sourceID
572 << "\tName: " << iter->name
573 << "\tDomainID: " << iter->domainID
574 << "\tState: " << iter->sourceState
575 << "\tVolume: " << iter->volume << std::endl;
577 sendTelnetLine(filedescriptor, output);
581 sendError(filedescriptor,"ERROR: mDatabasehandler->getListSources");
585 /****************************************************************************/
586 void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor)
587 /****************************************************************************/
589 instance->listSinksCommandsExec(CmdQueue, filedescriptor);
592 /****************************************************************************/
593 void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
594 /****************************************************************************/
598 std::vector<am_Sink_s> listSinks;
599 if(E_OK == mDatabasehandler->getListSinks(listSinks))
601 std::stringstream output;
602 output << "\tSinks: " << listSinks.size() << std::endl;
603 for (std::vector<am_Sink_s>::iterator iter(listSinks.begin()); iter < listSinks.end(); iter++)
605 output << "\tID: " << iter->sinkID
606 << "\tDomainID: " << iter->domainID
607 << "\tName: " << iter->name
608 << "\tAvailable: " << iter->available.availability
609 << "\tVolume: " << iter->volume << std::endl;
612 sendTelnetLine(filedescriptor, output);
616 sendError(filedescriptor,"ERROR: mDatabasehandler->getListSinks");
620 /****************************************************************************/
621 void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor)
622 /****************************************************************************/
624 instance->listCrossfadersExec(CmdQueue, filedescriptor);
627 /****************************************************************************/
628 void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
629 /****************************************************************************/
633 std::vector<am_Crossfader_s> listCrossfaders;
634 if(E_OK == mDatabasehandler->getListCrossfaders(listCrossfaders))
636 std::stringstream output;
637 output << "\tCrossfaders: " << listCrossfaders.size() << std::endl;
638 for (std::vector<am_Crossfader_s>::iterator iter(listCrossfaders.begin()); iter < listCrossfaders.end(); iter++)
640 output << "\tID: " << iter->crossfaderID
641 << "\tName: " << iter->name
642 << "\tSourceID: " << iter->sourceID << std::endl;
645 sendTelnetLine(filedescriptor, output);
649 sendError(filedescriptor,"ERROR: mDatabasehandler->getListCrossfaders");
653 /****************************************************************************/
654 void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
655 /****************************************************************************/
657 instance->listDomainsCommandExec(CmdQueue, filedescriptor);
660 /****************************************************************************/
661 void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
662 /****************************************************************************/
666 std::vector<am_Domain_s> listDomains;
667 if(E_OK == mDatabasehandler->getListDomains(listDomains))
669 std::stringstream output;
670 output << "\tDomains: " << listDomains.size() << std::endl;
671 for (std::vector<am_Domain_s>::iterator iter(listDomains.begin()); iter < listDomains.end(); iter++)
673 output << "\tID: " << iter->domainID
674 << "\tName: " << iter->name
675 << "\tBusname: " << iter->busname
676 << "\tNodename: " << iter->nodename
677 << "\tState: " << static_cast<int>(iter->state) << std::endl;
680 sendTelnetLine(filedescriptor, output);
684 sendError(filedescriptor,"ERROR: mDatabasehandler->getListDomains");
688 /****************************************************************************/
689 void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
690 /****************************************************************************/
692 instance->listGatewaysCommandExec(CmdQueue, filedescriptor);
695 /****************************************************************************/
696 void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
697 /****************************************************************************/
701 std::vector<am_Gateway_s> listGateways;
702 if(E_OK == mDatabasehandler->getListGateways(listGateways))
704 std::stringstream output;
705 output << "\tGateways: " << listGateways.size();
707 for( std::vector<am_Gateway_s>::iterator iter(listGateways.begin()); iter < listGateways.end(); iter++)
709 output << "\tID: " << iter->gatewayID
710 << "\tName: " << iter->name
711 << "\tSourceID: " << iter->sourceID
712 << "\tSinkID: " << iter->sinkID << std::endl;
714 sendTelnetLine(filedescriptor, output);
718 sendError(filedescriptor,"ERROR: mDatabasehandler->getListGateways");
722 /****************************************************************************/
723 void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
724 /****************************************************************************/
726 instance->getRoutingCommandExec(CmdQueue, filedescriptor);
729 /****************************************************************************/
730 void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
731 /****************************************************************************/
734 (void) filedescriptor;
735 //TODO: fill with function
738 /****************************************************************************/
739 void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
740 /****************************************************************************/
742 instance->getSenderversionCommandExec(CmdQueue, filedescriptor);
745 /****************************************************************************/
746 void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
747 /****************************************************************************/
751 std::stringstream output;
752 output << "\tSender versions:" << std::endl << "\tCtrl: " << mControlSender->getInterfaceVersion() << " | " << "Cmd: " << mCommandSender->getInterfaceVersion() << " | " << "Routing: " << mRoutingSender->getInterfaceVersion() << std::endl;
754 sendTelnetLine(filedescriptor, output);
757 /****************************************************************************/
758 void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
759 /****************************************************************************/
761 instance->getReceiverversionCommandExec(CmdQueue, filedescriptor);
764 /****************************************************************************/
765 void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
766 /****************************************************************************/
770 std::stringstream output;
771 output << "\tReceiver versions:" << std::endl << "\tCtrl: " << mControlReceiver->getInterfaceVersion() << " | " << "Cmd: " << mCommandReceiver->getInterfaceVersion() << " | " << "Routing: " << mRoutingReceiver->getInterfaceVersion() << std::endl;
773 sendTelnetLine(filedescriptor, output);
777 /****************************************************************************/
778 void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
779 /****************************************************************************/
781 instance->infoSystempropertiesCommandExec(CmdQueue, filedescriptor);
784 /****************************************************************************/
785 void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
786 /****************************************************************************/
789 std::vector<am_SystemProperty_s> listSystemProperties;
791 if(E_OK == mDatabasehandler->getListSystemProperties(listSystemProperties))
793 std::stringstream output;
794 output << "\tSystemproperties: " << listSystemProperties.size() << std::endl;
796 std::vector<am_SystemProperty_s>::iterator it;
797 for (it = listSystemProperties.begin(); it < listSystemProperties.end(); it++)
799 output << "\tType: " << it->type << " Value: " << it->value << std::endl;
802 sendTelnetLine(filedescriptor, output);
806 sendError(filedescriptor,"ERROR: mDatabasehandler->getListSystemProperties");
812 /****************************************************************************/
813 void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
814 /****************************************************************************/
816 instance->setRoutingCommandExec(CmdQueue, filedescriptor);
819 /****************************************************************************/
820 void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
821 /****************************************************************************/
825 if (CmdQueue.size() >= 2)
829 std::istringstream istream_sourceID(CmdQueue.front());
831 std::istringstream istream_sinkID(CmdQueue.front());
834 am_sourceID_t sourceID = 0;
835 if (!(istream_sourceID >> sourceID))
838 am_sinkID_t sinkID = 0;
839 if (!(istream_sinkID >> sinkID))
844 sendError(filedescriptor, "Error parsing sourcID and sinkID");
849 std::cout << "setRoutingCommandExec(sourceID: " << sourceID << ",sinkID: " << sinkID << ")" << std::endl;
851 std::vector<am_Route_s> routingList;
852 if (E_OK == mRouter->getRoute(true, sourceID, sinkID, routingList))
854 std::stringstream output;
856 std::vector<am_Route_s>::iterator rlIter = routingList.begin();
857 for (int rlCnt = 1; rlIter < routingList.end(); rlIter++)
859 output << "#" << rlCnt << " ";
861 std::vector<am_RoutingElement_s>::iterator reIter = rlIter->route.begin();
862 for (; reIter < rlIter->route.end(); reIter++)
864 reIter->connectionFormat;
866 output << ">(" << reIter->sourceID << ")->--[D:" << reIter->domainID << "][F:" << reIter->connectionFormat << "]-->-(" << reIter->sinkID << ")" << std::endl;
872 sendTelnetLine(filedescriptor, output);
876 sendError(filedescriptor, "Error getting route");
882 if(!CmdQueue.empty())
885 sendError(filedescriptor,"Not enough arguments to set routing. Please enter sourceID and sinkID after command");
890 /****************************************************************************/
891 void CAmTelnetMenuHelper::setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor)
892 /****************************************************************************/
894 instance->setConnectionExec(CmdQueue, filedescriptor);
897 /****************************************************************************/
898 void CAmTelnetMenuHelper::setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
899 /****************************************************************************/
908 am_Error_e rError = E_OK;
910 if (CmdQueue.size() >= 2)
912 std::istringstream istream_sourceID(CmdQueue.front());
915 std::istringstream istream_sinkID(CmdQueue.front());
918 am_sourceID_t sourceID = 0;
919 if (!(istream_sourceID >> sourceID))
922 am_sinkID_t sinkID = 0;
923 if (!(istream_sinkID >> sinkID))
928 sendError(filedescriptor, "Error parsing sinkID and/or sourceID");
932 // Try to set up connection
933 am_mainConnectionID_t connID = 0;
934 rError = mCommandReceiver->connect(sourceID, sinkID, connID);
938 std::stringstream output;
939 output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl;
940 sendTelnetLine(filedescriptor, output);
944 sendError(filedescriptor, "Error connecting sourceID and sinkID");
950 // remove 1 element if list is not empty
951 if(!CmdQueue.empty())
954 sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command");
959 /****************************************************************************/
960 void CAmTelnetMenuHelper::setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor)
961 /****************************************************************************/
963 instance->setDisconnectConnIdExec(CmdQueue, filedescriptor);
966 /****************************************************************************/
967 void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
968 /****************************************************************************/
970 am_mainConnectionID_t connID = 0;
973 am_Error_e rError = E_OK;
975 if (CmdQueue.size() >= 1)
977 std::istringstream istream_connID(CmdQueue.front());
980 if (!(istream_connID >> connID))
985 sendError(filedescriptor, "Error parsing connID");
989 // Try to disconnect connection id
990 rError = mCommandReceiver->disconnect(connID);
994 std::stringstream output;
995 output << "ConnID " << connID << " closed successfully! " << std::endl;
996 sendTelnetLine(filedescriptor, output);
1000 sendError(filedescriptor, "Error disconnecting connectionID");
1005 sendError(filedescriptor, "Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command");
1010 /****************************************************************************/
1011 void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1012 /****************************************************************************/
1014 instance->setConnectionExec(CmdQueue, filedescriptor);
1017 /****************************************************************************/
1018 void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1019 /****************************************************************************/
1021 if (CmdQueue.size() >= 3)
1025 std::istringstream istream_sourceID(CmdQueue.front());
1028 std::istringstream istream_type(CmdQueue.front());
1031 std::istringstream istream_value(CmdQueue.front());
1034 unsigned int tmpType = 0;
1035 if (!(istream_type >> tmpType))
1038 am_MainSoundProperty_s soundProperty;
1039 if (tmpType < MSP_MAX)
1040 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1044 if (!(istream_value >> soundProperty.value))
1047 am_sinkID_t sourceID = 0;
1048 if (!(istream_sourceID >> sourceID))
1053 sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'");
1057 if (E_OK == mCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID))
1059 std::stringstream output;
1060 output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1061 sendTelnetLine(filedescriptor, output);
1065 sendError(filedescriptor, "Error setMainSourceSoundProperty");
1070 sendError(filedescriptor, "Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
1075 /****************************************************************************/
1076 void CAmTelnetMenuHelper::setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1077 /****************************************************************************/
1079 instance->setConnectionExec(CmdQueue, filedescriptor);
1082 /****************************************************************************/
1083 void CAmTelnetMenuHelper::setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1084 /****************************************************************************/
1086 unsigned int tmpType = 0;
1089 if (CmdQueue.size() >= 3)
1091 std::istringstream istream_sinkID(CmdQueue.front());
1094 std::istringstream istream_type(CmdQueue.front());
1097 std::istringstream istream_value(CmdQueue.front());
1100 if (!(istream_type >> tmpType))
1103 am_MainSoundProperty_s soundProperty;
1104 if (tmpType < MSP_MAX)
1105 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1109 if (!(istream_value >> soundProperty.value))
1112 am_sinkID_t sinkID = 0;
1113 if (!(istream_sinkID >> sinkID))
1118 sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'");
1122 if (E_OK == mCommandReceiver->setMainSinkSoundProperty(soundProperty, sinkID))
1124 std::stringstream output;
1125 output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1126 sendTelnetLine(filedescriptor, output);
1130 sendError(filedescriptor, "Error setMainSinkSoundProperty");
1135 sendError(filedescriptor, "Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command");
1140 /****************************************************************************/
1141 void CAmTelnetMenuHelper::listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1142 /****************************************************************************/
1144 instance->listPluginsCommandExec(CmdQueue, filedescriptor);
1147 /****************************************************************************/
1148 void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1149 /****************************************************************************/
1152 std::vector<std::string> PlugInNames;
1153 std::vector<std::string>::iterator iter;
1154 std::stringstream output;
1157 if(E_OK == mCommandSender->getListPlugins(PlugInNames))
1159 output << "\tCommandSender Plugins loaded: " << PlugInNames.size() << std::endl;
1161 for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++)
1163 output << iter->c_str() << std::endl;
1168 sendError(filedescriptor,"ERROR: mCommandSender->getListPlugins");
1172 if(E_OK == mRoutingSender->getListPlugins(PlugInNames))
1174 output << std::endl << "\tRoutingSender Plugins loaded: " << PlugInNames.size() << std::endl;
1176 for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++)
1178 output << iter->c_str() << std::endl;
1183 sendError(filedescriptor,"ERROR: mRoutingSender->getListPlugins");
1187 sendTelnetLine(filedescriptor, output);
1191 /****************************************************************************/
1192 void CAmTelnetMenuHelper::listMainSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1193 /****************************************************************************/
1195 instance->listMainSourcesCommandExec(CmdQueue,filedescriptor);
1198 /****************************************************************************/
1199 void CAmTelnetMenuHelper::listMainSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1200 /****************************************************************************/
1203 std::vector<am_SourceType_s> listMainSources;
1205 if(E_OK == mDatabasehandler->getListMainSources(listMainSources))
1207 std::stringstream output;
1208 output << std::endl << "\tMainSources: " << listMainSources.size() << std::endl;
1210 std::vector<am_SourceType_s>::iterator iter;
1211 for (iter = listMainSources.begin(); iter < listMainSources.end(); iter++)
1213 output << "\t" << iter->name << "\tID: " << iter->sourceID
1214 << "\tClassID: " << iter->sourceClassID
1215 << "\tavailability: " << static_cast<int>(iter->availability.availability)
1216 << "\tavailabilityReason: " << static_cast<int>(iter->availability.availabilityReason) << std::endl;
1218 sendTelnetLine(filedescriptor,output);
1222 sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSources");
1226 /****************************************************************************/
1227 void CAmTelnetMenuHelper::listMainSinksCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1228 /****************************************************************************/
1230 instance->listMainSinksCommandExec(CmdQueue,filedescriptor);
1233 /****************************************************************************/
1234 void CAmTelnetMenuHelper::listMainSinksCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1235 /****************************************************************************/
1238 std::vector<am_SinkType_s> listMainSinks;
1240 if(E_OK == mDatabasehandler->getListMainSinks(listMainSinks))
1242 std::stringstream output;
1243 output << std::endl << "\tMainSinks: " << listMainSinks.size() << std::endl;
1245 std::vector<am_SinkType_s>::iterator iter;
1246 for ( iter = listMainSinks.begin(); iter < listMainSinks.end(); iter++)
1248 output << "\t" << iter->name << "\tID: " << iter->sinkID
1249 << "\tClassID: " << iter->sinkClassID
1250 << "\tavailability: " << static_cast<int>(iter->availability.availability)
1251 << "\tavailabilityReason: " << static_cast<int>(iter->availability.availabilityReason)
1252 << "\tMuteState: " << iter->muteState
1253 << "\tVolume: " << iter->volume << std::endl;
1255 sendTelnetLine(filedescriptor,output);
1259 sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks");
1263 /****************************************************************************/
1264 void CAmTelnetMenuHelper::listMainConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1265 /****************************************************************************/
1267 instance->listMainConnectionsCommandExec(CmdQueue,filedescriptor);
1270 /****************************************************************************/
1271 void CAmTelnetMenuHelper::listMainConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1272 /****************************************************************************/
1275 std::vector<am_MainConnection_s> listMainConnections;
1277 if(E_OK == mDatabasehandler->getListMainConnections(listMainConnections))
1279 std::stringstream output;
1280 output << std::endl << "\tMainConnections: " << listMainConnections.size() << std::endl;
1282 std::vector<am_MainConnection_s>::iterator iter;
1283 for (iter = listMainConnections.begin(); iter < listMainConnections.end(); iter++)
1285 output << "\tID: " << iter->mainConnectionID
1286 << "\tState: " << iter->connectionState
1287 << "\tDelay: " << iter->delay
1288 << "\tsourceID: " << iter->sourceID
1289 << "\tsinkID: " << iter->sinkID << std::endl;
1291 output << "ConnectionIDs: ";
1292 std::vector<am_connectionID_t>::iterator list_connIDs_iter = iter->listConnectionID.begin();
1293 for(;list_connIDs_iter < iter->listConnectionID.end();list_connIDs_iter++)
1295 output << *list_connIDs_iter << " ";
1298 output << std::endl;
1300 sendTelnetLine(filedescriptor,output);
1304 sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks");