1 /* 2 * Copyright (C) 2020 Emeric Poupon 3 * 4 * This file is part of LMS. 5 * 6 * LMS 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 3 of the License, or 9 * (at your option) any later version. 10 * 11 * LMS 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 LMS. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #pragma once 20 21 #include <cstddef> 22 #include <functional> 23 #include <string> 24 #include <vector> 25 26 #include "utils/Exception.hpp" 27 28 class ChildProcessException : public LmsException 29 { 30 public: 31 using LmsException::LmsException; 32 }; 33 34 class IChildProcess 35 { 36 public: 37 using Args = std::vector<std::string>; 38 39 virtual ~IChildProcess() = default; 40 41 enum class ReadResult 42 { 43 Success, 44 Error, 45 EndOfFile, 46 }; 47 48 using ReadCallback = std::function<void(ReadResult, std::size_t)>; 49 virtual void asyncRead(std::byte* data, std::size_t bufferSize, ReadCallback callback) = 0; 50 51 using WaitCallback = std::function<void(void)>; 52 virtual void asyncWaitForData(WaitCallback cb) = 0; 53 virtual std::size_t readSome(std::byte* data, std::size_t bufferSize) = 0; 54 virtual bool finished() = 0; 55 }; 56 57