Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into toolchain-2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
meyerj committed Apr 28, 2017
2 parents a35b2fb + 82d61af commit f2ccf6f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
4 changes: 1 addition & 3 deletions helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ IF ( BUILD_HELLOWORLD )
FILE( GLOB SRCS [^.]*.cpp )
FILE( GLOB HPPS [^.]*.hpp )

ADD_EXECUTABLE( helloworld ${SRCS} )
orocos_configure_executable( helloworld )

orocos_executable( helloworld ${SRCS} )
orocos_component( orocos-ocl-helloworld ${SRCS} )
SET_TARGET_PROPERTIES( orocos-ocl-helloworld PROPERTIES
SOVERSION ${OCL_SOVERSION}
Expand Down
57 changes: 56 additions & 1 deletion ocl/OSService.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

#include <rtt/os/fosi.h>
#include <rtt/Service.hpp>
#include <rtt/plugin/ServicePlugin.hpp>
#include <cstdlib>

#ifndef WIN32
#include <sys/wait.h>
#endif

// setEnvString and isEnv needed to be implemented because we
// can't provide a getenv() implementation on windows without leaking
Expand Down Expand Up @@ -80,6 +83,14 @@ namespace OCL
"The name of the environment variable to write.").arg("value","The text to set.");
addOperation("argc", &OSService::argc, this).doc("Returns the number of arguments, given to this application.");
addOperation("argv", &OSService::argv, this).doc("Returns the arguments as a sequence of strings, given to this application.");
addOperation("sleep", &OSService::sleep, this).doc("Suspend execution of the calling thread")
.arg("seconds", "Sleep for x seconds");
addOperation("usleep", &OSService::usleep, this).doc("Suspend execution of the calling thread")
.arg("microseconds", "Sleep for x microseconds");
addOperation("nanosleep", &OSService::nanosleep, this).doc("Suspend execution of the calling thread")
.arg("seconds", "Sleep for x seconds")
.arg("nanoseconds", "Sleep for x nanoseconds");
addOperation("execute", &OSService::execute, this).doc("Execute a shell command");
}

int argc(void)
Expand All @@ -101,14 +112,58 @@ namespace OCL
{
return getEnvString(arg.c_str());
}

bool isenv(const std::string& arg)
{
return isEnv(arg.c_str());
}

bool setenv(const std::string& arg, const std::string& value)
{
return ::setenv(arg.c_str(), value.c_str(), 1) == 0;
}

int sleep(unsigned int seconds)
{
TIME_SPEC rqtp, rmtp;
rqtp.tv_sec = seconds;
rqtp.tv_nsec = 0;
return rtos_nanosleep(&rqtp, &rmtp);
}

int usleep(unsigned int microseconds)
{
TIME_SPEC rqtp, rmtp;
rqtp.tv_sec = (microseconds / 1000000u);
rqtp.tv_nsec = (microseconds % 1000000u) * 1000u;
return rtos_nanosleep(&rqtp, &rmtp);
}

int nanosleep(unsigned int seconds, unsigned int nanoseconds)
{
TIME_SPEC rqtp, rmtp;
rqtp.tv_sec = seconds;
rqtp.tv_nsec = nanoseconds;
return rtos_nanosleep(&rqtp, &rmtp);
}

int execute(const std::string& command)
{
#ifdef WIN32
return system(command.c_str());
#else
int status = system(command.c_str());
if (status < 0) {
return status;
} else {
if (!WIFEXITED(status)) {
return -1;
} else {
return WEXITSTATUS(status);
}
}
#endif
}
};
}

Expand Down

0 comments on commit f2ccf6f

Please sign in to comment.