Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#351: refactor: moved changeable state into new Unit "WorkState.cpp"
Browse files Browse the repository at this point in the history
from Unit “Options.cpp”. The latter now contains only program options
(which cannot be changed without reload).
  • Loading branch information
hugbug committed Jan 22, 2019
1 parent bb1cb68 commit e3bd941
Show file tree
Hide file tree
Showing 26 changed files with 235 additions and 146 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
#
# This file is part of nzbget. See <http://nzbget.net>.
#
# Copyright (C) 2008-2016 Andrey Prygunkov <[email protected]>
# Copyright (C) 2008-2019 Andrey Prygunkov <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -68,6 68,8 @@ nzbget_SOURCES = \
daemon/main/nzbget.h \
daemon/main/Options.cpp \
daemon/main/Options.h \
daemon/main/WorkState.cpp \
daemon/main/WorkState.h \
daemon/main/Scheduler.cpp \
daemon/main/Scheduler.h \
daemon/main/StackTrace.cpp \
Expand Down
14 changes: 10 additions & 4 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 17,7 @@
#
# This file is part of nzbget. See <http://nzbget.net>.
#
# Copyright (C) 2008-2016 Andrey Prygunkov <[email protected]>
# Copyright (C) 2008-2019 Andrey Prygunkov <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -232,7 232,8 @@ am__nzbget_SOURCES_DIST = daemon/connect/Connection.cpp \
daemon/main/DiskService.h daemon/main/Maintenance.cpp \
daemon/main/Maintenance.h daemon/main/nzbget.cpp \
daemon/main/nzbget.h daemon/main/Options.cpp \
daemon/main/Options.h daemon/main/Scheduler.cpp \
daemon/main/Options.h daemon/main/WorkState.cpp \
daemon/main/WorkState.h daemon/main/Scheduler.cpp \
daemon/main/Scheduler.h daemon/main/StackTrace.cpp \
daemon/main/StackTrace.h daemon/nntp/ArticleDownloader.cpp \
daemon/nntp/ArticleDownloader.h daemon/nntp/ArticleWriter.cpp \
Expand Down Expand Up @@ -387,7 388,8 @@ am_nzbget_OBJECTS = daemon/connect/Connection.$(OBJEXT) \
daemon/main/CommandLineParser.$(OBJEXT) \
daemon/main/DiskService.$(OBJEXT) \
daemon/main/Maintenance.$(OBJEXT) daemon/main/nzbget.$(OBJEXT) \
daemon/main/Options.$(OBJEXT) daemon/main/Scheduler.$(OBJEXT) \
daemon/main/Options.$(OBJEXT) daemon/main/WorkState.$(OBJEXT) \
daemon/main/Scheduler.$(OBJEXT) \
daemon/main/StackTrace.$(OBJEXT) \
daemon/nntp/ArticleDownloader.$(OBJEXT) \
daemon/nntp/ArticleWriter.$(OBJEXT) \
Expand Down Expand Up @@ -720,7 722,8 @@ nzbget_SOURCES = daemon/connect/Connection.cpp \
daemon/main/DiskService.h daemon/main/Maintenance.cpp \
daemon/main/Maintenance.h daemon/main/nzbget.cpp \
daemon/main/nzbget.h daemon/main/Options.cpp \
daemon/main/Options.h daemon/main/Scheduler.cpp \
daemon/main/Options.h daemon/main/WorkState.cpp \
daemon/main/WorkState.h daemon/main/Scheduler.cpp \
daemon/main/Scheduler.h daemon/main/StackTrace.cpp \
daemon/main/StackTrace.h daemon/nntp/ArticleDownloader.cpp \
daemon/nntp/ArticleDownloader.h daemon/nntp/ArticleWriter.cpp \
Expand Down Expand Up @@ -1158,6 1161,8 @@ daemon/main/nzbget.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/Options.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/WorkState.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/Scheduler.$(OBJEXT): daemon/main/$(am__dirstamp) \
daemon/main/$(DEPDIR)/$(am__dirstamp)
daemon/main/StackTrace.$(OBJEXT): daemon/main/$(am__dirstamp) \
Expand Down Expand Up @@ -1553,6 1558,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/Options.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/Scheduler.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/StackTrace.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/WorkState.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/main/$(DEPDIR)/nzbget.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/nntp/$(DEPDIR)/ArticleDownloader.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@daemon/nntp/$(DEPDIR)/ArticleWriter.Po@am__quote@
Expand Down
9 changes: 5 additions & 4 deletions daemon/connect/WebDownloader.cpp
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2012-2016 Andrey Prygunkov <[email protected]>
* Copyright (C) 2012-2019 Andrey Prygunkov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,6 22,7 @@
#include "WebDownloader.h"
#include "Log.h"
#include "Options.h"
#include "WorkState.h"
#include "Util.h"
#include "FileSystem.h"

Expand Down Expand Up @@ -72,19 73,19 @@ void WebDownloader::Run()

