F´ Flight Software - C/C++ Documentation
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>
11 #include <Os/Os.hpp>
12 
13 namespace Os {
14 
15 struct RawTimeHandle {};
16 
17 class RawTime; // Forward declaration
18 
20  public:
21  // Serialization size for RawTime objects, configured in config/FpConfig.h
23 
24  enum Status {
30  };
31 
33  RawTimeInterface() = default;
34 
36  virtual ~RawTimeInterface() = default;
37 
40  virtual RawTimeHandle* getHandle() = 0;
41 
43  static RawTimeInterface* getDelegate(RawTimeHandleStorage& aligned_new_memory,
44  const RawTimeInterface* to_copy = nullptr);
45 
46  // ------------------------------------------------------------------
47  // RawTime operations to be implemented by an OSAL implementation
48  // ------------------------------------------------------------------
49 
56  virtual Status now() = 0;
57 
66  virtual Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const = 0;
67 
80  virtual Fw::SerializeStatus serialize(Fw::SerializeBufferBase& buffer) const = 0;
81 
95 
96 };
97 
98 class RawTime final : public RawTimeInterface {
99  public:
100  RawTime();
101  ~RawTime() final;
102 
104  RawTime(const RawTime& other);
105 
107  RawTime& operator=(const RawTime& other);
108 
111  RawTimeHandle* getHandle() override;
112 
113  // ------------------------------------------------------------
114  // Implementation-specific RawTime member functions
115  // ------------------------------------------------------------
116 
123  Status now() override;
124 
133  Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const override;
134 
147  Fw::SerializeStatus serialize(Fw::SerializeBufferBase& buffer) const override;
148 
162 
163  // ------------------------------------------------------------
164  // Common functions built on top of OS-specific functions
165  // ------------------------------------------------------------
166 
179  Status getDiffUsec(const RawTime& other, U32& result) const;
180 
181 
182  private:
183  // This section is used to store the implementation-defined RawTime handle. To Os::RawTime and fprime, this type is
184  // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store the handle in
185  // the byte-array here and set `m_handle_storage` to that address for storage.
186  //
187  alignas(FW_HANDLE_ALIGNMENT) RawTimeHandleStorage m_handle_storage;
188  RawTimeInterface& m_delegate;
189 };
190 } // namespace Os
191 
192 #endif
Operation was successful.
Definition: RawTime.hpp:25
U8 RawTimeHandleStorage[FW_RAW_TIME_HANDLE_MAX_SIZE]
Definition: Os.hpp:20
virtual Status now()=0
Get the current time.
static const FwSizeType SERIALIZED_SIZE
Definition: RawTime.hpp:22
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
Status now() override
Get the current time.
Definition: RawTime.cpp:36
RawTime()
Constructor.
Definition: RawTime.cpp:10
static RawTimeInterface * getDelegate(RawTimeHandleStorage &aligned_new_memory, const RawTimeInterface *to_copy=nullptr)
provide a pointer to a RawTime delegate object
virtual ~RawTimeInterface()=default
default virtual destructor
virtual Fw::SerializeStatus serialize(Fw::SerializeBufferBase &buffer) const =0
Serialize the contents of the RawTimeInterface object into a buffer.
SerializeStatus
forward declaration for string
virtual Fw::SerializeStatus deserialize(Fw::SerializeBufferBase &buffer)=0
Deserialize the contents of the RawTimeInterface object from a buffer.
RawTimeHandle * getHandle() override
return the underlying RawTime handle (implementation specific)
Definition: RawTime.cpp:31
RawTime does not support operation.
Definition: RawTime.hpp:28
virtual RawTimeHandle * getHandle()=0
return the underlying RawTime handle (implementation specific)
Operation result caused an overflow.
Definition: RawTime.hpp:26
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase &buffer) override
Deserialize the contents of the RawTimeInterface object from a buffer.
Definition: RawTime.cpp:51
~RawTime() final
Destructor.
Definition: RawTime.cpp:14
C++-compatible configuration header for fprime configuration.
RawTimeInterface()=default
default constructor
#define FW_RAW_TIME_SERIALIZATION_MAX_SIZE
Maximum allowed serialization size for Os::RawTime objects.
Definition: FpConfig.h:424
Parameters invalid for current platform.
Definition: RawTime.hpp:27
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
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
forward declaration
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition: FpConfig.h:440
virtual Status getTimeInterval(const Os::RawTime &other, Fw::TimeInterval &interval) const =0
Calculate the time interval between this and another raw time.
Status getDiffUsec(const RawTime &other, U32 &result) const
Calculate the difference in microseconds between two RawTime objects.
Definition: RawTime.cpp:56