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,
46 CommandSender *iCommandSender,
47 CommandReceiver *iCommandReceiver,
48 RoutingSender *iRoutingSender,
49 RoutingReceiver *iRoutingReceiver,
50 ControlSender *iControlSender,
51 ControlReceiver *iControlReceiver,
52 DatabaseHandler *iDatabasehandler,
54 TelnetServer *iTelnetServer)
55 /****************************************************************************/
56 : mTelenetServer(iTelnetServer)
57 , mSocketHandler(iSocketHandler)
58 , mCommandSender(iCommandSender)
59 , mCommandReceiver(iCommandReceiver)
60 , mRoutingSender(iRoutingSender)
61 , mRoutingReceiver(iRoutingReceiver)
62 , mControlSender(iControlSender)
63 , mControlReceiver(iControlReceiver)
64 , mDatabasehandler(iDatabasehandler)
71 /****************************************************************************/
72 CAmTelnetMenuHelper::~CAmTelnetMenuHelper()
73 /****************************************************************************/
77 /****************************************************************************/
78 void CAmTelnetMenuHelper::createCommandMaps()
79 /****************************************************************************/
83 mRootCommands.clear();
85 mRootCommands.insert(std::make_pair("help",sCommandPrototypeInfo("show all possible commands",&CAmTelnetMenuHelper::helpCommand)));
86 mRootCommands.insert(std::make_pair("list",sCommandPrototypeInfo("Go into 'list'-submenu",&CAmTelnetMenuHelper::rootListCommand)));
87 mRootCommands.insert(std::make_pair("info",sCommandPrototypeInfo("Go into 'info'-submenu",&CAmTelnetMenuHelper::rootInfoCommand)));
88 mRootCommands.insert(std::make_pair("set",sCommandPrototypeInfo("Go into 'set'-submenu",&CAmTelnetMenuHelper::rootSetCommand)));
89 mRootCommands.insert(std::make_pair("get",sCommandPrototypeInfo("Go into 'get'-submenu",&CAmTelnetMenuHelper::rootGetCommand)));
90 mRootCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("quit telnet session",&CAmTelnetMenuHelper::exitCommand)));
93 mListCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
94 mListCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("list all connections",&CAmTelnetMenuHelper::listConnectionsCommand)));
95 mListCommands.insert(std::make_pair("sources",sCommandPrototypeInfo("list all available sources",&CAmTelnetMenuHelper::listSourcesCommand)));
96 mListCommands.insert(std::make_pair("sinks",sCommandPrototypeInfo("list all available sinks",&CAmTelnetMenuHelper::listSinksCommands)));
97 mListCommands.insert(std::make_pair("crfaders",sCommandPrototypeInfo("list all crossfaders",&CAmTelnetMenuHelper::listCrossfaders)));
98 mListCommands.insert(std::make_pair("domains",sCommandPrototypeInfo("list all domains",&CAmTelnetMenuHelper::listDomainsCommand)));
99 mListCommands.insert(std::make_pair("gws",sCommandPrototypeInfo("list all gateways",&CAmTelnetMenuHelper::listGatewaysCommand)));
100 mListCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
101 mListCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
104 mSetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
105 mSetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
106 mSetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
107 mSetCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink",&CAmTelnetMenuHelper::setConnection)));
108 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)));
109 mSetCommands.insert(std::make_pair("disc",sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t this connection",&CAmTelnetMenuHelper::setDisconnectConnId)));
112 mGetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
113 mGetCommands.insert(std::make_pair("routing",sCommandPrototypeInfo("show current routing",&CAmTelnetMenuHelper::getRoutingCommand)));
114 mGetCommands.insert(std::make_pair("sendv",sCommandPrototypeInfo("show senderversion",&CAmTelnetMenuHelper::getSenderversionCommand)));
115 mGetCommands.insert(std::make_pair("recv",sCommandPrototypeInfo("show receiverversion ",&CAmTelnetMenuHelper::getReceiverversionCommand)));
116 mGetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
117 mGetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
120 mInfoCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
121 mInfoCommands.insert(std::make_pair("sysprop",sCommandPrototypeInfo("show all systemproperties",&CAmTelnetMenuHelper::infoSystempropertiesCommand)));
122 mInfoCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
123 mInfoCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
126 /****************************************************************************/
127 void CAmTelnetMenuHelper::setTelnetServer(TelnetServer* iTelnetServer)
128 /****************************************************************************/
130 mTelenetServer = iTelnetServer;
133 /****************************************************************************/
134 void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor)
135 /****************************************************************************/
137 EMainState state = eRootState;
138 std::map<int,EMainState>::iterator it;
139 std::stringstream welcome;
141 it = mCurrentMainStateMap.find(filedescriptor);
142 if( it != mCurrentMainStateMap.end())
144 // socket connection already exists, delete entry and go back to root state
145 mCurrentMainStateMap.erase(it);
148 it = mCurrentMainStateMap.begin();
150 // insert new socket connection
151 mCurrentMainStateMap.insert(it,std::make_pair<int,EMainState>(filedescriptor,state));
153 // Send welcome message
154 welcome << "Welcome to GENIVI AudioManager " << DAEMONVERSION << "\n>";
155 send(filedescriptor,welcome.str().c_str(),welcome.str().size(),0);
158 /****************************************************************************/
159 void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor)
160 /****************************************************************************/
162 std::map<int,EMainState>::iterator it;
164 it = mCurrentMainStateMap.find(filedescriptor);
165 if( it != mCurrentMainStateMap.end())
167 mCurrentMainStateMap.erase(it);
171 // connection not found
175 /****************************************************************************/
176 void CAmTelnetMenuHelper::enterCmdQueue(std::queue<std::string> & CmdQueue, int & filedescriptor)
177 /****************************************************************************/
179 std::map<int,EMainState>::iterator it;
181 tCommandMap::iterator cmditer;
183 // find current filedescriptor to get the current state of the telnet session
184 it = mCurrentMainStateMap.find(filedescriptor);
185 while(!CmdQueue.empty())
187 cmd = CmdQueue.front();
189 // Now remove the first command, it's stored in 'cmd'
191 // telnet session found. depending on the current state, different commands are available
195 cmditer = mRootCommands.find(cmd);
196 if(mRootCommands.end() != cmditer)
197 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
199 sendError(filedescriptor,"Command not found\n");
202 cmditer = mListCommands.find(cmd);
203 if(mListCommands.end() != cmditer)
204 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
206 sendError(filedescriptor,"Command not found\n");
209 cmditer = mInfoCommands.find(cmd);
210 if(mInfoCommands.end() != cmditer)
211 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
213 sendError(filedescriptor,"Command not found\n");
216 cmditer = mGetCommands.find(cmd);
217 if(mGetCommands.end() != cmditer)
218 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
220 sendError(filedescriptor,"Command not found\n");
223 cmditer = mSetCommands.find(cmd);
224 if(mSetCommands.end() != cmditer)
225 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
227 sendError(filedescriptor,"Command not found\n");
234 sendCurrentCmdPrompt(filedescriptor);
237 /****************************************************************************/
238 void CAmTelnetMenuHelper::sendError(int & filedescriptor, std::string error_string)
239 /****************************************************************************/
241 send(filedescriptor,error_string.c_str(),error_string.size(),0);
244 /****************************************************************************/
245 void CAmTelnetMenuHelper::sendTelnetLine(int & filedescriptor, std::stringstream &line)
246 /****************************************************************************/
248 send(filedescriptor,line.str().c_str(),line.str().size(),0);
251 /****************************************************************************/
252 void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int & filedescriptor)
253 /****************************************************************************/
255 std::map<int,EMainState>::iterator it;
256 std::stringstream outputstream;
257 outputstream << std::endl;
259 it = mCurrentMainStateMap.find(filedescriptor);
260 if( it != mCurrentMainStateMap.end())
265 outputstream << "\\>";
268 outputstream << "\\List>";
271 outputstream << "\\Get>";
274 outputstream << "\\Set>";
277 outputstream << "\\Info>";
283 send(filedescriptor,outputstream.str().c_str(),outputstream.str().size(),0);
288 // connection not found
292 /****************************************************************************/
293 void CAmTelnetMenuHelper::exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
294 /****************************************************************************/
296 instance->exitCommandExec(CmdQueue,filedescriptor);
299 /****************************************************************************/
300 void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
301 /****************************************************************************/
303 std::map<int,EMainState>::iterator it;
304 it = mCurrentMainStateMap.find(filedescriptor);
305 if( it != mCurrentMainStateMap.end())
307 if(DEBUG_ON)std::cout << "old state: " << it->second;
311 it->second = eRootState;
314 it->second = eRootState;;
317 it->second = eRootState;;
320 it->second = eRootState;;
323 it->second = eRootState;;
326 it->second = eRootState;
329 if(DEBUG_ON)std::cout << "new state: " << it->second << std::endl;
333 /****************************************************************************/
334 void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
335 /****************************************************************************/
337 instance->oneStepBackCommandExec(CmdQueue,filedescriptor);
340 /****************************************************************************/
341 void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
342 /****************************************************************************/
344 std::map<int,EMainState>::iterator it;
345 std::stringstream line;
346 std::stringstream output;
348 // Sending a last message to the client
349 output << "Your wish is my command ... bye!" << std::endl;
350 sendTelnetLine(filedescriptor,output);
353 tCommandMap::iterator iter;
354 it = mCurrentMainStateMap.find(filedescriptor);
355 if( it != mCurrentMainStateMap.end())
357 if(DEBUG_ON)std::cout << "removing client connection " << filedescriptor << std::endl;
359 if(NULL != mTelenetServer)
361 mTelenetServer->disconnectClient(filedescriptor);
362 mCurrentMainStateMap.erase(it);
366 // ASSERT mTelenetServer == NULL
367 if(DEBUG_ON)std::cout << "mTelenetServer";
372 /****************************************************************************/
373 void CAmTelnetMenuHelper::helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
374 /****************************************************************************/
376 instance->helpCommandExec(CmdQueue,filedescriptor);
379 /****************************************************************************/
380 void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
381 /****************************************************************************/
383 std::map<int,EMainState>::iterator it;
384 std::stringstream line;
385 tCommandMap::iterator cmdIter;
386 it = mCurrentMainStateMap.find(filedescriptor);
387 if( it != mCurrentMainStateMap.end())
389 line << "###################################################" << std::endl;
390 line << "###### The following commands are supported: ######"<< std::endl;
391 line << "###################################################" << std::endl << std::endl;
396 cmdIter = mRootCommands.begin();
397 while(cmdIter != mRootCommands.end())
399 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
404 cmdIter = mListCommands.begin();
405 while(cmdIter != mListCommands.end())
407 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
412 cmdIter = mGetCommands.begin();
413 while(cmdIter != mGetCommands.end())
415 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
420 cmdIter = mSetCommands.begin();
421 while(cmdIter != mSetCommands.end())
423 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
428 cmdIter = mInfoCommands.begin();
429 while(cmdIter != mInfoCommands.end())
431 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
438 sendTelnetLine(filedescriptor,line);
442 /****************************************************************************/
443 void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
444 /****************************************************************************/
446 instance->rootGetCommandExec(CmdQueue,filedescriptor);
449 /****************************************************************************/
450 void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
451 /****************************************************************************/
453 std::map<int,EMainState>::iterator it;
454 it = mCurrentMainStateMap.find(filedescriptor);
455 if( it != mCurrentMainStateMap.end())
457 it->second = eGetState;
461 /****************************************************************************/
462 void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
463 /****************************************************************************/
465 instance->rootSetCommandExec(CmdQueue,filedescriptor);
468 /****************************************************************************/
469 void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
470 /****************************************************************************/
472 std::map<int,EMainState>::iterator it;
473 it = mCurrentMainStateMap.find(filedescriptor);
474 if( it != mCurrentMainStateMap.end())
476 it->second = eSetState;
480 /****************************************************************************/
481 void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
482 /****************************************************************************/
484 instance->rootListCommandExec(CmdQueue,filedescriptor);
487 /****************************************************************************/
488 void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
489 /****************************************************************************/
491 std::map<int,EMainState>::iterator it;
492 it = mCurrentMainStateMap.find(filedescriptor);
493 if( it != mCurrentMainStateMap.end())
495 it->second = eListState;
499 /****************************************************************************/
500 void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
501 /****************************************************************************/
503 instance->rootInfoCommandExec(CmdQueue,filedescriptor);
506 /****************************************************************************/
507 void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
508 /****************************************************************************/
510 std::map<int,EMainState>::iterator it;
511 it = mCurrentMainStateMap.find(filedescriptor);
512 if( it != mCurrentMainStateMap.end())
514 it->second = eInfoState;
518 /****************************************************************************/
519 void CAmTelnetMenuHelper::listConnectionsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
520 /****************************************************************************/
522 instance->listConnectionsCommandExec(CmdQueue,filedescriptor);
525 /****************************************************************************/
526 void CAmTelnetMenuHelper::listConnectionsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
527 /****************************************************************************/
529 std::vector<am_Connection_s> listConnections;
530 std::stringstream line;
532 mDatabasehandler->getListConnections(listConnections);
534 line << "\tCurrent connections: " << listConnections.size() << std::endl;
536 sendTelnetLine(filedescriptor,line);
538 std::vector<am_Connection_s>::iterator it(listConnections.begin());
539 while(it != listConnections.end())
542 line << "\tID: " << it->connectionID
543 << "\tSrcID: " << it->sourceID
544 << "\tSinkID: " << it->sinkID
545 << "\tFormat: " << it->connectionFormat
546 << "\tdelay: " << it->delay
549 sendTelnetLine(filedescriptor,line);
554 /****************************************************************************/
555 void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
556 /****************************************************************************/
558 instance->listSourcesCommandExec(CmdQueue,filedescriptor);
561 /****************************************************************************/
562 void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
563 /****************************************************************************/
565 std::vector<am_Source_s> listSources;
566 std::stringstream line;
568 mDatabasehandler->getListSources(listSources);
570 line << "\tCurrent sources: " << listSources.size();
571 sendTelnetLine(filedescriptor,line);
573 std::vector<am_Source_s>::iterator it(listSources.begin());
574 while(it != listSources.end())
577 line << "\tID: " << it->sourceID
578 << "\tDomainID: " << it->domainID
579 << "\tName: " << it->name
580 << "\tState: " << it->sourceState
581 << "\tVolume: " << it->volume
584 sendTelnetLine(filedescriptor,line);
589 /****************************************************************************/
590 void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor)
591 /****************************************************************************/
593 instance->listSinksCommandsExec(CmdQueue,filedescriptor);
596 /****************************************************************************/
597 void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
598 /****************************************************************************/
600 std::vector<am_Sink_s> listSinks;
601 std::stringstream line;
603 mDatabasehandler->getListSinks(listSinks);
605 line << "\tCurrent sinks: " << listSinks.size() << std::endl;
606 sendTelnetLine(filedescriptor,line);
608 std::vector<am_Sink_s>::iterator it(listSinks.begin());
609 while(it != listSinks.end())
612 line << "\tID: " << it->sinkID
613 << "\tDomainID: " << it->domainID
614 << "\tName: " << it->name
615 << "\tAvailable: " << it->available.availability
616 << "\tVolume: " << it->volume
619 sendTelnetLine(filedescriptor,line);
624 /****************************************************************************/
625 void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor)
626 /****************************************************************************/
628 instance->listCrossfadersExec(CmdQueue,filedescriptor);
631 /****************************************************************************/
632 void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
633 /****************************************************************************/
635 std::vector<am_Crossfader_s> listCrossfaders;
636 std::stringstream line;
638 mDatabasehandler->getListCrossfaders(listCrossfaders);
640 line << "\tCurrent crossfaders: " << listCrossfaders.size();
641 sendTelnetLine(filedescriptor,line);
643 std::vector<am_Crossfader_s>::iterator it(listCrossfaders.begin());
644 while(it != listCrossfaders.end())
647 line << "\tID: " << it->crossfaderID
648 << "\tName: " << it->name
649 << "\tSourceID: " << it->sourceID
652 sendTelnetLine(filedescriptor,line);
657 /****************************************************************************/
658 void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
659 /****************************************************************************/
661 instance->listDomainsCommandExec(CmdQueue,filedescriptor);
664 /****************************************************************************/
665 void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
666 /****************************************************************************/
668 std::vector<am_Domain_s> listDomains;
669 std::stringstream line;
671 mDatabasehandler->getListDomains(listDomains);
673 line << "\tCurrent domains: " << listDomains.size()<<std::endl;
674 sendTelnetLine(filedescriptor,line);
676 std::vector<am_Domain_s>::iterator it(listDomains.begin());
677 while(it != listDomains.end())
680 line << "\tID: " << it->domainID
681 << "\tName: " << it->name
682 << "\tBusname: " << it->busname
683 << "\tNodename: " << it->nodename
684 << "\tState: " << static_cast<int>(it->state)
687 sendTelnetLine(filedescriptor,line);
692 /****************************************************************************/
693 void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
694 /****************************************************************************/
696 instance->listGatewaysCommandExec(CmdQueue,filedescriptor);
699 /****************************************************************************/
700 void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
701 /****************************************************************************/
703 std::vector<am_Gateway_s> listGateways;
704 std::stringstream line;
706 mDatabasehandler->getListGateways(listGateways);
708 line << "\tCurrent gateways: " << listGateways.size();
709 sendTelnetLine(filedescriptor,line);
711 std::vector<am_Gateway_s>::iterator it(listGateways.begin());
712 while(it != listGateways.end())
715 line << "\tID: " << it->gatewayID
716 << "\tName: " << it->name
717 << "\tSourceID: " << it->sourceID
718 << "\tSinkID: " << it->sinkID
721 sendTelnetLine(filedescriptor,line);
726 /****************************************************************************/
727 void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
728 /****************************************************************************/
730 instance->getRoutingCommandExec(CmdQueue,filedescriptor);
733 /****************************************************************************/
734 void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
735 /****************************************************************************/
737 //TODO: fill with function
740 /****************************************************************************/
741 void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
742 /****************************************************************************/
744 instance->getSenderversionCommandExec(CmdQueue,filedescriptor);
747 /****************************************************************************/
748 void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
749 /****************************************************************************/
751 std::stringstream line;
753 line << "\tSender versions:" << std::endl
754 << "\tCtrl: " << mControlSender->getInterfaceVersion() << " | "
755 << "Cmd: " << mCommandSender->getInterfaceVersion() << " | "
756 << "Routing: " << mRoutingSender->getInterfaceVersion() << std::endl;
758 sendTelnetLine(filedescriptor,line);
761 /****************************************************************************/
762 void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
763 /****************************************************************************/
765 instance->getReceiverversionCommandExec(CmdQueue,filedescriptor);
768 /****************************************************************************/
769 void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
770 /****************************************************************************/
772 std::stringstream line;
774 line << "\tReceiver versions:" << std::endl
775 << "\tCtrl: " << mControlReceiver->getInterfaceVersion() << " | "
776 << "Cmd: " << mCommandReceiver->getInterfaceVersion() << " | "
777 << "Routing: " << mRoutingReceiver->getInterfaceVersion() << std::endl;
779 sendTelnetLine(filedescriptor,line);
783 /****************************************************************************/
784 void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
785 /****************************************************************************/
787 instance->infoSystempropertiesCommandExec(CmdQueue,filedescriptor);
790 /****************************************************************************/
791 void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
792 /****************************************************************************/
794 std::vector<am_SystemProperty_s> listSystemProperties;
795 std::vector<am_SystemProperty_s>::iterator it;
796 std::stringstream line;
798 mDatabasehandler->getListSystemProperties(listSystemProperties);
800 line << "\tSystemproperties: ";
801 sendTelnetLine(filedescriptor,line);
803 for(it = listSystemProperties.begin(); it < listSystemProperties.end(); it++ )
806 line << "\tType: " << it->type << " Value: " << it->value << std::endl;
807 sendTelnetLine(filedescriptor,line);
811 /****************************************************************************/
812 void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
813 /****************************************************************************/
815 instance->setRoutingCommandExec(CmdQueue,filedescriptor);
818 /****************************************************************************/
819 void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
820 /****************************************************************************/
822 std::stringstream output;
823 std::vector<am_Route_s> routingList;
825 am_sourceID_t sourceID = 0;
826 am_sinkID_t sinkID = 0;
829 am_Error_e rError = E_OK;
832 if(CmdQueue.size() >= 2)
834 std::istringstream istream_sourceID(CmdQueue.front());
836 std::istringstream istream_sinkID(CmdQueue.front());
839 if(!(istream_sourceID >> sourceID))
841 if(!(istream_sinkID >> sinkID))
846 sendError(filedescriptor,"Error parsing sourcID and sinkID");
850 if(DEBUG_ON)std::cout << "setRoutingCommandExec(sourceID: " << sourceID << ",sinkID: " << sinkID << ")" << std::endl;
852 rError = mRouter->getRoute(true,sourceID,sinkID,routingList);
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");
883 output << "Not enough arguments to set routing. Please enter sourceID and sinkID after command" << std::endl;
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 /****************************************************************************/
901 std::stringstream output;
903 am_sourceID_t sourceID = 0;
904 am_sinkID_t sinkID = 0;
905 am_mainConnectionID_t connID = 0;
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 if(!(istream_sourceID >> sourceID))
921 if(!(istream_sinkID >> sinkID))
926 sendError(filedescriptor,"Error parsing sinkID and/or sourceID");
930 // Try to set up connection
931 rError = mCommandReceiver->connect(sourceID,sinkID,connID);
935 output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl;
936 sendTelnetLine(filedescriptor,output);
940 sendError(filedescriptor,"Error connecting sourceID and sinkID");
947 sendError(filedescriptor,"Not enough arguments to set routing. Please enter sourceID and sinkID after command");
952 /****************************************************************************/
953 void CAmTelnetMenuHelper::setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor)
954 /****************************************************************************/
956 instance->setDisconnectConnIdExec(CmdQueue,filedescriptor);
959 /****************************************************************************/
960 void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
961 /****************************************************************************/
963 std::stringstream output;
965 am_mainConnectionID_t connID = 0;
968 am_Error_e rError = E_OK;
970 if(CmdQueue.size() >= 1)
972 std::istringstream istream_connID(CmdQueue.front());
975 if(!(istream_connID >> connID))
980 sendError(filedescriptor,"Error parsing connID");
984 // Try to disconnect connection id
985 rError = mCommandReceiver->disconnect(connID);
989 output << "ConnID " << connID << " closed successfully! " << std::endl;
990 sendTelnetLine(filedescriptor,output);
994 sendError(filedescriptor,"Error disconnecting connectionID");
999 sendError(filedescriptor,"Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command");
1004 /****************************************************************************/
1005 void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1006 /****************************************************************************/
1008 instance->setConnectionExec(CmdQueue,filedescriptor);
1011 /****************************************************************************/
1012 void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1013 /****************************************************************************/
1015 std::stringstream output;
1016 am_sinkID_t sourceID;
1017 am_MainSoundProperty_s soundProperty;
1018 unsigned int tmpType = 0;
1021 if(CmdQueue.size() >= 3)
1023 std::istringstream istream_sourceID(CmdQueue.front());
1026 std::istringstream istream_type(CmdQueue.front());
1029 std::istringstream istream_value(CmdQueue.front());
1032 if(!(istream_type >> tmpType))
1035 if(tmpType < MSP_MAX)
1036 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1040 if(!(istream_value >> soundProperty.value))
1043 if(!(istream_sourceID >> sourceID))
1048 sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'");
1052 if(E_OK == mCommandReceiver->setMainSourceSoundProperty(soundProperty,sourceID))
1054 output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1055 sendTelnetLine(filedescriptor,output);
1059 sendError(filedescriptor,"Error setMainSourceSoundProperty");
1064 sendError(filedescriptor,"Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
1069 /****************************************************************************/
1070 void CAmTelnetMenuHelper::setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1071 /****************************************************************************/
1073 instance->setConnectionExec(CmdQueue,filedescriptor);
1076 /****************************************************************************/
1077 void CAmTelnetMenuHelper::setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1078 /****************************************************************************/
1080 std::stringstream output;
1082 am_MainSoundProperty_s soundProperty;
1083 unsigned int tmpType = 0;
1086 if(CmdQueue.size() >= 3)
1088 std::istringstream istream_sinkID(CmdQueue.front());
1091 std::istringstream istream_type(CmdQueue.front());
1094 std::istringstream istream_value(CmdQueue.front());
1097 if(!(istream_type >> tmpType))
1100 if(tmpType < MSP_MAX)
1101 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1105 if(!(istream_value >> soundProperty.value))
1108 if(!(istream_sinkID >> sinkID))
1113 sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'");
1117 if(E_OK == mCommandReceiver->setMainSinkSoundProperty(soundProperty,sinkID))
1119 output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1120 sendTelnetLine(filedescriptor,output);
1124 sendError(filedescriptor,"Error setMainSinkSoundProperty");
1129 sendError(filedescriptor,"Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command");
1135 /****************************************************************************/
1136 void CAmTelnetMenuHelper::listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1137 /****************************************************************************/
1139 instance->listPluginsCommandExec(CmdQueue,filedescriptor);
1142 /****************************************************************************/
1143 void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1144 /****************************************************************************/
1146 std::vector<std::string> PlugInNames;
1147 std::vector<std::string>::iterator iter;
1148 std::stringstream output;
1149 am_Error_e rError = E_OK;
1152 rError = mCommandSender->getListPlugins(PlugInNames);
1154 output << "CommandSender Plugins loaded: " << PlugInNames.size() << std::endl;
1156 for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
1158 output << iter->c_str() << std::endl;
1161 rError = mRoutingSender->getListPlugins(PlugInNames);
1163 output << std::endl << "RoutingSender Plugins loaded: " << PlugInNames.size() << std::endl;
1165 for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
1167 output << iter->c_str() << std::endl;
1170 sendTelnetLine(filedescriptor,output);