Skip to content

Commit

Permalink
[ntcore] Move metatopic creation from SetLocal to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Oct 17, 2024
1 parent c6f51be commit b7a2b0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
12 changes: 12 additions & 0 deletions ntcore/src/main/native/cpp/server/ServerClientLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

using namespace nt::server;

ServerClientLocal::ServerClientLocal(ServerStorage& storage, int id,
wpi::Logger& logger)
: ServerClient4Base{"", "", true, [](uint32_t) {}, storage, id, logger} {
// create local client meta topics
m_metaPub = storage.CreateMetaTopic("$serverpub");
m_metaSub = storage.CreateMetaTopic("$serversub");

// update meta topics
UpdateMetaClientPub();
UpdateMetaClientSub();
}

void ServerClientLocal::SendValue(ServerTopic* topic, const Value& value,
net::ValueSendMode mode) {
if (m_local) {
Expand Down
3 changes: 1 addition & 2 deletions ntcore/src/main/native/cpp/server/ServerClientLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace nt::server {

class ServerClientLocal final : public ServerClient4Base {
public:
ServerClientLocal(ServerStorage& storage, int id, wpi::Logger& logger)
: ServerClient4Base{"", "", true, [](uint32_t) {}, storage, id, logger} {}
ServerClientLocal(ServerStorage& storage, int id, wpi::Logger& logger);

bool ProcessIncomingText(std::string_view data) final { return false; }
bool ProcessIncomingBinary(std::span<const uint8_t> data) final {
Expand Down
14 changes: 3 additions & 11 deletions ntcore/src/main/native/cpp/server/ServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ ServerImpl::ServerImpl(wpi::Logger& logger)
m_clients.emplace_back(
std::make_unique<ServerClientLocal>(m_storage, 0, logger));
m_localClient = static_cast<ServerClientLocal*>(m_clients.back().get());

// create server meta topics
m_metaClients = m_storage.CreateMetaTopic("$clients");
}

std::pair<std::string, int> ServerImpl::AddClient(std::string_view name,
Expand Down Expand Up @@ -169,17 +172,6 @@ void ServerImpl::SetLocal(net::ServerMessageHandler* local,
net::ClientMessageQueue* queue) {
DEBUG4("SetLocal()");
m_localClient->SetLocal(local, queue);

// create server meta topics
m_metaClients = m_storage.CreateMetaTopic("$clients");

// create local client meta topics
m_localClient->m_metaPub = m_storage.CreateMetaTopic("$serverpub");
m_localClient->m_metaSub = m_storage.CreateMetaTopic("$serversub");

// update meta topics
m_localClient->UpdateMetaClientPub();
m_localClient->UpdateMetaClientSub();
}

bool ServerImpl::ProcessIncomingText(int clientId, std::string_view data) {
Expand Down

0 comments on commit b7a2b0f

Please sign in to comment.