Removed ResourcesWindow, SystemInfo. Fixed update mechanism in ConsoleLayout/LogWindow.

This commit is contained in:
Casey Langen 2016-07-20 00:04:15 -07:00
parent a8cb57b6a9
commit 791562fc93
10 changed files with 34 additions and 428 deletions

View File

@ -21,12 +21,10 @@ set (BOX_SRCS
./app/util/GlobalHotkeys.cpp
./app/util/Playback.cpp
./app/util/PreferenceKeys.cpp
./app/util/SystemInfo.cpp
./app/window/CategoryListView.cpp
./app/window/EntryWithHeader.cpp
./app/window/LogWindow.cpp
./app/window/OutputWindow.cpp
./app/window/ResourcesWindow.cpp
./app/window/ShortcutsWindow.cpp
./app/window/TrackListView.cpp
./app/window/TransportWindow.cpp

View File

@ -46,9 +46,6 @@
#include <boost/algorithm/string.hpp>
#define MESSAGE_TYPE_UPDATE 1001
#define UPDATE_INTERVAL_MS 1000
template <class T>
bool tostr(T& t, const std::string& s) {
std::istringstream iss(s);
@ -68,7 +65,6 @@ ConsoleLayout::ConsoleLayout(ITransport& transport, LibraryPtr library)
this->logs.reset(new LogWindow(this));
this->output.reset(new OutputWindow(this));
this->resources.reset(new ResourcesWindow(this));
this->commands.reset(new cursespp::TextInput());
this->commands->SetFocusOrder(0);
@ -78,7 +74,6 @@ ConsoleLayout::ConsoleLayout(ITransport& transport, LibraryPtr library)
this->AddWindow(this->commands);
this->AddWindow(this->logs);
this->AddWindow(this->output);
this->AddWindow(this->resources);
this->commands->EnterPressed.connect(this, &ConsoleLayout::OnEnterPressed);
@ -101,11 +96,8 @@ void ConsoleLayout::Layout() {
/* bottom left */
this->commands->MoveAndResize(x, cy - 3, cx / 2, 3);
/* top right */
this->logs->MoveAndResize(cx / 2, 0, cx / 2, cy - 3);
/* bottom right */
this->resources->MoveAndResize(cx / 2, cy - 3, cx / 2, 3);
/* right */
this->logs->MoveAndResize(cx / 2, 0, cx / 2, cy);
}
void ConsoleLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) {
@ -134,30 +126,6 @@ void ConsoleLayout::OnEnterPressed(TextInput *input) {
}
}
void ConsoleLayout::OnVisibilityChanged(bool visible) {
LayoutBase::OnVisibilityChanged(visible);
if (visible) {
this->UpdateWindows();
this->RemoveMessage(MESSAGE_TYPE_UPDATE);
this->PostMessage(MESSAGE_TYPE_UPDATE, 0, 0, UPDATE_INTERVAL_MS);
}
else {
this->RemoveMessage(MESSAGE_TYPE_UPDATE);
}
}
void ConsoleLayout::ProcessMessage(IMessage &message) {
if (message.Type() == MESSAGE_TYPE_UPDATE) {
this->UpdateWindows();
this->PostMessage(MESSAGE_TYPE_UPDATE, 0, 0, UPDATE_INTERVAL_MS);
}
}
void ConsoleLayout::UpdateWindows() {
this->logs->Update();
this->resources->Update();
}
void ConsoleLayout::Seek(const std::vector<std::string>& args) {
if (args.size() > 0) {

View File

@ -40,7 +40,6 @@
#include <app/window/LogWindow.h>
#include <app/window/OutputWindow.h>
#include <app/window/TransportWindow.h>
#include <app/window/ResourcesWindow.h>
#include <app/window/ShortcutsWindow.h>
#include <vector>
@ -66,14 +65,9 @@ namespace musik {
~ConsoleLayout();
virtual void Layout();
virtual void ProcessMessage(cursespp::IMessage &message);
virtual void OnVisibilityChanged(bool visible);
void SetShortcutsWindow(ShortcutsWindow* shortcuts);
virtual void SetShortcutsWindow(ShortcutsWindow* shortcuts);
private:
void UpdateWindows();
void OnEnterPressed(cursespp::TextInput* input);
void ListPlugins() const;
@ -89,7 +83,6 @@ namespace musik {
std::shared_ptr<LogWindow> logs;
std::shared_ptr<cursespp::TextInput> commands;
std::shared_ptr<OutputWindow> output;
std::shared_ptr<ResourcesWindow> resources;
musik::core::audio::ITransport& transport;
musik::core::LibraryPtr library;
};

View File

@ -1,187 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SystemInfo.h"
using namespace musik::box;
#ifdef WIN32
#include "windows.h"
#include "psapi.h"
#include "pdh.h"
class WindowsSystemInfo : public SystemInfo {
public:
WindowsSystemInfo();
virtual ~WindowsSystemInfo();
virtual int64 GetTotalVirtualMemory();
virtual int64 GetUsedVirtualMemory();
virtual int64 GetTotalPhysicalMemory();
virtual int64 GetUsedPhysicalMemory();
virtual double GetCpuUsage();
private:
ULARGE_INTEGER lastCpu, lastSysCpu, lastUserCpu;
int processorCount;
HANDLE self;
PDH_HQUERY cpuQuery;
PDH_HCOUNTER cpuTotal;
};
#endif
SystemInfo* SystemInfo::Create() {
#ifdef WIN32
return new WindowsSystemInfo();
#else
return new SystemInfo();
#endif
}
SystemInfo::SystemInfo() {
}
SystemInfo::~SystemInfo() {
}
int64 SystemInfo::GetTotalVirtualMemory() {
return 0;
}
int64 SystemInfo::GetUsedVirtualMemory() {
return 0;
}
int64 SystemInfo::GetTotalPhysicalMemory() {
return 0;
}
int64 SystemInfo::GetUsedPhysicalMemory() {
return 0;
}
double SystemInfo::GetCpuUsage() {
return 0;
}
#ifdef WIN32
#define GET_MEMORY_STATUS \
MEMORYSTATUSEX memInfo; \
memInfo.dwLength = sizeof(MEMORYSTATUSEX); \
GlobalMemoryStatusEx(&memInfo); \
#define GET_PROCESS_MEMORY_COUNTERS \
PROCESS_MEMORY_COUNTERS_EX pmc; \
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)); \
WindowsSystemInfo::WindowsSystemInfo() {
PdhOpenQuery(NULL, NULL, &cpuQuery);
PdhAddCounter(cpuQuery, "\\Processor(_Total)\\% Processor Time", NULL, &cpuTotal);
PdhCollectQueryData(cpuQuery);
SYSTEM_INFO sysInfo;
FILETIME ftime, fsys, fuser;
GetSystemInfo(&sysInfo);
processorCount = sysInfo.dwNumberOfProcessors;
GetSystemTimeAsFileTime(&ftime);
memcpy(&lastCpu, &ftime, sizeof(FILETIME));
self = GetCurrentProcess();
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&lastSysCpu, &fsys, sizeof(FILETIME));
memcpy(&lastUserCpu, &fuser, sizeof(FILETIME));
}
WindowsSystemInfo::~WindowsSystemInfo() {
PdhCloseQuery(cpuQuery);
}
int64 WindowsSystemInfo::GetTotalVirtualMemory() {
GET_MEMORY_STATUS
return memInfo.ullTotalPageFile;
}
int64 WindowsSystemInfo::GetUsedVirtualMemory() {
GET_PROCESS_MEMORY_COUNTERS
return pmc.PrivateUsage;
}
int64 WindowsSystemInfo::GetTotalPhysicalMemory() {
GET_MEMORY_STATUS
return memInfo.ullTotalPhys;
}
int64 WindowsSystemInfo::GetUsedPhysicalMemory() {
GET_PROCESS_MEMORY_COUNTERS
return pmc.WorkingSetSize;
}
double WindowsSystemInfo::GetCpuUsage() {
FILETIME ftime, fsys, fuser;
ULARGE_INTEGER now, sys, user;
double percent;
GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME));
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME));
percent =
(double) (sys.QuadPart - lastSysCpu.QuadPart) +
(double) (user.QuadPart - lastUserCpu.QuadPart);
ULONGLONG diff = now.QuadPart - lastCpu.QuadPart;
diff = std::max((ULONGLONG) 1, diff);
percent /= diff;
percent /= processorCount;
lastCpu = now;
lastUserCpu = user;
lastSysCpu = sys;
return (percent * 100.0f);
}
#endif

