EMANE  1.2.1
requestmessagehandler.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "requestmessagehandler.h"
34 #include "manifestqueryhandler.h"
36 #include "statisticqueryhandler.h"
41 #include "loglevelupdatehandler.h"
42 #include "errorresponse.h"
43 #include "remotecontrolportapi.pb.h"
44 
45 std::string
47  std::uint32_t u32Sequence)
48 
49 {
50  if(request.type() == EMANERemoteControlPortAPI::Request::TYPE_REQUEST_QUERY)
51  {
52  if(request.has_query())
53  {
54  const auto & query = request.query();
55 
57  {
58  return ManifestQueryHandler::process(u32Sequence,request.sequence());
59  }
61  {
62  if(query.has_configuration())
63  {
64  return ConfigurationQueryHandler::process(query.configuration(),u32Sequence,request.sequence());
65  }
66  else
67  {
68  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
69  "Configuration query request malformed: missing configuration message",
70  u32Sequence,
71  request.sequence());
72  }
73  }
75  {
76  if(query.has_statistic())
77  {
78  return StatisticQueryHandler::process(query.statistic(),u32Sequence,request.sequence());
79 
80  }
81  else
82  {
83  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
84  "Statistic query request malformed: missing statistic message",
85  u32Sequence,
86  request.sequence());
87  }
88  }
90  {
91  if(query.has_statistictable())
92  {
93  return StatisticTableQueryHandler::process(query.statistictable(),u32Sequence,request.sequence());
94  }
95  else
96  {
97  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
98  "Statistic Table query request malformed: missing statisticTable message",
99  u32Sequence,
100  request.sequence());
101 
102  }
103  }
104  }
105  else
106  {
107  ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
108  "Query request malformed: missing query message",
109  u32Sequence,
110  request.sequence());
111 
112  }
113  }
114  else if(request.type() == EMANERemoteControlPortAPI::Request::TYPE_REQUEST_UPDATE)
115  {
116  if(request.has_update())
117  {
118  const auto & update = request.update();
119 
121  {
122  if(update.has_configuration())
123  {
124  return ConfigurationUpdateHandler::process(update.configuration(),u32Sequence,request.sequence());
125  }
126  else
127  {
128  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
129  "Configuration update request malformed: missing configuration message",
130  u32Sequence,
131  request.sequence());
132  }
133  }
135  {
136  if(update.has_statisticclear())
137  {
138  return StatisticClearUpdateHandler::process(update.statisticclear(),u32Sequence,request.sequence());
139 
140  }
141  else
142  {
143  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
144  "Statistic Table update request malformed: missing statisticClear message",
145  u32Sequence,
146  request.sequence());
147  }
148  }
150  {
151  if(update.has_statistictableclear())
152  {
153  return StatisticTableClearUpdateHandler::process(update.statistictableclear(),u32Sequence,request.sequence());
154 
155  }
156  else
157  {
158  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
159  "Statistic Table Clear update request malformed: missing statisticTableClear message",
160  u32Sequence,
161  request.sequence());
162  }
163  }
164  else if(update.type() == EMANERemoteControlPortAPI::TYPE_UPDATE_LOGLEVEL)
165  {
166  if(update.has_loglevel())
167  {
168  return LogLevelUpdateHandler::process(update.loglevel(),u32Sequence,request.sequence());
169 
170  }
171  else
172  {
173  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
174  "Log Level update request malformed: missing LogLevel message",
175  u32Sequence,
176  request.sequence());
177  }
178  }
179  }
180  else
181  {
182  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
183  "Update request malformed: missing update message",
184  u32Sequence,
185  request.sequence());
186  }
187  }
188 
189  return ErrorResponse::serialize(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_MALFORMED,
190  "Request malformed: unknown request type",
191  u32Sequence,
192  request.sequence());
193 }
static std::string process(const EMANERemoteControlPortAPI::Request::Query::Statistic &statistic, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string process(std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string process(const EMANERemoteControlPortAPI::Request &request, std::uint32_t u32Sequence)
static std::string process(const EMANERemoteControlPortAPI::Request::Update::StatisticTableClear &statisticTableClear, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string process(const EMANERemoteControlPortAPI::Request::Update::StatisticClear &statisticClear, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string serialize(EMANERemoteControlPortAPI::Response::Error::ErrorType type, const std::string &sDescription, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string process(const EMANERemoteControlPortAPI::Request::Query::Configuration &configuration, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string process(const EMANERemoteControlPortAPI::Request::Update::LogLevel &logLevel, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string process(const EMANERemoteControlPortAPI::Request::Update::Configuration &configuration, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static std::string process(const EMANERemoteControlPortAPI::Request::Query::StatisticTable &statisticTable, std::uint32_t u32Sequence, std::uint32_t u32Reference)