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 
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 serializeTo(Fw::SerializeBufferBase& buffer) const = 0;
81 
95 };
96 
97 class RawTime final : public RawTimeInterface {
98  public:
99  RawTime();
100  ~RawTime() final;
101 
103  RawTime(const RawTime& other);
104 
106  RawTime& operator=(const RawTime& other);
107 
110  RawTimeHandle* getHandle() override;
111 
112  // ------------------------------------------------------------
113  // Implementation-specific RawTime member functions
114  // ------------------------------------------------------------
115 
122  Status now() override;
123 
132  Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const override;
133 
147 
161 
162  // ------------------------------------------------------------
163  // Common functions built on top of OS-specific functions
164  // ------------------------------------------------------------
165 
178  Status getDiffUsec(const RawTime& other, U32& result) const;
179 
181  bool operator==(const RawTime& other) const;
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
PlatformSizeType FwSizeType
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
Status now() override
Get the current time.
Definition: RawTime.cpp:36
virtual Fw::SerializeStatus deserializeFrom(Fw::SerializeBufferBase &buffer)=0
Deserialize the contents of the RawTimeInterface object from a buffer.
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
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition: FpConfig.h:322
virtual Fw::SerializeStatus serializeTo(Fw::SerializeBufferBase &buffer) const =0
Serialize the contents of the RawTimeInterface object into a buffer.
SerializeStatus
forward declaration for string
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
bool operator==(const RawTime &other) const
Compare whether two RawTime objects are the same (i.e. refer to the same microsecond) ...
Definition: RawTime.cpp:80
~RawTime() final
Destructor.
Definition: RawTime.cpp:14
#define FW_RAW_TIME_SERIALIZATION_MAX_SIZE
Maximum allowed serialization size for Os::RawTime objects.
Definition: FpConfig.h:306
Fw::SerializeStatus deserializeFrom(Fw::SerializeBufferBase &buffer) override
Deserialize the contents of the RawTimeInterface object from a buffer.
Definition: RawTime.cpp:51
Fw::SerializeStatus serializeTo(Fw::SerializeBufferBase &buffer) const override
Serialize the contents of the RawTimeInterface object into a buffer.
Definition: RawTime.cpp:46
RawTimeInterface()=default
default constructor
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
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
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