@@ -252,31 +252,33 @@ ::grpc::Status MockRobotService::StopAll(::grpc::ServerContext*,
252252 const std::shared_ptr<Resource> resource = r.second ;
253253 const ResourceName rn = to_proto (resource->get_resource_name ());
254254 const std::string rn_ = rn.SerializeAsString ();
255- if (extra. find (rn_) != extra. end ()) {
256- try {
257- Stoppable::stop_if_stoppable (resource, extra. at (rn_));
258- } catch ( const std::runtime_error& err ) {
255+
256+ auto stop_without_extra = [&status_message,
257+ &status]( const std::shared_ptr<Resource>& resource) {
258+ if ( auto stoppable = std::dynamic_pointer_cast<Stoppable>(resource) ) {
259259 try {
260+ stoppable->stop ();
261+ return ;
262+ } catch (const std::runtime_error& err) {
260263 status_message = err.what ();
261- Stoppable::stop_if_stoppable (resource);
262- } catch (std::runtime_error& err) {
263- status_message = err.what ();
264- status = grpc::UNKNOWN;
265264 } catch (...) {
266265 status_message = " unknown error" ;
267- status = grpc::UNKNOWN;
268266 }
267+ status = grpc::UNKNOWN;
269268 }
270- } else {
269+ };
270+
271+ if (extra.find (rn_) != extra.end ()) {
271272 try {
272- Stoppable::stop_if_stoppable (resource);
273- } catch (std::runtime_error& err) {
273+ if (auto stoppable = std::dynamic_pointer_cast<Stoppable>(resource)) {
274+ stoppable->stop (extra.at (rn_));
275+ }
276+ } catch (const std::runtime_error& err) {
274277 status_message = err.what ();
275- status = grpc::UNKNOWN;
276- } catch (...) {
277- status_message = " unknown error" ;
278- status = grpc::UNKNOWN;
278+ stop_without_extra (resource);
279279 }
280+ } else {
281+ stop_without_extra (resource);
280282 }
281283 }
282284
0 commit comments