Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
FrameworkApp Class Reference

Base class for applications using the framework. More...

#include <FrameworkApp.h>

+ Inheritance diagram for FrameworkApp:
+ Collaboration diagram for FrameworkApp:

Public Member Functions

 FrameworkApp (int port, const char *name="AppTask", uint16_t stackSize=2048, UBaseType_t priority=tskIDLE_PRIORITY+1)
 Constructor.
 
virtual ~FrameworkApp ()=default
 Virtual destructor.
 
virtual void start ()
 Initializes the application and its framework services.
 
void onStart () override
 Starts the Framework Manager.
 
- Public Member Functions inherited from FrameworkController
 FrameworkController (const char *name, Router &sharedRouter, uint16_t stackSize=1024, UBaseType_t priority=tskIDLE_PRIORITY+1)
 Constructor.
 
void run () override final
 Main task loop.
 
const char * getName () const
 Get the name of this controller.
 
void enableEventQueue (size_t depth=8)
 Enable the event queue for this controller.
 
QueueHandle_t getEventQueue () const
 Get the event queue for this controller.
 
bool getNextEvent (Event &event, uint32_t timeoutMs)
 Check if there are any pending events in the queue.
 
- Public Member Functions inherited from FrameworkTask
 FrameworkTask (const char *name, uint16_t stackSize=1024, UBaseType_t priority=1)
 Constructor.
 
virtual ~FrameworkTask ()
 Destructor.
 
bool start ()
 Starts the task via FreeRTOS.
 
void suspend ()
 Suspends the task using vTaskSuspend().
 
void resume ()
 Resumes the task using vTaskResume().
 
TaskHandle_t getHandle () const
 Returns the FreeRTOS task handle.
 
const char * getName () const
 Returns the task name.
 
void notify (uint8_t index, uint32_t value=1)
 Sends a notification to this task using an index.
 
void notify (Notification n, uint32_t value=1)
 Sends a notification using a framework-defined enum.
 
void notifyFromISR (uint8_t index, uint32_t value=1, BaseType_t *pxHigherPriorityTaskWoken=nullptr)
 Sends a notification from an ISR (by index).
 
void notifyFromISR (Notification n, uint32_t value=1, BaseType_t *pxHigherPriorityTaskWoken=nullptr)
 Sends a notification from ISR using enum identifier.
 
bool waitFor (uint8_t index, TickType_t timeout=portMAX_DELAY)
 Waits for a notification (by index).
 
bool waitFor (Notification n, TickType_t timeout=portMAX_DELAY)
 Waits for a notification (by enum identifier).
 
Notification waitForAny (uint8_t index, uint32_t mask, TickType_t timeout=portMAX_DELAY)
 waits for any notification matching the given mask.
 

Protected Member Functions

virtual void initRoutes ()
 Define the application's HTTP routes.
 
- Protected Member Functions inherited from FrameworkController
virtual void onEvent (const Event &event)
 Called when an event is dispatched to this controller.
 
virtual TickType_t getPollIntervalTicks ()
 Returns the polling interval in ticks used in run().
 
virtual void poll ()
 Called during every loop iteration for non-blocking background logic.
 
void runEvery (uint32_t intervalMs, const std::function< void()> &fn, const char *id)
 Run a function periodically with millisecond resolution.
 
- Protected Member Functions inherited from FrameworkTask
uint32_t waitFor (TickType_t timeout=portMAX_DELAY)
 Wait for any notification (default index).
 
bool createQueue (size_t itemSize, size_t length)
 Creates an internal FreeRTOS queue.
 
bool sendToQueue (const void *item, TickType_t timeout=0)
 Sends an item to the internal queue.
 
bool receiveFromQueue (void *item, TickType_t timeout=portMAX_DELAY)
 Receives an item from the internal queue.
 

Protected Attributes

Router router
 Router instance for handling HTTP routes.
 
HttpServer server
 Embedded HTTP server instance.
 
FrameworkManager manager
 Responsible for launching system services and networking.
 
- Protected Attributes inherited from FrameworkController
Routerrouter
 Handles path-to-handler mapping - reference to shared Router instance.
 
- Protected Attributes inherited from FrameworkTask
const char * _name
 
uint16_t _stackSize
 
UBaseType_t _priority
 
TaskHandle_t _handle = nullptr
 
QueueHandle_t _queue = nullptr
 

Detailed Description

FrameworkApp is designed to be subclassed by user applications. It wires together the HTTP server, routing system, and task management. Derived classes override initRoutes() to register route handlers, and run() to implement application logic.

Definition at line 39 of file FrameworkApp.h.

Constructor & Destructor Documentation

◆ FrameworkApp()

