Skip to content

Feature create devices after bus creation#954

Merged
akuker merged 10 commits intodevelopfrom
feature_create_devices_after_bus_creation
Nov 2, 2022
Merged

Feature create devices after bus creation#954
akuker merged 10 commits intodevelopfrom
feature_create_devices_after_bus_creation

Conversation

@akuker
Copy link
Copy Markdown
Member

@akuker akuker commented Nov 1, 2022

In preparation of the upcoming banana pi support, I needed to restructure how the program arguments are parsed. Currently, the 'bus' object needs to be created before we can parse the arguments. However, with the bpi updates, I need to have the program arguments as an input to creating the 'bus' object.

Attached is my proposed approach. Basically, it saves off the program args related to device creation, then processes them later (after the bus and associated controllers/executor/etc are created).

@akuker akuker changed the base branch from master to develop November 1, 2022 15:59
@akuker akuker requested a review from uweseimet November 1, 2022 16:29
@akuker akuker marked this pull request as ready for review November 1, 2022 16:29
Copy link
Copy Markdown
Contributor

@uweseimet uweseimet left a comment

Choose a reason for hiding this comment

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

I'm not familiar with the changes that require creating the devices after the bus. I would expect the devices not to know anything about/depend on the type of bus, and currently the device factory creates them without any information on a bus. Can you please explain?
Maybe this is related to the fact that the device factory knows the controller manager, and this one knows the bus?
The factory currently needs the controller manager only for creating the host services device. I would like to get rid of this dependency, but have not yet had a closer look at alternatives.

string value;
};
typedef std::vector<optarg_struct> optarg_queue_type;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use a standard multimap instead of custom containers here, e.g.:

unordered_multimap<int, string> optargs;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can do

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm wondering if this makes more sense as a FIFO Queue. With the multimap, can we guarantee that the arguments will come out in the same order they went in?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@uweseimet I changed it to a double ended queue (deque). let me know if you have any objections!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@akuker Ordering would indeed be an issue with the multimap, so we cannot use it here. I am going to approve the PR, but before you merge, please replace "typedef" by "using", as recommended for modern C++. A minor change only.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done. Thanks!

@akuker
Copy link
Copy Markdown
Member Author

akuker commented Nov 1, 2022

I'm not familiar with the changes that require creating the devices after the bus. I would expect the devices not to know anything about/depend on the type of bus, and currently the device factory creates them without any information on a bus. Can you please explain? Maybe this is related to the fact that the device factory knows the controller manager, and this one knows the bus? The factory currently needs the controller manager only for creating the host services device. I would like to get rid of this dependency, but have not yet had a closer look at alternatives.

With the current implementation, the executor is used as part of the ParseArgument() routine. The constructor for executor uses controller manager in its constructor. Controller manager uses bus in its constructure. So, with the current architecture, you need to have the bus object created in order to run ParseArgument().

With the current implementation of GPIOBUS, this is fine. However, with the upcoming revision, we need to know what type of board we're connected to (fullspec/aibom/standard/gamernium) before we call the GPIOBUS::Init() function. See:
https://github.com/akuker/RASCSI/blob/feature_bpi4/cpp/hal/gpiobus.cpp#L77

Note that this change is NOT NEEDED currently. But, I'd prefer to do any small, benign changes early. If you prefer I can lump this in with the feature_bpi branch.

@akuker
Copy link
Copy Markdown
Member Author

akuker commented Nov 1, 2022

Also note that this moves the log level setting earlier in the start-up process. This can be useful when trying to debug issues during initialization.

@uweseimet
Copy link
Copy Markdown
Contributor

@akuker Looks as if my guess about the manager and its bus argument was quite right. Actually, I don't have a strong opinion on when to merge these changes. I'm fine with doing this early. I intend to resolve the dependency between the controller manager and the bus sooner or later, but this requires also to change the host services and I do not yet know how exactly this change should look like. Otherwise I would already have done it ;-).
So from my perspective, let's merge your changes early, after replacing the vector with the nested struct by a multimap.

@uweseimet
Copy link
Copy Markdown
Contributor

uweseimet commented Nov 2, 2022

@akuker I hope I can simplify the parsing again after having a good solution for #959. Resolving #955 should help with making the parser testable.

@akuker akuker merged commit 31dd063 into develop Nov 2, 2022
@akuker akuker deleted the feature_create_devices_after_bus_creation branch November 2, 2022 13:59
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Nov 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

uweseimet added a commit that referenced this pull request Nov 2, 2022
commit c41373d
Author: Uwe Seimet <48174652+uweseimet@users.noreply.github.com>
Date:   Wed Nov 2 15:36:19 2022 +0100

    Use lambdas for dispatcher, code cleanup, test updates (#958)

    * Using lambdas instead of member function pointers simplifies the command dispatching and reduces the code volume

    * Removed duplicate error handling

    * Fix for issue #956

    * Unit test updates

    * Resolved SonarQube issues

commit 31dd063
Author: akuker <34318535+akuker@users.noreply.github.com>
Date:   Wed Nov 2 08:58:59 2022 -0500

    Create devices after bus creation (#954)
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.

2 participants