EMANE  1.2.1
otatransmittercontrolmessage.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 "otatransmitter.pb.h"
36 
37 class EMANE::Controls::OTATransmitterControlMessage::Implementation
38 {
39 public:
40  Implementation(){}
41 
42  Implementation(const OTATransmitters & otaTransmitters):
43  otaTransmitters_{otaTransmitters}{}
44 
45  const OTATransmitters & getOTATransmitters() const
46  {
47  return otaTransmitters_;
48  }
49 
50 private:
51  const OTATransmitters otaTransmitters_;
52 };
53 
54 EMANE::Controls::OTATransmitterControlMessage::
55 OTATransmitterControlMessage(const OTATransmitterControlMessage & msg):
56  ControlMessage{IDENTIFIER},
57  pImpl_{new Implementation{*msg.pImpl_}}
58 {}
59 
61 
62 EMANE::Controls::OTATransmitterControlMessage::
63 OTATransmitterControlMessage(const OTATransmitters & otaTransmitters):
64  ControlMessage{IDENTIFIER},
65  pImpl_{new Implementation{otaTransmitters}}{}
66 
69 {
70  return pImpl_->getOTATransmitters();
71 }
72 
75 {
76  OTATransmitters otaTransmitters;
77 
78  EMANEMessage::OTATransmitterControlMessage msg;
79 
80  msg.ParseFromString(serialization);
81 
82  if(!msg.ParseFromString(serialization))
83  {
84  throw SerializationException("unable to deserialize : OTATransmitterControlMessage");
85  }
86 
87  for(int i = 0; i < msg.nemid_size(); ++i)
88  {
89  otaTransmitters.insert(msg.nemid(i));
90  }
91 
92  return new OTATransmitterControlMessage{otaTransmitters};
93 }
94 
95 
98 {
99  return new OTATransmitterControlMessage{otaTransmitters};
100 }
101 
103 {
104  Serialization serialization;
105 
106  EMANEMessage::OTATransmitterControlMessage msg;
107 
108  const OTATransmitters & otaTransmitters = pImpl_->getOTATransmitters();
109 
110  OTATransmitters::const_iterator iter = otaTransmitters.begin();
111 
112  for(; iter != otaTransmitters.end(); ++iter)
113  {
114  msg.add_nemid(*iter);
115  }
116 
117  if(!msg.SerializeToString(&serialization))
118  {
119  throw SerializationException("unable to serialize OTATransmitterControlMessage");
120  }
121 
122  return serialization;
123 }
124 
125 
128 {
129  return new OTATransmitterControlMessage{*this};
130 }
std::set< NEMId > OTATransmitters
std::string Serialization
Definition: serializable.h:42
static OTATransmitterControlMessage * create(const Serialization &serialization)
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
OTATransmitterControlMessage * clone() const override
The OTA Transmitter Control Message is by the emulator physical layer to specify the NEM Id of the so...
ControlMessage interface is the base for all control messages.
ControlMessage(ControlMessageId id)