1 /** 2 * @file 3 * @brief This is a message class for thread safe comunication between ClipProcessingJobs and OpenCV classes 4 * @author Jonathan Thomas <jonathan@openshot.org> 5 * @author Brenno Caldato <brenno.caldato@outlook.com> 6 * 7 * @ref License 8 */ 9 10 /* LICENSE 11 * 12 * Copyright (c) 2008-2019 OpenShot Studios, LLC 13 * <http://www.openshotstudios.com/>. This file is part of 14 * OpenShot Library (libopenshot), an open-source project dedicated to 15 * delivering high quality video editing and animation solutions to the 16 * world. For more information visit <http://www.openshot.org/>. 17 * 18 * OpenShot Library (libopenshot) is free software: you can redistribute it 19 * and/or modify it under the terms of the GNU Lesser General Public License 20 * as published by the Free Software Foundation, either version 3 of the 21 * License, or (at your option) any later version. 22 * 23 * OpenShot Library (libopenshot) is distributed in the hope that it will be 24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 * GNU Lesser General Public License for more details. 27 * 28 * You should have received a copy of the GNU Lesser General Public License 29 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>. 30 */ 31 32 #ifndef OPENSHOT_PROCESSINGCONTROLLER_H 33 #define OPENSHOT_PROCESSINGCONTROLLER_H 34 35 #include <iostream> 36 #include <thread> 37 #include <mutex> 38 39 40 class ProcessingController{ 41 private: 42 uint processingProgress; 43 bool processingFinished; 44 bool stopProcessing; 45 bool error = true; 46 std::string error_message; 47 48 std::mutex mtxProgress; 49 std::mutex mtxFinished; 50 std::mutex mtxStop; 51 std::mutex mtxerror; 52 53 public: 54 ProcessingController()55 ProcessingController(){ 56 processingProgress = 0; 57 stopProcessing = false; 58 processingFinished = false; 59 } 60 GetFinished()61 int GetFinished(){ 62 std::lock_guard<std::mutex> lck (mtxFinished); 63 bool f = processingFinished; 64 return f; 65 } 66 SetFinished(bool f)67 void SetFinished(bool f){ 68 std::lock_guard<std::mutex> lck (mtxFinished); 69 processingFinished = f; 70 } 71 SetProgress(uint p)72 void SetProgress(uint p){ 73 std::lock_guard<std::mutex> lck (mtxProgress); 74 processingProgress = p; 75 } 76 GetProgress()77 int GetProgress(){ 78 std::lock_guard<std::mutex> lck (mtxProgress); 79 uint p = processingProgress; 80 return p; 81 } 82 CancelProcessing()83 void CancelProcessing(){ 84 std::lock_guard<std::mutex> lck (mtxStop); 85 stopProcessing = true; 86 } 87 ShouldStop()88 bool ShouldStop(){ 89 std::lock_guard<std::mutex> lck (mtxStop); 90 bool s = stopProcessing; 91 return s; 92 } 93 SetError(bool err,std::string message)94 void SetError(bool err, std::string message){ 95 std::lock_guard<std::mutex> lck (mtxerror); 96 error = err; 97 error_message = message; 98 } 99 GetError()100 bool GetError(){ 101 std::lock_guard<std::mutex> lck (mtxerror); 102 bool e = error; 103 return e; 104 } 105 GetErrorMessage()106 std::string GetErrorMessage(){ 107 std::lock_guard<std::mutex> lck (mtxerror); 108 std::string message = error_message; 109 return message; 110 } 111 112 }; 113 114 #endif