mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 10:49:33 +02:00
move location update to DiscoverabilityManager
This commit is contained in:
parent
6e84e94b86
commit
91b473f035
4 changed files with 95 additions and 42 deletions
|
@ -87,6 +87,7 @@
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "AudioClient.h"
|
#include "AudioClient.h"
|
||||||
|
#include "DiscoverabilityManager.h"
|
||||||
#include "InterfaceVersion.h"
|
#include "InterfaceVersion.h"
|
||||||
#include "LODManager.h"
|
#include "LODManager.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
@ -367,11 +368,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
connect(&domainHandler, &DomainHandler::hostnameChanged,
|
connect(&domainHandler, &DomainHandler::hostnameChanged,
|
||||||
DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);
|
DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress);
|
||||||
|
|
||||||
// update our location every 5 seconds in the data-server, assuming that we are authenticated with one
|
// update our location every 5 seconds in the metaverse server, assuming that we are authenticated with one
|
||||||
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000;
|
const qint64 DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5 * 1000;
|
||||||
|
|
||||||
locationUpdateTimer = new QTimer(this);
|
locationUpdateTimer = new QTimer(this);
|
||||||
connect(locationUpdateTimer, &QTimer::timeout, this, &Application::updateLocationInServer);
|
auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
|
||||||
|
connect(locationUpdateTimer, &QTimer::timeout, discoverabilityManager.data(), &DiscoverabilityManager::updateLocation);
|
||||||
locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);
|
locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);
|
||||||
|
|
||||||
connect(nodeList.data(), &NodeList::nodeAdded, this, &Application::nodeAdded);
|
connect(nodeList.data(), &NodeList::nodeAdded, this, &Application::nodeAdded);
|
||||||
|
@ -3191,45 +3193,6 @@ void Application::updateWindowTitle(){
|
||||||
_window->setWindowTitle(title);
|
_window->setWindowTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::updateLocationInServer() {
|
|
||||||
|
|
||||||
AccountManager& accountManager = AccountManager::getInstance();
|
|
||||||
auto addressManager = DependencyManager::get<AddressManager>();
|
|
||||||
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
|
||||||
|
|
||||||
if (accountManager.isLoggedIn() && domainHandler.isConnected()
|
|
||||||
&& (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) {
|
|
||||||
|
|
||||||
// construct a QJsonObject given the user's current address information
|
|
||||||
QJsonObject rootObject;
|
|
||||||
|
|
||||||
QJsonObject locationObject;
|
|
||||||
|
|
||||||
QString pathString = addressManager->currentPath();
|
|
||||||
|
|
||||||
const QString LOCATION_KEY_IN_ROOT = "location";
|
|
||||||
|
|
||||||
const QString PATH_KEY_IN_LOCATION = "path";
|
|
||||||
locationObject.insert(PATH_KEY_IN_LOCATION, pathString);
|
|
||||||
|
|
||||||
if (!addressManager->getRootPlaceID().isNull()) {
|
|
||||||
const QString PLACE_ID_KEY_IN_LOCATION = "place_id";
|
|
||||||
locationObject.insert(PLACE_ID_KEY_IN_LOCATION,
|
|
||||||
uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID()));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
|
|
||||||
locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION,
|
|
||||||
uuidStringWithoutCurlyBraces(domainHandler.getUUID()));
|
|
||||||
}
|
|
||||||
|
|
||||||
rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
|
|
||||||
|
|
||||||
accountManager.authenticatedRequest("/api/v1/user/location", QNetworkAccessManager::PutOperation,
|
|
||||||
JSONCallbackParameters(), QJsonDocument(rootObject).toJson());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::clearDomainOctreeDetails() {
|
void Application::clearDomainOctreeDetails() {
|
||||||
qDebug() << "Clearing domain octree details...";
|
qDebug() << "Clearing domain octree details...";
|
||||||
// reset the environment so that we don't erroneously end up with multiple
|
// reset the environment so that we don't erroneously end up with multiple
|
||||||
|
|
|
@ -318,7 +318,6 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
void updateLocationInServer();
|
|
||||||
void nodeAdded(SharedNodePointer node);
|
void nodeAdded(SharedNodePointer node);
|
||||||
void nodeKilled(SharedNodePointer node);
|
void nodeKilled(SharedNodePointer node);
|
||||||
void packetSent(quint64 length);
|
void packetSent(quint64 length);
|
||||||
|
|
65
interface/src/DiscoverabilityManager.cpp
Normal file
65
interface/src/DiscoverabilityManager.cpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
//
|
||||||
|
// DiscoverabilityManager.cpp
|
||||||
|
// interface/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2015-03-09.
|
||||||
|
// Copyright 2015 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 <QtCore/QJsonDocument>
|
||||||
|
|
||||||
|
#include <AccountManager.h>
|
||||||
|
#include <AddressManager.h>
|
||||||
|
#include <DomainHandler.h>
|
||||||
|
#include <NodeList.h>
|
||||||
|
#include <UUID.h>
|
||||||
|
|
||||||
|
#include "DiscoverabilityManager.h"
|
||||||
|
|
||||||
|
const QString API_USER_LOCATION_PATH = "/api/v1/user/location";
|
||||||
|
|
||||||
|
void DiscoverabilityManager::updateLocation() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
auto addressManager = DependencyManager::get<AddressManager>();
|
||||||
|
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||||
|
|
||||||
|
if (accountManager.isLoggedIn() && domainHandler.isConnected()
|
||||||
|
&& (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) {
|
||||||
|
|
||||||
|
// construct a QJsonObject given the user's current address information
|
||||||
|
QJsonObject rootObject;
|
||||||
|
|
||||||
|
QJsonObject locationObject;
|
||||||
|
|
||||||
|
QString pathString = addressManager->currentPath();
|
||||||
|
|
||||||
|
const QString LOCATION_KEY_IN_ROOT = "location";
|
||||||
|
|
||||||
|
const QString PATH_KEY_IN_LOCATION = "path";
|
||||||
|
locationObject.insert(PATH_KEY_IN_LOCATION, pathString);
|
||||||
|
|
||||||
|
if (!addressManager->getRootPlaceID().isNull()) {
|
||||||
|
const QString PLACE_ID_KEY_IN_LOCATION = "place_id";
|
||||||
|
locationObject.insert(PLACE_ID_KEY_IN_LOCATION,
|
||||||
|
uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID()));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
|
||||||
|
locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION,
|
||||||
|
uuidStringWithoutCurlyBraces(domainHandler.getUUID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
|
||||||
|
|
||||||
|
accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::PutOperation,
|
||||||
|
JSONCallbackParameters(), QJsonDocument(rootObject).toJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiscoverabilityManager::removeLocation() {
|
||||||
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
|
accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::DeleteOperation);
|
||||||
|
}
|
26
interface/src/DiscoverabilityManager.h
Normal file
26
interface/src/DiscoverabilityManager.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
//
|
||||||
|
// DiscoverabilityManager.h
|
||||||
|
// interface/src
|
||||||
|
//
|
||||||
|
// Created by Stephen Birarda on 2015-03-09.
|
||||||
|
// Copyright 2015 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_DiscoverabilityManager_h
|
||||||
|
#define hifi_DiscoverabilityManager_h
|
||||||
|
|
||||||
|
#include <DependencyManager.h>
|
||||||
|
|
||||||
|
class DiscoverabilityManager : public QObject, public Dependency {
|
||||||
|
Q_OBJECT
|
||||||
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updateLocation();
|
||||||
|
void removeLocation();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_DiscoverabilityManager_h
|
Loading…
Reference in a new issue