Skip to content

Commit

Permalink
[ntcore] Move ServerImpl.m_local to ServerClientLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Oct 16, 2024
1 parent f086214 commit 487fbf8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
18 changes: 9 additions & 9 deletions ntcore/src/main/native/cpp/server/ServerClientLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,43 @@ using namespace nt::server;

void ServerClientLocal::SendValue(ServerTopic* topic, const Value& value,
net::ValueSendMode mode) {
if (m_server.m_local) {
m_server.m_local->ServerSetValue(topic->localTopic, value);
if (m_local) {
m_local->ServerSetValue(topic->localTopic, value);
}
}

void ServerClientLocal::SendAnnounce(ServerTopic* topic,
std::optional<int> pubuid) {
if (m_server.m_local) {
if (m_local) {
auto& sent = m_announceSent[topic];
if (sent) {
return;
}
sent = true;

topic->localTopic = m_server.m_local->ServerAnnounce(
topic->name, 0, topic->typeStr, topic->properties, pubuid);
topic->localTopic = m_local->ServerAnnounce(topic->name, 0, topic->typeStr,
topic->properties, pubuid);
}
}

void ServerClientLocal::SendUnannounce(ServerTopic* topic) {
if (m_server.m_local) {
if (m_local) {
auto& sent = m_announceSent[topic];
if (!sent) {
return;
}
sent = false;
m_server.m_local->ServerUnannounce(topic->name, topic->localTopic);
m_local->ServerUnannounce(topic->name, topic->localTopic);
}
}

void ServerClientLocal::SendPropertiesUpdate(ServerTopic* topic,
const wpi::json& update,
bool ack) {
if (m_server.m_local) {
if (m_local) {
if (!m_announceSent.lookup(topic)) {
return;
}
m_server.m_local->ServerPropertiesUpdate(topic->name, update, ack);
m_local->ServerPropertiesUpdate(topic->name, update, ack);
}
}
7 changes: 6 additions & 1 deletion ntcore/src/main/native/cpp/server/ServerClientLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ class ServerClientLocal final : public ServerClient4Base {
void SendOutgoing(uint64_t curTimeMs, bool flush) final {}
void Flush() final {}

void SetQueue(net::ClientMessageQueue* queue) { m_queue = queue; }
void SetLocal(net::ServerMessageHandler* local,
net::ClientMessageQueue* queue) {
m_local = local;
m_queue = queue;
}

private:
net::ServerMessageHandler* m_local = nullptr;
net::ClientMessageQueue* m_queue = nullptr;
};

Expand Down
3 changes: 1 addition & 2 deletions ntcore/src/main/native/cpp/server/ServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,7 @@ void ServerImpl::SendOutgoing(int clientId, uint64_t curTimeMs) {
void ServerImpl::SetLocal(net::ServerMessageHandler* local,
net::ClientMessageQueue* queue) {
DEBUG4("SetLocal()");
m_local = local;
m_localClient->SetQueue(queue);
m_localClient->SetLocal(local, queue);

// create server meta topics
m_metaClients = CreateMetaTopic("$clients");
Expand Down
2 changes: 0 additions & 2 deletions ntcore/src/main/native/cpp/server/ServerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ServerImpl final {
friend class ServerClient3;
friend class ServerClient4;
friend class ServerClient4Base;
friend class ServerClientLocal;

public:
explicit ServerImpl(wpi::Logger& logger);
Expand Down Expand Up @@ -91,7 +90,6 @@ class ServerImpl final {

private:
wpi::Logger& m_logger;
net::ServerMessageHandler* m_local{nullptr};
bool m_controlReady{false};

ServerClientLocal* m_localClient;
Expand Down

0 comments on commit 487fbf8

Please sign in to comment.