14 ::grpc::Status fail(::grpc::StatusCode code,
const char* message)
const noexcept;
16 ::grpc::Status failNoRequest()
const noexcept;
18 ::grpc::Status failNoResource(
const std::string& name)
const noexcept;
20 ::grpc::Status failStdException(
const std::exception& xcp)
const noexcept;
22 ::grpc::Status failUnknownException()
const noexcept;
37 template <
typename Callable>
38 ::grpc::Status operator()(Callable&& callable)
const noexcept try {
40 return failNoRequest();
42 const auto resource = rs_->resource_manager()->resource<ServiceType>(request_->name());
44 return failNoResource(request_->name());
46 return invoke_(std::forward<Callable>(callable), std::move(resource));
47 }
catch (
const std::exception& xcp) {
48 return failStdException(xcp);
50 return failUnknownException();
53 auto getExtra()
const {
54 return request_->has_extra() ? from_proto(request_->extra()) : ProtoStruct{};
58 template <
typename Callable,
typename... Args>
59 using is_void_result = std::is_void<std::result_of_t<Callable(Args...)>>;
64 template <
typename Callable,
65 typename ResourcePtrType,
66 std::enable_if_t<!is_void_result<Callable, ServiceHelper&, ResourcePtrType&&>::value,
68 ::grpc::Status invoke_(Callable&& callable, ResourcePtrType&& resource)
const {
69 return std::forward<Callable>(callable)(*
this, std::forward<ResourcePtrType>(resource));
75 template <
typename Callable,
76 typename ResourcePtrType,
77 std::enable_if_t<is_void_result<Callable, ServiceHelper&, ResourcePtrType&&>::value,
79 ::grpc::Status invoke_(Callable&& callable, ResourcePtrType&& resource)
const {
80 std::forward<Callable>(callable)(*
this, std::forward<ResourcePtrType>(resource));
85 RequestType* request_;
90 return ServiceHelper<ServiceType, RequestType>{method, rs, request};