WPILibC++  unspecified
IStorage.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef NTCORE_ISTORAGE_H_
9 #define NTCORE_ISTORAGE_H_
10 
11 #include <functional>
12 #include <memory>
13 #include <vector>
14 
15 #include <wpi/ArrayRef.h>
16 #include <wpi/Twine.h>
17 
18 #include "Message.h"
19 #include "ntcore_cpp.h"
20 
21 namespace nt {
22 
23 class IDispatcher;
24 class INetworkConnection;
25 
26 class IStorage {
27  public:
28  IStorage() = default;
29  IStorage(const IStorage&) = delete;
30  IStorage& operator=(const IStorage&) = delete;
31  virtual ~IStorage() = default;
32 
33  // Accessors required by Dispatcher. An interface is used for
34  // generation of outgoing messages to break a dependency loop between
35  // Storage and Dispatcher.
36  virtual void SetDispatcher(IDispatcher* dispatcher, bool server) = 0;
37  virtual void ClearDispatcher() = 0;
38 
39  // Required for wire protocol 2.0 to get the entry type of an entry when
40  // receiving entry updates (because the length/type is not provided in the
41  // message itself). Not used in wire protocol 3.0.
42  virtual NT_Type GetMessageEntryType(unsigned int id) const = 0;
43 
44  virtual void ProcessIncoming(std::shared_ptr<Message> msg,
45  INetworkConnection* conn,
46  std::weak_ptr<INetworkConnection> conn_weak) = 0;
47  virtual void GetInitialAssignments(
48  INetworkConnection& conn,
49  std::vector<std::shared_ptr<Message>>* msgs) = 0;
50  virtual void ApplyInitialAssignments(
51  INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
52  bool new_server, std::vector<std::shared_ptr<Message>>* out_msgs) = 0;
53 
54  // Filename-based save/load functions. Used both by periodic saves and
55  // accessible directly via the user API.
56  virtual const char* SavePersistent(const Twine& filename,
57  bool periodic) const = 0;
58  virtual const char* LoadPersistent(
59  const Twine& filename,
60  std::function<void(size_t line, const char* msg)> warn) = 0;
61 };
62 
63 } // namespace nt
64 
65 #endif // NTCORE_ISTORAGE_H_
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
Definition: IStorage.h:26
Definition: IStorage.h:21
Definition: IDispatcher.h:21
Definition: INetworkConnection.h:18
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79