OverSimMessage.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00019 #include <omnetpp.h>
00020 #include <cnetcommbuffer.h>
00021 #include "OverSimMessage_m.h"
00022 #include "OverSimMessage.h"
00023 
00024 Register_Class(OverSimMessage);
00025 
00026 void OverSimMessage::parsimPack(cCommBuffer *b)
00027 {
00028     cObject::parsimPack(b);
00029 
00030     if (getContextPointer() || getControlInfo())
00031         throw cRuntimeError(this, "netPack(): cannot pack object with "
00032                                 "contextPointer or controlInfo set");
00033     if (getParList().size() > 0) {
00034         b->packFlag(true);
00035         b->packObject(&getParList());
00036     } else {
00037         b->packFlag(false);
00038     }
00039 
00040     if (b->packFlag(getEncapsulatedPacket() != NULL))
00041         b->packObject(getEncapsulatedPacket());
00042 }
00043 
00044 void OverSimMessage::parsimUnpack(cCommBuffer *b)
00045 {
00046     int len = 0;
00047     cNetCommBuffer *netBuffer = dynamic_cast<cNetCommBuffer*>(b);
00048     if (netBuffer != NULL) {
00049         len = netBuffer->getRemainingMessageSize();
00050     }
00051     cObject::parsimUnpack(b);
00052 
00053     ASSERT(getShareCount() == 0);
00054 
00055     if (b->checkFlag()) {
00056         cArray *parlistptr = static_cast<cArray*>(b->unpackObject());
00057         std::cout << "still there: " << *parlistptr << std::endl;
00058         for (int i=0; i<parlistptr->size(); i++) {
00059             std::cout << "i: " << i << " " << parlistptr->get(i) << std::endl;
00060             addObject(static_cast<cObject*>(parlistptr->get(i)->dup()));
00061         }
00062         delete parlistptr;
00063     }
00064 
00065     if (b->checkFlag()) {
00066         encapsulate((cPacket *) b->unpackObject());
00067     }
00068 
00069     // set the length of the received message
00070     // TODO: doesn't contain the length of the string for the object type
00071     setByteLength(len);
00072 }
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3