1 /*
2  *  This file is part of nzbget. See <http://nzbget.net>.
3  *
4  *  Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
5  *  Copyright (C) 2007-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef FRONTEND_H
23 #define FRONTEND_H
24 
25 #include "Thread.h"
26 #include "Log.h"
27 #include "DownloadInfo.h"
28 #include "MessageBase.h"
29 #include "QueueEditor.h"
30 #include "Observer.h"
31 
32 class Frontend : public Thread
33 {
34 public:
35 	Frontend();
36 
37 protected:
38 	bool m_summary = false;
39 	bool m_fileList = false;
40 	uint32 m_neededLogEntries = 0;
41 	uint32 m_neededLogFirstId = 0;
42 	int m_updateInterval;
43 
44 	// summary
45 	int m_currentDownloadSpeed = 0;
46 	int64 m_remainingSize = 0;
47 	bool m_pauseDownload = false;
48 	int m_downloadLimit = 0;
49 	int m_threadCount = 0;
50 	int m_postJobCount = 0;
51 	int m_upTimeSec = 0;
52 	int m_dnTimeSec = 0;
53 	int64 m_allBytes = 0;
54 	bool m_standBy = false;
55 	Mutex m_waitMutex;
56 	ConditionVar m_waitCond;
57 
58 	virtual void Stop();
59 	bool PrepareData();
60 	void FreeData();
61 	GuardedMessageList GuardMessages();
62 	bool IsRemoteMode();
63 	void InitMessageBase(SNzbRequestBase* messageBase, int request, int size);
64 	void ServerPauseUnpause(bool pause);
65 	bool RequestPauseUnpause(bool pause);
66 	void ServerSetDownloadRate(int rate);
67 	bool RequestSetDownloadRate(int rate);
68 	bool ServerEditQueue(DownloadQueue::EEditAction action, int offset, int entry);
69 	bool RequestEditQueue(DownloadQueue::EEditAction action, int offset, int id);
70 	void Wait(int milliseconds);
71 
72 private:
73 	class WorkStateObserver : public Observer
74 	{
75 	public:
76 		Frontend* m_owner;
Update(Subject * caller,void * aspect)77 		virtual void Update(Subject* caller, void* aspect) { m_owner->WorkStateUpdate(caller, aspect); }
78 	};
79 
80 	MessageList m_remoteMessages;
81 	WorkStateObserver m_workStateObserver;
82 
83 	bool RequestMessages();
84 	bool RequestFileList();
85 	void WorkStateUpdate(Subject* caller, void* aspect);
86 };
87 
88 #endif
89