F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
RawTime.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/RawTime.hpp
3 // \brief common definitions for Os::RawTime
4 // ======================================================================
5 #ifndef OS_RAWTIME_HPP_
6 #define OS_RAWTIME_HPP_
7 
8 #include <FpConfig.hpp>
10 #include <Fw/Time/TimeInterval.hpp>
11 #include <Os/Os.hpp>
12 
13 
14 namespace Os {
15 
16 struct RawTimeHandle {};
17 
18 class RawTime; // Forward declaration
19 
21 
22  public:
23 
24  // Serialization size for RawTime objects, configured in config/FpConfig.h
26 
27  enum Status {
32  };
33 
35  RawTimeInterface() = default;
36 
38  virtual ~RawTimeInterface() = default;
39 
42  virtual RawTimeHandle* getHandle() = 0;
43 
45  static RawTimeInterface* getDelegate(RawTimeHandleStorage& aligned_new_memory, const RawTimeInterface* to_copy=nullptr);
46 
47  // ------------------------------------------------------------------
48  // RawTime operations to be implemented by an OSAL implementation
49  // ------------------------------------------------------------------
50 
57  virtual Status now() = 0;
58 
67  virtual Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const = 0;
68 
82 
96 
97 };
98 
99 class RawTime final : public RawTimeInterface {
100  public:
101  RawTime();
102  ~RawTime() final;
103 
105  RawTime(const RawTime& other);
106 
108  RawTime& operator=(const RawTime& other);
109 
112  RawTimeHandle* getHandle() override;
113 
114  // ------------------------------------------------------------
115  // Implementation-specific RawTime member functions
116  // ------------------------------------------------------------
117 
124  Status now() override;
125 
134  Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const override;
135 
148  Fw::SerializeStatus serialize(Fw::SerializeBufferBase& buffer) const override;
149 
163 
164  // ------------------------------------------------------------
165  // Common functions built on top of OS-specific functions
166  // ------------------------------------------------------------
167 
180  Status getDiffUsec(const RawTime& other, U32& result) const;
181 
182 
183  private:
184  // This section is used to store the implementation-defined RawTime handle. To Os::RawTime and fprime, this type is
185  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store the handle in
186  // the byte-array here and set `m_handle_storage` to that address for storage.
187  //
188  alignas(FW_HANDLE_ALIGNMENT) RawTimeHandleStorage m_handle_storage;
189  RawTimeInterface& m_delegate;
190 };
191 } // namespace Os
192 
193 #endif
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition: FpConfig.h:440
#define FW_RAW_TIME_SERIALIZATION_MAX_SIZE
Maximum allowed serialization size for Os::RawTime objects.
Definition: FpConfig.h:424
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
C++-compatible configuration header for fprime configuration.
U8 RawTimeHandleStorage[FW_RAW_TIME_HANDLE_MAX_SIZE]
Definition: Os.hpp:20
forward declaration
RawTimeHandle * getHandle() override
return the underlying RawTime handle (implementation specific)
Definition: RawTime.cpp:31
RawTime()
Constructor.
Definition: RawTime.cpp:10
~RawTime() final
Destructor.
Definition: RawTime.cpp:14
Status getDiffUsec(const RawTime &other, U32 &result) const
Calculate the difference in microseconds between two RawTime objects.
Definition: RawTime.cpp:56
Status now() override
Get the current time.
Definition: RawTime.cpp:36
Status getTimeInterval(const Os::RawTime &other, Fw::TimeInterval &interval) const override
Calculate the time interval between this and another raw time.
Definition: RawTime.cpp:41
RawTime & operator=(const RawTime &other)
assignment operator that copies the internal representation
Definition: RawTime.cpp:24
Fw::SerializeStatus serialize(Fw::SerializeBufferBase &buffer) const override
Serialize the contents of the RawTimeInterface object into a buffer.
Definition: RawTime.cpp:46
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase &buffer) override
Deserialize the contents of the RawTimeInterface object from a buffer.
Definition: RawTime.cpp:51
static const FwSizeType SERIALIZED_SIZE
Definition: RawTime.hpp:25
RawTimeInterface()=default
default constructor
@ INVALID_PARAMS
Parameters invalid for current platform.
Definition: RawTime.hpp:30
@ OP_OK
Operation was successful.
Definition: RawTime.hpp:28
@ OTHER_ERROR
All other errors.
Definition: RawTime.hpp:31
@ OP_OVERFLOW
Operation result caused an overflow.
Definition: RawTime.hpp:29
virtual ~RawTimeInterface()=default
default virtual destructor
virtual Status getTimeInterval(const Os::RawTime &other, Fw::TimeInterval &interval) const =0
Calculate the time interval between this and another raw time.
virtual RawTimeHandle * getHandle()=0
return the underlying RawTime handle (implementation specific)
virtual Status now()=0
Get the current time.
static RawTimeInterface * getDelegate(RawTimeHandleStorage &aligned_new_memory, const RawTimeInterface *to_copy=nullptr)
provide a pointer to a RawTime delegate object
virtual Fw::SerializeStatus serialize(Fw::SerializeBufferBase &buffer) const =0
Serialize the contents of the RawTimeInterface object into a buffer.
virtual Fw::SerializeStatus deserialize(Fw::SerializeBufferBase &buffer)=0
Deserialize the contents of the RawTimeInterface object from a buffer.
SerializeStatus
forward declaration for string