-
Notifications
You must be signed in to change notification settings - Fork 25
RSDK-11050: Reconfigure fix #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
55a1411
bebbbf5
d04368a
4358c29
538e6e0
9f6b8b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,23 +116,22 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { | |
"unable to reconfigure resource " + cfg.resource_name().name() + | ||
" as it doesn't exist."); | ||
} | ||
try { | ||
Reconfigurable::reconfigure_if_reconfigurable(res, deps, cfg); | ||
|
||
if (auto reconfigurable = std::dynamic_pointer_cast<Reconfigurable>(res)) { | ||
reconfigurable->reconfigure(deps, cfg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⬇️
|
||
res->set_log_level(cfg.get_log_level()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we no longer need the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! |
||
return grpc::Status(); | ||
} catch (const std::exception& exc) { | ||
return grpc::Status(::grpc::INTERNAL, exc.what()); | ||
} | ||
|
||
// if the type isn't reconfigurable by default, replace it | ||
try { | ||
Stoppable::stop_if_stoppable(res); | ||
} catch (const std::exception& err) { | ||
VIAM_SDK_LOG(error) << "unable to stop resource: " << err.what(); | ||
if (auto stoppable = std::dynamic_pointer_cast<Stoppable>(res)) { | ||
stoppable->stop(); | ||
} | ||
|
||
const std::shared_ptr<const ModelRegistration> reg = | ||
Registry::get().lookup_model(cfg.name()); | ||
|
||
// TODO RSDK-11067 new resource gets constructed while old one is still alive. | ||
if (reg) { | ||
try { | ||
const std::shared_ptr<Resource> resource = reg->construct_resource(deps, cfg); | ||
|
@@ -186,10 +185,8 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service { | |
"unable to remove resource " + name.to_string() + " as it doesn't exist."); | ||
} | ||
|
||
try { | ||
Stoppable::stop_if_stoppable(res); | ||
} catch (const std::exception& err) { | ||
VIAM_SDK_LOG(error) << "unable to stop resource: " << err.what(); | ||
if (auto stoppable = std::dynamic_pointer_cast<Stoppable>(res)) { | ||
stoppable->stop(); | ||
} | ||
|
||
manager->remove(name); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,16 @@ namespace sdk { | |
std::shared_ptr<Resource> ResourceManager::resource(const std::string& name) { | ||
const std::lock_guard<std::mutex> lock(lock_); | ||
|
||
if (resources_.find(name) != resources_.end()) { | ||
return resources_.at(name); | ||
auto res_it = resources_.find(name); | ||
if (res_it != resources_.end()) { | ||
return res_it->second; | ||
} | ||
|
||
if (short_names_.find(name) != short_names_.end()) { | ||
const std::string short_name = short_names_.at(name); | ||
if (resources_.find(short_name) != resources_.end()) { | ||
return resources_.at(short_name); | ||
auto name_it = short_names_.find(name); | ||
if (name_it != short_names_.end()) { | ||
res_it = resources_.find(name_it->second); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, this was a latent bug, in that the old code tried to look up the resource by short name a second time, rather than by using the "long name" it dug out of the short names map. Is that basically it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think the original logic was correct, the issue was just that it was discarding the result of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see I missed the |
||
if (res_it != resources_.end()) { | ||
return res_it->second; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
reconfigure_if_reconfigurable
is going away, I thinkstop_if_stoppable
should too. I don't think they are clearer than just usingdynamic_pointer_cast
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed