libUTL++
HostOS.h
1 #pragma once
2 
4 
5 #include <libutl/Array.h>
6 #include <libutl/Pathname.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
21 
23 class HostOS : public Object
24 {
27 
28 public:
30  virtual char getPathSeparator() const = 0;
31 
36  virtual void chdir(const Pathname& path) = 0;
37 
39  virtual void daemonInit() = 0;
40 
42 
43 
49  virtual int run(const Pathname& path, const TArray<String>& args) = 0;
50 
59  int run(const String& cmd);
61 
63 
64 
65  void
66  msleep(uint64_t msec) const
67  {
68  usleep(msec * (uint64_t)1000);
69  }
70 
72  virtual void sleep(uint_t sec) const = 0;
73 
75  void
76  sleep(uint_t sec, uint_t usec) const
77  {
78  sleep(sec);
79  usleep(usec);
80  }
81 
83  virtual void usleep(uint64_t usec) const = 0;
84 
86  virtual void yield() const;
88 
90 
91 
95  virtual String getEnv(const String& envVarName) const = 0;
96 
103  virtual String setEnv(const String& envVarName, const String& envVarVal) = 0;
104 
110  virtual String remEnv(const String& envVarName) = 0;
112 };
113 
115 
120 #if UTL_HOST_OS == UTL_OS_MINGW
121 class MinGWhostOS;
122 extern MinGWhostOS* hostOS;
123 #elif UTL_HOST_OS == UTL_OS_LINUX
124 class LinuxHostOS;
125 extern LinuxHostOS* hostOS;
126 #else
127 extern HostOS* hostOS;
128 #endif
129 
131 
132 UTL_NS_END;
133 
135 
136 #if UTL_HOST_OS == UTL_OS_MINGW
137 #include <libutl/MinGWhostOS.h>
138 #else
139 #include <libutl/LinuxHostOS.h>
140 #endif
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
Filesystem pathname.
Definition: Pathname.h:32
MinGW Host OS functionality.
Definition: MinGWhostOS.h:22
Character string.
Definition: String.h:31
Template version of Array.
Definition: TArray.h:25
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
void msleep(uint64_t msec) const
Sleep for the given number of milliseconds.
Definition: HostOS.h:66
Abstraction for common OS functionality.
Definition: HostOS.h:23
#define UTL_CLASS_DECL_ABC(DC, BC)
Declaration of standard UTL++ functionality for an abstract base class (ABC).
Definition: macros.h:650
void sleep(uint_t sec, uint_t usec) const
Sleep for the given number of seconds and microseconds.
Definition: HostOS.h:76
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Encapsulate common UNIX OS functionality.
Definition: LinuxHostOS.h:22
Root of UTL++ class hierarchy.
Definition: Object.h:52