InfiniTimeOrg / InfiniTime

Firmware for Pinetime smartwatch written in C++ and based on FreeRTOS
GNU General Public License v3.0
2.64k stars 903 forks source link

App controller #1840

Closed minacode closed 6 months ago

minacode commented 10 months ago

This PR stems from #1571 and is related to #1262. It is a draft, because there is work left to do (see the open problems below).

This PR implements an AppController class as a single place in the code where all non-core apps are registered. Short-term this allows us to implement optional apps (see #1408). Long-term this allows us to implement dynamically loadable apps.

Currently the app Twos is handled by the AppController as an example, mostly because it has no dependencies and is therefore simple to handle.

The implementation uses the Apps enum (see also #1760), but removes all entries of apps that will be handled by the AppController. Instead, the entry Dynamic is added to the enum. The ids of dynamic apps are then calculated by Dynamic + <offset> where <offset> is the id of an app inside the AppController (e.g. an array index). This leads to a lot of static_cast everywhere.

All places, where the current apps where hardcoded before have to use the AppController now.

Apps that can be used with the AppController must implement a Get method and its symbol like this:

...
public:
  static std::unique_ptr<Twos> Get() {
    return std::make_unique<Twos>();
  }

  static constexpr const char* Symbol {"2"};

The AppController saves those contructors internally and can reference them via the Dynamic + <offset> ids described above.

There are also already fragments of an AppInterface in the code that every Get method must receive. The AppInterface bundles all the controllers that apps can require.

The current version runs with InfiniSim if you use my branch.

Feedback and ideas would be very apprechiated :blush:

Open Problems:
github-actions[bot] commented 10 months ago

Build checks have not completed. Possible reasons for this are:

  1. The checks need to be approved by a maintainer
  2. The branch has conflicts
  3. The firmware build has failed
JF002 commented 6 months ago

@minacode Thanks for your work on this topic! Since you created this PR, we merged #1894 which, I think, does mostly the same functionality at build time. Is this OK for you if we close this PR in favor of #1894 ?

minacode commented 6 months ago

Yes, absolutely :)