ntcore: Add support for local-only operation (#2204)

StartLocal() causes future calls to StartServer() or StartClient() to have
no effect. StopLocal() re-enables these calls.
This commit is contained in:
Peter Johnson
2019-12-29 14:56:41 -06:00
committed by GitHub
parent 44bcf7fb4d
commit 6ea13ea8f3
11 changed files with 123 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -61,7 +61,8 @@ class NetworkTableInstance final {
kNetModeServer = NT_NET_MODE_SERVER,
kNetModeClient = NT_NET_MODE_CLIENT,
kNetModeStarting = NT_NET_MODE_STARTING,
kNetModeFailure = NT_NET_MODE_FAILURE
kNetModeFailure = NT_NET_MODE_FAILURE,
kNetModeLocal = NT_NET_MODE_LOCAL
};
/**
@@ -298,6 +299,19 @@ class NetworkTableInstance final {
*/
unsigned int GetNetworkMode() const;
/**
* Starts local-only operation. Prevents calls to StartServer or StartClient
* from taking effect. Has no effect if StartServer or StartClient
* has already been called.
*/
void StartLocal();
/**
* Stops local-only operation. StartServer or StartClient can be called after
* this call to start a server or client.
*/
void StopLocal();
/**
* Starts a server using the specified filename, listening address, and port.
*

View File

@@ -81,6 +81,10 @@ inline unsigned int NetworkTableInstance::GetNetworkMode() const {
return ::nt::GetNetworkMode(m_handle);
}
inline void NetworkTableInstance::StartLocal() { ::nt::StartLocal(m_handle); }
inline void NetworkTableInstance::StopLocal() { ::nt::StopLocal(m_handle); }
inline void NetworkTableInstance::StartServer(const Twine& persist_filename,
const char* listen_address,
unsigned int port) {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -95,6 +95,7 @@ enum NT_NetworkMode {
NT_NET_MODE_CLIENT = 0x02, /* running in client mode */
NT_NET_MODE_STARTING = 0x04, /* flag for starting (either client or server) */
NT_NET_MODE_FAILURE = 0x08, /* flag for failure (either client or server) */
NT_NET_MODE_LOCAL = 0x10, /* running in local-only mode */
};
/*
@@ -1037,6 +1038,19 @@ void NT_SetNetworkIdentity(NT_Inst inst, const char* name, size_t name_len);
*/
unsigned int NT_GetNetworkMode(NT_Inst inst);
/**
* Starts local-only operation. Prevents calls to NT_StartServer or
* NT_StartClient from taking effect. Has no effect if NT_StartServer or
* NT_StartClient has already been called.
*/
void NT_StartLocal(NT_Inst inst);
/**
* Stops local-only operation. NT_StartServer or NT_StartClient can be called
* after this call to start a server or client.
*/
void NT_StopLocal(NT_Inst inst);
/**
* Starts a server using the specified filename, listening address, and port.
*

View File

@@ -1130,6 +1130,19 @@ unsigned int GetNetworkMode();
*/
unsigned int GetNetworkMode(NT_Inst inst);
/**
* Starts local-only operation. Prevents calls to StartServer or StartClient
* from taking effect. Has no effect if StartServer or StartClient
* has already been called.
*/
void StartLocal(NT_Inst inst);
/**
* Stops local-only operation. StartServer or StartClient can be called after
* this call to start a server or client.
*/
void StopLocal(NT_Inst inst);
/**
* Starts a server using the specified filename, listening address, and port.
*