if ((((Status == adFailed) && (remainedDownloadRetries > 1)) ||
((Status == adConnectError) && (remainedConnectRetries > 1)))
&& !IsStopped() && !(!m_force && g_Options->GetPauseDownload()))
&& !IsStopped() && !(!m_force && g_WorkState->GetPauseDownload()))
{
detail("Waiting %i sec to retry", g_Options->GetUrlInterval());
int msec = 0;
while (!IsStopped() && (msec < g_Options->GetUrlInterval() * 1000) &&
!(!m_force && g_Options->GetPauseDownload()))
!(!m_force && g_WorkState->GetPauseDownload()))
{
usleep(100 * 1000);
msec = 100;
}
}

if (IsStopped() || (!m_force && g_Options->GetPauseDownload()))
if (IsStopped() || (!m_force && g_WorkState->GetPauseDownload()))
{
Status = adRetry;
break;
Expand Down
7 changes: 4 additions & 3 deletions daemon/extension/PostScript.cpp
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2016 Andrey Prygunkov <[email protected]>
* Copyright (C) 2007-2019 Andrey Prygunkov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -23,6 23,7 @@
#include "Log.h"
#include "Util.h"
#include "Options.h"
#include "WorkState.h"

static const int POSTPROCESS_PARCHECK = 92;
static const int POSTPROCESS_SUCCESS = 93;
Expand Down Expand Up @@ -272,14 273,14 @@ void PostScriptController::AddMessage(Message::EKind kind, const char* text)
m_postInfo->SetProgressLabel(text);
}

