From f33d3a3b36169c671330c43434e28134bd30467d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 20 Sep 2016 13:24:03 -0700 Subject: [PATCH] Migrate logging functionality to shared library --- interface/src/Application.h | 2 +- interface/src/ui/LogDialog.h | 2 +- interface/src/ui/Snapshot.cpp | 2 +- libraries/networking/src/HifiSockAddr.cpp | 30 ------------- libraries/networking/src/HifiSockAddr.h | 3 -- libraries/networking/src/LimitedNodeList.cpp | 1 + .../src/shared}/AbstractLoggerInterface.h | 0 .../shared/src/shared}/FileLogger.cpp | 9 ++-- .../shared/src/shared}/FileLogger.h | 2 +- .../shared/src/shared}/FileUtils.cpp | 0 .../shared/src/shared}/FileUtils.h | 0 libraries/shared/src/shared/NetworkUtils.cpp | 42 +++++++++++++++++++ libraries/shared/src/shared/NetworkUtils.h | 17 ++++++++ tests/render-perf/src/main.cpp | 22 ++++++---- 14 files changed, 83 insertions(+), 49 deletions(-) rename {interface/src => libraries/shared/src/shared}/AbstractLoggerInterface.h (100%) rename {interface/src => libraries/shared/src/shared}/FileLogger.cpp (97%) rename {interface/src => libraries/shared/src/shared}/FileLogger.h (97%) rename {interface/src => libraries/shared/src/shared}/FileUtils.cpp (100%) rename {interface/src => libraries/shared/src/shared}/FileUtils.h (100%) create mode 100644 libraries/shared/src/shared/NetworkUtils.cpp create mode 100644 libraries/shared/src/shared/NetworkUtils.h diff --git a/interface/src/Application.h b/interface/src/Application.h index 4c52ff8526..2dc60c2438 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -44,12 +44,12 @@ #include #include #include +#include #include "avatar/MyAvatar.h" #include "Bookmarks.h" #include "Camera.h" #include "ConnectionMonitor.h" -#include "FileLogger.h" #include "gpu/Context.h" #include "Menu.h" #include "octree/OctreePacketProcessor.h" diff --git a/interface/src/ui/LogDialog.h b/interface/src/ui/LogDialog.h index c38cf84f00..1493a43f01 100644 --- a/interface/src/ui/LogDialog.h +++ b/interface/src/ui/LogDialog.h @@ -20,7 +20,7 @@ #include #include -#include "AbstractLoggerInterface.h" +#include class KeywordHighlighter : public QSyntaxHighlighter { Q_OBJECT diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index c2fcafb2f3..a0ee260bcc 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libraries/networking/src/HifiSockAddr.cpp b/libraries/networking/src/HifiSockAddr.cpp index bde0aca7b7..d6981f420d 100644 --- a/libraries/networking/src/HifiSockAddr.cpp +++ b/libraries/networking/src/HifiSockAddr.cpp @@ -124,36 +124,6 @@ QDataStream& operator>>(QDataStream& dataStream, HifiSockAddr& sockAddr) { return dataStream; } -QHostAddress getGuessedLocalAddress() { - - QHostAddress localAddress; - - foreach(const QNetworkInterface &networkInterface, QNetworkInterface::allInterfaces()) { - if (networkInterface.flags() & QNetworkInterface::IsUp - && networkInterface.flags() & QNetworkInterface::IsRunning - && networkInterface.flags() & ~QNetworkInterface::IsLoopBack) { - // we've decided that this is the active NIC - // enumerate it's addresses to grab the IPv4 address - foreach(const QNetworkAddressEntry &entry, networkInterface.addressEntries()) { - // make sure it's an IPv4 address that isn't the loopback - if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol && !entry.ip().isLoopback()) { - - // set our localAddress and break out - localAddress = entry.ip(); - break; - } - } - } - - if (!localAddress.isNull()) { - break; - } - } - - // return the looked up local address - return localAddress; -} - uint qHash(const HifiSockAddr& key, uint seed) { // use the existing QHostAddress and quint16 hash functions to get our hash return qHash(key.getAddress(), seed) ^ qHash(key.getPort(), seed); diff --git a/libraries/networking/src/HifiSockAddr.h b/libraries/networking/src/HifiSockAddr.h index 063a41a202..c4ff8cb246 100644 --- a/libraries/networking/src/HifiSockAddr.h +++ b/libraries/networking/src/HifiSockAddr.h @@ -91,9 +91,6 @@ namespace std { }; } - -QHostAddress getGuessedLocalAddress(); - Q_DECLARE_METATYPE(HifiSockAddr); #endif // hifi_HifiSockAddr_h diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index ec4b2c3573..ce555315e8 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/interface/src/AbstractLoggerInterface.h b/libraries/shared/src/shared/AbstractLoggerInterface.h similarity index 100% rename from interface/src/AbstractLoggerInterface.h rename to libraries/shared/src/shared/AbstractLoggerInterface.h diff --git a/interface/src/FileLogger.cpp b/libraries/shared/src/shared/FileLogger.cpp similarity index 97% rename from interface/src/FileLogger.cpp rename to libraries/shared/src/shared/FileLogger.cpp index 754fa7f474..ef3436a8d7 100644 --- a/interface/src/FileLogger.cpp +++ b/libraries/shared/src/shared/FileLogger.cpp @@ -15,11 +15,12 @@ #include #include -#include -#include -#include +#include "FileUtils.h" +#include "NetworkUtils.h" + +#include "../NumericalConstants.h" +#include "../SharedUtil.h" -#include "HifiSockAddr.h" static const QString FILENAME_FORMAT = "hifi-log_%1_%2.txt"; static const QString DATETIME_FORMAT = "yyyy-MM-dd_hh.mm.ss"; diff --git a/interface/src/FileLogger.h b/libraries/shared/src/shared/FileLogger.h similarity index 97% rename from interface/src/FileLogger.h rename to libraries/shared/src/shared/FileLogger.h index 950590e789..697b96c6d8 100644 --- a/interface/src/FileLogger.h +++ b/libraries/shared/src/shared/FileLogger.h @@ -13,7 +13,7 @@ #define hifi_FileLogger_h #include "AbstractLoggerInterface.h" -#include +#include "../GenericQueueThread.h" #include diff --git a/interface/src/FileUtils.cpp b/libraries/shared/src/shared/FileUtils.cpp similarity index 100% rename from interface/src/FileUtils.cpp rename to libraries/shared/src/shared/FileUtils.cpp diff --git a/interface/src/FileUtils.h b/libraries/shared/src/shared/FileUtils.h similarity index 100% rename from interface/src/FileUtils.h rename to libraries/shared/src/shared/FileUtils.h diff --git a/libraries/shared/src/shared/NetworkUtils.cpp b/libraries/shared/src/shared/NetworkUtils.cpp new file mode 100644 index 0000000000..50356d30fc --- /dev/null +++ b/libraries/shared/src/shared/NetworkUtils.cpp @@ -0,0 +1,42 @@ +// +// Created by Bradley Austin Davis on 2016/09/20 +// Copyright 2013-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 "NetworkUtils.h" +#include + +QHostAddress getGuessedLocalAddress() { + + QHostAddress localAddress; + + foreach(const QNetworkInterface &networkInterface, QNetworkInterface::allInterfaces()) { + if (networkInterface.flags() & QNetworkInterface::IsUp + && networkInterface.flags() & QNetworkInterface::IsRunning + && networkInterface.flags() & ~QNetworkInterface::IsLoopBack) { + // we've decided that this is the active NIC + // enumerate it's addresses to grab the IPv4 address + foreach(const QNetworkAddressEntry &entry, networkInterface.addressEntries()) { + // make sure it's an IPv4 address that isn't the loopback + if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol && !entry.ip().isLoopback()) { + + // set our localAddress and break out + localAddress = entry.ip(); + break; + } + } + } + + if (!localAddress.isNull()) { + break; + } + } + + // return the looked up local address + return localAddress; +} + + diff --git a/libraries/shared/src/shared/NetworkUtils.h b/libraries/shared/src/shared/NetworkUtils.h new file mode 100644 index 0000000000..b881441004 --- /dev/null +++ b/libraries/shared/src/shared/NetworkUtils.h @@ -0,0 +1,17 @@ +// +// Created by Bradley Austin Davis on 2016/09/20 +// Copyright 2013-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 +// + +#pragma once +#ifndef hifi_shared_NetworkUtils_h +#define hifi_shared_NetworkUtils_h + +#include + +QHostAddress getGuessedLocalAddress(); + +#endif // hifi_shared_NetworkUtils_h diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index 238972dc00..4745529f19 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -32,12 +32,11 @@ #include +#include +#include +#include #include -//#include -//#include -//#include - #include #include #include @@ -149,6 +148,7 @@ public: }; #else + class QWindowCamera : public Camera { Key forKey(int key) { switch (key) { @@ -417,6 +417,7 @@ public: }; render::ItemID BackgroundRenderData::_item = 0; +QSharedPointer logger; namespace render { template <> const ItemKey payloadGetKey(const BackgroundRenderData::Pointer& stuff) { @@ -1069,12 +1070,14 @@ private: bool QTestWindow::_cullingEnabled = true; void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { - if (!message.isEmpty()) { + QString logMessage = LogHandler::getInstance().printMessage((LogMsgType)type, context, message); + + if (!logMessage.isEmpty()) { #ifdef Q_OS_WIN - OutputDebugStringA(message.toLocal8Bit().constData()); + OutputDebugStringA(logMessage.toLocal8Bit().constData()); OutputDebugStringA("\n"); #endif - std::cout << message.toLocal8Bit().constData() << std::endl; + logger->addMessage(qPrintable(logMessage + "\n")); } } @@ -1082,11 +1085,14 @@ const char * LOG_FILTER_RULES = R"V0G0N( hifi.gpu=true )V0G0N"; + int main(int argc, char** argv) { - QApplication app(argc, argv); + QGuiApplication app(argc, argv); QCoreApplication::setApplicationName("RenderPerf"); QCoreApplication::setOrganizationName("High Fidelity"); QCoreApplication::setOrganizationDomain("highfidelity.com"); + logger.reset(new FileLogger()); + qInstallMessageHandler(messageHandler); QLoggingCategory::setFilterRules(LOG_FILTER_RULES); QTestWindow::setup();