KDIS  2-8-x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Bundle.h
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
29 
30 /********************************************************************
31  class: Bundle
32  DIS: 1278.2 - draft
33  created: 14/12/2012
34  author: Karl Jones
35 
36  purpose: Bundling is defined as the process of concatenating two or more PDUs
37  into a single network datagram so that they can be transmitted and relayed
38  through the network in one operation. The increase in network efficiency by
39  the use of bundling works best when there are many PDUs ready to be transmitted
40  at the same time. Simulations may choose to delay transmission of a PDU for a
41  short amount of time to allow more PDUs to become ready to add to the bundle.
42  However, this increases latency, which is undesirable. The latency increase should be
43  weighed against network performance gains in determining the bundling delay.
44  Bundling is also useful when two or more PDUs have to be delivered in order as a single
45  coherent unit. Network layers do not split datagrams so bundled PDUs will arrive
46  at the receiver in their original concatenated format.
47 
48  This class allows you to package multiple PDU up for sending, it is not used for receiving data.
49 
50 *********************************************************************/
51 
52 #pragma once
53 
54 #include "./Header.h"
55 #include "./../Extras/KRef_Ptr.h"
56 #include <vector>
57 
58 namespace KDIS {
59 namespace PDU {
60 
61 /************************************************************************/
62 // Define the type of pointer we are using for PDU,
63 // do we want a weak reference or a ref counter?
64 // By default we use a ref counted pointer, however if you want to use a standard
65 // pointer or one of your own then simply change it below.
66 /************************************************************************/
67 typedef KDIS::UTILS::KRef_Ptr<Header> PduPtr; // Ref counter
68 //typedef Header * PduPtr; // Weak ref
69 
71 {
72 protected:
73 
74  std::vector<KDataStream> m_vStreams;
75 
76  std::vector<PduPtr> m_vRefHeaders;
77 
79 
80  //************************************
81  // FullName: KDIS::PDU::Bundle::AddPDU
82  //!Description: Calculate the total length of the Bundle.
83  //************************************
84  void calculateLength();
85 
86 public:
87 
88  Bundle();
89 
90  virtual ~Bundle();
91 
92  //************************************
93  // FullName: KDIS::PDU::Bundle::AddPDU
94  //!Description: Adds a PDU stream or referenced PDU to the bundle.
95  //! Throws exeption PDU_TOO_LARGE if the total bundles length is greater than MAX_PDU_SIZE
96  // Parameter: const Header & H, PduPtr H.
97  //************************************
98  void AddPDU( const KDataStream & K ) throw( KException );
99  void AddPDU( PduPtr H ) throw( KException );
100 
101  //************************************
102  // FullName: KDIS::PDU::Bundle::SetPDUs
103  //!Description: Set multiple PDU.
104  //! Throws exeption PDU_TOO_LARGE if the total bundles length is greater than MAX_PDU_SIZE
105  // Parameter: const vector<KDataStream> & P, const vector<PduPtr> & P
106  //************************************
107  void SetPDUs( const std::vector<KDataStream> & P ) throw( KException );
108  void SetPDUs( const std::vector<PduPtr> & P ) throw( KException );
109  void SetPDUs( const std::vector<KDataStream> & Streams, const std::vector<PduPtr> & References ) throw( KException );
110 
111  //************************************
112  // FullName: KDIS::PDU::Bundle::GetPDUStreams
113  // KDIS::PDU::Bundle::GetRefPDUs
114  //!Description: Gets the stored PDU stremas or referenced PDUs.
115  //************************************
116  const std::vector<KDataStream> & GetPDUStreams() const;
117  const std::vector<PduPtr> & GetRefPDUs() const;
118 
119  //************************************
120  // FullName: KDIS::PDU::Bundle::ClearPDUs
121  //!Description: Clears stored PDUs.
122  //************************************
123  void ClearPDUs();
124 
125  //************************************
126  // FullName: KDIS::PDU::Bundle::ClearPDUs
127  //!Description: Returns total length of all PDU in bytes.
128  //************************************
129  KUINT16 GetLength();
130 
131  //************************************
132  // FullName: KDIS::PDU::Bundle::GetAsString
133  //!Description: Returns a string representation of the PDU.
134  //************************************
135  virtual KString GetAsString();
136 
137  //************************************
138  // FullName: KDIS::PDU::Bundle::Encode
139  //!Description: Convert To Network Data.
140  // Parameter: KDataStream & stream
141  //************************************
142  virtual KDataStream Encode() const;
143  virtual void Encode( KDataStream & stream ) const;
144 
145  KBOOL operator == ( const Bundle & Value ) const;
146  KBOOL operator != ( const Bundle & Value ) const;
147 };
148 
149 } // END namespace PDU
150 } // END namespace KDIS
151 
std::vector< KDataStream > m_vStreams
Definition: Bundle.h:74
KUINT16 m_ui16Length
Definition: Bundle.h:78
unsigned short int KUINT16
Definition: KDefines.h:101
Definition: KDefines.h:182
Definition: KDataStream.h:48
bool KBOOL
Definition: KDefines.h:119
std::string KString
Definition: KDefines.h:116
KDIS::UTILS::KRef_Ptr< Header > PduPtr
Definition: Bundle.h:67
Definition: Bundle.h:70
std::vector< PduPtr > m_vRefHeaders
Definition: Bundle.h:76
#define KDIS_EXPORT
Definition: KDefines.h:82
Definition: KRef_Ptr.h:73