diff --git a/domain-server/src/DomainMetadata.cpp b/domain-server/src/DomainMetadata.cpp new file mode 100644 index 0000000000..f584198b51 --- /dev/null +++ b/domain-server/src/DomainMetadata.cpp @@ -0,0 +1,51 @@ +// +// DomainMetadata.cpp +// domain-server/src +// +// Created by Zach Pomerantz on 5/25/2016. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +#include "DomainMetadata.h" + +#include +#include + +#include "DomainServerNodeData.h" + +QVariantMap getMetadata() { + static const QString DEFAULT_HOSTNAME = "*"; + + auto nodeList = DependencyManager::get(); + int numConnectedUnassigned = 0; + QVariantMap userHostnames; + + // figure out the breakdown of currently connected interface clients + nodeList->eachNode([&numConnectedUnassigned, &userHostnames](const SharedNodePointer& node) { + auto linkedData = node->getLinkedData(); + if (linkedData) { + auto nodeData = static_cast(linkedData); + + if (!nodeData->wasAssigned()) { + ++numConnectedUnassigned; + + // increment the count for this hostname (or the default if we don't have one) + auto placeName = nodeData->getPlaceName(); + auto hostname = placeName.isEmpty() ? DEFAULT_HOSTNAME : placeName; + userHostnames[hostname] = userHostnames[hostname].toInt() + 1; + } + } + }); + + QVariantMap metadata; + + static const QString HEARTBEAT_NUM_USERS_KEY = "num_users"; + metadata[HEARTBEAT_NUM_USERS_KEY] = numConnectedUnassigned; + + static const QString HEARTBEAT_USER_HOSTNAMES_KEY = "user_hostnames"; + metadata[HEARTBEAT_USER_HOSTNAMES_KEY] = userHostnames; + + return metadata; +} diff --git a/domain-server/src/DomainMetadata.h b/domain-server/src/DomainMetadata.h new file mode 100644 index 0000000000..3cd160ce85 --- /dev/null +++ b/domain-server/src/DomainMetadata.h @@ -0,0 +1,21 @@ +// +// DomainMetadata.h +// domain-server/src +// +// Created by Zach Pomerantz on 5/25/2016. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +#ifndef hifi_DomainMetadata_h +#define hifi_DomainMetadata_h + +#include + +QVariantMap getMetadata(); + +// TODO: Encapsulate +class DomainMetadata { }; + +#endif // hifi_DomainMetadata_h diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index ae3c26a34d..f05dfd2c6d 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -1067,41 +1067,6 @@ void DomainServer::performIPAddressUpdate(const HifiSockAddr& newPublicSockAddr) sendHeartbeatToMetaverse(newPublicSockAddr.getAddress().toString()); } -QVariantMap getMetadata() { - static const QString DEFAULT_HOSTNAME = "*"; - - auto nodeList = DependencyManager::get(); - int numConnectedUnassigned = 0; - QVariantMap userHostnames; - - // figure out the breakdown of currently connected interface clients - nodeList->eachNode([&numConnectedUnassigned, &userHostnames](const SharedNodePointer& node) { - auto linkedData = node->getLinkedData(); - if (linkedData) { - auto nodeData = static_cast(linkedData); - - if (!nodeData->wasAssigned()) { - ++numConnectedUnassigned; - - // increment the count for this hostname (or the default if we don't have one) - auto placeName = nodeData->getPlaceName(); - auto hostname = placeName.isEmpty() ? DEFAULT_HOSTNAME : placeName; - userHostnames[hostname] = userHostnames[hostname].toInt() + 1; - } - } - }); - - QVariantMap metadata; - - static const QString HEARTBEAT_NUM_USERS_KEY = "num_users"; - metadata[HEARTBEAT_NUM_USERS_KEY] = numConnectedUnassigned; - - static const QString HEARTBEAT_USER_HOSTNAMES_KEY = "user_hostnames"; - metadata[HEARTBEAT_USER_HOSTNAMES_KEY] = userHostnames; - - return metadata; -} - void DomainServer::sendHeartbeatToMetaverse(const QString& networkAddress) { auto nodeList = DependencyManager::get(); const QUuid& domainID = nodeList->getSessionUUID(); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index c39e405380..0f93c50468 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -26,6 +26,7 @@ #include #include "DomainGatekeeper.h" +#include "DomainMetadata.h" #include "DomainServerSettingsManager.h" #include "DomainServerWebSessionData.h" #include "WalletTransaction.h"