Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

app.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Daedalus Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * Contributed by the Daedalus Research Group, http://daedalus.cs.berkeley.edu
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                         // enableRecv_ only if recv() exists in Tcl
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 }

Generated on Tue Apr 20 12:14:10 2004 for NS2.26SourcesOriginal by doxygen 1.3.3