diff options
Diffstat (limited to 'comm')
-rw-r--r-- | comm/OLD/TclAgent.cc | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/comm/OLD/TclAgent.cc b/comm/OLD/TclAgent.cc index a72bee0..032cf73 100644 --- a/comm/OLD/TclAgent.cc +++ b/comm/OLD/TclAgent.cc @@ -12,16 +12,16 @@ * $CurLog$ */ -#include "TextStream.h" +#include "uch.h" #include "ccu/String.h" #include "TkMultiplexer.h" #include <stdio.h> #include <string.h> extern "C" { -#include <tcl.h> +#include "tcl.h" } -#undef const + class TclAgent : public UchTextService { public: @@ -32,8 +32,10 @@ public: void SetLostServerCmd (const char*); void SetAbandonCmd (const char*); void SetClosingCmd (const char*); -inline const char* GetName () const { return tclName; } +inline char* GetName () const { return (char*)(const char*) tclName; } +static int Create (ClientData, Tcl_Interp*, int, char*[]); +static int HandleCmd (ClientData, Tcl_Interp*, int, char*[]); protected: CcuString tclName; @@ -42,8 +44,6 @@ protected: CcuString lostServerCmd; CcuString abandonCmd; - Tcl_CmdBuf buffer; - cmd_res Execute (const UchTextLine&); void LostServer (); void GotServer (); @@ -56,10 +56,9 @@ TclAgent :: TclAgent (Tcl_Interp* i, const char* nm) tclName (nm), gotServerCmd (), lostServerCmd (), - abandonCmd () + abandonCmd (), + interp (i) { - interp = i; - buffer = Tcl_CreateCmdBuf (); } void @@ -82,7 +81,6 @@ TclAgent :: SetAbandonCmd (const char* cmd) TclAgent :: ~TclAgent () { - Tcl_DeleteCmdBuf (buffer); } /* @@ -99,7 +97,7 @@ TclAgent :: Execute (const UchTextLine& line) char* p; - sprintf (buf, "catch { %s.%s ", tclName, (const char*) (line [0])); + sprintf (buf, "catch { %s.%s ", GetName (), (const char*) (line [0])); p = buf + strlen (buf); for (int i = 1; i < line.NumWords (); i++) { @@ -122,7 +120,7 @@ TclAgent :: LostServer () UchTextService::LostServer (); if (lostServerCmd) - Tcl_GlobalEval (interp, (char*)(const char*)lostServerCmd); + Tcl_GlobalEval (interp, (char*)(const char*) lostServerCmd); } void @@ -131,7 +129,7 @@ TclAgent :: GotServer () UchTextService::GotServer (); if (gotServerCmd) - Tcl_GlobalEval (interp, (char*)(const char*)gotServerCmd); + Tcl_GlobalEval (interp, (char*)(const char*) gotServerCmd); } void @@ -140,7 +138,7 @@ TclAgent :: AbandonRestart () if (abandonCmd) Tcl_GlobalEval (interp, (char*)(const char*) abandonCmd); - Tcl_DeleteCommand (interp, (char*)(const char*) tclName); + Tcl_DeleteCommand (interp, GetName ()); CloseNow (); } @@ -155,14 +153,14 @@ TclAgent :: AbandonRestart () * agentname closenow */ int -AgentCmd (ClientData data, Tcl_Interp* interp, int argc, char* argv []) +TclAgent :: HandleCmd (ClientData data, Tcl_Interp* interp, int argc, char* argv []) { - TclAgent* agent = (TclAgent*) data; + TclAgent* agent = (TclAgent*) data; /* check arguments: at least two */ if (argc < 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " status | close | closenow | send request [args ...]\"", (char *) NULL); + " status | close | closenow | send request [args ...]\"", 0); return TCL_ERROR; } @@ -172,7 +170,7 @@ AgentCmd (ClientData data, Tcl_Interp* interp, int argc, char* argv []) if (strcmp (cmd, "send") == 0) { if (argc < 3) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " send request [args ...]\"", (char *) NULL); + " send request [args ...]\"", 0); return TCL_ERROR; } @@ -188,7 +186,7 @@ AgentCmd (ClientData data, Tcl_Interp* interp, int argc, char* argv []) /* simple commands */ if (argc != 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " status | close | closenow | send request [args ...]\"", (char *) NULL); + " status | close | closenow | send request [args ...]\"", 0); return TCL_ERROR; } @@ -208,68 +206,68 @@ AgentCmd (ClientData data, Tcl_Interp* interp, int argc, char* argv []) break; } } else if (strcmp (cmd, "close") == 0) { - Tcl_DeleteCommand (interp, (char*) agent->GetName ()); + Tcl_DeleteCommand (interp, agent->GetName ()); agent->Close (); } else if (strcmp (cmd, "closenow") == 0) { - Tcl_DeleteCommand (interp, (char*) agent->GetName ()); + Tcl_DeleteCommand (interp, agent->GetName ()); agent->CloseNow (); } else { - Tcl_AppendResult(interp, "bad option name: \"", cmd, - "\"", (char *) NULL); + Tcl_AppendResult(interp, "bad option name: \"", cmd, "\"", 0); return TCL_ERROR; } return TCL_OK; } + +UchTkMultiplexer TheMpx; + /* * command to create a new agent: * agent name [-option value ...] */ int -CreateAgentCmd (ClientData, Tcl_Interp* interp, int argc, char* argv []) +TclAgent :: Create (ClientData, Tcl_Interp* interp, int argc, char* argv []) { - TclAgent* agent; - /* check arguments: at least two, and even number overall */ if (argc < 2 || (argc & 01) != 0) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " name [-option value ...]\"", (char *) NULL); + " name [-option value ...]\"", 0); return TCL_ERROR; } char* name = argv [1]; char* host = 0; - agent = new TclAgent (interp, name); + TclAgent* agent = new TclAgent (interp, name); for (int i = 2; i < argc; i++) { char* option = argv [i++]; char* value = argv [i]; if (strcmp (option, "-host") == 0) host = value; - else - if (strcmp (option, "-name") == 0) + + else if (strcmp (option, "-name") == 0) name = value; - else - if (strcmp (option, "-init") == 0) + + else if (strcmp (option, "-init") == 0) agent->SetGotServerCmd (value); - else - if (strcmp (option, "-lost") == 0) + + else if (strcmp (option, "-lost") == 0) agent->SetLostServerCmd (value); - else - if (strcmp (option, "-abandon") == 0) + + else if (strcmp (option, "-abandon") == 0) agent->SetAbandonCmd (value); + else { - Tcl_AppendResult(interp, "bad option name: \"", argv[i-1], - "\"", (char *) NULL); + Tcl_AppendResult (interp, "bad option name: \"", argv[i-1], "\"", 0); return TCL_ERROR; } } - agent->Init (name, host); + agent->Init (TheMpx, name, host); /* define the command for manipulating the source */ - Tcl_CreateCommand (interp, name, AgentCmd, (ClientData) agent, 0); + Tcl_CreateCommand (interp, name, TclAgent::HandleCmd, (ClientData) agent, 0); return TCL_OK; } @@ -277,18 +275,17 @@ CreateAgentCmd (ClientData, Tcl_Interp* interp, int argc, char* argv []) //---------------- initialization /* - * initialize the audio gizmo + * initialize the agent gizmo * returns 0 if error and leaves the message in interp->result */ -UchTkMultiplexer mpx; extern "C" int -InitAgent (Tcl_Interp* interp) +Tcl_AppInit (Tcl_Interp* interp) { - Tcl_CreateCommand (interp, "agent", CreateAgentCmd, 0, 0); + Tcl_CreateCommand (interp, "agent", TclAgent::Create, 0, 0); return 1; -} +} extern "C" int tkmain (int, char* []); |