WPILibC++  unspecified
InstanceImpl.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2016-2018. 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_INSTANCEIMPL_H_
9 #define NTCORE_INSTANCEIMPL_H_
10 
11 #include <atomic>
12 #include <memory>
13 
14 #include <support/UidVector.h>
15 #include <support/mutex.h>
16 
17 #include "ConnectionNotifier.h"
18 #include "Dispatcher.h"
19 #include "DsClient.h"
20 #include "EntryNotifier.h"
21 #include "Log.h"
22 #include "LoggerImpl.h"
23 #include "RpcServer.h"
24 #include "Storage.h"
25 
26 namespace nt {
27 
28 class InstanceImpl {
29  public:
30  explicit InstanceImpl(int inst);
31  ~InstanceImpl();
32 
33  // Instance repository
34  static InstanceImpl* GetDefault();
35  static InstanceImpl* Get(int inst);
36  static int GetDefaultIndex();
37  static int Alloc();
38  static void Destroy(int inst);
39 
40  LoggerImpl logger_impl;
41  wpi::Logger logger;
42  ConnectionNotifier connection_notifier;
43  EntryNotifier entry_notifier;
44  RpcServer rpc_server;
45  Storage storage;
46  Dispatcher dispatcher;
47  DsClient ds_client;
48 
49  private:
50  static int AllocImpl();
51 
52  static std::atomic<int> s_default;
53  static std::atomic<InstanceImpl*> s_fast_instances[10];
54  static wpi::UidVector<std::unique_ptr<InstanceImpl>, 10> s_instances;
55  static wpi::mutex s_mutex;
56 };
57 
58 } // namespace nt
59 
60 #endif // NTCORE_INSTANCEIMPL_H_
Definition: Dispatcher.h:130
Definition: DsClient.h:19
Definition: InstanceImpl.h:28
Definition: Storage.h:48
Definition: EntryNotifier.h:75
Definition: IEntryNotifier.h:16
Definition: LoggerImpl.h:58
Definition: UidVector.h:23
Definition: ConnectionNotifier.h:46
Definition: Logger.h:30
Definition: RpcServer.h:83