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 CAmTelnetMenuHelper.cpp
19 * For further information see http://www.genivi.org/.
23 #include "CAmTelnetMenuHelper.h"
26 #include "CAmRouter.h"
27 #include "CAmTelnetServer.h"
28 #include "CAmDatabaseHandler.h"
29 #include "CAmControlSender.h"
30 #include "CAmCommandSender.h"
31 #include "CAmRoutingSender.h"
32 #include "CAmRoutingReceiver.h"
33 #include "CAmCommandReceiver.h"
34 #include "CAmControlReceiver.h"
35 #include "shared/CAmDltWrapper.h"
37 static const std::string COLOR_WELCOME("\033[1;33m\033[44m");
38 static const std::string COLOR_HEAD("\033[1m\033[42m");
39 static const std::string COLOR_DEFAULT("\033[0m");
44 CAmTelnetMenuHelper* CAmTelnetMenuHelper::instance = NULL;
46 /****************************************************************************/
47 CAmTelnetMenuHelper::CAmTelnetMenuHelper(CAmSocketHandler *iSocketHandler, CAmCommandSender *iCommandSender, CAmCommandReceiver *iCommandReceiver, CAmRoutingSender *iRoutingSender, CAmRoutingReceiver *iRoutingReceiver, CAmControlSender *iControlSender, CAmControlReceiver *iControlReceiver, CAmDatabaseHandler *iDatabasehandler, CAmRouter *iRouter, CAmTelnetServer *iTelnetServer)
48 /****************************************************************************/
49 :mpTelenetServer(iTelnetServer), mpSocketHandler(iSocketHandler), mpCommandSender(iCommandSender), mpCommandReceiver(iCommandReceiver), mpRoutingSender(iRoutingSender), mpRoutingReceiver(iRoutingReceiver), mpControlSender(iControlSender), mpControlReceiver(iControlReceiver), mpDatabasehandler(iDatabasehandler), mpRouter(iRouter)
55 /****************************************************************************/
56 CAmTelnetMenuHelper::~CAmTelnetMenuHelper()
57 /****************************************************************************/
61 /****************************************************************************/
62 void CAmTelnetMenuHelper::createCommandMaps()
63 /****************************************************************************/
67 mRootCommands.clear();
69 mRootCommands.insert(std::make_pair("help", sCommandPrototypeInfo("show all possible commands", &CAmTelnetMenuHelper::helpCommand)));
70 mRootCommands.insert(std::make_pair("list", sCommandPrototypeInfo("Go into 'list'-submenu", &CAmTelnetMenuHelper::rootListCommand)));
71 mRootCommands.insert(std::make_pair("info", sCommandPrototypeInfo("Go into 'info'-submenu", &CAmTelnetMenuHelper::rootInfoCommand)));
72 mRootCommands.insert(std::make_pair("set", sCommandPrototypeInfo("Go into 'set'-submenu", &CAmTelnetMenuHelper::rootSetCommand)));
73 mRootCommands.insert(std::make_pair("get", sCommandPrototypeInfo("Go into 'get'-submenu", &CAmTelnetMenuHelper::rootGetCommand)));
74 mRootCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("quit telnet session", &CAmTelnetMenuHelper::exitCommand)));
77 mListCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
78 mListCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("list all connections", &CAmTelnetMenuHelper::listConnectionsCommand)));
79 mListCommands.insert(std::make_pair("sources", sCommandPrototypeInfo("list all available sources", &CAmTelnetMenuHelper::listSourcesCommand)));
80 mListCommands.insert(std::make_pair("sinks", sCommandPrototypeInfo("list all available sinks", &CAmTelnetMenuHelper::listSinksCommands)));
81 mListCommands.insert(std::make_pair("crfaders", sCommandPrototypeInfo("list all crossfaders", &CAmTelnetMenuHelper::listCrossfaders)));
82 mListCommands.insert(std::make_pair("domains", sCommandPrototypeInfo("list all domains", &CAmTelnetMenuHelper::listDomainsCommand)));
83 mListCommands.insert(std::make_pair("gws", sCommandPrototypeInfo("list all gateways", &CAmTelnetMenuHelper::listGatewaysCommand)));
84 mListCommands.insert(std::make_pair("mainconn", sCommandPrototypeInfo("list all main connections", &CAmTelnetMenuHelper::listMainConnectionsCommand)));
85 mListCommands.insert(std::make_pair("mainsinks", sCommandPrototypeInfo("list all main sinks", &CAmTelnetMenuHelper::listMainSinksCommand)));
86 mListCommands.insert(std::make_pair("mainsources", sCommandPrototypeInfo("list all main sources", &CAmTelnetMenuHelper::listMainSourcesCommand)));
87 mListCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
88 mListCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
91 mSetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
92 mSetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
93 mSetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
94 mSetCommands.insert(std::make_pair("conn", sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink", &CAmTelnetMenuHelper::setConnection)));
95 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)));
96 mSetCommands.insert(std::make_pair("disc", sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t this connection", &CAmTelnetMenuHelper::setDisconnectConnId)));
99 mGetCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
100 mGetCommands.insert(std::make_pair("routing", sCommandPrototypeInfo("show current routing", &CAmTelnetMenuHelper::getRoutingCommand)));
101 mGetCommands.insert(std::make_pair("sendv", sCommandPrototypeInfo("show senderversion", &CAmTelnetMenuHelper::getSenderversionCommand)));
102 mGetCommands.insert(std::make_pair("recv", sCommandPrototypeInfo("show receiverversion ", &CAmTelnetMenuHelper::getReceiverversionCommand)));
103 mGetCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
104 mGetCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
107 mInfoCommands.insert(std::make_pair("help", sCommandPrototypeInfo(std::string("show all possible commands"), &CAmTelnetMenuHelper::helpCommand)));
108 mInfoCommands.insert(std::make_pair("sysprop", sCommandPrototypeInfo("show all systemproperties", &CAmTelnetMenuHelper::infoSystempropertiesCommand)));
109 mInfoCommands.insert(std::make_pair("..", sCommandPrototypeInfo("one step back in menu tree (back to root folder)", &CAmTelnetMenuHelper::oneStepBackCommand)));
110 mInfoCommands.insert(std::make_pair("exit", sCommandPrototypeInfo("close telnet session", &CAmTelnetMenuHelper::exitCommand)));
113 /****************************************************************************/
114 void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor)
115 /****************************************************************************/
117 EMainState state = eRootState;
118 std::map<int, EMainState>::iterator it;
119 std::stringstream welcome;
121 it = mCurrentMainStateMap.find(filedescriptor);
122 if (it != mCurrentMainStateMap.end())
124 // socket connection already exists, delete entry and go back to root state
125 mCurrentMainStateMap.erase(it);
128 it = mCurrentMainStateMap.begin();
130 // insert new socket connection
131 mCurrentMainStateMap.insert(it, std::make_pair<int, EMainState>(filedescriptor, state));
133 // Send welcome message
134 welcome << COLOR_WELCOME << "Welcome to GENIVI AudioManager " << DAEMONVERSION << COLOR_DEFAULT << "\n>";
135 send(filedescriptor, welcome.str().c_str(), welcome.str().size(), 0);
136 logInfo("[TN] New connection: ",filedescriptor);
139 /****************************************************************************/
140 void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor)
141 /****************************************************************************/
143 std::map<int, EMainState>::iterator it;
145 it = mCurrentMainStateMap.find(filedescriptor);
146 if (it != mCurrentMainStateMap.end())
148 mCurrentMainStateMap.erase(it);
152 logError("[TN] socketConnectionsClosed, fd not found, ",filedescriptor);
156 /****************************************************************************/
157 void CAmTelnetMenuHelper::enterCmdQueue(std::queue<std::string> & CmdQueue, int & filedescriptor)
158 /****************************************************************************/
160 std::map<int, EMainState>::iterator it;
162 tCommandMap::iterator cmditer;
164 // find current filedescriptor to get the current state of the telnet session
165 it = mCurrentMainStateMap.find(filedescriptor);
166 while (!CmdQueue.empty())
168 cmd = CmdQueue.front();
170 // Now remove the first command, it's stored in 'cmd'
172 // telnet session found. depending on the current state, different commands are available
176 cmditer = mRootCommands.find(cmd);
177 if (mRootCommands.end() != cmditer)
178 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
180 sendError(filedescriptor, "Command not found\n");
183 cmditer = mListCommands.find(cmd);
184 if (mListCommands.end() != cmditer)
185 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
187 sendError(filedescriptor, "Command not found\n");
190 cmditer = mInfoCommands.find(cmd);
191 if (mInfoCommands.end() != cmditer)
192 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
194 sendError(filedescriptor, "Command not found\n");
197 cmditer = mGetCommands.find(cmd);
198 if (mGetCommands.end() != cmditer)
199 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
201 sendError(filedescriptor, "Command not found\n");
204 cmditer = mSetCommands.find(cmd);
205 if (mSetCommands.end() != cmditer)
206 cmditer->second.CommandPrototype(CmdQueue, filedescriptor);
208 sendError(filedescriptor, "Command not found\n");
215 sendCurrentCmdPrompt(filedescriptor);
218 /****************************************************************************/
219 void CAmTelnetMenuHelper::sendError(int & filedescriptor, std::string error_string)
220 /****************************************************************************/
222 send(filedescriptor, error_string.c_str(), error_string.size(), 0);
225 /****************************************************************************/
226 void CAmTelnetMenuHelper::sendTelnetLine(int & filedescriptor, std::stringstream &line)
227 /****************************************************************************/
229 send(filedescriptor, line.str().c_str(), line.str().size(), 0);
232 /****************************************************************************/
233 void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int & filedescriptor)
234 /****************************************************************************/
236 std::map<int, EMainState>::iterator it;
237 std::stringstream outputstream;
238 outputstream << std::endl;
240 it = mCurrentMainStateMap.find(filedescriptor);
241 if (it != mCurrentMainStateMap.end())
246 outputstream << "\\>";
249 outputstream << "\\List>";
252 outputstream << "\\Get>";
255 outputstream << "\\Set>";
258 outputstream << "\\Info>";
264 send(filedescriptor, outputstream.str().c_str(), outputstream.str().size(), 0);
269 logInfo("[TN] sendCurrentCmdPrompt, fd not found: ",filedescriptor);
273 /****************************************************************************/
274 void CAmTelnetMenuHelper::exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
275 /****************************************************************************/
277 instance->exitCommandExec(CmdQueue, filedescriptor);
280 /****************************************************************************/
281 void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
282 /****************************************************************************/
285 std::map<int, EMainState>::iterator it;
286 it = mCurrentMainStateMap.find(filedescriptor);
287 if (it != mCurrentMainStateMap.end())
292 it->second = eRootState;
295 it->second = eRootState;
299 it->second = eRootState;
303 it->second = eRootState;
307 it->second = eRootState;
311 it->second = eRootState;
315 logInfo("[TN] oneStepBackCommandExec, state: ",it->second);
319 /****************************************************************************/
320 void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
321 /****************************************************************************/
323 instance->oneStepBackCommandExec(CmdQueue, filedescriptor);
326 /****************************************************************************/
327 void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
328 /****************************************************************************/
331 std::map<int, EMainState>::iterator it;
332 std::stringstream line;
333 std::stringstream output;
335 // Sending a last message to the client
336 output << "bye!" << COLOR_DEFAULT << std::endl;
337 sendTelnetLine(filedescriptor, output);
339 tCommandMap::iterator iter;
340 it = mCurrentMainStateMap.find(filedescriptor);
341 if (it != mCurrentMainStateMap.end())
343 if (NULL != mpTelenetServer)
345 logInfo("[TN] exitCommandExec, removing fd ",filedescriptor);
346 mpTelenetServer->disconnectClient(filedescriptor);
347 mCurrentMainStateMap.erase(it);
351 logError("[TN] exitCommandExec, mpTelenetServer == NULL, fd ",filedescriptor);
356 /****************************************************************************/
357 void CAmTelnetMenuHelper::helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
358 /****************************************************************************/
360 instance->helpCommandExec(CmdQueue, filedescriptor);
363 /****************************************************************************/
364 void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
365 /****************************************************************************/
368 std::map<int, EMainState>::iterator it;
369 std::stringstream line;
370 tCommandMap::iterator cmdIter;
371 it = mCurrentMainStateMap.find(filedescriptor);
372 if (it != mCurrentMainStateMap.end())
374 line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl;
375 line << COLOR_HEAD << "###### The following commands are supported: ######" << COLOR_DEFAULT << std::endl;
376 line << COLOR_HEAD << "###################################################" << COLOR_DEFAULT << std::endl << std::endl;
381 cmdIter = mRootCommands.begin();
382 while (cmdIter != mRootCommands.end())
384 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
389 cmdIter = mListCommands.begin();
390 while (cmdIter != mListCommands.end())
392 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
397 cmdIter = mGetCommands.begin();
398 while (cmdIter != mGetCommands.end())
400 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
405 cmdIter = mSetCommands.begin();
406 while (cmdIter != mSetCommands.end())
408 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
413 cmdIter = mInfoCommands.begin();
414 while (cmdIter != mInfoCommands.end())
416 line << cmdIter->first << "\t\t- " << cmdIter->second.info << std::endl;
423 sendTelnetLine(filedescriptor, line);
427 /****************************************************************************/
428 void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
429 /****************************************************************************/
431 instance->rootGetCommandExec(CmdQueue, filedescriptor);
434 /****************************************************************************/
435 void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
436 /****************************************************************************/
439 std::map<int, EMainState>::iterator it;
440 it = mCurrentMainStateMap.find(filedescriptor);
441 if (it != mCurrentMainStateMap.end())
443 it->second = eGetState;
447 /****************************************************************************/
448 void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
449 /****************************************************************************/
451 instance->rootSetCommandExec(CmdQueue, filedescriptor);
454 /****************************************************************************/
455 void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
456 /****************************************************************************/
459 std::map<int, EMainState>::iterator it;
460 it = mCurrentMainStateMap.find(filedescriptor);
461 if (it != mCurrentMainStateMap.end())
463 it->second = eSetState;
467 /****************************************************************************/
468 void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
469 /****************************************************************************/
471 instance->rootListCommandExec(CmdQueue, filedescriptor);
474 /****************************************************************************/
475 void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
476 /****************************************************************************/
479 std::map<int, EMainState>::iterator it;
480 it = mCurrentMainStateMap.find(filedescriptor);
481 if (it != mCurrentMainStateMap.end())
483 it->second = eListState;
487 /****************************************************************************/
488 void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
489 /****************************************************************************/
491 instance->rootInfoCommandExec(CmdQueue, filedescriptor);
494 /****************************************************************************/
495 void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
496 /****************************************************************************/
499 std::map<int, EMainState>::iterator it;
500 it = mCurrentMainStateMap.find(filedescriptor);
501 if (it != mCurrentMainStateMap.end())
503 it->second = eInfoState;
507 /****************************************************************************/
508 void CAmTelnetMenuHelper::listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
509 /****************************************************************************/
511 instance->listConnectionsCommandExec(CmdQueue, filedescriptor);
514 /****************************************************************************/
515 void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
516 /****************************************************************************/
520 std::vector<am_Connection_s> listConnections;
521 if(E_OK == mpDatabasehandler->getListConnections(listConnections))
523 std::stringstream output;
524 output << "\tConnections: " << listConnections.size() << std::endl;
525 for (std::vector<am_Connection_s>::iterator iter(listConnections.begin()); iter < listConnections.end(); iter++)
527 output << "\tID: " << iter->connectionID
528 << "\tSrcID: " << iter->sourceID
529 << "\tSinkID: " << iter->sinkID
530 << "\tFormat: " << iter->connectionFormat
531 << "\tdelay: " << iter->delay << std::endl;
533 sendTelnetLine(filedescriptor, output);
537 sendError(filedescriptor,"ERROR: mDatabasehandler->getListConnections");
541 /****************************************************************************/
542 void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
543 /****************************************************************************/
545 instance->listSourcesCommandExec(CmdQueue, filedescriptor);
548 /****************************************************************************/
549 void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
550 /****************************************************************************/
554 std::vector<am_Source_s> listSources;
555 if(E_OK == mpDatabasehandler->getListSources(listSources))
557 std::stringstream output;
558 output << "\tSources: " << listSources.size() << std::endl;
559 for (std::vector<am_Source_s>::iterator iter(listSources.begin()); iter < listSources.end(); iter++)
561 output << "\tID: " << iter->sourceID
562 << "\tName: " << iter->name
563 << "\tDomainID: " << iter->domainID
564 << "\tState: " << iter->sourceState
565 << "\tVolume: " << iter->volume << std::endl;
567 sendTelnetLine(filedescriptor, output);
571 sendError(filedescriptor,"ERROR: mDatabasehandler->getListSources");
575 /****************************************************************************/
576 void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor)
577 /****************************************************************************/
579 instance->listSinksCommandsExec(CmdQueue, filedescriptor);
582 /****************************************************************************/
583 void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
584 /****************************************************************************/
588 std::vector<am_Sink_s> listSinks;
589 if(E_OK == mpDatabasehandler->getListSinks(listSinks))
591 std::stringstream output;
592 output << "\tSinks: " << listSinks.size() << std::endl;
593 for (std::vector<am_Sink_s>::iterator iter(listSinks.begin()); iter < listSinks.end(); iter++)
595 output << "\tID: " << iter->sinkID
596 << "\tDomainID: " << iter->domainID
597 << "\tName: " << iter->name
598 << "\tAvailable: " << iter->available.availability
599 << "\tVolume: " << iter->volume << std::endl;
602 sendTelnetLine(filedescriptor, output);
606 sendError(filedescriptor,"ERROR: mDatabasehandler->getListSinks");
610 /****************************************************************************/
611 void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor)
612 /****************************************************************************/
614 instance->listCrossfadersExec(CmdQueue, filedescriptor);
617 /****************************************************************************/
618 void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
619 /****************************************************************************/
623 std::vector<am_Crossfader_s> listCrossfaders;
624 if(E_OK == mpDatabasehandler->getListCrossfaders(listCrossfaders))
626 std::stringstream output;
627 output << "\tCrossfaders: " << listCrossfaders.size() << std::endl;
628 for (std::vector<am_Crossfader_s>::iterator iter(listCrossfaders.begin()); iter < listCrossfaders.end(); iter++)
630 output << "\tID: " << iter->crossfaderID
631 << "\tName: " << iter->name
632 << "\tSourceID: " << iter->sourceID << std::endl;
635 sendTelnetLine(filedescriptor, output);
639 sendError(filedescriptor,"ERROR: mDatabasehandler->getListCrossfaders");
643 /****************************************************************************/
644 void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
645 /****************************************************************************/
647 instance->listDomainsCommandExec(CmdQueue, filedescriptor);
650 /****************************************************************************/
651 void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
652 /****************************************************************************/
656 std::vector<am_Domain_s> listDomains;
657 if(E_OK == mpDatabasehandler->getListDomains(listDomains))
659 std::stringstream output;
660 output << "\tDomains: " << listDomains.size() << std::endl;
661 for (std::vector<am_Domain_s>::iterator iter(listDomains.begin()); iter < listDomains.end(); iter++)
663 output << "\tID: " << iter->domainID
664 << "\tName: " << iter->name
665 << "\tBusname: " << iter->busname
666 << "\tNodename: " << iter->nodename
667 << "\tState: " << static_cast<int>(iter->state) << std::endl;
670 sendTelnetLine(filedescriptor, output);
674 sendError(filedescriptor,"ERROR: mDatabasehandler->getListDomains");
678 /****************************************************************************/
679 void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
680 /****************************************************************************/
682 instance->listGatewaysCommandExec(CmdQueue, filedescriptor);
685 /****************************************************************************/
686 void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
687 /****************************************************************************/
691 std::vector<am_Gateway_s> listGateways;
692 if(E_OK == mpDatabasehandler->getListGateways(listGateways))
694 std::stringstream output;
695 output << "\tGateways: " << listGateways.size();
697 for( std::vector<am_Gateway_s>::iterator iter(listGateways.begin()); iter < listGateways.end(); iter++)
699 output << "\tID: " << iter->gatewayID
700 << "\tName: " << iter->name
701 << "\tSourceID: " << iter->sourceID
702 << "\tSinkID: " << iter->sinkID << std::endl;
704 sendTelnetLine(filedescriptor, output);
708 sendError(filedescriptor,"ERROR: mDatabasehandler->getListGateways");
712 /****************************************************************************/
713 void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
714 /****************************************************************************/
716 instance->getRoutingCommandExec(CmdQueue, filedescriptor);
719 /****************************************************************************/
720 void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
721 /****************************************************************************/
724 (void) filedescriptor;
725 //TODO: fill with function
728 /****************************************************************************/
729 void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
730 /****************************************************************************/
732 instance->getSenderversionCommandExec(CmdQueue, filedescriptor);
735 /****************************************************************************/
736 void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
737 /****************************************************************************/
741 std::stringstream output;
742 std::string versionCommand;
743 std::string versionRouting;
744 std::string versionControl;
745 mpControlSender->getInterfaceVersion(versionControl);
746 mpRoutingSender->getInterfaceVersion(versionRouting);
747 mpCommandSender->getInterfaceVersion(versionCommand);
748 output << "\tSender versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl;
750 sendTelnetLine(filedescriptor, output);
753 /****************************************************************************/
754 void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
755 /****************************************************************************/
757 instance->getReceiverversionCommandExec(CmdQueue, filedescriptor);
760 /****************************************************************************/
761 void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
762 /****************************************************************************/
766 std::stringstream output;
767 std::string versionCommand;
768 std::string versionRouting;
769 std::string versionControl;
770 mpControlReceiver->getInterfaceVersion(versionControl);
771 mpRoutingReceiver->getInterfaceVersion(versionRouting);
772 mpCommandReceiver->getInterfaceVersion(versionCommand);
773 output << "\tReceiver versions:" << std::endl << "\tCtrl: " << versionControl << " | " << "Cmd: " << versionCommand << " | " << "Routing: " << versionRouting << std::endl;
775 sendTelnetLine(filedescriptor, output);
779 /****************************************************************************/
780 void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
781 /****************************************************************************/
783 instance->infoSystempropertiesCommandExec(CmdQueue, filedescriptor);
786 /****************************************************************************/
787 void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
788 /****************************************************************************/
791 std::vector<am_SystemProperty_s> listSystemProperties;
793 if(E_OK == mpDatabasehandler->getListSystemProperties(listSystemProperties))
795 std::stringstream output;
796 output << "\tSystemproperties: " << listSystemProperties.size() << std::endl;
798 std::vector<am_SystemProperty_s>::iterator it;
799 for (it = listSystemProperties.begin(); it < listSystemProperties.end(); it++)
801 output << "\tType: " << it->type << " Value: " << it->value << std::endl;
804 sendTelnetLine(filedescriptor, output);
808 sendError(filedescriptor,"ERROR: mDatabasehandler->getListSystemProperties");
814 /****************************************************************************/
815 void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
816 /****************************************************************************/
818 instance->setRoutingCommandExec(CmdQueue, filedescriptor);
821 /****************************************************************************/
822 void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
823 /****************************************************************************/
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");
848 std::vector<am_Route_s> routingList;
849 if (E_OK == mpRouter->getRoute(true, sourceID, sinkID, routingList))
851 std::stringstream output;
853 std::vector<am_Route_s>::iterator rlIter = routingList.begin();
854 for (int rlCnt = 1; rlIter < routingList.end(); rlIter++)
856 output << "#" << rlCnt << " ";
858 std::vector<am_RoutingElement_s>::iterator reIter = rlIter->route.begin();
859 for (; reIter < rlIter->route.end(); reIter++)
861 reIter->connectionFormat;
863 output << ">(" << reIter->sourceID << ")->--[D:" << reIter->domainID << "][F:" << reIter->connectionFormat << "]-->-(" << reIter->sinkID << ")" << std::endl;
869 sendTelnetLine(filedescriptor, output);
873 sendError(filedescriptor, "Error getting route");
879 if(!CmdQueue.empty())
882 sendError(filedescriptor,"Not enough arguments to set routing. Please enter sourceID and sinkID after command");
887 /****************************************************************************/
888 void CAmTelnetMenuHelper::setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor)
889 /****************************************************************************/
891 instance->setConnectionExec(CmdQueue, filedescriptor);
894 /****************************************************************************/
895 void CAmTelnetMenuHelper::setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
896 /****************************************************************************/
899 am_Error_e rError = E_OK;
901 if (CmdQueue.size() >= 2)
903 std::istringstream istream_sourceID(CmdQueue.front());
906 std::istringstream istream_sinkID(CmdQueue.front());
909 am_sourceID_t sourceID = 0;
910 if (!(istream_sourceID >> sourceID))
913 am_sinkID_t sinkID = 0;
914 if (!(istream_sinkID >> sinkID))
919 sendError(filedescriptor, "Error parsing sinkID and/or sourceID");
923 // Try to set up connection
924 am_mainConnectionID_t connID = 0;
925 rError = mpCommandReceiver->connect(sourceID, sinkID, connID);
929 std::stringstream output;
930 output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl;
931 sendTelnetLine(filedescriptor, output);
935 sendError(filedescriptor, "Error connecting sourceID and sinkID");
941 // remove 1 element if list is not empty
942 if(!CmdQueue.empty())
945 sendError(filedescriptor, "Not enough arguments to set routing. Please enter sourceID and sinkID after command");
950 /****************************************************************************/
951 void CAmTelnetMenuHelper::setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor)
952 /****************************************************************************/
954 instance->setDisconnectConnIdExec(CmdQueue, filedescriptor);
957 /****************************************************************************/
958 void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
959 /****************************************************************************/
961 am_mainConnectionID_t connID = 0;
964 am_Error_e rError = E_OK;
966 if (CmdQueue.size() >= 1)
968 std::istringstream istream_connID(CmdQueue.front());
971 if (!(istream_connID >> connID))
976 sendError(filedescriptor, "Error parsing connID");
980 // Try to disconnect connection id
981 rError = mpCommandReceiver->disconnect(connID);
985 std::stringstream output;
986 output << "ConnID " << connID << " closed successfully! " << std::endl;
987 sendTelnetLine(filedescriptor, output);
991 sendError(filedescriptor, "Error disconnecting connectionID");
996 sendError(filedescriptor, "Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command");
1001 /****************************************************************************/
1002 void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1003 /****************************************************************************/
1005 instance->setConnectionExec(CmdQueue, filedescriptor);
1008 /****************************************************************************/
1009 void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1010 /****************************************************************************/
1012 if (CmdQueue.size() >= 3)
1016 std::istringstream istream_sourceID(CmdQueue.front());
1019 std::istringstream istream_type(CmdQueue.front());
1022 std::istringstream istream_value(CmdQueue.front());
1025 unsigned int tmpType = 0;
1026 if (!(istream_type >> tmpType))
1029 am_MainSoundProperty_s soundProperty;
1030 if (tmpType < MSP_MAX)
1031 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1035 if (!(istream_value >> soundProperty.value))
1038 am_sinkID_t sourceID = 0;
1039 if (!(istream_sourceID >> sourceID))
1044 sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'");
1048 if (E_OK == mpCommandReceiver->setMainSourceSoundProperty(soundProperty, sourceID))
1050 std::stringstream output;
1051 output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1052 sendTelnetLine(filedescriptor, output);
1056 sendError(filedescriptor, "Error setMainSourceSoundProperty");
1061 sendError(filedescriptor, "Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
1066 /****************************************************************************/
1067 void CAmTelnetMenuHelper::setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1068 /****************************************************************************/
1070 instance->setConnectionExec(CmdQueue, filedescriptor);
1073 /****************************************************************************/
1074 void CAmTelnetMenuHelper::setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1075 /****************************************************************************/
1077 unsigned int tmpType = 0;
1080 if (CmdQueue.size() >= 3)
1082 std::istringstream istream_sinkID(CmdQueue.front());
1085 std::istringstream istream_type(CmdQueue.front());
1088 std::istringstream istream_value(CmdQueue.front());
1091 if (!(istream_type >> tmpType))
1094 am_MainSoundProperty_s soundProperty;
1095 if (tmpType < MSP_MAX)
1096 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1100 if (!(istream_value >> soundProperty.value))
1103 am_sinkID_t sinkID = 0;
1104 if (!(istream_sinkID >> sinkID))
1109 sendError(filedescriptor, "Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'");
1113 if (E_OK == mpCommandReceiver->setMainSinkSoundProperty(soundProperty, sinkID))
1115 std::stringstream output;
1116 output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1117 sendTelnetLine(filedescriptor, output);
1121 sendError(filedescriptor, "Error setMainSinkSoundProperty");
1126 sendError(filedescriptor, "Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command");
1131 /****************************************************************************/
1132 void CAmTelnetMenuHelper::listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1133 /****************************************************************************/
1135 instance->listPluginsCommandExec(CmdQueue, filedescriptor);
1138 /****************************************************************************/
1139 void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1140 /****************************************************************************/
1143 std::vector<std::string> PlugInNames;
1144 std::vector<std::string>::iterator iter;
1145 std::stringstream output;
1148 if(E_OK == mpCommandSender->getListPlugins(PlugInNames))
1150 output << "\tCommandSender Plugins loaded: " << PlugInNames.size() << std::endl;
1152 for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++)
1154 output << iter->c_str() << std::endl;
1159 sendError(filedescriptor,"ERROR: mCommandSender->getListPlugins");
1163 if(E_OK == mpRoutingSender->getListPlugins(PlugInNames))
1165 output << std::endl << "\tRoutingSender Plugins loaded: " << PlugInNames.size() << std::endl;
1167 for (iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++)
1169 output << iter->c_str() << std::endl;
1174 sendError(filedescriptor,"ERROR: mRoutingSender->getListPlugins");
1177 sendTelnetLine(filedescriptor, output);
1181 /****************************************************************************/
1182 void CAmTelnetMenuHelper::listMainSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1183 /****************************************************************************/
1185 instance->listMainSourcesCommandExec(CmdQueue,filedescriptor);
1188 /****************************************************************************/
1189 void CAmTelnetMenuHelper::listMainSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1190 /****************************************************************************/
1193 std::vector<am_SourceType_s> listMainSources;
1195 if(E_OK == mpDatabasehandler->getListMainSources(listMainSources))
1197 std::stringstream output;
1198 output << std::endl << "\tMainSources: " << listMainSources.size() << std::endl;
1200 std::vector<am_SourceType_s>::iterator iter;
1201 for (iter = listMainSources.begin(); iter < listMainSources.end(); iter++)
1203 output << "\t" << iter->name << "\tID: " << iter->sourceID
1204 << "\tClassID: " << iter->sourceClassID
1205 << "\tavailability: " << static_cast<int>(iter->availability.availability)
1206 << "\tavailabilityReason: " << static_cast<int>(iter->availability.availabilityReason) << std::endl;
1208 sendTelnetLine(filedescriptor,output);
1212 sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSources");
1216 /****************************************************************************/
1217 void CAmTelnetMenuHelper::listMainSinksCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1218 /****************************************************************************/
1220 instance->listMainSinksCommandExec(CmdQueue,filedescriptor);
1223 /****************************************************************************/
1224 void CAmTelnetMenuHelper::listMainSinksCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1225 /****************************************************************************/
1228 std::vector<am_SinkType_s> listMainSinks;
1230 if(E_OK == mpDatabasehandler->getListMainSinks(listMainSinks))
1232 std::stringstream output;
1233 output << std::endl << "\tMainSinks: " << listMainSinks.size() << std::endl;
1235 std::vector<am_SinkType_s>::iterator iter;
1236 for ( iter = listMainSinks.begin(); iter < listMainSinks.end(); iter++)
1238 output << "\t" << iter->name << "\tID: " << iter->sinkID
1239 << "\tClassID: " << iter->sinkClassID
1240 << "\tavailability: " << static_cast<int>(iter->availability.availability)
1241 << "\tavailabilityReason: " << static_cast<int>(iter->availability.availabilityReason)
1242 << "\tMuteState: " << iter->muteState
1243 << "\tVolume: " << iter->volume << std::endl;
1245 sendTelnetLine(filedescriptor,output);
1249 sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks");
1253 /****************************************************************************/
1254 void CAmTelnetMenuHelper::listMainConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1255 /****************************************************************************/
1257 instance->listMainConnectionsCommandExec(CmdQueue,filedescriptor);
1260 /****************************************************************************/
1261 void CAmTelnetMenuHelper::listMainConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1262 /****************************************************************************/
1265 std::vector<am_MainConnection_s> listMainConnections;
1267 if(E_OK == mpDatabasehandler->getListMainConnections(listMainConnections))
1269 std::stringstream output;
1270 output << std::endl << "\tMainConnections: " << listMainConnections.size() << std::endl;
1272 std::vector<am_MainConnection_s>::iterator iter;
1273 for (iter = listMainConnections.begin(); iter < listMainConnections.end(); iter++)
1275 output << "\tID: " << iter->mainConnectionID
1276 << "\tState: " << iter->connectionState
1277 << "\tDelay: " << iter->delay
1278 << "\tsourceID: " << iter->sourceID
1279 << "\tsinkID: " << iter->sinkID << std::endl;
1281 output << "ConnectionIDs: ";
1282 std::vector<am_connectionID_t>::iterator list_connIDs_iter = iter->listConnectionID.begin();
1283 for(;list_connIDs_iter < iter->listConnectionID.end();list_connIDs_iter++)
1285 output << *list_connIDs_iter << " ";
1288 output << std::endl;
1290 sendTelnetLine(filedescriptor,output);
1294 sendError(filedescriptor,"ERROR: mDatabasehandler->getListMainSinks");