RINASim  October 2016
Documentation of framework for OMNeT++
PDUData.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 /*
24  * @file PDUData.cc
25  * @author Marcel Marek (imarek@fit.vutbr.cz)
26  * @date Oct 30, 2015
27  * @brief
28  * @detail
29  */
30 
31 #include <PDUData.h>
33 PDUData::PDUData(const char* name, int kind): PDUData_Base(name, kind)
34 {
35 
36 }
37 
39 {
40 
41 }
42 
43 PDUData::PDUData(const PDUData& other): ::PDUData_Base(other)
44 {
45  copy(other);
46 }
47 
48 void PDUData::copy(const PDUData& other)
49 {
50  for(auto it = other.encapData.begin(); it != other.encapData.end(); ++it)
51  {
52  Data* tmpData = (*it)->dup();
53  take(tmpData);
54  encapData.push_back(tmpData);
55  }
56 
57 }
58 
60 {
61 
62  take(data);
63  encapData.push_back(data);
64  addByteLength(data->getByteLength());
65  switch(data->getDataType()){
66  case DATA_SDU_COMPLETE:
67  {
68  completeSDU = true;
69  break;
70  }
71  case DATA_FIRST_FRAG:
72  {
73  firstFragment = true;
74  break;
75  }
76  case DATA_MIDDLE_FRAG:
77  {
78  midFragment = true;
79  break;
80  }
81  case DATA_LAST_FRAG:
82  {
83  lastFragment = true;
84  break;
85  }
86  }
87 
88 }
89 
91 {
92 
93  if(encapData.size() > 0){
94  Data* data = encapData.front();
95  encapData.erase(encapData.begin());
96  addByteLength(0 - data->getByteLength());
97 
98  drop(data);
99 
100  return data;
101  }else{
102  return nullptr;
103  }
104 
105 
106 }
107 
108 void PDUData::forEachChild(cVisitor *v)
109 {
110  for (auto it = encapData.begin(); it != encapData.end(); ++it)
111  {
112  v->visit(*it);
113  }
114 
115 
116 }
PDUData(const char *name=nullptr, int kind=0)
Definition: PDUData.cc:33
Definition: Data.h:36
virtual Data * dup() const
Definition: Data.h:44
virtual void forEachChild(cVisitor *v)
Definition: PDUData.cc:108
bool midFragment
Definition: PDUData_m.h:59
Register_Class(PDUData)
virtual Data * decapsulate()
Definition: PDUData.cc:90
void copy(const PDUData &other)
Definition: PDUData.cc:48
bool lastFragment
Definition: PDUData_m.h:61
virtual ~PDUData()
Definition: PDUData.cc:38
std::vector< Data * > encapData
Definition: PDUData.h:42
bool firstFragment
Definition: PDUData_m.h:60
virtual void encapsulate(Data *data)
Definition: PDUData.cc:59
virtual int getDataType() const
Definition: Data_m.cc:216
bool completeSDU
Definition: PDUData_m.h:62