EMANE  1.2.1
manifestqueryhandler.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 
34 #include "manifestqueryhandler.h"
35 #include "buildidservice.h"
37 
38 std::string
40  std::uint32_t u32Reference)
41 {
43 
45 
46  response.set_type(EMANERemoteControlPortAPI::Response::TYPE_RESPONSE_QUERY);
47 
48  auto pQuery = response.mutable_query();
49 
51 
52  auto pManifest = pQuery->mutable_manifest();
53 
54  using Component = EMANERemoteControlPortAPI::Response::Query::Manifest::NEM::Component;
55 
56 
57  for(const auto & nem : componentMap)
58  {
59  auto pNEM = pManifest->add_nems();
60 
61  pNEM->set_id(nem.first);
62 
63  for(const auto & component : nem.second)
64  {
65  auto pComponent = pNEM->add_components();
66 
67  pComponent->set_buildid(std::get<0>(component));
68 
69  ComponentType componentType{std::get<1>(component)};
70 
71  pComponent->set_type(componentType == ComponentType::COMPONENT_PHYILAYER ?
72  Component::TYPE_COMPONENT_PHY :
73  componentType == ComponentType::COMPONENT_MACILAYER ?
74  Component::TYPE_COMPONENT_MAC :
75  componentType == ComponentType::COMPONENT_SHIMILAYER ?
76  Component::TYPE_COMPONENT_SHIM:
77  Component::TYPE_COMPONENT_TRANSPORT);
78 
79  pComponent->set_plugin(std::get<2>(component));
80  }
81  }
82 
83  response.set_reference(u32Reference);
84 
85  response.set_sequence(u32Sequence);
86 
87  std::string sSerialization;
88 
89  if(!response.SerializeToString(&sSerialization))
90  {
91  throw SerializationException("unable to serialize manifest query response");
92  }
93 
94  return sSerialization;
95 }
static std::string process(std::uint32_t u32Sequence, std::uint32_t u32Reference)
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
const NEMLayerComponentBuildIdMap & getNEMLayerComponentBuildIdMap() const
static BuildIdService * instance()
Definition: singleton.h:56
Generic interface used to configure and control all components.
Definition: component.h:81