EMANE  1.2.1
pathlossevent.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 "pathlossevent.pb.h"
36 
37 class EMANE::Events::PathlossEvent::Implementation
38 {
39 public:
40  Implementation(const Pathlosses & pathlosses):
41  pathlosses_{pathlosses}{}
42 
43  const Pathlosses & getPathlosses() const
44  {
45  return pathlosses_;
46  }
47 
48 private:
49  Pathlosses pathlosses_;
50 };
51 
54 {
56 
57  if(!msg.ParseFromString(serialization))
58  {
59  throw SerializationException("unable to deserialize PathlossEvent");
60  }
61 
62  Pathlosses pathlosses;
63 
64  for(const auto & pathloss : msg.pathlosses())
65  {
66  pathlosses.push_back({static_cast<EMANE::NEMId>(pathloss.nemid()),
67  pathloss.forwardpathlossdb(),
68  pathloss.reversepathlossdb()});
69  }
70 
71  pImpl_.reset(new Implementation{pathlosses});
72 }
73 
76  pImpl_{new Implementation{pathlosses}}{}
77 
80  pImpl_{new Implementation{rhs.getPathlosses()}}{}
81 
83 {
84  pImpl_.reset(new Implementation{rhs.getPathlosses()});
85  return *this;
86 }
87 
90  pImpl_{new Implementation{{}}}
91 {
92  rval.pImpl_.swap(pImpl_);
93 }
94 
96 {
97  rval.pImpl_.swap(pImpl_);
98  return *this;
99 }
100 
102 
104 {
105  return pImpl_->getPathlosses();
106 }
107 
109 {
110  Serialization serialization;
111 
113 
114  for(auto & pathloss : pImpl_->getPathlosses())
115  {
116  auto pPathlossMessage = msg.add_pathlosses();
117 
118  pPathlossMessage->set_nemid(pathloss.getNEMId());
119 
120  pPathlossMessage->set_forwardpathlossdb(pathloss.getForwardPathlossdB());
121 
122  pPathlossMessage->set_reversepathlossdb(pathloss.getReversePathlossdB());
123  }
124 
125  if(!msg.SerializeToString(&serialization))
126  {
127  throw SerializationException("unable to serialize PathlossEvent");
128  }
129 
130  return serialization;
131 }
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
A pathloss event is used to set the pathloss from one or more transmitting NEMs to a receiving NEM...
Definition: pathlossevent.h:52
Serialization serialize() const override
PathlossEvent & operator=(const PathlossEvent &rhs)
std::list< Pathloss > Pathlosses
Definition: pathloss.h:95
std::uint16_t NEMId
Definition: types.h:52
PathlossEvent(const Serialization &serialization)
const Pathlosses & getPathlosses() const