[Sofaswitch-svn] [commit] r96 - sofaswitch/trunk/sound
Author: derek Date: Mon Sep 18 01:08:55 2006 New Revision: 96 Modified: sofaswitch/trunk/sound/comms.cxx sofaswitch/trunk/sound/comms.h sofaswitch/trunk/sound/main.cxx sofaswitch/trunk/sound/main.h Log: First cut of a command line interface. Primary purpose of this command line interface is to generate DTMF characters for the controller Modified: sofaswitch/trunk/sound/comms.cxx ============================================================================== --- sofaswitch/trunk/sound/comms.cxx (original) +++ sofaswitch/trunk/sound/comms.cxx Mon Sep 18 01:08:55 2006 @@ -32,6 +32,7 @@ #include "comms.h" #include "audio.h" +#include "main.h" #define new PNEW @@ -111,11 +112,31 @@ MessageFrame::WaitForTermination(); } +void Comms::SendMessageToController(PString & message) +{ + SendThisMessageTo(message, currentController); +} + + void Comms::SilentlyEndAll() { } +BOOL Comms::SendDtmf(const PString & dtmfVals) +{ + cout << "Received DTMF from the controller of " << dtmfVals << " " << PTime(); + return TRUE; +} + + +void Comms::ProcessRequestNewId(PStringArray &cmds, PString & sender) +{ + currentController = sender; + PString answer = PString("REQUESTNEWID ") + Audio::Current().GetNodeId(); + SendThisMessageTo(answer, sender); + return; +} void Comms::ProcessHangup(PStringArray &cmds, PString & sender) { Modified: sofaswitch/trunk/sound/comms.h ============================================================================== --- sofaswitch/trunk/sound/comms.h (original) +++ sofaswitch/trunk/sound/comms.h Mon Sep 18 01:08:55 2006 @@ -70,6 +70,9 @@ terminated */ virtual void WaitForTermination(); + /**Send this message to the current controller. Typically, this will be a + * message stating that dtmf has been read from the keyboard. */ + void SendMessageToController(PString & message); /**Report if we were stopped by hangup */ BOOL StoppedByHangup() { return stopByHangup; } @@ -78,6 +81,16 @@ BOOL StoppedByExit() { return stopByExit; } protected: + + /**We have a DTMF string from our current master. Display this DTMF on the console. + We always return TRUE, cause we can always do this right. */ + virtual BOOL SendDtmf(const PString & dtmfVals); + + /**we have received a command asking us to provide the id of a new + communications nodes, that will be controlled only by the remote + node */ + virtual void ProcessRequestNewId(PStringArray &cmds, PString & sender); + /**The supervisor has completed. This method is called when this supervisor instance terminates. Since there is only one Supervisor instance, this method is only every called once. */ @@ -139,6 +152,9 @@ /**The terminating condition was */ BOOL stopByExit; + /**The id of the last node who has requested a sound worker. This node will + receive all dtmf messages. */ + PString currentController; }; #endif Modified: sofaswitch/trunk/sound/main.cxx ============================================================================== --- sofaswitch/trunk/sound/main.cxx (original) +++ sofaswitch/trunk/sound/main.cxx Mon Sep 18 01:08:55 2006 @@ -15,14 +15,73 @@ */ #include <ptlib.h> -#include "version.h" + + #include "audio.h" -#include "main.h" #include "comms.h" +#include "main.h" +#include "version.h" - #define new PNEW +///////////////////////////////////////////////////////////////////////////// +void UserInterface::Main() +{ + PConsoleChannel console(PConsoleChannel::StandardInput); + + cout << "This program will waits for user commands, and generates DTMF messages as required" << endl; + + + console.SetReadTimeout(500); + + PThread::Yield(); + + PStringStream help; + help << "Press : " << endl + << " H or ? help on this interface" << endl + << " D dtmf Send dtmf message text to the controller" + << " X or Q exit " << endl; + + + cout << endl << endl << help; + + for (;(!endNow) && (!comms.IsTerminated());) { + char ch = console.ReadChar(); + + if (endNow) + break; + + switch (tolower(ch)) { + case 'd' : + { + PString message; + console >> message; + comms.SendMessageToController(message); + cout << "Command ? " << flush; + } + break; + case 'x' : + case 'q' : + cout << "Exiting." << endl; + PTRACE(3, "End this program now "); + return; + break; + case '?' : + case 'h' : + cout << help << endl; + cout << "Command ? " << flush; + default: + break; + } // end switch + } // end for +} + +void UserInterface::Terminate() +{ + endNow = TRUE; +} + +///////////////////////////////////////////////////////////////////////////// Audio::Audio() : PProcess("Derek Smithies code factory", "audio", MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER) @@ -123,16 +182,16 @@ server = args.GetOptionString("server"); PTRACE(3, "server is " << server); } else { - server = "beta"; - PTRACE(3, "Select a default server of beta"); + server = "localhost"; + PTRACE(3, "Select a default server of localhost"); } PString ourId; if (args.HasOption("id")) { - ourId = args.GetOptionString("id"); + nodeId = args.GetOptionString("id"); PTRACE(3, "our ID is " << ourId); } else { - ourId = "sound"; + nodeId = "sound"; PTRACE(3, "Select a default ID of " << ourId); } @@ -171,9 +230,10 @@ PTRACE(3, "Failed to construct a writer for the audio. Exit now "); return; } - - c.WaitForTermination(); + UserInterface ui(c, soundPlayer, soundRecorder); + c.WaitForTermination(); + PTRACE(3, "End of comms object, exit program "); #if PTRACING Modified: sofaswitch/trunk/sound/main.h ============================================================================== --- sofaswitch/trunk/sound/main.h (original) +++ sofaswitch/trunk/sound/main.h Mon Sep 18 01:08:55 2006 @@ -19,7 +19,49 @@ #ifndef _MAIN_H #define _MAIN_H +#include <ptlib.h> +#include "comms.h" + + +/**This class manages the user interface during program execution. It reads + the keyboard to generate dtmf events as required, and displays some + rudimentary status information */ +class UserInterface: public PThread +{ + PCLASSINFO(UserInterface, PThread); + +public: + /**construct this class, to have access to the communications and sound modules */ + UserInterface(Comms & _comms, PSoundChannel &_player, PSoundChannel & _recorder) + : PThread(1000, NoAutoDeleteThread), + comms(_comms), + player(_player), + recorder(_recorder) + { endNow = FALSE; Resume(); } + + /**The main method where everything happens */ + void Main(); + + /**This method is used to shutdown the operation of this class */ + virtual void Terminate(); + + protected: + /**Reference to the class that does all the communications */ + Comms & comms; + + /**Reference to the class that does all the playing of audio to the speaker */ + PSoundChannel & player; + + /**Reference to the class that does all of the recording of audio from the microphone */ + PSoundChannel & recorder; + + /**Variable used to indicate it is time to finish */ + BOOL endNow; +}; + +///////////////////////////////////////////////////////////////////////////// + /**The parent class, that hides the int main(int argc, char **argv). This handles all command line parsing, and creation of the relevant @@ -43,6 +85,8 @@ static Audio & Current() { return (Audio &)PProcess::Current(); } + /**Report the node id of this particular entity, as seen by the sofa switch server */ + PString GetNodeId() { return nodeId; } protected: /**The selected audio device name */ PString devName; @@ -55,6 +99,9 @@ /**Device for playing audio */ PSoundChannel soundPlayer; + + /**The id of this particular entity, as seen by the sofaswitch server */ + PString nodeId; };
participants (1)
-
SofaSWITCH SVN