EMANE  1.2.1
nemlayerstate.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008 - DRS CenGen, LLC, Columbia, Maryland
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 DRS CenGen, 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 
34 #include "nemlayerstate.h"
35 #include "nemstatefullayer.h"
36 #include "logservice.h"
37 
38 EMANE::NEMLayerState::NEMLayerState(const char * pzStateName):
39  pzStateName_(pzStateName){}
40 
42 
44  NEMLayer *,
45  Registrar &)
46 {
49  "NEMLayer invalid %s transition in %s state",
50  "initialize",
51  getStateName().c_str());
52 }
53 
55  NEMLayer *,
56  const ConfigurationUpdate &)
57 {
60  "NEMLayer invalid %s transition in %s state",
61  "configure",
62  getStateName().c_str());
63 }
64 
66  NEMLayer *)
67 {
70  "NEMLayer invalid %s transition in %s state",
71  "start",
72  getStateName().c_str());
73 }
74 
76  NEMLayer *)
77 {
80  "NEMLayer invalid %s transition in %s state",
81  "postStart",
82  getStateName().c_str());
83 }
84 
86  NEMLayer *)
87 {
90  "NEMLayer invalid %s transition in %s state",
91  "stop",
92  getStateName().c_str());
93 }
94 
96  NEMLayer *)
97  throw()
98 {
100  ERROR_LEVEL,
101  "NEMLayer invalid %s transition in %s state",
102  "destroy",
103  getStateName().c_str());
104 }
105 
107  NEMLayer *,
108  const ConfigurationUpdate &)
109 {
111  ERROR_LEVEL,
112  "NEMLayer %s not valid in %s state",
113  "processConfigurationUpdate",
114  getStateName().c_str());
115 }
116 
118  NEMLayer *,
119  const ControlMessages &)
120 {
122  ERROR_LEVEL,
123  "NEMLayer %s not valid in %s state",
124  "processDownstreamControl",
125  getStateName().c_str());
126 }
127 
129  NEMLayer *,
130  DownstreamPacket &,
131  const ControlMessages &)
132 {
134  ERROR_LEVEL,
135  "NEMLayer %s not valid in %s state",
136  "processDownstreamPacket",
137  getStateName().c_str());
138 }
139 
141  NEMLayer *,
142  UpstreamPacket &,
143  const ControlMessages &)
144 {
146  ERROR_LEVEL,
147  "NEMLayer %s not valid in %s state",
148  "processUpstreamPacket",
149  getStateName().c_str());
150 }
151 
153  NEMLayer *,
154  const ControlMessages &)
155 {
157  ERROR_LEVEL,
158  "NEMLayer %s not valid in %s state",
159  "processUpstreamControl",
160  getStateName().c_str());
161 }
162 
164  NEMLayer *,
165  const EventId &,
166  const Serialization &)
167 {
169  ERROR_LEVEL,
170  "NEMLayer %s not valid in %s state",
171  "processEvent",
172  getStateName().c_str());
173 }
174 
175 
177  NEMLayer *,
178  TimerEventId,
179  const TimePoint &,
180  const TimePoint &,
181  const TimePoint &,
182  const void *)
183 {
185  ERROR_LEVEL,
186  "NEMLayer %s not valid in %s state",
187  "processTimedEvent",
188  getStateName().c_str());
189 }
190 
191 
193  NEMLayerState * pState)
194 {
195  pStatefulLayer->changeState(pState);
196 }
197 
199 {
200  return pzStateName_;
201 }
std::string Serialization
Definition: serializable.h:42
A Packet class that allows upstream processing to strip layer headers as the packet travels up the st...
virtual void processEvent(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, const EventId &id, const Serialization &serialization)
virtual void processTimedEvent(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, TimerEventId eventId, const TimePoint &expireTime, const TimePoint &scheduleTime, const TimePoint &fireTime, const void *arg)
The Registrar interface provides access to all of the emulator registrars.
Definition: registrar.h:50
virtual void handleStop(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer)
virtual void processDownstreamControl(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, const ControlMessages &msgs)
virtual void handleConfigure(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, const ConfigurationUpdate &update)
std::list< const ControlMessage * > ControlMessages
void changeState(NEMLayerState *pState)
NEMLayerState(const char *pzStateName)
void changeState(NEMStatefulLayer *pStatefulLayer, NEMLayerState *pState)
Base class for NEMLayer containers. Builders construct NEMLayer objects to contain derived instances ...
Definition: nemlayer.h:57
std::uint16_t EventId
Definition: types.h:53
virtual void handleDestroy(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer)
std::string getStateName() const
Specialized packet the allows downstream processing to add layer specific headers as the packet trave...
virtual void handlePostStart(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer)
virtual void processUpstreamPacket(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, UpstreamPacket &pkt, const ControlMessages &msgs)
const char * pzStateName_
Encapsulated behavior associated with an NEMLayer depending on the layer&#39;s current context...
Definition: nemlayerstate.h:50
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
virtual void processConfiguration(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, const ConfigurationUpdate &update)
std::size_t TimerEventId
Definition: types.h:54
A layer stack that enforces component state transition rules. The stateful layer is not a fully funct...
Clock::time_point TimePoint
Definition: types.h:50
virtual ~NEMLayerState()=0
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)
static LogService * instance()
Definition: singleton.h:56
virtual void processDownstreamPacket(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, DownstreamPacket &pkt, const ControlMessages &msgs)
virtual void processUpstreamControl(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, const ControlMessages &msgs)
virtual void handleStart(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer)
virtual void handleInitialize(NEMStatefulLayer *pStatefulLayer, NEMLayer *pLayer, Registrar &registrar)