clmessage.cc

00001 /*
00002  * Copyright (c) 2006 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029  
00030 #include "clmessage.h"
00031 #include <iostream>
00032 
00033 #include"deprecated.h"
00034 
00035 /*
00036 ClMessage static method: it is used to register a new clMessage
00037 */
00038 
00039 ClMessage_t ClMessage::nType_ = 0;
00040 
00041 ClMessage_t ClMessage::addClMessage()
00042 {
00043         return nType_++;
00044 }
00045 
00046 static unsigned int lastId = 0;
00047 
00048 /*
00049 ------------------------------------------------
00050 */
00051 
00052 ClMessage::ClMessage(int verbosity, ClMessage_t type) 
00053 : verbosity_(verbosity), 
00054   type_(type), 
00055   destType_(BROADCAST), 
00056   source_(0), 
00057   dest_(CLBROADCASTADDR) 
00058 {
00059         uid_ = lastId++;
00060 }
00061 
00062 ClMessage::ClMessage(int verbosity, ClMessage_t type, DestinationType dtype, int source, int value)
00063 : verbosity_(verbosity), 
00064   type_(type), 
00065   source_(source), 
00066   destType_(dtype), 
00067   dest_(value) 
00068 {
00069   PRINT_WARNING_DEPRECATED_FUNCTION;
00070   uid_ = lastId++;
00071 }
00072 
00073 ClMessage::ClMessage(int verbosity, ClMessage_t type, DestinationType dtype, int value)
00074 : verbosity_(verbosity), 
00075   type_(type), 
00076   source_(-1), 
00077   destType_(dtype), 
00078   dest_(value) 
00079 {
00080         uid_ = lastId++;
00081 }
00082 
00083 
00084 ClMessage::ClMessage(ClMessage *m)
00085 {
00086         type_ = m->type_;
00087         destType_ = m-> destType_;
00088         source_ = m->source_;
00089         dest_ = m->dest_;
00090         verbosity_ = m->verbosity_;
00091         uid_ = m->uid_;
00092 }
00093 
00094 ClMessage::~ClMessage()
00095 {
00096 }
00097 
00098 // return the destination type of the message
00099 DestinationType ClMessage::getDestType()
00100 {
00101         return destType_;
00102 }
00103 
00104 // return the destination of the message
00105 int ClMessage::getDest()
00106 {
00107         return (dest_);
00108 }
00109 
00110 // retrun a copy of the message
00111 ClMessage *ClMessage::copy()
00112 {
00113   cerr << "FATAL: ClMessage::copy() method was not re-implemented by some "
00114        << "class derived from ClMessage. This would likely result in data "
00115        << "loss. Please implement this method. " 
00116        << endl << " Exiting..." << endl;
00117   exit(1);
00118 }
00119 
00120 int ClMessage::verbosity()
00121 {
00122         return verbosity_;
00123 }
00124 
00125 ClMessage_t ClMessage::type()
00126 {
00127         return type_;
00128 }
00129 
00130 ClDirection ClMessage::direction()
00131 {
00132         return direction_;
00133 }
00134 
00135 void ClMessage::direction(ClDirection dir)
00136 {
00137         direction_ = dir;
00138 }
00139 
00140 int ClMessage::getSource()
00141 {
00142         return source_;
00143 }
00144 
00145 void ClMessage::setSource(int src)
00146 {
00147         source_ = src;
00148 }
00149 
00150 
00151 void ClMessage::setDest(int dst)
00152 {
00153   dest_ = dst;
00154 }
00155 
00156 
00157 unsigned int ClMessage::uid()
00158 {
00159         return uid_;
00160 }

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2