1 /* 2 * This file is part of nzbget. See <http://nzbget.net>. 3 * 4 * Copyright (C) 2007-2017 Andrey Prygunkov <hugbug@users.sourceforge.net> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 21 #ifndef QUEUESCRIPT_H 22 #define QUEUESCRIPT_H 23 24 #include "DownloadInfo.h" 25 #include "ScriptConfig.h" 26 27 class QueueScriptCoordinator 28 { 29 public: 30 enum EEvent 31 { 32 qeFileDownloaded, // lowest priority 33 qeUrlCompleted, 34 qeNzbMarked, 35 qeNzbAdded, 36 qeNzbNamed, 37 qeNzbDownloaded, 38 qeNzbDeleted // highest priority 39 }; 40 Stop()41 void Stop() { m_stopped = true; } 42 void InitOptions(); 43 void EnqueueScript(NzbInfo* nzbInfo, EEvent event); 44 void CheckQueue(); 45 bool HasJob(int nzbId, bool* active); 46 int GetQueueSize(); 47 static NzbInfo* FindNzbInfo(DownloadQueue* downloadQueue, int nzbId); 48 49 private: 50 class QueueItem 51 { 52 public: QueueItem(int nzbId,ScriptConfig::Script * script,EEvent event)53 QueueItem(int nzbId, ScriptConfig::Script* script, EEvent event) : 54 m_nzbId(nzbId), m_script(script), m_event(event) {} GetNzbId()55 int GetNzbId() { return m_nzbId; } GetScript()56 ScriptConfig::Script* GetScript() { return m_script; } GetEvent()57 EEvent GetEvent() { return m_event; } 58 private: 59 int m_nzbId; 60 ScriptConfig::Script* m_script; 61 EEvent m_event; 62 }; 63 64 typedef std::deque<std::unique_ptr<QueueItem>> Queue; 65 66 Queue m_queue; 67 Mutex m_queueMutex; 68 std::unique_ptr<QueueItem> m_curItem; 69 bool m_hasQueueScripts = false; 70 bool m_stopped = false; 71 72 bool UsableScript(ScriptConfig::Script& script, NzbInfo* nzbInfo, EEvent event); 73 }; 74 75 extern QueueScriptCoordinator* g_QueueScriptCoordinator; 76 77 #endif 78