View File

@ -1,54 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
namespace musik {
namespace box {
class SystemInfo {
public:
static SystemInfo* Create();
virtual ~SystemInfo();
virtual int64 GetTotalVirtualMemory();
virtual int64 GetUsedVirtualMemory();
virtual int64 GetTotalPhysicalMemory();
virtual int64 GetUsedPhysicalMemory();
virtual double GetCpuUsage();
protected:
SystemInfo();
};
}
}

View File

@ -45,6 +45,12 @@ using namespace cursespp;
typedef IScrollAdapter::IEntry IEntry;
#define REFRESH 1000
#define DEBOUNCE_REFRESH() \
this->RemoveMessage(REFRESH); \
this->PostMessage(REFRESH, 0, 0, 250);
LogWindow::LogWindow(IWindow *parent)
: ScrollableWindow(parent) {
this->adapter = new SimpleScrollAdapter();
@ -66,6 +72,23 @@ void LogWindow::ClearContents() {
this->OnAdapterChanged();
}
void LogWindow::ProcessMessage(IMessage &message) {
if (message.Type() == REFRESH) {
this->Update();
}
else {
ScrollableWindow::ProcessMessage(message);
}
}
void LogWindow::OnVisibilityChanged(bool visible) {
ScrollableWindow::OnVisibilityChanged(visible);
if (visible) {
DEBOUNCE_REFRESH();
}
}
void LogWindow::Update() {
boost::mutex::scoped_lock lock(pendingMutex);
@ -73,8 +96,6 @@ void LogWindow::Update() {
return;
}
WINDOW* contents = this->GetContent();
for (size_t i = 0; i < pending.size(); i++) {
int64 attrs = COLOR_PAIR(CURSESPP_TEXT_DEFAULT);
@ -116,4 +137,6 @@ void LogWindow::OnLogged( /* from a background thread */
entry->tag = tag;
entry->message = message;
pending.push_back(entry);
DEBOUNCE_REFRESH();
}

View File

@ -57,12 +57,16 @@ namespace musik {
virtual ~LogWindow();
void ClearContents();
void Update();
virtual void ProcessMessage(cursespp::IMessage &message);
virtual void OnVisibilityChanged(bool visible);
protected:
virtual cursespp::IScrollAdapter& GetScrollAdapter();
private:
void Update();
void OnLogged(
musik::debug::log_level level,
std::string tag,

View File

@ -1,75 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ResourcesWindow.h"
#include <cursespp/Screen.h>
#include <cursespp/Colors.h>
#include <boost/format.hpp>
#include <core/debug.h>
using namespace musik::box;
using namespace cursespp;
#define BYTES_PER_MEGABYTE 1048576.0f
ResourcesWindow::ResourcesWindow(IWindow *parent)
: Window(parent) {
this->systemInfo = SystemInfo::Create();
}
ResourcesWindow::~ResourcesWindow() {
delete this->systemInfo;
}
void ResourcesWindow::Update() {
this->Clear();
double virtualMemoryUsed = (double) systemInfo->GetUsedVirtualMemory() / BYTES_PER_MEGABYTE;
double physicalMemoryUsed = (double) systemInfo->GetUsedPhysicalMemory() / BYTES_PER_MEGABYTE;
double cpuUsage = (double) systemInfo->GetCpuUsage();
wprintw(
this->GetContent(),
"cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)",
cpuUsage,
virtualMemoryUsed,
physicalMemoryUsed);
this->Repaint();
}

View File

@ -1,60 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007-2016 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cursespp/curses_config.h>
#include <cursespp/Window.h>
#include <app/util/SystemInfo.h>
namespace musik {
namespace box {
class ResourcesWindow :
public cursespp::Window
#if (__clang_major__ == 7 && __clang_minor__ == 3)
, public std::enable_shared_from_this<ResourcesWindow>
#endif
{
public:
ResourcesWindow(cursespp::IWindow *parent = NULL);
virtual ~ResourcesWindow();
virtual void Update();
private:
SystemInfo* systemInfo;
};
}
}

View File

@ -135,12 +135,10 @@
<ClCompile Include="app\util\Hotkeys.cpp" />
<ClCompile Include="app\util\Playback.cpp" />
<ClCompile Include="app\util\PreferenceKeys.cpp" />
<ClCompile Include="app\util\SystemInfo.cpp" />
<ClCompile Include="app\window\CategoryListView.cpp" />
<ClCompile Include="app\window\EntryWithHeader.cpp" />
<ClCompile Include="app\window\LogWindow.cpp" />
<ClCompile Include="app\window\OutputWindow.cpp" />
<ClCompile Include="app\window\ResourcesWindow.cpp" />
<ClCompile Include="app\window\ShortcutsWindow.cpp" />
<ClCompile Include="app\window\TrackListView.cpp" />
<ClCompile Include="app\window\TransportWindow.cpp" />
@ -192,12 +190,10 @@
<ClInclude Include="app\util\Hotkeys.h" />
<ClInclude Include="app\util\Playback.h" />
<ClInclude Include="app\util\PreferenceKeys.h" />
<ClInclude Include="app\util\SystemInfo.h" />
<ClInclude Include="app\window\CategoryListView.h" />
<ClInclude Include="app\window\EntryWithHeader.h" />
<ClInclude Include="app\window\LogWindow.h" />
<ClInclude Include="app\window\OutputWindow.h" />
<ClInclude Include="app\window\ResourcesWindow.h" />
<ClInclude Include="app\window\ShortcutsWindow.h" />
<ClInclude Include="app\window\TrackListView.h" />
<ClInclude Include="app\window\TransportWindow.h" />
@ -248,4 +244,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>