mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[ntcore] NetworkTables 4 (#3217)
This commit is contained in:
@@ -2,45 +2,62 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#ifndef NTCORE_INSTANCEIMPL_H_
|
||||
#define NTCORE_INSTANCEIMPL_H_
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/mutex.h>
|
||||
|
||||
#include "ConnectionNotifier.h"
|
||||
#include "Dispatcher.h"
|
||||
#include "DsClient.h"
|
||||
#include "EntryNotifier.h"
|
||||
#include "ConnectionList.h"
|
||||
#include "Handle.h"
|
||||
#include "LocalStorage.h"
|
||||
#include "Log.h"
|
||||
#include "LoggerImpl.h"
|
||||
#include "RpcServer.h"
|
||||
#include "Storage.h"
|
||||
#include "NetworkClient.h"
|
||||
#include "NetworkServer.h"
|
||||
|
||||
namespace nt {
|
||||
|
||||
class InstanceImpl {
|
||||
public:
|
||||
explicit InstanceImpl(int inst);
|
||||
~InstanceImpl();
|
||||
|
||||
// Instance repository
|
||||
static InstanceImpl* GetDefault();
|
||||
static InstanceImpl* Get(int inst);
|
||||
static InstanceImpl* GetHandle(NT_Handle handle) {
|
||||
return Get(Handle{handle}.GetInst());
|
||||
}
|
||||
static InstanceImpl* GetTyped(NT_Handle handle, Handle::Type type) {
|
||||
return Get(Handle{handle}.GetTypedInst(type));
|
||||
}
|
||||
static int GetDefaultIndex();
|
||||
static int Alloc();
|
||||
static void Destroy(int inst);
|
||||
|
||||
void StartLocal();
|
||||
void StopLocal();
|
||||
void StartServer(std::string_view persistFilename,
|
||||
std::string_view listenAddress, unsigned int port3,
|
||||
unsigned int port4);
|
||||
void StopServer();
|
||||
void StartClient3();
|
||||
void StartClient4();
|
||||
void StopClient();
|
||||
void SetIdentity(std::string_view identity);
|
||||
|
||||
std::shared_ptr<NetworkServer> GetServer();
|
||||
std::shared_ptr<INetworkClient> GetClient();
|
||||
|
||||
LoggerImpl logger_impl;
|
||||
wpi::Logger logger;
|
||||
ConnectionNotifier connection_notifier;
|
||||
EntryNotifier entry_notifier;
|
||||
RpcServer rpc_server;
|
||||
Storage storage;
|
||||
Dispatcher dispatcher;
|
||||
DsClient ds_client;
|
||||
ConnectionList connectionList;
|
||||
LocalStorage localStorage;
|
||||
std::atomic<int> networkMode{NT_NET_MODE_NONE};
|
||||
|
||||
private:
|
||||
static int AllocImpl();
|
||||
@@ -49,8 +66,12 @@ class InstanceImpl {
|
||||
static constexpr int kNumInstances = 16;
|
||||
static std::atomic<InstanceImpl*> s_instances[kNumInstances];
|
||||
static wpi::mutex s_mutex;
|
||||
|
||||
wpi::mutex m_mutex;
|
||||
std::string m_identity;
|
||||
std::shared_ptr<NetworkServer> m_networkServer;
|
||||
std::shared_ptr<INetworkClient> m_networkClient;
|
||||
int m_inst;
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
|
||||
#endif // NTCORE_INSTANCEIMPL_H_
|
||||
|
||||
Reference in New Issue
Block a user