Files
MuditaOS/module-sys/Service/Timer.hpp
Roman Kubiak b4814861b0 [EGD-4318] enable service desktop (#973)
* [EGD-3688] Relax retries count for send
enable ServiceDesktop

* [EGD-3688] Relax retries count for send
enable ServiceDesktop

* [EGD-4318] enable service desktop and USB communication
CDC for serial port (communication with Mudita Center)
MTP for file transfer

* [EGD-4318] include path fix

* [egd-4318] constexpr brought back

* [EGD-4318]: review changes
- all BSP specific code moved to bsp files
- added a device listener class for USB
- simplified WorkerDesktop

* [EGD-4318] more reivew fixes mostly include paths and enums

* [EGD-4319] review fixes for SP2FET

* [EGD-4318] updates for large messages sent from phone

* [EGD-4318] more review fixes
- error checks on linux (ptms open and ptsname)
- removed all vfs
- service-desktop won't start if worker init fails

* [EGD-4318] updated return values for usbInit

* Update module-services/service-desktop/WorkerDesktop.cpp

Co-authored-by: Piotr Tanski <piotr.tanski@mudita.com>

* Update module-services/service-desktop/endpoints/update/UpdateMuditaOS.hpp

Co-authored-by: Piotr Tanski <piotr.tanski@mudita.com>

* [EGD-4318] review fixes
- removed #define
- return values for usbInit

* Update module-bsp/board/linux/usb_cdc/usb_cdc.cpp

Co-authored-by: Piotr Tanski <piotr.tanski@mudita.com>

* [EGD-4318] updated taglib

* [EGD-4318] style fixes

* Update module-bsp/board/linux/usb_cdc/usb_cdc.cpp

Co-authored-by: Alek Rudnik <54846206+alekrudnik@users.noreply.github.com>

* [EGD-4318] switches from freertos Timer class to sys::Timer

* Update module-services/service-desktop/WorkerDesktop.cpp

Co-authored-by: Piotr Tanski <piotr.tanski@mudita.com>

* Update module-services/service-desktop/WorkerDesktop.cpp

Co-authored-by: Piotr Tanski <piotr.tanski@mudita.com>

* [EGD-4318] added mutex/lock during raw data transfers

* [EGD-4318] if the TAR file is zero size or invalid
mtar_close causes HF. This is a workaround

* [EGD-4318] timer should not start on constructor

* [EGD-4318] getRawMode is const noecept

Co-authored-by: unknown <atom@prostate.local>
Co-authored-by: Piotr Tanski <piotr.tanski@mudita.com>
Co-authored-by: Alek Rudnik <54846206+alekrudnik@users.noreply.github.com>
2020-11-19 17:44:23 +01:00

86 lines
2.5 KiB
C++

// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
#include "FreeRTOS.h"
#include "portmacro.h" // for TickType_t
#include <module-os/RTOSWrapper/include/timer.hpp> // for Timer
#include <functional> // for function
#include <string> // for string
namespace sys
{
class Service;
} // namespace sys
namespace sys
{
using ms = unsigned int;
/// Base timer for all coarse timers in system
class Timer : public cpp_freertos::Timer
{
public:
static const ms timeout_infinite;
enum class Type
{
Periodic,
SingleShot
};
/// Create named timer and register it in parent
/// @param name this will be name of timer + postfix
/// @param parent service on which behalf timer events will be sent and received
/// @param interval time for next timer event in
Timer(const std::string &name, Service *parent, ms interval, Type type = Type::Periodic);
/// Create timer with default name `_<id_number>` and register it in parent
/// @param parent service on which behalf timer events will be sent and received
/// @param interval time for next timer event in
Timer(Service *parent, ms interval, Type type = Type::Periodic);
Timer() = delete;
Timer(const Timer &) = delete;
Timer operator=(const Timer &) = delete;
/// just to stop timer
~Timer() override;
/// This is final by design - to avoid missuse we send Timer notification to Service
/// and then handle it like any other event. Not by callback as this could cause unrestricted access (no mutex)
void Run() final;
/// executed when we receive timeout notification (from overriden Run()) on bus
void onTimeout();
/// @defgroup API
/// {
void start();
void reload(ms from_time = 0);
void stop();
void setInterval(ms new_interval);
/// }
protected:
Service *parent = nullptr;
private:
Type type;
ms interval;
std::function<void(Timer &)> callback = nullptr;
const std::string name;
public:
void connect(std::function<void(Timer &)> new_callback)
{
callback = new_callback;
}
[[nodiscard]] constexpr auto getName() const -> const std::string &
{
return name;
}
};
}; // namespace sys