6 #ifndef IFW_CTD_SYSTEM_HPP_
7 #define IFW_CTD_SYSTEM_HPP_
13 #include "rad/Logger.hpp"
15 #include "ctd/defines/defines.hpp"
24 void Sleep(
const float sleep_time);
31 struct timespec& time_spec);
35 struct timeval& time_val);
38 std::string
IsoTime(
const double time_since_epoch,
39 const uint8_t prec = 6);
46 const std::string&
object,
47 const std::string& location);
53 std::string
GenUniqueId(
const std::string& prefix =
"");
56 int64_t
Random(
const int64_t min_val,
57 const int64_t max_val);
65 std::string
ExecCommand(
const std::string& command);
72 explicit Mutex(
const std::string&
id);
76 const std::string&
Id()
const;
78 void Lock(
bool& timed_out,
86 static bool s_initialized;
87 static bool s_debug_mode;
88 static pthread_mutex_t s_gen_mutex;
89 static void _take_gen_mutex();
90 static void _release_gen_mutex();
92 static std::map<std::string, std::shared_ptr<pthread_mutex_t> > s_mutexes;
95 pthread_mutex_t* m_sem_ptr;
100 namespace testUtils {
104 std::string
GetResDir(
const std::string& module_path,
105 const std::string& res_dir =
"test/resource");
109 const std::string& res_dir =
"test/resource");
115 #define BEGIN_CRIT_SEC(id) { \
116 ctd::system::Mutex tmpMutex(id); \
118 #define END_CRIT_SEC }
124 #endif // IFW_CTD_SYSTEM_HPP_
void Sleep(const float sleep_time)
Sleep.
Definition: system.cpp:19
int64_t Random(const int64_t min_val, const int64_t max_val)
Generate an int64_t random number in the inteval specified.
Definition: system.cpp:141
Mutex(const std::string &id)
Definition: system.cpp:199
void SecondsToTimeVal(const double time, struct timeval &time_val)
Convert time in seconds since epoch to timeval struct.
Definition: system.cpp:51
std::string GenUniqueId(const std::string &prefix="")
Generate a unique UUID based ID. A prefix may be prepended, if requested.
Definition: system.cpp:127
double Time()
Return the time in seconds since epoch.
Definition: system.cpp:32
optional bool timeout
Definition: requests.proto:13
void AssertPtr(const void *ptr, const std::string &object, const std::string &location)
Check if pointer is NULL. If yes, throw rad::Exception.
Definition: system.cpp:92
std::string GetResDir(const std::string &module_path, const std::string &res_dir="test/resource")
Derives the "resource" directory from the current working point.
Definition: system.cpp:318
base::threading::internal::NoMutex Mutex
Definition: easylogging++.h:1066
void SetRootEnvVars(const std::string &module_path, const std::string &res_dir="test/resource")
Set the root environment variables: CFGROOT, INTROOT, DATAROOT.
Definition: system.cpp:353
static void Clear()
Releases (deletes) all semaphores allocated. Use with caution!!
Definition: system.cpp:261
std::string ExecCommand(const std::string &command)
Execute a shell command (synchroneously).
Definition: system.cpp:168
void SecondsToTimeSpec(const double time, struct timespec &time_spec)
Convert time in seconds since epoch to a timespec struct.
Definition: system.cpp:42
std::string Platform()
Get the name of the platform (OS).
Definition: system.cpp:105
void Unlock()
Definition: system.cpp:302
void Lock(bool &timed_out, const double timeout=ctd::defines::NO_TIMEOUT)
Definition: system.cpp:268
const std::string & Id() const
Definition: system.cpp:312
std::string IsoTime(const double time_since_epoch, const uint8_t prec=6)
Generate ISO8601 timestamp from provided time in seconds since epoch.
Definition: system.cpp:60
~Mutex()
Definition: system.cpp:247
const int64_t NO_TIMEOUT
Definition: defines.hpp:206
std::string IsoTimeNow(const int8_t prec=6)
Generate ISO8601 timestamp from time of invoking this function.
Definition: system.cpp:85