if (g_Options->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority())
if (g_WorkState->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority())
{
time_t stageTime = m_postInfo->GetStageTime();
time_t startTime = m_postInfo->GetStartTime();
time_t waitTime = Util::CurrentTime();

// wait until Post-processor is unpaused
while (g_Options->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority() && !IsStopped())
while (g_WorkState->GetPausePostProcess() && !m_postInfo->GetNzbInfo()->GetForcePriority() && !IsStopped())
{
usleep(100 * 1000);

Expand Down
3 changes: 2 additions & 1 deletion daemon/feed/FeedCoordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,7 @@
#include "nzbget.h"
#include "FeedCoordinator.h"
#include "Options.h"
#include "WorkState.h"
#include "WebDownloader.h"
#include "Util.h"
#include "FileSystem.h"
Expand Down Expand Up @@ -98,7 99,7 @@ void FeedCoordinator::Run()
while (!IsStopped())
{
// this code should not be called too often, once per second is OK
if (!g_Options->GetPauseDownload() || m_force || g_Options->GetUrlForce())
if (!g_WorkState->GetPauseDownload() || m_force || g_Options->GetUrlForce())
{
Guard guard(m_downloadsMutex);

Expand Down
13 changes: 7 additions & 6 deletions daemon/frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <[email protected]>
* Copyright (C) 2007-2016 Andrey Prygunkov <[email protected]>
* Copyright (C) 2007-2019 Andrey Prygunkov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -21,6 21,7 @@

#include "nzbget.h"
#include "Options.h"
#include "WorkState.h"
#include "Frontend.h"
#include "Log.h"
#include "Connection.h"
Expand Down Expand Up @@ -57,8 58,8 @@ bool Frontend::PrepareData()
if (m_summary)
{
m_currentDownloadSpeed = g_StatMeter->CalcCurrentDownloadSpeed();
m_pauseDownload = g_Options->GetPauseDownload();
m_downloadLimit = g_Options->GetDownloadRate();
m_pauseDownload = g_WorkState->GetPauseDownload();
m_downloadLimit = g_WorkState->GetSpeedLimit();
m_threadCount = Thread::GetThreadCount();
g_StatMeter->CalcTotalStat(&m_upTimeSec, &m_dnTimeSec, &m_allBytes, &m_standBy);

Expand Down Expand Up @@ -108,8 109,8 @@ void Frontend::ServerPauseUnpause(bool pause)
}
else
{
g_Options->SetResumeTime(0);
g_Options->SetPauseDownload(pause);
g_WorkState->SetResumeTime(0);
g_WorkState->SetPauseDownload(pause);
}
}

Expand All @@ -121,7 122,7 @@ void Frontend::ServerSetDownloadRate(int rate)
}
else
{
g_Options->SetDownloadRate(rate);
g_WorkState->SetSpeedLimit(rate);
}
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/frontend/NCursesFrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <[email protected]>
* Copyright (C) 2007-2016 Andrey Prygunkov <[email protected]>
* Copyright (C) 2007-2019 Andrey Prygunkov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion daemon/main/CommandLineParser.h
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2016 Andrey Prygunkov <[email protected]>
* Copyright (C) 2007-2019 Andrey Prygunkov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
11 changes: 6 additions & 5 deletions daemon/main/DiskService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,7 @@
#include "nzbget.h"
#include "DiskService.h"
#include "Options.h"
#include "WorkState.h"
#include "StatMeter.h"
#include "Log.h"
#include "Util.h"
Expand All @@ -38,7 39,7 @@ void DiskService::ServiceWork()
{
debug("Disk service work");

if (!g_Options->GetPauseDownload() &&
if (!g_WorkState->GetPauseDownload() &&
g_Options->GetDiskSpace() > 0 && !g_StatMeter->GetStandBy())
{
// check free disk space every 1 second
Expand All @@ -59,7 60,7 @@ void DiskService::CheckDiskSpace()
if (freeSpace > -1 && freeSpace / 1024 / 1024 < g_Options->GetDiskSpace())
{
warn("Low disk space on %s. Pausing download", g_Options->GetDestDir());
g_Options->SetPauseDownload(true);
g_WorkState->SetPauseDownload(true);
}

if (!Util::EmptyStr(g_Options->GetInterDir()))
Expand All @@ -68,7 69,7 @@ void DiskService::CheckDiskSpace()
if (freeSpace > -1 && freeSpace / 1024 / 1024 < g_Options->GetDiskSpace())
{
warn("Low disk space on %s. Pausing download", g_Options->GetInterDir());
g_Options->SetPauseDownload(true);
g_WorkState->SetPauseDownload(true);
}
}
}
Expand Down Expand Up @@ -106,7 107,7 @@ void DiskService::CheckRequiredDir()
info("All required directories available");
}

g_Options->SetTempPauseDownload(false);
g_Options->SetTempPausePostprocess(false);
g_WorkState->SetTempPauseDownload(false);
g_WorkState->SetTempPausePostprocess(false);
m_waitingRequiredDir = false;
}
33 changes: 4 additions & 29 deletions daemon/main/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2004 Sven Henkel <[email protected]>
* Copyright (C) 2007-2016 Andrey Prygunkov <[email protected]>
* Copyright (C) 2007-2019 Andrey Prygunkov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -300,6 300,7 @@ class Options
bool GetDirectRename() { return m_directRename; }
bool GetReorderFiles() { return m_reorderFiles; }
EFileNaming GetFileNaming() { return m_fileNaming; }
int GetDownloadRate() const { return m_downloadRate; }

Categories* GetCategories() { return &m_categories; }
Category* FindCategory(const char* name, bool searchAliases) { return m_categories.FindCategory(name, searchAliases); }
Expand All @@ -311,24 312,6 @@ class Options
bool GetDaemonMode() { return m_daemonMode; }
void SetRemoteClientMode(bool remoteClientMode) { m_remoteClientMode = remoteClientMode; }
bool GetRemoteClientMode() { return m_remoteClientMode; }
void SetPauseDownload(bool pauseDownload) { m_pauseDownload = pauseDownload; }
bool GetPauseDownload() const { return m_pauseDownload; }
void SetPausePostProcess(bool pausePostProcess) { m_pausePostProcess = pausePostProcess; }
bool GetPausePostProcess() const { return m_pausePostProcess; }
void SetPauseScan(bool pauseScan) { m_pauseScan = pauseScan; }
bool GetPauseScan() const { return m_pauseScan; }
void SetTempPauseDownload(bool tempPauseDownload) { m_tempPauseDownload = tempPauseDownload; }
bool GetTempPauseDownload() const { return m_tempPauseDownload; }
bool GetTempPausePostprocess() const { return m_tempPausePostprocess; }
void SetTempPausePostprocess(bool tempPausePostprocess) { m_tempPausePostprocess = tempPausePostprocess; }
void SetDownloadRate(int rate) { m_downloadRate = rate; }
int GetDownloadRate() const { return m_downloadRate; }
void SetResumeTime(time_t resumeTime) { m_resumeTime = resumeTime; }
time_t GetResumeTime() const { return m_resumeTime; }
void SetLocalTimeOffset(int localTimeOffset) { m_localTimeOffset = localTimeOffset; }
int GetLocalTimeOffset() { return m_localTimeOffset; }
void SetQuotaReached(bool quotaReached) { m_quotaReached = quotaReached; }
bool GetQuotaReached() { return m_quotaReached; }

private:
OptEntries m_optEntries;
Expand Down Expand Up @@ -450,20 433,12 @@ class Options
int m_dailyQuota = 0;
bool m_reorderFiles = false;
EFileNaming m_fileNaming = nfArticle;
int m_downloadRate = 0;

// Current state
// Application mode
bool m_serverMode = false;
bool m_daemonMode = false;
bool m_remoteClientMode = false;
bool m_pauseDownload = false;
bool m_pausePostProcess = false;
bool m_pauseScan = false;
bool m_tempPauseDownload = true;
bool m_tempPausePostprocess = true;
int m_downloadRate = 0;
time_t m_resumeTime = 0;
int m_localTimeOffset = 0;
bool m_quotaReached = false;

void Init(const char* exeName, const char* configFilename, bool noConfig,
CmdOptList* commandLineOptions, bool noDiskAccess, Extender* extender);
Expand Down
Loading

0 comments on commit e3bd941

Please sign in to comment.