iri_base_driver.cpp
Go to the documentation of this file.
00001 #include "iri_base_driver/iri_base_driver.h"
00002 
00003 namespace iri_base_driver
00004 {
00005 
00006 IriBaseDriver::IriBaseDriver() : driver_id_("none")
00007 {
00008   pthread_mutex_init(&this->access_,NULL);
00009 }
00010 
00011 void IriBaseDriver::lock(void)
00012 {
00013   pthread_mutex_lock(&this->access_);
00014 }
00015 
00016 void IriBaseDriver::unlock(void)
00017 {
00018   pthread_mutex_unlock(&this->access_);
00019 }
00020 
00021 bool IriBaseDriver::try_enter(void)
00022 {
00023   if(pthread_mutex_trylock(&this->access_)==0)
00024     return true;
00025   else
00026     return false;
00027 }
00028 
00029 void IriBaseDriver::setDriverId(const std::string & id)
00030 {
00031   driver_id_ = id;
00032 }
00033 
00034 void IriBaseDriver::doOpen(void)
00035 {
00036   if(openDriver()) this->state_ = OPENED;
00037 }
00038 
00039 void IriBaseDriver::doClose(void)
00040 {
00041   this->preCloseHook();
00042   if(closeDriver()) this->state_ = CLOSED;
00043 }
00044 
00045 void IriBaseDriver::doStart(void)
00046 {
00047   if(startDriver()) this->state_ = RUNNING;
00048 }
00049 
00050 void IriBaseDriver::doStop(void)
00051 {
00052   if(stopDriver()) this->state_ = OPENED;
00053 }
00054 
00055 std::string IriBaseDriver::getID(void)
00056 {
00057   return driver_id_;
00058 }
00059 
00060 void IriBaseDriver::setPreCloseHook(hookFunction f)
00061 {
00062   preCloseHook = f;
00063 }
00064 
00065 IriBaseDriver::~IriBaseDriver()
00066 {
00067   pthread_mutex_destroy(&this->access_);
00068 }
00069 
00070 }


iri_base_driver
Author(s): Joan Perez, jnperez at iri.upc.edu
autogenerated on Fri Dec 6 2013 19:58:57