EMANE  1.2.1
commeffectevent.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 "commeffectevent.pb.h"
36 
37 class EMANE::Events::CommEffectEvent::Implementation
38 {
39 public:
40  Implementation(const CommEffects & commEffects):
41  commEffects_{commEffects}{}
42 
43  const CommEffects & getCommEffects() const
44  {
45  return commEffects_;
46  }
47 
48 private:
49  CommEffects commEffects_;
50 };
51 
54 {
56 
57  if(!msg.ParseFromString(serialization))
58  {
59  throw SerializationException("unable to deserialize CommEffectEvent");
60  }
61 
62  CommEffects commEffects;
63 
64  for(const auto & effect : msg.commeffects())
65  {
66  commEffects.push_back({static_cast<EMANE::NEMId>(effect.nemid()),
67  std::chrono::duration_cast<Microseconds>(DoubleSeconds{effect.latencyseconds()}),
68  std::chrono::duration_cast<Microseconds>(DoubleSeconds{effect.jitterseconds()}),
69  effect.probabilityloss(),
70  effect.probabilityduplicate(),
71  effect.unicastbitratebps(),
72  effect.broadcastbitratebps(),
73  });
74  }
75 
76  pImpl_.reset(new Implementation{commEffects});
77 }
78 
81  pImpl_{new Implementation{commEffects}}{}
82 
85  pImpl_{new Implementation{rhs.getCommEffects()}}{}
86 
88 {
89  pImpl_.reset(new Implementation{rhs.getCommEffects()});
90  return *this;
91 }
92 
95  pImpl_{new Implementation{{}}}
96 {
97  rval.pImpl_.swap(pImpl_);
98 }
99 
102 {
103  rval.pImpl_.swap(pImpl_);
104  return *this;
105 }
106 
108 
111 {
112  return pImpl_->getCommEffects();
113 }
114 
116 {
117  Serialization serialization;
118 
120 
121  for(auto & commEffect : pImpl_->getCommEffects())
122  {
123  auto pCommEffectMessage = msg.add_commeffects();
124 
125  pCommEffectMessage->set_nemid(commEffect.getNEMId());
126  pCommEffectMessage->set_latencyseconds(std::chrono::duration_cast<DoubleSeconds>(commEffect.getLatency()).count());
127  pCommEffectMessage->set_jitterseconds(std::chrono::duration_cast<DoubleSeconds>(commEffect.getJitter()).count());
128  pCommEffectMessage->set_probabilityloss(commEffect.getProbabilityLoss());
129  pCommEffectMessage->set_probabilityduplicate(commEffect.getProbabilityDuplicate());
130  pCommEffectMessage->set_unicastbitratebps(commEffect.getUnicastBitRate());
131  pCommEffectMessage->set_broadcastbitratebps(commEffect.getBroadcastBitRate());
132  }
133 
134  if(!msg.SerializeToString(&serialization))
135  {
136  throw SerializationException("unable to serialize CommEffectEvent");
137  }
138 
139  return serialization;
140 }
std::string Serialization
Definition: serializable.h:42
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
Event interface is the base for all events.
Definition: event.h:46
Serialization serialize() const override
CommEffectEvent(const Serialization &serialization)
CommEffectEvent & operator=(const CommEffectEvent &rhs)
std::list< CommEffect > CommEffects
Definition: commeffect.h:131
Comm Effect events are used to set asynchronous link characteristics from one or more transmitting NE...
std::chrono::duration< double > DoubleSeconds
Definition: types.h:47
std::uint16_t NEMId
Definition: types.h:52
const CommEffects & getCommEffects() const