17 if (GetEnvironmentVariable(name, c,
sizeof (c)) > 0) {
23 bool isEnv(
const char* name)
27 if (GetEnvironmentVariable(name, &c,
sizeof (c)) > 0)
return true;
31 int setenv(
const char *name,
const char *value,
int overwrite)
36 if (GetEnvironmentVariable(name, &c,
sizeof (c)) > 0)
return 0;
39 if (SetEnvironmentVariable(name, value) != 0)
return 0;
46 char* c = getenv(name);
48 return std::string(c);
53 if( getenv(name) )
return true;
73 doc(
"A service that provides access to some useful Operating System functions.");
76 "Returns the value of an environment variable. If it is not set, returns the empty string.").arg(
"name",
77 "The name of the environment variable to read.");
79 "Checks if an environment variable exists").arg(
"name",
80 "The name of the environment variable to check.");
82 "Sets an environment variable.").arg(
"name",
83 "The name of the environment variable to write.").arg(
"value",
"The text to set.");
87 .arg(
"seconds",
"Sleep for x seconds");
89 .arg(
"milliseconds",
"Sleep for x milliseconds");
91 .arg(
"microseconds",
"Sleep for x microseconds");
93 .arg(
"seconds",
"Sleep for x seconds")
94 .arg(
"nanoseconds",
"Sleep for x nanoseconds");
103 std::vector<std::string>
argv(
void)
107 std::vector<std::string> ret(a);
108 for (
int i = 0; i != a; ++i)
109 ret[i] = std::string(args[i]);
113 std::string
getenv(
const std::string& arg)
120 return isEnv(arg.c_str());
123 bool setenv(
const std::string& arg,
const std::string& value)
125 return ::setenv(arg.c_str(), value.c_str(), 1) == 0;
131 rqtp.tv_sec = seconds;
139 rqtp.tv_sec = (milliseconds / 1000u);
140 rqtp.tv_nsec = (milliseconds % 1000u) * 1000000u;
147 rqtp.tv_sec = (microseconds / 1000000u);
148 rqtp.tv_nsec = (microseconds % 1000000u) * 1000u;
152 int nanosleep(
unsigned int seconds,
unsigned int nanoseconds)
155 rqtp.tv_sec = seconds;
156 rqtp.tv_nsec = nanoseconds;
163 return system(command.c_str());
165 int status = system(command.c_str());
169 if (!WIFEXITED(status)) {
172 return WEXITSTATUS(status);
Variable opBinary s not applicable to args
int nanosleep(unsigned int seconds, unsigned int nanoseconds)
bool isEnv(const char *name)
int rtos_nanosleep(const TIME_SPEC *rqtp, TIME_SPEC *rmtp)
#define ORO_SERVICE_NAMED_PLUGIN(SERVICE, NAME)
Operation< Signature > & addOperation(Operation< Signature > &op)
bool setenv(const std::string &arg, const std::string &value)
int usleep(unsigned int microseconds)
std::vector< std::string > argv(void)
char ** __os_main_argv(void)
int millisleep(unsigned int milliseconds)
bool isenv(const std::string &arg)
const std::string & doc() const
int execute(const std::string &command)
std::string getenv(const std::string &arg)
std::string getEnvString(const char *name)
int setenv(const char *name, const char *value, int overwrite)
int sleep(unsigned int seconds)
struct timespec TIME_SPEC
OSService(RTT::TaskContext *parent)