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

object.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) 1994 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 Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
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 
00035 #ifndef lint
00036 static const char rcsid[] =
00037     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/common/object.cc,v 1.18 2000/09/01 03:04:06 haoboy Exp $ (LBL)";
00038 #endif
00039 
00040 #include <stdarg.h>
00041 
00042 #include "object.h"
00043 #include "packet.h"
00044 #include "flags.h"
00045 
00046 NsObject::~NsObject()
00047 {
00048 }
00049 
00050 NsObject::NsObject()
00051 {
00052         // Turn off debug by default
00053         debug_ = 0;
00054 }
00055 
00056 void
00057 NsObject::delay_bind_init_all()
00058 {
00059         delay_bind_init_one("debug_");
00060 }
00061 
00062 int
00063 NsObject::delay_bind_dispatch(const char *varName, const char *localName, TclObject *tracer)
00064 {
00065         if (delay_bind_bool(varName, localName, "debug_", &debug_, tracer)) 
00066                 return TCL_OK;
00067         return TclObject::delay_bind_dispatch(varName, localName, tracer);
00068 }
00069 
00070 void NsObject::reset()
00071 {
00072 }
00073 
00074 int NsObject::command(int argc, const char*const* argv)
00075 {
00076         if (argc == 2) {
00077                 if (strcmp(argv[1], "reset") == 0) {
00078                         reset();
00079                         return (TCL_OK);
00080                 }
00081         }
00082         return (TclObject::command(argc, argv));
00083 }
00084 
00085 /*
00086  * Packets may be handed to NsObjects at sheduled points
00087  * in time since a node is an event handler and a packet
00088  * is an event.  Packets should be the only type of event
00089  * scheduled on a node so we can carry out the cast below.
00090  */
00091 void NsObject::handle(Event* e)
00092 {
00093         recv((Packet*)e);
00094 }
00095 
00096 void NsObject::recv(Packet *p, const char*)
00097 {
00098         Packet::free(p);
00099 }
00100 
00101 // Debugging output for all TclObjects. By default, print to stdout
00102 void NsObject::debug(const char *fmt, ...)
00103 {
00104         if (!debug_)
00105                 return;
00106         va_list ap;
00107         va_start(ap, fmt);
00108         vprintf(fmt, ap);
00109 }

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