1 // Copyright 2018 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_RAW_CLIENT_WRAPPER_UTILS_H 16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_RAW_CLIENT_WRAPPER_UTILS_H 17 18 #include "google/cloud/storage/internal/raw_client.h" 19 #include "google/cloud/storage/version.h" 20 #include <type_traits> 21 22 namespace google { 23 namespace cloud { 24 namespace storage { 25 inline namespace STORAGE_CLIENT_NS { 26 namespace internal { 27 /** 28 * Defines types to wrap `RawClient` function calls. 29 * 30 * We have a couple of classes that basically wrap every function in `RawClient` 31 * with some additional behavior (`LoggingClient` logs every call, and 32 * `RetryClient` retries every call). Instead of hand-coding every wrapped 33 * function we use a helper to wrap it, and in turn those helpers use the 34 * meta-functions defined here. 35 */ 36 namespace raw_client_wrapper_utils { 37 38 /** 39 * Metafunction to determine if @p F is a pointer to member function with the 40 * expected signature for a `RawClient` member function. 41 * 42 * This is the generic case, where the type does not match the expected 43 * signature and so member type aliases do not exist. 44 * 45 * @tparam F the type to check against the expected signature. 46 */ 47 template <typename F> 48 struct Signature {}; 49 50 /** 51 * Partial specialization for the above `Signature` metafunction. 52 * 53 * This is the case where the type actually matches the expected signature. The 54 * class also extracts the request and response types used in the 55 * implementation of `CallWithRetry()`. 56 * 57 * @tparam Request the RPC request type. 58 * @tparam Response the RPC response type. 59 */ 60 template <typename Request, typename Response> 61 struct Signature<StatusOr<Response> ( 62 google::cloud::storage::internal::RawClient::*)(Request const&)> { 63 using RequestType = Request; 64 using ReturnType = StatusOr<Response>; 65 }; 66 67 } // namespace raw_client_wrapper_utils 68 } // namespace internal 69 } // namespace STORAGE_CLIENT_NS 70 } // namespace storage 71 } // namespace cloud 72 } // namespace google 73 74 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_RAW_CLIENT_WRAPPER_UTILS_H 75