mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-04 05:06:58 -04:00
* [EGD-2306] DESKTOP application initial commit most of this code is foreign and unverified it's low level magic numbers for the platform on Linux i used PTY to simulate a serial line * [EGD-2306] Add contact-list and contact-count commands * [EGD-2306] Add command for geting contact by id and minor fixes * [EGD-2856][WIP] Add basic serial parser * [EGD-2855] Set usb device config buffer property cacheable * [EGD-2856] Separate handlers from fsms, add status codes * [EGD-2855] fd passed to state machine for linux renderer support * [EGD-2856] Fix warnings * [EGD-2855] New send task added and buffer queque * [EGD-2856] Add simple ServiceDesktop documentation * [EGD-2855] rt1051 worker refactor * [EGD-2855] Added service workers for desktop app. Changed linux USB driver mock up. Added queue name mapping for service workers. Added queue registry support (maybe redundant with mapping) * [EGD-2855] Added proper message pointer to queue send and memory free Added bsp driver namespace for linux and rt1051 * [EGD-2856] Major cleanup * [EGD-2856] Fix typo * [EGD-2856] Fix warnings * [EGD-2856] Delete recursive fsm calling to prevent stack overflow * [EGD-2856] Reduce http codes * [EGD-2856] Rename serial parser to parser * [EGD-2855] USB_CDC drives renames and cleanups Service Worker queue cleanups * [EGD-2855] Service Worker queue cleanups * [EGD2855] Fixed external driver import * [EGD-2856] Remove redundant message type * [EGD-2856] Switch on enums instead of ints, and other minor changes requested after code review * [EGD-2855] usb driver moved to bsp directory structure, pull request fixes * [EGD-2855] clang #include fix * [EGD-2856] Add tinyfsm as git submodule, update readme and minor fix Co-authored-by: rkubiak01 <56821808+rkubiak01@users.noreply.github.com> Co-authored-by: PrzeBrudny <60609703+PrzeBrudny@users.noreply.github.com>
97 lines
2.7 KiB
C++
97 lines
2.7 KiB
C++
/*
|
|
* @file Worker.hpp
|
|
* @author Robert Borzecki (robert.borzecki@mudita.com)
|
|
* @date 30 maj 2019
|
|
* @brief
|
|
* @copyright Copyright (C) 2019 mudita.com
|
|
* @details
|
|
*/
|
|
#ifndef MODULE_SYS_SERVICE_WORKER_HPP_
|
|
#define MODULE_SYS_SERVICE_WORKER_HPP_
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "Service.hpp"
|
|
|
|
namespace sys {
|
|
|
|
class WorkerQueueInfo {
|
|
public:
|
|
std::string name;
|
|
int elementSize;
|
|
int length;
|
|
};
|
|
|
|
struct WorkerCommand {
|
|
uint32_t command = 0;
|
|
uint32_t* data = NULL;
|
|
};
|
|
|
|
/*
|
|
* @brief Worker is a wrapper for freeRTOS task used to separate sysmanager environment from
|
|
* the rest of the system. Its purpose is to handle asynchronous events like IRQ or timers.
|
|
* Flow of creating worker is as follows:
|
|
* - create new Worker object and provide pointer to the service that owns the worker,
|
|
* - call init method and provide list of parameters to create queues. Those queues can be later
|
|
* used to wake up the worker.
|
|
* - call run method to start the worker.
|
|
* Flow for closing the worker is as follows:
|
|
* - call stop method - task will send a close confirmation to the service after exiting its main loop
|
|
* - call deinit to destroy all queues ued by the worker
|
|
* - delete the object.
|
|
*
|
|
*/
|
|
class Worker {
|
|
protected:
|
|
const static uint32_t SERVICE_QUEUE_LENGTH = 10;
|
|
const static uint32_t SERVICE_QUEUE_SIZE = sizeof( WorkerCommand );
|
|
const std::string SERVICE_QUEUE_NAME = "ServiceQueue";
|
|
|
|
sys::Service* service;
|
|
//queue used by service to send commands to service.
|
|
xQueueHandle serviceQueue;
|
|
std::vector<xQueueHandle> queues;
|
|
QueueSetHandle_t queueSet;
|
|
std::map<xQueueHandle, std::string> queueNameMap;
|
|
xTaskHandle taskHandle;
|
|
|
|
friend void workerTaskFunction(void *ptr);
|
|
|
|
public:
|
|
Worker( sys::Service* service );
|
|
virtual ~Worker();
|
|
|
|
/**
|
|
* This function is responsible for creating all queues provided in the constructor.
|
|
* When all queues are created this method creates set of queues.
|
|
*/
|
|
virtual bool init( std::list<WorkerQueueInfo> queues = std::list<WorkerQueueInfo>());
|
|
virtual bool deinit();
|
|
/**
|
|
* This method starts RTOS thread that waits for incomming queue events.
|
|
*/
|
|
virtual bool run();
|
|
/**
|
|
* Sends stop command to worker.
|
|
*/
|
|
virtual bool stop();
|
|
/**
|
|
* This method is called from thread when new message arrives in queue.
|
|
* @param queueID Index of the queue in the queues vector.
|
|
*/
|
|
virtual bool handleMessage( uint32_t queueID );
|
|
/**
|
|
* @brief Sends command and pointer to data to worker
|
|
*/
|
|
virtual bool send( uint32_t cmd, uint32_t* data );
|
|
/**
|
|
* @brief Returns handle to queue by its name
|
|
*/
|
|
virtual xQueueHandle getQueueByName(std::string);
|
|
};
|
|
|
|
} /* namespace sys */
|
|
|
|
#endif /* MODULE_SYS_SERVICE_WORKER_HPP_ */
|