connector.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 MASH Research
00017  *  Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Research Group may be
00019  *    used 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 
00035 #ifndef lint
00036 static const char rcsid[] =
00037     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/connector.cc,v 1.14 1998/12/08 23:43:05 haldar Exp $ ";
00038 #endif
00039 
00040 #include "packet.h"
00041 #include "connector.h"
00042 
00043 static class ConnectorClass : public TclClass {
00044 public:
00045     ConnectorClass() : TclClass("Connector") {}
00046     TclObject* create(int, const char*const*) {
00047         return (new Connector);
00048     }
00049 } class_connector;
00050 
00051 Connector::Connector() : target_(0), drop_(0)
00052 {
00053 }
00054 
00055 
00056 int Connector::command(int argc, const char*const* argv)
00057 {
00058     Tcl& tcl = Tcl::instance();
00059     /*XXX*/
00060     if (argc == 2) {
00061         if (strcmp(argv[1], "target") == 0) {
00062             if (target_ != 0)
00063                 tcl.result(target_->name());
00064             return (TCL_OK);
00065         }
00066         if (strcmp(argv[1], "drop-target") == 0) {
00067             if (drop_ != 0)
00068                 tcl.resultf("%s", drop_->name());
00069             return (TCL_OK);
00070         }
00071         if (strcmp(argv[1], "isDynamic") == 0) {
00072             return TCL_OK;
00073         }
00074     }
00075 
00076     else if (argc == 3) {
00077         if (strcmp(argv[1], "target") == 0) {
00078             if (*argv[2] == '0') {
00079                 target_ = 0;
00080                 return (TCL_OK);
00081             }
00082             target_ = (NsObject*)TclObject::lookup(argv[2]);
00083             if (target_ == 0) {
00084                 tcl.resultf("no such object %s", argv[2]);
00085                 return (TCL_ERROR);
00086             }
00087             return (TCL_OK);
00088         }
00089         if (strcmp(argv[1], "drop-target") == 0) {
00090             drop_ = (NsObject*)TclObject::lookup(argv[2]);
00091             if (drop_ == 0) {
00092                 tcl.resultf("no object %s", argv[2]);
00093                 return (TCL_ERROR);
00094             }
00095             return (TCL_OK);
00096         }
00097     }
00098     return (NsObject::command(argc, argv));
00099 }
00100 
00101 void Connector::recv(Packet* p, Handler* h)
00102 {
00103     send(p, h);
00104 }
00105 
00106 void Connector::drop(Packet* p)
00107 {
00108     if (drop_ != 0)
00109         drop_->recv(p);
00110     else
00111         Packet::free(p);
00112 }
00113 
00114 void Connector::drop(Packet* p, const char *s)
00115 {
00116     if (drop_ != 0)
00117         drop_->recv(p, s);
00118     else
00119         Packet::free(p);
00120 }

Generated on Tue Mar 6 16:47:43 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6