Skip to content

Instantly share code, notes, and snippets.

@pattacini
Last active March 30, 2017 20:02
Show Gist options
  • Save pattacini/6572864f8ec97c7f4639 to your computer and use it in GitHub Desktop.
Save pattacini/6572864f8ec97c7f4639 to your computer and use it in GitHub Desktop.
yarp,testIsRunning
# Copyright: (C) 2016 iCub Facility - Istituto Italiano di Tecnologia
# Author: Ugo Pattacini <ugo.pattacini@iit.it>
# CopyPolicy: Released under the terms of the GNU GPL v2.0.
cmake_minimum_required(VERSION 2.6)
set(PROJECTNAME testIsRunning)
project(${PROJECTNAME})
find_package(YARP)
list(APPEND CMAKE_MODULE_PATH ${YARP_MODULE_PATH})
find_package(ICUBcontrib)
list(APPEND CMAKE_MODULE_PATH ${ICUBCONTRIB_MODULE_PATH})
include(ICUBcontribHelpers)
include(ICUBcontribOptions)
icubcontrib_set_default_prefix()
set(sources main.cpp)
source_group("Source Files" FILES ${sources})
include_directories(${YARP_INCLUDE_DIRS})
add_executable(${PROJECTNAME} ${sources})
target_link_libraries(${PROJECTNAME} ${YARP_LIBRARIES})
/*
* Copyright (C) 2016 iCub Facility - Istituto Italiano di Tecnologia
* Author: Ugo Pattacini
* email: ugo.pattacini@iit.it
* Permission is granted to copy, distribute, and/or modify this program
* under the terms of the GNU General Public License, version 2 or any
* later version published by the Free Software Foundation.
*
* A copy of the license can be found at
* http://www.robotcub.org/icub/license/gpl.txt
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details
*/
#include <cstdio>
#include <yarp/os/all.h>
using namespace yarp::os;
class TestThread : public RateThread
{
double t0;
bool justStopped;
public:
TestThread() : RateThread(1000)
{
t0=Time::now();
justStopped=false;
}
void run()
{
printf("running...\n");
if ((Time::now()-t0>5.0) && !justStopped)
{
askToStop();
justStopped=true;
printf("stopped!\n");
}
}
};
class TestModule: public RFModule
{
TestThread test;
public:
bool configure(ResourceFinder &rf)
{
printf("isRunning()==%s\n",test.isRunning()?"true":"false");
bool ret=test.start();
printf("start()==%s\n",ret?"true":"false");
printf("isRunning()==%s\n",test.isRunning()?"true":"false");
return true;
}
bool close()
{
test.stop();
return true;
}
double getPeriod()
{
return 1.0;
}
bool updateModule()
{
if (!test.isRunning())
{
printf("isRunning()==%s\n",test.isRunning()?"true":"false");
bool ret=test.start();
printf("start()==%s\n",ret?"true":"false");
printf("isRunning()==%s\n",test.isRunning()?"true":"false");
}
return true;
}
};
int main()
{
Network yarp;
if (!yarp.checkNetwork())
return 1;
TestModule mod;
ResourceFinder rf;
return mod.runModule(rf);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment