1 /* 2 This file is part of Android File Transfer For Linux. 3 Copyright (C) 2015-2020 Vladimir Menshakov 4 5 This library is free software; you can redistribute it and/or modify it 6 under the terms of the GNU Lesser General Public License as published by 7 the Free Software Foundation; either version 2.1 of the License, 8 or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public License 16 along with this library; if not, write to the Free Software Foundation, 17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 #ifndef AFTL_MTP_USB_BULKPIPE_H 21 #define AFTL_MTP_USB_BULKPIPE_H 22 23 #include <mtp/Token.h> 24 #include <mtp/ByteArray.h> 25 #include <mtp/ptp/IObjectStream.h> 26 27 namespace mtp { namespace usb 28 { 29 class Device; 30 DECLARE_PTR(Device); 31 class Configuration; 32 DECLARE_PTR(Configuration); 33 class Interface; 34 DECLARE_PTR(Interface); 35 class Endpoint; 36 DECLARE_PTR(Endpoint); 37 class BulkPipe; 38 DECLARE_PTR(BulkPipe); 39 40 class BulkPipe //! USB BulkPipe, incapsulate three (in, out, interrupt) endpoints, allowing easier data transfer 41 { 42 std::mutex _mutex; 43 DevicePtr _device; 44 ConfigurationPtr _conf; 45 InterfacePtr _interface; 46 EndpointPtr _in, _out, _interrupt; 47 ITokenPtr _claimToken; 48 ICancellableStreamPtr _currentStream; 49 50 private: 51 void SetCurrentStream(const ICancellableStreamPtr &stream); 52 ICancellableStreamPtr GetCurrentStream(); 53 54 class CurrentStreamSetter; 55 56 public: 57 BulkPipe(DevicePtr device, ConfigurationPtr conf, InterfacePtr interface, EndpointPtr in, EndpointPtr out, EndpointPtr interrupt, ITokenPtr claimToken); 58 ~BulkPipe(); 59 60 DevicePtr GetDevice() const; 61 InterfacePtr GetInterface() const; 62 63 ByteArray ReadInterrupt(int timeout); 64 65 void Read(const IObjectOutputStreamPtr &outputStream, int timeout = 10000); 66 void Write(const IObjectInputStreamPtr &inputStream, int timeout = 10000); 67 void Cancel(); 68 69 static BulkPipePtr Create(const usb::DevicePtr & device, const ConfigurationPtr & conf, const usb::InterfacePtr & owner, ITokenPtr claimToken); 70 }; 71 72 }} 73 74 #endif /* BULKPIPE_H */ 75