Skip to content
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

Unify service arrays into a simple struct array #14

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

nbes4
Copy link
Contributor

@nbes4 nbes4 commented Jun 15, 2024

Hello! Congratulations on such a cool project 😃, immediately had to play around with it upon reading about it. After reading into the code to start defining my own services, I noticed that the service arrays could be unified into an array containing simple structs to improve a bunch of things (see below).

Instead of maintaining three different arrays, everything goes into an array of simple structs (see services.c), like:

 const ServiceDesc_t service_descriptors[] = {
    {
        .name = xstr(SERVICE_NAME_USB), 
        .service_func = usb_service,
        .startup = true
    },
    // more service descriptor definitions here ...
};
  • No longer need to watch out for service_functions and service_strings to have the same order
  • No longer need to watch out for spelling errors in the startup_services, just a simple boolean
  • No more (sizeof(service_strings)/sizeof(service_strings[0])) just access service_descriptors_length
  • No more strcmp to find startup services in taskman_service just check the startup bool
  • No more duplicate static variables in memory (since they are now extern in the header file)

@mcknly
Copy link
Owner

mcknly commented Jun 17, 2024

Thanks for the interest! Your proposed changes to the services infrastructure is logical and I like how it can simplify adding new services. I need a little more time to review, in the mean time I have created a new branch called services-refactor, can you modify your PR to target that branch? I will merge in your code so we have a sandbox before pulling into main. Thanks again for using the project!

@nbes4 nbes4 changed the base branch from main to services-refactor June 18, 2024 15:05
@nbes4
Copy link
Contributor Author

nbes4 commented Jun 18, 2024

Thanks for your reply @mcknly. I changed the base branch of the PR from main to services-refactor. No stress about the review 👍

Copy link
Owner

@mcknly mcknly left a comment

Choose a reason for hiding this comment

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

Looks good. Merging into services-refactor branch for some testing and documentation updates (README etc.) before bumping to main.

@mcknly mcknly merged commit 08605ac into mcknly:services-refactor Jun 18, 2024
@nbes4
Copy link
Contributor Author

nbes4 commented Jun 19, 2024

Awesome, let me know if you find any bugs or discuss the changes.

@mcknly
Copy link
Owner

mcknly commented Jun 20, 2024

@nbes4 I've updated the services-refactor branch with some additional documentation - can you pull the latest and have a look? Start with services.h, read through all the comments, and see if it all makes sense from a new user perspective.

Also, I put a file header in services.c, with your github username as author. If you want it to show anything different feel free to change and submit another PR to the branch.

If all is good I will pull it into main. Thanks again for the contribution!

@mcknly
Copy link
Owner

mcknly commented Jun 20, 2024

Here's the direct link if it's easier...

@nbes4
Copy link
Contributor Author

nbes4 commented Jun 22, 2024

@mcknly Looks good! I added some comments to your commit, don't know if GitHub notifies you of them

mcknly added a commit that referenced this pull request Jun 24, 2024
* Unify service arrays into a simple struct array (#14)

* Group service arrays into simple struct

* Use size_t and fixed typo

* Added some additional documentation to support new service descriptors structure, bump BBOS version to 0.2

* Minor comments & formatting

---------

Co-authored-by: nbes4 <[email protected]>
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.

None yet

2 participants