mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
CComponents: add new header file cc_signals.h with some basic members
This commit is contained in:
@@ -44,4 +44,5 @@ libneutrino_gui_components_a_SOURCES = \
|
|||||||
cc_item_progressbar.cpp \
|
cc_item_progressbar.cpp \
|
||||||
cc_item_shapes.cpp \
|
cc_item_shapes.cpp \
|
||||||
cc_item_text.cpp \
|
cc_item_text.cpp \
|
||||||
cc_item_tvpic.cpp
|
cc_item_tvpic.cpp \
|
||||||
|
cc_timer.cpp
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#define __COMPONENTS__
|
#define __COMPONENTS__
|
||||||
|
|
||||||
#include "cc_types.h"
|
#include "cc_types.h"
|
||||||
|
#include "cc_signals.h"
|
||||||
#include <gui/widget/textbox.h>
|
#include <gui/widget/textbox.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -38,7 +39,7 @@
|
|||||||
Basic attributes and member functions for component sub classes
|
Basic attributes and member functions for component sub classes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CComponents : public COSDFader
|
class CComponents : public CComponentsSignals, public COSDFader
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
///pixel buffer handling, returns pixel buffer depends of given parameters
|
///pixel buffer handling, returns pixel buffer depends of given parameters
|
||||||
|
89
src/gui/components/cc_signals.h
Normal file
89
src/gui/components/cc_signals.h
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// 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 <sigc++/slot.h>
|
||||||
|
|
||||||
|
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<void> 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 <sigc++/signal.h>
|
||||||
|
|
||||||
|
|
||||||
|
class CComponentsSignals : public sigc::trackable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CComponentsSignals(){};
|
||||||
|
|
||||||
|
sigc::signal<void> OnBeforePaint;
|
||||||
|
sigc::signal<void> OnAfterPaint;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
104
src/gui/components/cc_timer.cpp
Normal file
104
src/gui/components/cc_timer.cpp
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
#include <neutrino.h>
|
||||||
|
|
||||||
|
#include "cc_timer.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <system/helpers.h>
|
||||||
|
|
||||||
|
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<CComponentsTimer*>(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<void*>(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;
|
||||||
|
}
|
69
src/gui/components/cc_timer.h
Normal file
69
src/gui/components/cc_timer.h
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CC_TIMER__
|
||||||
|
#define __CC_TIMER__
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sigc++/signal.h>
|
||||||
|
|
||||||
|
//! 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<void> OnTimer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user