1/* 2 Copyright (c) 2013 Arduino LLC. All right reserved. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17*/ 18 19#ifndef PROCESS_H_ 20#define PROCESS_H_ 21 22#include <Bridge.h> 23 24class Process :public Stream { 25public: 26// Constructor with a user provided BridgeClass instance 27Process(BridgeClass &_b = Bridge) : 28bridge(_b),started(false),buffered(0),readPos(0) { } 29~Process(); 30 31voidbegin(const String &command); 32voidaddParameter(const String ¶m); 33unsigned intrun(); 34voidrunAsynchronously(); 35 boolean running(); 36unsigned intexitValue(); 37voidclose(); 38 39unsigned intrunShellCommand(const String &command); 40voidrunShellCommandAsynchronously(const String &command); 41 42operatorbool() { 43return started; 44} 45 46// Stream methods 47// (read from process stdout) 48intavailable(); 49intread(); 50intpeek(); 51// (write to process stdin) 52size_twrite(uint8_t); 53voidflush(); 54// TODO: add optimized function for block write 55 56private: 57 BridgeClass &bridge; 58uint8_t handle; 59 String *cmdline; 60 boolean started; 61 62private: 63voiddoBuffer(); 64uint8_t buffered; 65uint8_t readPos; 66static const int BUFFER_SIZE =64; 67uint8_t buffer[BUFFER_SIZE]; 68 69}; 70 71#endif