FrameworkApp::FrameworkApp ( int  port,
const char *  name = "AppTask",
uint16_t  stackSize = 2048,
UBaseType_t  priority = tskIDLE_PRIORITY + 1 
)

Constructor.

Initializes the HTTP server with the given port and binds the router. The router is passed to the server constructor so it can handle incoming requests based on the defined routes.

You can choose to call initRoutes() in the constructor of your subclass to ensure routes are set up before the server starts. This keeps the constructor focused on initialization and ensures routing is handled in one place.

Parameters
portThe TCP port to listen on.
nameThe name of the FreeRTOS task.
stackSizeStack size allocated to the task.
priorityTask priority.

Initializes the HTTP server with the given port and binds the router. The router is passed to the server constructor so it can handle incoming requests based on the defined routes.

You can choose to call initRoutes() in the constructor of your subclass to ensure routes are set up before the server starts. This keeps the constructor focused on initialization and ensures routing is handled in one place.

Parameters
portThe TCP port to listen on.
nameThe name of the FreeRTOS task.
stackSizeStack size allocated to the task.
priorityTask priority.

Definition at line 22 of file FrameworkApp.cpp.

23 : FrameworkController(name, router, stackSize, priority),
24 router(),
25 server(port, router),
26 manager(this, router)
27{
28 manager.start();
29}
HttpServer server
Embedded HTTP server instance.
Router router
Router instance for handling HTTP routes.
FrameworkManager manager
Responsible for launching system services and networking.
Base class for event-driven control logic in embedded applications.
bool start()
Starts the task via FreeRTOS.

References manager, and FrameworkTask::start().

+ Here is the call graph for this function:

◆ ~FrameworkApp()

virtual FrameworkApp::~FrameworkApp ( )
virtualdefault

Allows derived classes to clean up resources.

Member Function Documentation

◆ initRoutes()

virtual void FrameworkApp::initRoutes ( )
inlineprotectedvirtual

You must implement this method in your subclass. Define your routes here using router.addRoute(...). This centralizes route logic and ensures all endpoints are registered before the server runs.

Example:

router.addRoute("GET", "/", [](HttpRequest& req, HttpResponse& res, const std::vector<std::string>&) {
res.send("Hello from root!");
});
Forward declaration for potential routing needs.
Definition HttpRequest.h:32
Represents an HTTP response object.
void send(const std::string &body)
Send a full response including headers and body.
void addRoute(const std::string &method, const std::string &path, RouteHandler handler, std::vector< Middleware > middleware={})
Register a route with optional middleware.
Definition Router.cpp:144

Or bind member functions:

router.addRoute("GET", "/status",
std::bind(&MyApp::handleStatus, this, _1, _2, _3));

Reimplemented from FrameworkController.

Reimplemented in App.

Definition at line 111 of file FrameworkApp.h.

111{} // Default no-op

◆ onStart()

void FrameworkApp::onStart ( )
overridevirtual

This is called by the FrameworkApp::start() method once the FreeRTOS task has been created and is ready to run. It calls the base class onStart() method to ensure that routes are initialized before the server starts accepting requests.

Reimplemented from FrameworkController.

Definition at line 37 of file FrameworkApp.cpp.

38{
39 FrameworkController::onStart(); // Call base class start logic (including any route initialization)
40}
virtual void onStart()
Called once at task start before entering the main loop.

References FrameworkController::onStart().

Referenced by App::onStart().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start()

void FrameworkApp::start ( )
virtual

Initializes the application and its framework services.

This method is responsible for setting up the application and preparing it to handle incoming requests. It usually includes:

  • Starting the FrameworkManager (network and service initialization)
  • Setting up logging or middleware
  • Any other application-specific initialization

It is typically called before run() to ensure the application is fully ready before entering the main loop.

This method is responsible for setting up the application and preparing it to handle incoming requests. It usually includes:

  • Starting the FrameworkManager (network and service initialization)
  • Setting up logging or middleware
  • Any other application-specific initialization

It is typically called before run() to ensure the application is fully ready before entering the main loop.

Definition at line 32 of file FrameworkApp.cpp.

33{
34 FrameworkController::start(); // Start this app's task and calls run(), you are safely in the FreeRTOS task context in run())
35}

References FrameworkTask::start().

Referenced by FrameworkManager::onStart().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ manager

FrameworkManager FrameworkApp::manager
protected

Definition at line 116 of file FrameworkApp.h.

Referenced by FrameworkApp().

◆ router

Router FrameworkApp::router
protected

Definition at line 114 of file FrameworkApp.h.

Referenced by App::initRoutes(), and App::onStart().

◆ server

HttpServer FrameworkApp::server
protected

Definition at line 115 of file FrameworkApp.h.

Referenced by App::onEvent().


The documentation for this class was generated from the following files: