OverSim
OverSimMessage.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
19 #include <omnetpp.h>
20 #include <cnetcommbuffer.h>
21 #include "OverSimMessage_m.h"
22 #include "OverSimMessage.h"
23 
25 
26 void OverSimMessage::parsimPack(cCommBuffer *b)
27 {
29 
30  if (getContextPointer() || getControlInfo())
31  throw cRuntimeError(this, "netPack(): cannot pack object with "
32  "contextPointer or controlInfo set");
33  if (getParList().size() > 0) {
34  b->packFlag(true);
35  b->packObject(&getParList());
36  } else {
37  b->packFlag(false);
38  }
39 
40  if (b->packFlag(getEncapsulatedPacket() != NULL))
41  b->packObject(getEncapsulatedPacket());
42 }
43 
44 void OverSimMessage::parsimUnpack(cCommBuffer *b)
45 {
46  int len = 0;
47  cNetCommBuffer *netBuffer = dynamic_cast<cNetCommBuffer*>(b);
48  if (netBuffer != NULL) {
49  len = netBuffer->getRemainingMessageSize();
50  }
52 
53  ASSERT(getShareCount() == 0);
54 
55  if (b->checkFlag()) {
56  cArray *parlistptr = static_cast<cArray*>(b->unpackObject());
57  std::cout << "still there: " << *parlistptr << std::endl;
58  for (int i=0; i<parlistptr->size(); i++) {
59  std::cout << "i: " << i << " " << parlistptr->get(i) << std::endl;
60  addObject(static_cast<cObject*>(parlistptr->get(i)->dup()));
61  }
62  delete parlistptr;
63  }
64 
65  if (b->checkFlag()) {
66  encapsulate((cPacket *) b->unpackObject());
67  }
68 
69  // set the length of the received message
70  // TODO: doesn't contain the length of the string for the object type
71  setByteLength(len);
72 }