Skip to content

Conversation

@stuqdog
Copy link
Member

@stuqdog stuqdog commented Feb 14, 2024

Adds Reconfigurable base class, analogized from Stoppable

/// @brief Reconfigures a resource.
/// @param deps Dependencies of the resource.
/// @param cfg The resource's config.
virtual void reconfigure(const Dependencies& deps, const ResourceConfig& cfg) = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to change the signature of reconfigure to take its args by const&. I think this especially makes sense for the cfg; I could theoretically imagine someone wanting non-const access to deps but I think passing deps by value would be a bit strange, and I suspect that const& dependencies will be correct and manageable. In the worst case, we can add an override of reconfigure that isn't const&. Happy to revisit if others have thoughts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine.

@stuqdog stuqdog marked this pull request as ready for review February 15, 2024 19:47
@stuqdog stuqdog requested a review from a team as a code owner February 15, 2024 19:47
@stuqdog stuqdog requested review from a team, acmorrow, benjirewis, njooma and purplenicole730 and removed request for a team, benjirewis and njooma February 15, 2024 19:47
Copy link
Member

@purplenicole730 purplenicole730 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, and a question. I'm happy for the answer to the question to be "let's do that in a subsequent step/review".

@@ -0,0 +1,20 @@
#include <memory>
#include <viam/sdk/resource/reconfigurable.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "associated" include should always be first, in a standalone block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed this! Thanks for the catch :)

/// @param resource the Resource to reconfigure.
/// @param deps Dependencies of the resource.
/// @param cfg The resource's config.
static void reconfigure_if_reconfigurable(const std::shared_ptr<Resource>& resource,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we discussed this before or not, but I wonder if you could just make this a non-virtual method of Resource:

class Resource {
    ...
    void reconfigure(const Dep..., const Res...);
    ...
};

void Resource::reconfigure(...) {
    auto reconfigurable_res = std::dynamic_pointer_cast<Reconfigurable>(resource);
    if (reconfigurable_res) {
        reconfigurable_res->reconfigure(...);
    }

Same could be done for stop / Stoppable?

Copy link
Member Author

@stuqdog stuqdog Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, it seems nice to have stop and reconfigure sit on the Resource class. Happy enough to make the change here, it seems pretty simple.

One clarifying point/question, I believe the methods will have to be static because otherwise the this arg is a raw pointer, but dynamic_pointer_cast requires a shared_ptr. Is there some cleverness I'm missing for how to have a non-static member method allow for a dynamic_pointer_cast of this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry - I hadn't really focused on the fact that it took a shared_ptr arg. But I don't think it is an obstacle: you can just use plain dynamic_cast instead of dynamic_pointer_cast.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that maybe bugs me about my proposal is that having reconfigure and (even more so) stop methods on Resource that may be no-ops feels a tiny bit disingenuous, in that you could call the method but it does nothing unless the dynamic type of the object happens to have opted in by deriving from the right mixins. Let's get this merged as is and then think a little harder about it. If we end up with lots of mixins for optional behavior, I also don't want to necessarily clutter the Resource class with convenience entry points for all of them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool sounds good, I'll make a ticket for revisiting.

/// @brief Reconfigures a resource.
/// @param deps Dependencies of the resource.
/// @param cfg The resource's config.
virtual void reconfigure(const Dependencies& deps, const ResourceConfig& cfg) = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine.

@stuqdog stuqdog merged commit 5c1e819 into viamrobotics:main Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants