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 /****************************************************************************/
55 : mTelenetServer(NULL)
56 , mSocketHandler(iSocketHandler)
57 , mCommandSender(iCommandSender)
58 , mCommandReceiver(iCommandReceiver)
59 , mRoutingSender(iRoutingSender)
60 , mRoutingReceiver(iRoutingReceiver)
61 , mControlSender(iControlSender)
62 , mControlReceiver(iControlReceiver)
63 , mDatabasehandler(iDatabasehandler)
70 /****************************************************************************/
71 CAmTelnetMenuHelper::~CAmTelnetMenuHelper()
72 /****************************************************************************/
76 /****************************************************************************/
77 void CAmTelnetMenuHelper::createCommandMaps()
78 /****************************************************************************/
82 mRootCommands.clear();
84 mRootCommands.insert(std::make_pair("help",sCommandPrototypeInfo("show all possible commands",&CAmTelnetMenuHelper::helpCommand)));
85 mRootCommands.insert(std::make_pair("list",sCommandPrototypeInfo("Go into 'list'-submenu",&CAmTelnetMenuHelper::rootListCommand)));
86 mRootCommands.insert(std::make_pair("info",sCommandPrototypeInfo("Go into 'info'-submenu",&CAmTelnetMenuHelper::rootInfoCommand)));
87 mRootCommands.insert(std::make_pair("set",sCommandPrototypeInfo("Go into 'set'-submenu",&CAmTelnetMenuHelper::rootSetCommand)));
88 mRootCommands.insert(std::make_pair("get",sCommandPrototypeInfo("Go into 'get'-submenu",&CAmTelnetMenuHelper::rootGetCommand)));
89 mRootCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("quit telnet session",&CAmTelnetMenuHelper::exitCommand)));
92 mListCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
93 mListCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("list all connections",&CAmTelnetMenuHelper::listConnectionsCommand)));
94 mListCommands.insert(std::make_pair("sources",sCommandPrototypeInfo("list all available sources",&CAmTelnetMenuHelper::listSourcesCommand)));
95 mListCommands.insert(std::make_pair("sinks",sCommandPrototypeInfo("list all available sinks",&CAmTelnetMenuHelper::listSinksCommands)));
96 mListCommands.insert(std::make_pair("crfaders",sCommandPrototypeInfo("list all crossfaders",&CAmTelnetMenuHelper::listCrossfaders)));
97 mListCommands.insert(std::make_pair("domains",sCommandPrototypeInfo("list all domains",&CAmTelnetMenuHelper::listDomainsCommand)));
98 mListCommands.insert(std::make_pair("gws",sCommandPrototypeInfo("list all gateways",&CAmTelnetMenuHelper::listGatewaysCommand)));
99 mListCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
100 mListCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
103 mSetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
104 mSetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
105 mSetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
106 mSetCommands.insert(std::make_pair("conn",sCommandPrototypeInfo("use 'conn sourceId sinkId' to connect a source and a sink",&CAmTelnetMenuHelper::setConnection)));
107 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)));
108 mSetCommands.insert(std::make_pair("disc",sCommandPrototypeInfo("use 'disc connectionID' to disconnect \n\t this connection",&CAmTelnetMenuHelper::setDisconnectConnId)));
111 mGetCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
112 mGetCommands.insert(std::make_pair("routing",sCommandPrototypeInfo("show current routing",&CAmTelnetMenuHelper::getRoutingCommand)));
113 mGetCommands.insert(std::make_pair("sendv",sCommandPrototypeInfo("show senderversion",&CAmTelnetMenuHelper::getSenderversionCommand)));
114 mGetCommands.insert(std::make_pair("recv",sCommandPrototypeInfo("show receiverversion ",&CAmTelnetMenuHelper::getReceiverversionCommand)));
115 mGetCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
116 mGetCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
119 mInfoCommands.insert(std::make_pair("help",sCommandPrototypeInfo(std::string("show all possible commands"),&CAmTelnetMenuHelper::helpCommand)));
120 mInfoCommands.insert(std::make_pair("sysprop",sCommandPrototypeInfo("show all systemproperties",&CAmTelnetMenuHelper::infoSystempropertiesCommand)));
121 mInfoCommands.insert(std::make_pair("..",sCommandPrototypeInfo("one step back in menu tree (back to root folder)",&CAmTelnetMenuHelper::oneStepBackCommand)));
122 mInfoCommands.insert(std::make_pair("exit",sCommandPrototypeInfo("close telnet session",&CAmTelnetMenuHelper::exitCommand)));
125 /****************************************************************************/
126 void CAmTelnetMenuHelper::setTelnetServer(TelnetServer* iTelnetServer)
127 /****************************************************************************/
129 mTelenetServer = iTelnetServer;
132 /****************************************************************************/
133 void CAmTelnetMenuHelper::newSocketConnection(int filedescriptor)
134 /****************************************************************************/
136 EMainState state = eRootState;
137 std::map<int,EMainState>::iterator it;
138 std::stringstream welcome;
140 it = mCurrentMainStateMap.find(filedescriptor);
141 if( it != mCurrentMainStateMap.end())
143 // socket connection already exists, delete entry and go back to root state
144 mCurrentMainStateMap.erase(it);
147 it = mCurrentMainStateMap.begin();
149 // insert new socket connection
150 mCurrentMainStateMap.insert(it,std::make_pair<int,EMainState>(filedescriptor,state));
152 // Send welcome message
153 welcome << "Welcome to GENIVI AudioManager " << DAEMONVERSION << "\n>";
154 send(filedescriptor,welcome.str().c_str(),welcome.str().size(),0);
157 /****************************************************************************/
158 void CAmTelnetMenuHelper::socketConnectionsClosed(int filedescriptor)
159 /****************************************************************************/
161 std::map<int,EMainState>::iterator it;
163 it = mCurrentMainStateMap.find(filedescriptor);
164 if( it != mCurrentMainStateMap.end())
166 mCurrentMainStateMap.erase(it);
170 // connection not found
174 /****************************************************************************/
175 void CAmTelnetMenuHelper::enterCmdQueue(std::queue<std::string> & CmdQueue, int & filedescriptor)
176 /****************************************************************************/
178 std::map<int,EMainState>::iterator it;
180 tCommandMap::iterator cmditer;
182 // find current filedescriptor to get the current state of the telnet session
183 it = mCurrentMainStateMap.find(filedescriptor);
184 while(!CmdQueue.empty())
186 cmd = CmdQueue.front();
188 // Now remove the first command, it's stored in 'cmd'
190 // telnet session found. depending on the current state, different commands are available
194 cmditer = mRootCommands.find(cmd);
195 if(mRootCommands.end() != cmditer)
196 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
198 sendError(filedescriptor,"Command not found\n");
201 cmditer = mListCommands.find(cmd);
202 if(mListCommands.end() != cmditer)
203 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
205 sendError(filedescriptor,"Command not found\n");
208 cmditer = mInfoCommands.find(cmd);
209 if(mInfoCommands.end() != cmditer)
210 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
212 sendError(filedescriptor,"Command not found\n");
215 cmditer = mGetCommands.find(cmd);
216 if(mGetCommands.end() != cmditer)
217 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
219 sendError(filedescriptor,"Command not found\n");
222 cmditer = mSetCommands.find(cmd);
223 if(mSetCommands.end() != cmditer)
224 cmditer->second.CommandPrototype(CmdQueue,filedescriptor);
226 sendError(filedescriptor,"Command not found\n");
233 sendCurrentCmdPrompt(filedescriptor);
236 /****************************************************************************/
237 void CAmTelnetMenuHelper::sendError(int & filedescriptor, std::string error_string)
238 /****************************************************************************/
240 send(filedescriptor,error_string.c_str(),error_string.size(),0);
243 /****************************************************************************/
244 void CAmTelnetMenuHelper::sendTelnetLine(int & filedescriptor, std::stringstream &line)
245 /****************************************************************************/
247 send(filedescriptor,line.str().c_str(),line.str().size(),0);
250 /****************************************************************************/
251 void CAmTelnetMenuHelper::sendCurrentCmdPrompt(int & filedescriptor)
252 /****************************************************************************/
254 std::map<int,EMainState>::iterator it;
255 std::stringstream outputstream;
256 outputstream << std::endl;
258 it = mCurrentMainStateMap.find(filedescriptor);
259 if( it != mCurrentMainStateMap.end())
264 outputstream << "\\>";
267 outputstream << "\\List>";
270 outputstream << "\\Get>";
273 outputstream << "\\Set>";
276 outputstream << "\\Info>";
282 send(filedescriptor,outputstream.str().c_str(),outputstream.str().size(),0);
287 // connection not found
291 /****************************************************************************/
292 void CAmTelnetMenuHelper::exitCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
293 /****************************************************************************/
295 instance->exitCommandExec(CmdQueue,filedescriptor);
298 /****************************************************************************/
299 void CAmTelnetMenuHelper::oneStepBackCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
300 /****************************************************************************/
302 std::map<int,EMainState>::iterator it;
303 it = mCurrentMainStateMap.find(filedescriptor);
304 if( it != mCurrentMainStateMap.end())
306 if(DEBUG_ON)std::cout << "old state: " << it->second;
310 it->second = eRootState;
313 it->second = eRootState;;
316 it->second = eRootState;;
319 it->second = eRootState;;
322 it->second = eRootState;;
325 it->second = eRootState;
328 if(DEBUG_ON)std::cout << "new state: " << it->second << std::endl;
332 /****************************************************************************/
333 void CAmTelnetMenuHelper::oneStepBackCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
334 /****************************************************************************/
336 instance->oneStepBackCommandExec(CmdQueue,filedescriptor);
339 /****************************************************************************/
340 void CAmTelnetMenuHelper::exitCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
341 /****************************************************************************/
343 std::map<int,EMainState>::iterator it;
344 std::stringstream line;
345 std::stringstream output;
347 // Sending a last message to the client
348 output << "Your wish is my command ... bye!" << std::endl;
349 sendTelnetLine(filedescriptor,output);
352 tCommandMap::iterator iter;
353 it = mCurrentMainStateMap.find(filedescriptor);
354 if( it != mCurrentMainStateMap.end())
356 if(DEBUG_ON)std::cout << "removing client connection " << filedescriptor << std::endl;
358 if(NULL != mTelenetServer)
360 mTelenetServer->disconnectClient(filedescriptor);
361 mCurrentMainStateMap.erase(it);
365 // ASSERT mTelenetServer == NULL
366 if(DEBUG_ON)std::cout << "mTelenetServer";
371 /****************************************************************************/
372 void CAmTelnetMenuHelper::helpCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
373 /****************************************************************************/
375 instance->helpCommandExec(CmdQueue,filedescriptor);
378 /****************************************************************************/
379 void CAmTelnetMenuHelper::helpCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
380 /****************************************************************************/
382 std::map<int,EMainState>::iterator it;
383 std::stringstream line;
384 tCommandMap::iterator cmdIter;
385 it = mCurrentMainStateMap.find(filedescriptor);
386 if( it != mCurrentMainStateMap.end())
388 line << "###################################################" << std::endl;
389 line << "###### The following commands are supported: ######"<< std::endl;
390 line << "###################################################" << std::endl << std::endl;
395 cmdIter = mRootCommands.begin();
396 while(cmdIter != mRootCommands.end())
398 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
403 cmdIter = mListCommands.begin();
404 while(cmdIter != mListCommands.end())
406 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
411 cmdIter = mGetCommands.begin();
412 while(cmdIter != mGetCommands.end())
414 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
419 cmdIter = mSetCommands.begin();
420 while(cmdIter != mSetCommands.end())
422 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
427 cmdIter = mInfoCommands.begin();
428 while(cmdIter != mInfoCommands.end())
430 line << cmdIter->first << "\t- " << cmdIter->second.info << std::endl;
437 sendTelnetLine(filedescriptor,line);
441 /****************************************************************************/
442 void CAmTelnetMenuHelper::rootGetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
443 /****************************************************************************/
445 instance->rootGetCommandExec(CmdQueue,filedescriptor);
448 /****************************************************************************/
449 void CAmTelnetMenuHelper::rootGetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
450 /****************************************************************************/
452 std::map<int,EMainState>::iterator it;
453 it = mCurrentMainStateMap.find(filedescriptor);
454 if( it != mCurrentMainStateMap.end())
456 it->second = eGetState;
460 /****************************************************************************/
461 void CAmTelnetMenuHelper::rootSetCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
462 /****************************************************************************/
464 instance->rootSetCommandExec(CmdQueue,filedescriptor);
467 /****************************************************************************/
468 void CAmTelnetMenuHelper::rootSetCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
469 /****************************************************************************/
471 std::map<int,EMainState>::iterator it;
472 it = mCurrentMainStateMap.find(filedescriptor);
473 if( it != mCurrentMainStateMap.end())
475 it->second = eSetState;
479 /****************************************************************************/
480 void CAmTelnetMenuHelper::rootListCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
481 /****************************************************************************/
483 instance->rootListCommandExec(CmdQueue,filedescriptor);
486 /****************************************************************************/
487 void CAmTelnetMenuHelper::rootListCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
488 /****************************************************************************/
490 std::map<int,EMainState>::iterator it;
491 it = mCurrentMainStateMap.find(filedescriptor);
492 if( it != mCurrentMainStateMap.end())
494 it->second = eListState;
498 /****************************************************************************/
499 void CAmTelnetMenuHelper::rootInfoCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
500 /****************************************************************************/
502 instance->rootInfoCommandExec(CmdQueue,filedescriptor);
505 /****************************************************************************/
506 void CAmTelnetMenuHelper::rootInfoCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
507 /****************************************************************************/
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 /****************************************************************************/
528 std::vector<am_Connection_s> listConnections;
529 std::stringstream line;
531 mDatabasehandler->getListConnections(listConnections);
533 line << "\tCurrent connections: " << listConnections.size() << std::endl;
535 sendTelnetLine(filedescriptor,line);
537 std::vector<am_Connection_s>::iterator it(listConnections.begin());
538 while(it != listConnections.end())
541 line << "\tID: " << it->connectionID
542 << "\tSrcID: " << it->sourceID
543 << "\tSinkID: " << it->sinkID
544 << "\tFormat: " << it->connectionFormat
545 << "\tdelay: " << it->delay
548 sendTelnetLine(filedescriptor,line);
553 /****************************************************************************/
554 void CAmTelnetMenuHelper::listSourcesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
555 /****************************************************************************/
557 instance->listSourcesCommandExec(CmdQueue,filedescriptor);
560 /****************************************************************************/
561 void CAmTelnetMenuHelper::listSourcesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
562 /****************************************************************************/
564 std::vector<am_Source_s> listSources;
565 std::stringstream line;
567 mDatabasehandler->getListSources(listSources);
569 line << "\tCurrent sources: " << listSources.size();
570 sendTelnetLine(filedescriptor,line);
572 std::vector<am_Source_s>::iterator it(listSources.begin());
573 while(it != listSources.end())
576 line << "\tID: " << it->sourceID
577 << "\tDomainID: " << it->domainID
578 << "\tName: " << it->name
579 << "\tState: " << it->sourceState
580 << "\tVolume: " << it->volume
583 sendTelnetLine(filedescriptor,line);
588 /****************************************************************************/
589 void CAmTelnetMenuHelper::listSinksCommands(std::queue<std::string> & CmdQueue, int & filedescriptor)
590 /****************************************************************************/
592 instance->listSinksCommandsExec(CmdQueue,filedescriptor);
595 /****************************************************************************/
596 void CAmTelnetMenuHelper::listSinksCommandsExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
597 /****************************************************************************/
599 std::vector<am_Sink_s> listSinks;
600 std::stringstream line;
602 mDatabasehandler->getListSinks(listSinks);
604 line << "\tCurrent sinks: " << listSinks.size() << std::endl;
605 sendTelnetLine(filedescriptor,line);
607 std::vector<am_Sink_s>::iterator it(listSinks.begin());
608 while(it != listSinks.end())
611 line << "\tID: " << it->sinkID
612 << "\tDomainID: " << it->domainID
613 << "\tName: " << it->name
614 << "\tAvailable: " << it->available.availability
615 << "\tVolume: " << it->volume
618 sendTelnetLine(filedescriptor,line);
623 /****************************************************************************/
624 void CAmTelnetMenuHelper::listCrossfaders(std::queue<std::string> & CmdQueue, int & filedescriptor)
625 /****************************************************************************/
627 instance->listCrossfadersExec(CmdQueue,filedescriptor);
630 /****************************************************************************/
631 void CAmTelnetMenuHelper::listCrossfadersExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
632 /****************************************************************************/
634 std::vector<am_Crossfader_s> listCrossfaders;
635 std::stringstream line;
637 mDatabasehandler->getListCrossfaders(listCrossfaders);
639 line << "\tCurrent crossfaders: " << listCrossfaders.size();
640 sendTelnetLine(filedescriptor,line);
642 std::vector<am_Crossfader_s>::iterator it(listCrossfaders.begin());
643 while(it != listCrossfaders.end())
646 line << "\tID: " << it->crossfaderID
647 << "\tName: " << it->name
648 << "\tSourceID: " << it->sourceID
651 sendTelnetLine(filedescriptor,line);
656 /****************************************************************************/
657 void CAmTelnetMenuHelper::listDomainsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
658 /****************************************************************************/
660 instance->listDomainsCommandExec(CmdQueue,filedescriptor);
663 /****************************************************************************/
664 void CAmTelnetMenuHelper::listDomainsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
665 /****************************************************************************/
667 std::vector<am_Domain_s> listDomains;
668 std::stringstream line;
670 mDatabasehandler->getListDomains(listDomains);
672 line << "\tCurrent domains: " << listDomains.size()<<std::endl;
673 sendTelnetLine(filedescriptor,line);
675 std::vector<am_Domain_s>::iterator it(listDomains.begin());
676 while(it != listDomains.end())
679 line << "\tID: " << it->domainID
680 << "\tName: " << it->name
681 << "\tBusname: " << it->busname
682 << "\tNodename: " << it->nodename
683 << "\tState: " << static_cast<int>(it->state)
686 sendTelnetLine(filedescriptor,line);
691 /****************************************************************************/
692 void CAmTelnetMenuHelper::listGatewaysCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
693 /****************************************************************************/
695 instance->listGatewaysCommandExec(CmdQueue,filedescriptor);
698 /****************************************************************************/
699 void CAmTelnetMenuHelper::listGatewaysCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
700 /****************************************************************************/
702 std::vector<am_Gateway_s> listGateways;
703 std::stringstream line;
705 mDatabasehandler->getListGateways(listGateways);
707 line << "\tCurrent gateways: " << listGateways.size();
708 sendTelnetLine(filedescriptor,line);
710 std::vector<am_Gateway_s>::iterator it(listGateways.begin());
711 while(it != listGateways.end())
714 line << "\tID: " << it->gatewayID
715 << "\tName: " << it->name
716 << "\tSourceID: " << it->sourceID
717 << "\tSinkID: " << it->sinkID
720 sendTelnetLine(filedescriptor,line);
725 /****************************************************************************/
726 void CAmTelnetMenuHelper::getRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
727 /****************************************************************************/
729 instance->getRoutingCommandExec(CmdQueue,filedescriptor);
732 /****************************************************************************/
733 void CAmTelnetMenuHelper::getRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
734 /****************************************************************************/
736 //TODO: fill with function
739 /****************************************************************************/
740 void CAmTelnetMenuHelper::getSenderversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
741 /****************************************************************************/
743 instance->getSenderversionCommandExec(CmdQueue,filedescriptor);
746 /****************************************************************************/
747 void CAmTelnetMenuHelper::getSenderversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
748 /****************************************************************************/
750 std::stringstream line;
752 line << "\tSender versions:" << std::endl
753 << "\tCtrl: " << mControlSender->getInterfaceVersion() << " | "
754 << "Cmd: " << mCommandSender->getInterfaceVersion() << " | "
755 << "Routing: " << mRoutingSender->getInterfaceVersion() << std::endl;
757 sendTelnetLine(filedescriptor,line);
760 /****************************************************************************/
761 void CAmTelnetMenuHelper::getReceiverversionCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
762 /****************************************************************************/
764 instance->getReceiverversionCommandExec(CmdQueue,filedescriptor);
767 /****************************************************************************/
768 void CAmTelnetMenuHelper::getReceiverversionCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
769 /****************************************************************************/
771 std::stringstream line;
773 line << "\tReceiver versions:" << std::endl
774 << "\tCtrl: " << mControlReceiver->getInterfaceVersion() << " | "
775 << "Cmd: " << mCommandReceiver->getInterfaceVersion() << " | "
776 << "Routing: " << mRoutingReceiver->getInterfaceVersion() << std::endl;
778 sendTelnetLine(filedescriptor,line);
782 /****************************************************************************/
783 void CAmTelnetMenuHelper::infoSystempropertiesCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
784 /****************************************************************************/
786 instance->infoSystempropertiesCommandExec(CmdQueue,filedescriptor);
789 /****************************************************************************/
790 void CAmTelnetMenuHelper::infoSystempropertiesCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
791 /****************************************************************************/
793 std::vector<am_SystemProperty_s> listSystemProperties;
794 std::vector<am_SystemProperty_s>::iterator it;
795 std::stringstream line;
797 mDatabasehandler->getListSystemProperties(listSystemProperties);
799 line << "\tSystemproperties: ";
800 sendTelnetLine(filedescriptor,line);
802 for(it = listSystemProperties.begin(); it < listSystemProperties.end(); it++ )
805 line << "\tType: " << it->type << " Value: " << it->value << std::endl;
806 sendTelnetLine(filedescriptor,line);
810 /****************************************************************************/
811 void CAmTelnetMenuHelper::setRoutingCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
812 /****************************************************************************/
814 instance->setRoutingCommandExec(CmdQueue,filedescriptor);
817 /****************************************************************************/
818 void CAmTelnetMenuHelper::setRoutingCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
819 /****************************************************************************/
821 std::stringstream output;
822 std::vector<am_Route_s> routingList;
824 am_sourceID_t sourceID = 0;
825 am_sinkID_t sinkID = 0;
828 am_Error_e rError = E_OK;
831 if(CmdQueue.size() >= 2)
833 std::istringstream istream_sourceID(CmdQueue.front());
835 std::istringstream istream_sinkID(CmdQueue.front());
838 if(!(istream_sourceID >> sourceID))
840 if(!(istream_sinkID >> sinkID))
845 sendError(filedescriptor,"Error parsing sourcID and sinkID");
849 if(DEBUG_ON)std::cout << "setRoutingCommandExec(sourceID: " << sourceID << ",sinkID: " << sinkID << ")" << std::endl;
851 rError = mRouter->getRoute(true,sourceID,sinkID,routingList);
855 std::vector<am_Route_s>::iterator rlIter = routingList.begin();
856 for(int rlCnt = 1;rlIter < routingList.end();rlIter++)
858 output << "#" << rlCnt << " ";
860 std::vector<am_RoutingElement_s>::iterator reIter = rlIter->route.begin();
861 for(;reIter < rlIter->route.end();reIter++)
863 reIter->connectionFormat;
865 output << ">(" << reIter->sourceID << ")->--[D:"<< reIter->domainID <<"][F:"<< reIter->connectionFormat <<"]-->-(" << reIter->sinkID<< ")" << std::endl;
871 sendTelnetLine(filedescriptor,output);
875 sendError(filedescriptor,"Error getting route");
882 output << "Not enough arguments to set routing. Please enter sourceID and sinkID after command" << std::endl;
889 /****************************************************************************/
890 void CAmTelnetMenuHelper::setConnection(std::queue<std::string> & CmdQueue, int & filedescriptor)
891 /****************************************************************************/
893 instance->setConnectionExec(CmdQueue,filedescriptor);
896 /****************************************************************************/
897 void CAmTelnetMenuHelper::setConnectionExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
898 /****************************************************************************/
900 std::stringstream output;
902 am_sourceID_t sourceID = 0;
903 am_sinkID_t sinkID = 0;
904 am_mainConnectionID_t connID = 0;
907 am_Error_e rError = E_OK;
909 if(CmdQueue.size() >= 2)
911 std::istringstream istream_sourceID(CmdQueue.front());
914 std::istringstream istream_sinkID(CmdQueue.front());
917 if(!(istream_sourceID >> sourceID))
920 if(!(istream_sinkID >> sinkID))
925 sendError(filedescriptor,"Error parsing sinkID and/or sourceID");
929 // Try to set up connection
930 rError = mCommandReceiver->connect(sourceID,sinkID,connID);
934 output << "ConnID: " << connID << "\tSrc: " << sourceID << " ---> Sink: " << sinkID << std::endl;
935 sendTelnetLine(filedescriptor,output);
939 sendError(filedescriptor,"Error connecting sourceID and sinkID");
946 sendError(filedescriptor,"Not enough arguments to set routing. Please enter sourceID and sinkID after command");
951 /****************************************************************************/
952 void CAmTelnetMenuHelper::setDisconnectConnId(std::queue<std::string> & CmdQueue, int & filedescriptor)
953 /****************************************************************************/
955 instance->setDisconnectConnIdExec(CmdQueue,filedescriptor);
958 /****************************************************************************/
959 void CAmTelnetMenuHelper::setDisconnectConnIdExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
960 /****************************************************************************/
962 std::stringstream output;
964 am_mainConnectionID_t connID = 0;
967 am_Error_e rError = E_OK;
969 if(CmdQueue.size() >= 1)
971 std::istringstream istream_connID(CmdQueue.front());
974 if(!(istream_connID >> connID))
979 sendError(filedescriptor,"Error parsing connID");
983 // Try to disconnect connection id
984 rError = mCommandReceiver->disconnect(connID);
988 output << "ConnID " << connID << " closed successfully! " << std::endl;
989 sendTelnetLine(filedescriptor,output);
993 sendError(filedescriptor,"Error disconnecting connectionID");
998 sendError(filedescriptor,"Not enough arguments to disconnect a Main Connection, please enter 'connectionID' after command");
1003 /****************************************************************************/
1004 void CAmTelnetMenuHelper::setSourceSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1005 /****************************************************************************/
1007 instance->setConnectionExec(CmdQueue,filedescriptor);
1010 /****************************************************************************/
1011 void CAmTelnetMenuHelper::setSourceSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1012 /****************************************************************************/
1014 std::stringstream output;
1015 am_sinkID_t sourceID;
1016 am_MainSoundProperty_s soundProperty;
1017 unsigned int tmpType = 0;
1020 if(CmdQueue.size() >= 3)
1022 std::istringstream istream_sourceID(CmdQueue.front());
1025 std::istringstream istream_type(CmdQueue.front());
1028 std::istringstream istream_value(CmdQueue.front());
1031 if(!(istream_type >> tmpType))
1034 if(tmpType < MSP_MAX)
1035 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1039 if(!(istream_value >> soundProperty.value))
1042 if(!(istream_sourceID >> sourceID))
1047 sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sourceID'");
1051 if(E_OK == mCommandReceiver->setMainSourceSoundProperty(soundProperty,sourceID))
1053 output << "MainSourceSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1054 sendTelnetLine(filedescriptor,output);
1058 sendError(filedescriptor,"Error setMainSourceSoundProperty");
1063 sendError(filedescriptor,"Not enough arguments to set MainSourceSoundProperty, please enter 'sourceID', 'type' and 'value' after command");
1068 /****************************************************************************/
1069 void CAmTelnetMenuHelper::setSinkSoundProperties(std::queue<std::string> & CmdQueue, int & filedescriptor)
1070 /****************************************************************************/
1072 instance->setConnectionExec(CmdQueue,filedescriptor);
1075 /****************************************************************************/
1076 void CAmTelnetMenuHelper::setSinkSoundPropertiesExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1077 /****************************************************************************/
1079 std::stringstream output;
1081 am_MainSoundProperty_s soundProperty;
1082 unsigned int tmpType = 0;
1085 if(CmdQueue.size() >= 3)
1087 std::istringstream istream_sinkID(CmdQueue.front());
1090 std::istringstream istream_type(CmdQueue.front());
1093 std::istringstream istream_value(CmdQueue.front());
1096 if(!(istream_type >> tmpType))
1099 if(tmpType < MSP_MAX)
1100 soundProperty.type = static_cast<am_MainSoundPropertyType_e>(tmpType);
1104 if(!(istream_value >> soundProperty.value))
1107 if(!(istream_sinkID >> sinkID))
1112 sendError(filedescriptor,"Error parsing MainSinkSoundProperty 'type', 'value' or 'sinkID'");
1116 if(E_OK == mCommandReceiver->setMainSinkSoundProperty(soundProperty,sinkID))
1118 output << "MainSinkSoundProperty set: " << soundProperty.type << "->" << soundProperty.value << std::endl;
1119 sendTelnetLine(filedescriptor,output);
1123 sendError(filedescriptor,"Error setMainSinkSoundProperty");
1128 sendError(filedescriptor,"Not enough arguments to set MainSinkSoundProperty, please enter 'sinkID', 'type' and 'value' after command");
1134 /****************************************************************************/
1135 void CAmTelnetMenuHelper::listPluginsCommand(std::queue<std::string> & CmdQueue, int & filedescriptor)
1136 /****************************************************************************/
1138 instance->listPluginsCommandExec(CmdQueue,filedescriptor);
1141 /****************************************************************************/
1142 void CAmTelnetMenuHelper::listPluginsCommandExec(std::queue<std::string> & CmdQueue, int & filedescriptor)
1143 /****************************************************************************/
1145 std::vector<std::string> PlugInNames;
1146 std::vector<std::string>::iterator iter;
1147 std::stringstream output;
1148 am_Error_e rError = E_OK;
1151 rError = mCommandSender->getListPlugins(PlugInNames);
1153 output << "CommandSender Plugins loaded: " << PlugInNames.size() << std::endl;
1155 for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
1157 output << iter->c_str() << std::endl;
1160 rError = mRoutingSender->getListPlugins(PlugInNames);
1162 output << std::endl << "RoutingSender Plugins loaded: " << PlugInNames.size() << std::endl;
1164 for(iter = PlugInNames.begin(); iter < PlugInNames.end(); iter++ )
1166 output << iter->c_str() << std::endl;
1169 sendTelnetLine(filedescriptor,output);