12 ::grpc::Status fail(::grpc::StatusCode code,
const char* message)
const noexcept;
14 ::grpc::Status failNoRequest()
const noexcept;
16 ::grpc::Status failNoResource(
const std::string& name)
const noexcept;
18 ::grpc::Status failStdException(
const std::exception& xcp)
const noexcept;
20 ::grpc::Status failUnknownException()
const noexcept;
35 template <
typename Callable>
36 ::grpc::Status operator()(Callable&& callable)
const noexcept try {
38 return failNoRequest();
40 const auto resource = rs_->resource_manager()->resource<ServiceType>(request_->name());
42 return failNoResource(request_->name());
44 return invoke_(std::forward<Callable>(callable), std::move(resource));
45 }
catch (
const std::exception& xcp) {
46 return failStdException(xcp);
48 return failUnknownException();
51 auto getExtra()
const {
52 return request_->has_extra() ? struct_to_map(request_->extra()) : ProtoStruct{};
56 template <
typename Callable,
typename... Args>
57 using is_void_result = std::is_void<std::result_of_t<Callable(Args...)>>;
62 template <
typename Callable,
63 typename ResourcePtrType,
64 std::enable_if_t<!is_void_result<Callable, ServiceHelper&, ResourcePtrType&&>::value,
66 ::grpc::Status invoke_(Callable&& callable, ResourcePtrType&& resource)
const {
67 return std::forward<Callable>(callable)(*
this, std::forward<ResourcePtrType>(resource));
73 template <
typename Callable,
74 typename ResourcePtrType,
75 std::enable_if_t<is_void_result<Callable, ServiceHelper&, ResourcePtrType&&>::value,
77 ::grpc::Status invoke_(Callable&& callable, ResourcePtrType&& resource)
const {
78 std::forward<Callable>(callable)(*
this, std::forward<ResourcePtrType>(resource));
83 RequestType* request_;
88 return ServiceHelper<ServiceType, RequestType>{method, rs, request};