00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "app.h"
00039 #include "agent.h"
00040
00041
00042 static class ApplicationClass : public TclClass {
00043 public:
00044 ApplicationClass() : TclClass("Application") {}
00045 TclObject* create(int, const char*const*) {
00046 return (new Application);
00047 }
00048 } class_application;
00049
00050
00051 Application::Application() : enableRecv_(0), enableResume_(0)
00052 {
00053 }
00054
00055
00056 int Application::command(int argc, const char*const* argv)
00057 {
00058 Tcl& tcl = Tcl::instance();
00059
00060 if (argc == 2) {
00061 if (strcmp(argv[1], "start") == 0) {
00062
00063 tcl.evalf("[%s info class] info instprocs", name_);
00064 char result[1024];
00065 sprintf(result, " %s ", tcl.result());
00066 enableRecv_ = (strstr(result, " recv ") != 0);
00067 enableResume_ = (strstr(result, " resume ") != 0);
00068 start();
00069 return (TCL_OK);
00070 }
00071 if (strcmp(argv[1], "stop") == 0) {
00072 stop();
00073 return (TCL_OK);
00074 }
00075 if (strcmp(argv[1], "agent") == 0) {
00076 tcl.resultf("%s", agent_->name());
00077 return (TCL_OK);
00078 }
00079 }
00080 else if (argc == 3) {
00081 if (strcmp(argv[1], "attach-agent") == 0) {
00082 agent_ = (Agent*) TclObject::lookup(argv[2]);
00083 if (agent_ == 0) {
00084 tcl.resultf("no such agent %s", argv[2]);
00085 return(TCL_ERROR);
00086 }
00087 agent_->attachApp(this);
00088 return(TCL_OK);
00089 }
00090 if (strcmp(argv[1], "send") == 0) {
00091 send(atoi(argv[2]));
00092 return(TCL_OK);
00093 }
00094 }
00095 return (Process::command(argc, argv));
00096 }
00097
00098
00099 void Application::start()
00100 {
00101 }
00102
00103
00104 void Application::stop()
00105 {
00106 }
00107
00108
00109 void Application::send(int nbytes)
00110 {
00111 agent_->sendmsg(nbytes);
00112 }
00113
00114
00115 void Application::recv(int nbytes)
00116 {
00117 if (! enableRecv_)
00118 return;
00119 Tcl& tcl = Tcl::instance();
00120 tcl.evalf("%s recv %d", name_, nbytes);
00121 }
00122
00123
00124 void Application::resume()
00125 {
00126 if (! enableResume_)
00127 return;
00128 Tcl& tcl = Tcl::instance();
00129 tcl.evalf("%s resume", name_);
00130 }