EMANE  1.2.1
loglevelupdatehandler.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 
34 #include "loglevelupdatehandler.h"
36 #include "logservice.h"
37 
38 std::string
41  std::uint32_t u32Sequence,
42  std::uint32_t u32Reference)
43 {
45 
46  int iLogLevel = logLevel.level();
47 
48  if(iLogLevel >= 0 && iLogLevel <= 4)
49  {
50  LogServiceSingleton::instance()->setLogLevel(static_cast<EMANE::LogLevel>(iLogLevel));
51 
52  response.set_type(EMANERemoteControlPortAPI::Response::TYPE_RESPONSE_UPDATE);
53 
54  auto pUpdate = response.mutable_update();
55 
57  }
58  else
59  {
60  response.set_type(EMANERemoteControlPortAPI::Response::TYPE_RESPONSE_ERROR);
61 
62  auto pError = response.mutable_error();
63 
64  pError->set_type(EMANERemoteControlPortAPI::Response::Error::TYPE_ERROR_PARAMETER);
65 
66  pError->set_description("Log level out of allowable range [0,4]");
67  }
68 
69  response.set_reference(u32Reference);
70 
71  response.set_sequence(u32Sequence);
72 
73  std::string sSerialization;
74 
75  if(!response.SerializeToString(&sSerialization))
76  {
77  throw SerializationException("unable to serialize log level update response");
78  }
79 
80  return sSerialization;
81 }
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
static std::string process(const EMANERemoteControlPortAPI::Request::Update::LogLevel &logLevel, std::uint32_t u32Sequence, std::uint32_t u32Reference)
static LogService * instance()
Definition: singleton.h:56
void setLogLevel(LogLevel level)
Definition: logservice.cc:157