From 10a0f86449b0add770be0baf71144ff8c7d3ede0 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sun, 3 Aug 2014 19:27:14 +0200 Subject: [PATCH] CComponents: add new header file cc_signals.h with some basic members Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/47315210708628954a332319443874a726c917a0 Author: Thilo Graf Date: 2014-08-03 (Sun, 03 Aug 2014) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/gui/components/Makefile.am | 3 +- src/gui/components/cc_base.h | 3 +- src/gui/components/cc_signals.h | 89 +++++++++++++++++++++++++++ src/gui/components/cc_timer.cpp | 104 ++++++++++++++++++++++++++++++++ src/gui/components/cc_timer.h | 69 +++++++++++++++++++++ 5 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 src/gui/components/cc_signals.h create mode 100644 src/gui/components/cc_timer.cpp create mode 100644 src/gui/components/cc_timer.h diff --git a/src/gui/components/Makefile.am b/src/gui/components/Makefile.am index 1e618566b..d34b274af 100644 --- a/src/gui/components/Makefile.am +++ b/src/gui/components/Makefile.am @@ -44,4 +44,5 @@ libneutrino_gui_components_a_SOURCES = \ cc_item_progressbar.cpp \ cc_item_shapes.cpp \ cc_item_text.cpp \ - cc_item_tvpic.cpp + cc_item_tvpic.cpp \ + cc_timer.cpp diff --git a/src/gui/components/cc_base.h b/src/gui/components/cc_base.h index d1b7ebb04..106d11c2e 100644 --- a/src/gui/components/cc_base.h +++ b/src/gui/components/cc_base.h @@ -27,6 +27,7 @@ #define __COMPONENTS__ #include "cc_types.h" +#include "cc_signals.h" #include #include #include @@ -38,7 +39,7 @@ Basic attributes and member functions for component sub classes */ -class CComponents : public COSDFader +class CComponents : public CComponentsSignals, public COSDFader { private: ///pixel buffer handling, returns pixel buffer depends of given parameters diff --git a/src/gui/components/cc_signals.h b/src/gui/components/cc_signals.h new file mode 100644 index 000000000..795dd92ef --- /dev/null +++ b/src/gui/components/cc_signals.h @@ -0,0 +1,89 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Classes for generic GUI-related components. + Copyright (C) 2013, Thilo Graf 'dbt' + + License: GPL + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/// Basic CComponentSignals class header. +/*! +Basic signal declarations for component sub classes + +This class provides some general declarations of signals based up libsigc++. +For more details see: http://libsigc.sourceforge.net/doc.shtml + +If you want to use a signal in a class, some steps are required +example: + +#include + +class CYourClass : sigc::trackable //<- not forget, requierd by destructor! +{ + public: + CYourClass(); + ~CYourClass(); + + //...your other stuff + + //here is the member we will connect to a signal, here we have a member with one parameter (void*) + void DoThis(void* arg) + { + //do something here + }; + + //this is the member we will use to connect with a signal + void RunExample() + { + CReceiverClass receiver; + //this object contains the member in which is placed a signal, here: OnBeforePaint + //note: OnBeforePaint is already inherited, if you use any CComponent Class. Otherwise, it must be done separatly + //eg: class CNotACComponentClass : public CComponentSignals + //this also handles the derivation of sigc::trackable + + // here we use a void* parameter, can be filled with any stuff you can cast, you can use also other types + void *vptr = yourStuff; + + //now we create a slot... + sigc::slot0 sl = sigc::bind<0>(sigc::mem_fun1(*this, &CYourClass::DoThis), vptr); + + //...and connect with signal in the receiver object + receiver.OnBeforePaint.connect(sl); + + //thats' all. If DoThis(bla) is connected, OnBeforePaint is doing the same like the DoThis(), but in the foreign object + }; +}; +*/ + +#ifndef __CC_SIGNALS_H__ +#define __CC_SIGNALS_H____ + +#include + + +class CComponentsSignals : public sigc::trackable +{ + public: + CComponentsSignals(){}; + + sigc::signal OnBeforePaint; + sigc::signal OnAfterPaint; +}; + + +#endif diff --git a/src/gui/components/cc_timer.cpp b/src/gui/components/cc_timer.cpp new file mode 100644 index 000000000..7fd27fd62 --- /dev/null +++ b/src/gui/components/cc_timer.cpp @@ -0,0 +1,104 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Generic Timer. + Copyright (C) 2013, Thilo Graf 'dbt' + + License: GPL + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include "cc_timer.h" +#include +#include +#include + +using namespace std; + +CComponentsTimer::CComponentsTimer( const int& interval) +{ + tm_thread = 0; + tm_interval = interval; + if (startTimer()) + printf("[CComponentsTimer] [%s] timer started\n", __func__); +} + +CComponentsTimer::~CComponentsTimer() +{ + if (stopTimer()) + printf("[CComponentsTimer] [%s] timer stopped\n", __func__); +} + +//thread handle +void* CComponentsTimer::initTimerThread(void *arg) +{ + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,0); + pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS,0); + + CComponentsTimer *timer = static_cast(arg); + + //start loop + while(timer) { + timer->OnTimer(); + mySleep(timer->tm_interval); + } + + return 0; +} + +//start up running timer with own thread, return true on succses +bool CComponentsTimer::startTimer() +{ + void *ptr = static_cast(this); + + if(!tm_thread) { + int res = pthread_create (&tm_thread, NULL, initTimerThread, ptr) ; + if (res != 0){ + printf("[CComponentsTimer] [%s] pthread_create %s\n", __func__, strerror(errno)); + return false; + } + } + printf("[CComponentsTimer] [%s] timer thread [%lu] created with interval = %d\n", __func__, tm_thread, tm_interval); + return true; +} + +//stop ticking timer and kill thread, return true on succses +bool CComponentsTimer::stopTimer() +{ + int thres = 0; + if(tm_thread) { + thres = pthread_cancel(tm_thread); + printf("[CComponentsTimer] [%s] waiting for timer thread terminate ...\n", __func__); + if (thres != 0) + printf("[CComponentsTimer] [%s] pthread_cancel %s\n", __func__, strerror(errno)); + thres = pthread_join(tm_thread, NULL); + if (thres != 0) + printf("[CComponentsTimer] [%s] pthread_join %s\n", __func__, strerror(errno)); + } + if (thres == 0){ + tm_thread = 0; + return true; + } + + return false; +} diff --git a/src/gui/components/cc_timer.h b/src/gui/components/cc_timer.h new file mode 100644 index 000000000..b313dcb01 --- /dev/null +++ b/src/gui/components/cc_timer.h @@ -0,0 +1,69 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Classes for generic GUI-related components. + Copyright (C) 2013, Thilo Graf 'dbt' + + License: GPL + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + 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. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __CC_TIMER__ +#define __CC_TIMER__ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +//! Member of CComponents. Provides a generic timer class +/*! + +*/ + +class CComponentsTimer : public sigc::trackable +{ + private: + ///thread + pthread_t tm_thread; + ///refresh interval in seconds + int tm_interval; + ///init function to start timer in own thread + static void* initTimerThread(void *arg); + + public: + ///class constructor, parameter interval sets the interval in seconds, default value=1 (1 sec) + CComponentsTimer(const int& interval = 1); + ~CComponentsTimer(); + + ///start timer thread, returns true on success, if false causes log output + bool startTimer(); + ///stop timer thread, returns true on success, if false causes log output + bool stopTimer(); + + ///returns true, if timer is running in thread + bool isRun() const {return tm_thread == 0 ? false:true;}; + ///set another interval in seconds + void setTimerIntervall(const int& seconds){tm_interval = seconds;}; + + ///signal for timer event, use this in your class where ever you need time controled actions + ///for more details see also CComponentsSignals for similar handlings + sigc::signal OnTimer; +}; + +#endif