Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
entry_manager.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
18#include <iostream>
19
21{
23
24 EntryManager::EntryManager(std::vector<std::string> required_entries):required_entries_(required_entries) {}
25
26 EntryManager::EntryManager(std::vector<std::string> required_entries, std::vector<std::string> camera_entries)
27 :required_entries_(required_entries), camera_entries_(camera_entries){}
28
30 {
31 for(auto i = entry_list_.begin(); i < entry_list_.end(); ++i)
32 {
33 if(i->name_.compare(entry.name_) == 0)
34 {
35 // name entry wont change
36 i->available_ = entry.available_;
37 i->timestamp_ = entry.timestamp_;
38 return;
39 }
40 }
41 entry_list_.push_back(entry);
42 }
43
44 std::vector<Entry> EntryManager::get_entries() const
45 {
46 // returns the copy of the original list
47 return std::vector<Entry>(entry_list_);
48 }
49
50 void EntryManager::delete_entry(const std::string& name)
51 {
52 for(auto i = entry_list_.begin(); i < entry_list_.end(); ++i)
53 {
54 if(i->name_.compare(name) == 0)
55 {
56 entry_list_.erase(i);
57 return;
58 }
59 }
60 }
61
62 boost::optional<Entry> EntryManager::get_entry_by_name(const std::string& name) const
63 {
64 for(auto i = entry_list_.begin(); i < entry_list_.end(); ++i)
65 {
66 if(i->name_.compare(name) == 0)
67 {
68 return *i;
69 }
70 }
71 // use boost::optional because requested entry might not exist
72 return boost::none;
73 }
74
75 bool EntryManager::is_entry_required(const std::string& name) const
76 {
77 for(auto i = required_entries_.begin(); i < required_entries_.end(); ++i)
78 {
79 if(i->compare(name) == 0)
80 {
81 return true;
82 }
83 }
84 return false;
85 }
86
87 int EntryManager::is_camera_entry_required(const std::string& name) const
88 {
89 for(int i = 0;i < camera_entries_.size(); i++)
90 {
91 if(camera_entries_[i].compare(name) == 0)
92 {
93 return i;
94 }
95 }
96
97 // default like above?
98 return -1;
99 }
100
101
102}
std::vector< Entry > entry_list_
private list to keep track of all entries
std::vector< std::string > required_entries_
bool is_entry_required(const std::string &name) const
Check if the entry is required.
boost::optional< Entry > get_entry_by_name(const std::string &name) const
Get a entry using name as the key.
EntryManager()
Default constructor for EntryManager.
void delete_entry(const std::string &name)
Delete an entry using the given name as the key.
int is_camera_entry_required(const std::string &name) const
Check if the entry is a required camera entry.
void update_entry(const Entry &entry)
Add a new entry if the given name does not exist. Update an existing entry if the given name exists.
std::vector< std::string > camera_entries_
std::vector< Entry > get_entries() const
Get all registed entries as a list.
An entry represents a driver details for the purposes of tracking.
Definition: entry.hpp:27
bool available_
Availability flag of a driver.
Definition: entry.hpp:29
std::string name_
Fully specified node name of a driver.
Definition: entry.hpp:31
long timestamp_
The timestamp at which the entry was last updated.
Definition: entry.hpp:33