9 #include <boost/thread/thread.hpp>
10 #include <boost/bind.hpp>
14 namespace cppexamples {
34 OpenRAVEExample(
const std::string& viewername=
"qtcoin") : _viewername(viewername), _bDestroyThread(false) {
36 GetSingleton() =
this;
37 signal(SIGINT,sigint_handler);
41 GetSingleton() = NULL;
43 if( _thopenrave.joinable() ) {
48 virtual int main(
int argc,
char ** argv)
56 if( _viewername.size() > 0 ) {
63 _bDestroyThread =
false;
64 _thopenrave = boost::thread(boost::bind(&OpenRAVEExample::_demothreadwrapper,
this,argc,argv));
77 return !_bDestroyThread;
81 _bDestroyThread =
true;
85 virtual void demothread(
int argc,
char ** argv) = 0;
92 std::string _viewername;
94 boost::thread _thopenrave;
96 void quitviewer(
void *) {
98 _viewer->quitmainloop();
102 void _demothreadwrapper(
int argc,
char ** argv) {
103 boost::shared_ptr<void> quitviewer((
void*)NULL, boost::bind(&OpenRAVEExample::quitviewer,
this,_1));
107 static void sigint_handler(
int sig)
109 if( !!OpenRAVEExample::GetSingleton() ) {
110 OpenRAVEExample::GetSingleton()->Exit();