kvh_geo_fog_3d_packet_storage.hpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (Apache 2.0)
3  *
4  * Copyright (c) 2019, The MITRE Corporation.
5  * All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * https://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Sections of this project contains content developed by The MITRE Corporation.
20  * If this code is used in a deployment or embedded within another project,
21  * it is requested that you send an email to opensource@mitre.org in order to
22  * let us know where this software is being used.
23  *********************************************************************/
24 
34 #pragma once
35 
36 // STD
37 #include <map>
38 #include <memory> // share_ptr
39 #include <vector>
40 #include <typeinfo>
41 
42 
43 // GEO-FOG SDK
44 #include "an_packet_protocol.h"
45 #include "spatial_packets.h"
47 
48 namespace kvh
49 {
50 
58  typedef std::map<packet_id_e, std::pair<bool, std::shared_ptr<void>>> KvhPacketMap;
59 
65  typedef std::vector<std::pair<packet_id_e, uint16_t>> KvhPacketRequest;
66 
68  {
69 
70  private:
71  KvhPacketMap packetMap_;
72 
75  public:
77 
84  int Init(KvhPacketRequest &);
85 
103  template <class T>
104  int UpdatePacket(packet_id_e _packetId, T& _packetData)
105  {
106  // Check if packet type matches packet id
107  if (supportedPackets_.count(_packetId) <= 0 || packetTypeStr_[_packetId] != typeid(T).name())
108  {
109  return -1;
110  }
111  else if (this->Contains(_packetId))
112  {
113  *static_cast<T*>(packetMap_[_packetId].second.get()) = _packetData;
114  return 0;
115  }
116 
117  return -2;
118  }
119 
126  int SetPacketUpdated(packet_id_e, bool);
127 
135 
143  template <class T>
144  int GetPacket(packet_id_e _packetId, T& _packet)
145  {
146  // Check if packet types matches id
147  if (supportedPackets_.count(_packetId) <= 0 || packetTypeStr_[_packetId] != typeid(T).name())
148  {
149  return -1;
150  }
151  else if (this->Contains(_packetId))
152  {
153  _packet = *static_cast<T*>(packetMap_[_packetId].second.get());
154  return 0;
155  }
156 
157  return -2;
158  }
159 
167  bool Contains(packet_id_e);
168 
175  int Size();
176 
182  static void PrintPacketTypes();
183 
189  static void PrintPacketSizes();
190  };
191 } // namespace kvh
global variables used to store packet information.
std::map< packet_id_e, std::string > packetTypeStr_
Holds the string value for the different types of structs.
std::set< packet_id_e > supportedPackets_
Set of packets containing all packet_id&#39;s we support.
packet_id_e
std::vector< std::pair< packet_id_e, uint16_t > > KvhPacketRequest
int Init(KvhPacketRequest &)
Correctly sets up a KvhPacketMap for the requested packets.
int GetPacket(packet_id_e _packetId, T &_packet)
int SetPacketUpdated(packet_id_e, bool)
bool PacketIsUpdated(packet_id_e)
static void PrintPacketTypes()
std::map< packet_id_e, std::pair< bool, std::shared_ptr< void > > > KvhPacketMap
static void PrintPacketSizes()
bool Contains(packet_id_e)
int UpdatePacket(packet_id_e _packetId, T &_packetData)


kvh_geo_fog_3d_driver
Author(s): Trevor Bostic , Zach LaCelle
autogenerated on Fri Jan 24 2020 03:18:17