2 #include <rtt/Service.hpp> 3 #include <rtt/plugin/ServicePlugin.hpp> 11 std::string getEnvString(
const char *name)
14 if (GetEnvironmentVariable(name, c,
sizeof (c)) > 0) {
20 bool isEnv(
const char* name)
24 if (GetEnvironmentVariable(name, &c,
sizeof (c)) > 0)
return true;
28 int setenv(
const char *name,
const char *value,
int overwrite)
33 if (GetEnvironmentVariable(name, &c,
sizeof (c)) > 0)
return 0;
36 if (SetEnvironmentVariable(name, value) != 0)
return 0;
40 std::string getEnvString(
const char *name)
43 char* c = getenv(name);
45 return std::string(c);
48 bool isEnv(
const char* name)
50 if( getenv(name) )
return true;
55 #include <rtt/os/startstop.h> 68 RTT::Service(
"os", parent)
70 doc(
"A service that provides access to some useful Operating System functions.");
72 addOperation(
"getenv", &OSService::getenv,
this).doc(
73 "Returns the value of an environment variable. If it is not set, returns the empty string.").arg(
"name",
74 "The name of the environment variable to read.");
75 addOperation(
"isenv", &OSService::isenv,
this).doc(
76 "Checks if an environment variable exists").arg(
"name",
77 "The name of the environment variable to check.");
78 addOperation(
"setenv", &OSService::setenv,
this).doc(
79 "Sets an environment variable.").arg(
"name",
80 "The name of the environment variable to write.").arg(
"value",
"The text to set.");
81 addOperation(
"argc", &OSService::argc,
this).doc(
"Returns the number of arguments, given to this application.");
82 addOperation(
"argv", &OSService::argv,
this).doc(
"Returns the arguments as a sequence of strings, given to this application.");
87 return __os_main_argc();
90 std::vector<std::string> argv(
void)
93 char** args = __os_main_argv();
94 std::vector<std::string> ret(a);
95 for (
int i = 0; i != a; ++i)
96 ret[i] = std::string(args[i]);
100 std::string getenv(
const std::string& arg)
102 return getEnvString(arg.c_str());
104 bool isenv(
const std::string& arg)
106 return isEnv(arg.c_str());
108 bool setenv(
const std::string& arg,
const std::string& value)
110 return ::setenv(arg.c_str(), value.c_str(), 1) == 0;
The Orocos Component Library.
A service that provides access to some useful Operating System functions.