EMANE  1.2.1
flowcontrolcontrolmessage.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater,
3  * New Jersey
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Adjacent Link LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
35 #include "flowcontrol.pb.h"
36 
37 class EMANE::Controls::FlowControlControlMessage::Implementation
38 {
39 public:
40  Implementation(std::uint16_t u16Tokens):
41  u16Tokens_{u16Tokens}{}
42 
43  std::uint16_t getTokens() const
44  {
45  return u16Tokens_;
46  }
47 
48 private:
49  const std::uint16_t u16Tokens_;
50 };
51 
52 EMANE::Controls::FlowControlControlMessage::
53 FlowControlControlMessage(const FlowControlControlMessage & msg):
54  ControlMessage{IDENTIFIER},
55  pImpl_{new Implementation{*msg.pImpl_}}
56 {}
57 
58 EMANE::Controls::FlowControlControlMessage::FlowControlControlMessage(std::uint16_t u16Tokens):
59  ControlMessage{IDENTIFIER},
60  pImpl_{new Implementation{u16Tokens}}
61 {}
62 
64 {}
65 
67 {
68  return pImpl_->getTokens();
69 }
70 
71 
73 {
74  Serialization serialization;
75 
76  EMANEMessage::FlowControlControlMessage msg;
77  msg.set_tokens(pImpl_->getTokens());
78 
79  if(!msg.SerializeToString(&serialization))
80  {
81  throw SerializationException("unable to serialize FlowControlControlMessage");
82  }
83 
84  return serialization;
85 }
86 
89 {
90  return new FlowControlControlMessage{u16Tokens};
91 }
92 
95 {
96  EMANEMessage::FlowControlControlMessage msg;
97 
98  if(!msg.ParseFromString(serialization))
99  {
100  throw SerializationException("unable to deserialize : FlowControlControlMessage");
101  }
102 
103  return new FlowControlControlMessage{static_cast<std::uint16_t>(msg.tokens())};
104 }
105 
108 {
109  return new FlowControlControlMessage{*this};
110 }
std::string Serialization
Definition: serializable.h:42
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
FlowControlControlMessage * clone() const override
static FlowControlControlMessage * create(const Serialization &serialization)
Flow Control Control Messages are sent between a MAC layer and a transport in order to communicate da...
ControlMessage(ControlMessageId id)