/* * A "FTP" like Application that keeps track of the * received application sequence number. */ #include "app.h" class StapApp : public Application { public: StapApp(); virtual void recv(int nbytes); protected: virtual int command(int argc, const char*const* argv); virtual void start(); virtual void stop(); private: int maxbytes_; int rbytes_,rnexts_; }; static class StapAppClass : public TclClass { public: StapAppClass() : TclClass("Application/Stap") {} TclObject* create(int, const char*const*) { return (new StapApp); } } class_app_stap; StapApp::StapApp() { maxbytes_= -1; rbytes_ = rnexts_ = 0; } int StapApp::command(int argc, const char*const* argv) { Tcl& tcl = Tcl::instance(); if (argc == 2) { if (strcmp(argv[1], "bytes?") == 0) { tcl.resultf("%d",rbytes_); return TCL_OK; } else if (strcmp(argv[1], "seqno?") == 0) { tcl.resultf("%d",rnexts_); return TCL_OK; } } return (Application::command(argc, argv)); } void StapApp::start() { if (maxbytes_>0) send(maxbytes_); else send(-1); } void StapApp::stop() { agent_->close(); } /* * Note this is called by recvBytes() of the agent, not by the buffer */ void StapApp::recv(int nbytes) { rbytes_ += nbytes; }