ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
NetworkTable.hpp
1 /*
2  * Copyright 2021 Marcus Behel
3  *
4  * This file is part of ArPiRobot-CoreLib.
5  *
6  * ArPiRobot-CoreLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * ArPiRobot-CoreLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with ArPiRobot-CoreLib. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <unordered_map>
23 #include <string>
24 #include <mutex>
25 
26 namespace arpirobot{
32  class NetworkTable{
33  public:
34 
40  static void set(std::string key, std::string value);
41 
47  static std::string get(std::string key);
48 
54  static bool has(std::string key);
55 
62  static bool changed(std::string key);
63 
64  private:
65  static bool isInSync();
66  static void startSync();
67  static void sendAllValues();
68  static void finishSync(std::unordered_map<std::string, std::string> dataFromDs);
69  static void abortSync();
70 
71  static void setFromRobot(std::string key, std::string value);
72  static void setFromDs(std::string key, std::string value);
73 
74  static std::unordered_map<std::string, std::string> data;
75  static std::unordered_map<std::string, bool> dataChanged;
76  static std::mutex lock;
77  static bool inSync;
78 
79  friend class NetworkManager;
80  };
81 
82 }
Definition: NetworkManager.hpp:101
Definition: NetworkTable.hpp:32
static bool changed(std::string key)
static void set(std::string key, std::string value)
static std::string get(std::string key)
static bool has(std::string key)
Definition: ArduinoDevice.hpp:27