Free Electron
GlobalDictionary.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __Global_Dictonary_h__
8 #define __Global_Dictonary_h__
9 
10 namespace beacon
11 {
12 
13 /***************************************************************************//**
14  @brief Global Dictionary of name/value strings
15 
16  @ingroup beacon
17 *//****************************************************************************/
18 class FE_DL_EXPORT GlobalDictionary
19 {
20  public:
22  virtual ~GlobalDictionary();
23 
24  /// @brief Initialize Global Dictionary with the given entries
25  virtual void setInitialEntries(const std::vector<std::pair<fe::String,fe::String>> &entries);
26 
27  /// @brief Starts the Global Dictionary with the port for receiving requests
28  virtual bool start(uint16_t receivePort);
29 
30  /// @brief Stop the Global Dictionary server
31  virtual void stop(void);
32 
33  /// @brief Returns to true if the Global Dictionary server is running
34  virtual bool running(void);
35 
36  /// @brief Delete entries by the given ID
37  virtual void deleteEntriesByID(uint8_t id);
38 
39  /// @brief Clears the entire Global Dictionary
40  virtual void clear();
41 
42  /// @brief Returns to true if the Global Dictionary server is running
43  virtual uint64_t getUpdateCounter() { return m_updateCounter; };
44 
45  protected:
46  bool m_initialized;
47  bool m_done;
48  bool m_running;
49  std::vector<uint8_t> m_responseMsg;
50  char m_fromIPaddress[16]; // Address from where the request came from
51 
52  std::thread* m_requestThread;
53  fe::sp<fe::SingleMaster> m_spSingleMaster;
54  fe::sp<fe::ext::MessageReliableUDPI> m_reliableMessageSystem;
55  std::map<fe::String, std::pair<uint8_t,fe::String>> m_globalDictionary;
56  std::atomic<uint64_t> m_updateCounter;
57 
58  virtual void requestThread();
59 
60  /// Global dictionary functions
61  virtual void dictionaryGet(char *nameList, char *nameListEnd, uint16_t responsePort);
62  virtual void dictionarySet(uint8_t id, char *nameValueList, char *nameValueListEnd, uint16_t responsePort);
63  virtual void dictionaryUnset(char *nameList, char *nameListEnd, uint16_t responsePort);
64  virtual void dictionaryGetRegex(char *nameList, uint16_t responsePort);
65  virtual void dictionaryClear(uint16_t responsePort);
66  virtual void displayDictionary();
67 
68  void setupSimpleResponse(uint8_t type, uint16_t result);
69  void sendResponseMsg(uint16_t responsePort);
70 };
71 
72 } // namespace beacon
73 
74 #endif // __Global_Dictonary_h__
virtual uint64_t getUpdateCounter()
Returns to true if the Global Dictionary server is running.
Definition: GlobalDictionary.h:43
Global Dictionary of name/value strings.
Definition: GlobalDictionary.h:18
Definition: BeaconClient.cc:16