1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #ifndef __cplusplus 8 #error "C++ Only file" 9 #endif // __cplusplus 10 11 #include <stdlib.h> 12 13 #include <block-client/client.h> 14 #include <fbl/macros.h> 15 #include <lib/zx/fifo.h> 16 #include <zircon/types.h> 17 18 namespace block_client { 19 20 class Client { 21 public: 22 DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(Client); 23 24 // Constructs an invalid Client. 25 // 26 // It is invalid to call any block client operations with this 27 // empty block client wrapper. 28 Client(); 29 30 // Constructs a valid Client, capable of issuing 31 // block client operations. 32 explicit Client(fifo_client_t* client); 33 Client(Client&& other); 34 Client& operator=(Client&& other); 35 ~Client(); 36 37 // Initializer for a BlockClient, which, on success, 38 // will make |out| a valid Client. 39 static zx_status_t Create(zx::fifo fifo, Client* out); 40 41 // BLOCK CLIENT OPERATIONS. 42 43 // Issues a group of block requests over the underlying fifo, 44 // and waits for a response. 45 zx_status_t Transaction(block_fifo_request_t* requests, size_t count) const; 46 47 private: 48 // Replace the current fifo_client with a new one. 49 void Reset(fifo_client_t* client = nullptr); 50 51 // Relinquish the underlying fifo client without destroying it. 52 fifo_client_t* Release(); 53 54 fifo_client_t* client_; 55 }; 56 57 } // namespace block_client 58