File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
5454 ModuleService& parent;
5555
5656 // TODO(RSDK-6528) - to the extent possible, switch to using `server_helper`
57- ::grpc::Status AddResource (::grpc::ServerContext*,
57+ ::grpc::Status AddResource (::grpc::ServerContext* ctx ,
5858 const ::viam::module ::v1::AddResourceRequest* request,
5959 ::viam::module ::v1::AddResourceResponse*) override {
6060 const viam::app::v1::ComponentConfig& proto = request->config ();
@@ -74,7 +74,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
7474 }
7575 };
7676 try {
77- parent.server_ ->add_resource (res);
77+ parent.server_ ->add_resource (res, ctx-> deadline () );
7878 } catch (const std::exception& exc) {
7979 return grpc::Status (::grpc::INTERNAL, exc.what ());
8080 }
Original file line number Diff line number Diff line change @@ -44,7 +44,21 @@ void Server::register_service(grpc::Service* service) {
4444 builder_->RegisterService (service);
4545}
4646
47+ namespace {
48+ bool deadline_exceeded (const std::chrono::system_clock::time_point& deadline) {
49+ return deadline < std::chrono::system_clock::now (); // deadline is before now
50+ }
51+ } // namespace
52+
4753void Server::add_resource (std::shared_ptr<Resource> resource) {
54+ add_resource (std::move (resource), boost::none);
55+ }
56+
57+ void Server::add_resource (std::shared_ptr<Resource> resource,
58+ boost::optional<std::chrono::system_clock::time_point> deadline) {
59+ if (deadline && deadline_exceeded (*deadline)) {
60+ throw Exception (ErrorCondition::k_general, " Deadline expired" );
61+ }
4862 auto api = resource->api ();
4963 if (managed_servers_.find (api) == managed_servers_.end ()) {
5064 std::ostringstream buffer;
Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ class Server {
5050 // / @throws `Exception` if a matching `ResourceServer` doesn't exist in the server.
5151 void add_resource (std::shared_ptr<Resource> resource);
5252
53+ // / @brief Adds a specific managed resource to the associated resource server
54+ // / @param resource The resource to add
55+ // / @param deadline Deadline after which to not add the resource
56+ // / @throws `Exception` if a matching `ResourceServer` doesn't exist in the server.
57+ // / @throws `Exception` if the deadline is not nil and has passed
58+ void add_resource (std::shared_ptr<Resource> resource,
59+ boost::optional<std::chrono::system_clock::time_point> deadline);
60+
5361 // / @brief Adds a listening port to the server.
5462 // / @param address The address to listen at.
5563 // / @param creds The server credentials; defaults to a insecure server credentials.
You can’t perform that action at this time.
0 commit comments