19#ifndef DRUMSTICK_ALSATIMER_H
20#define DRUMSTICK_ALSATIMER_H
23 #include <alsa/asoundlib.h>
29#include <QReadWriteLock>
40#if defined(DRUMSTICK_STATIC)
41#define DRUMSTICK_ALSA_EXPORT
43#if defined(drumstick_alsa_EXPORTS)
44#define DRUMSTICK_ALSA_EXPORT Q_DECL_EXPORT
46#define DRUMSTICK_ALSA_EXPORT Q_DECL_IMPORT
70 explicit TimerInfo(
const snd_timer_info_t* other);
87 snd_timer_info_t *m_Info;
97 friend class TimerQuery;
98 friend class TimerGlobalInfo;
99 friend class QueueTimer;
104 explicit TimerId(
const snd_timer_id_t *other);
105 TimerId(
int cls,
int scls,
int card,
int dev,
int sdev);
123 snd_timer_id_t *m_Info;
138 friend class TimerQuery;
161 snd_timer_ginfo_t* m_Info;
173 TimerQuery(
const QString& deviceName,
int openMode);
174 TimerQuery(
const QString& deviceName,
int openMode, snd_config_t* conf);
182 void setGlobalParams(snd_timer_gparams_t* params);
183 void getGlobalParams(snd_timer_gparams_t* params);
184 void getGlobalStatus(snd_timer_gstatus_t* status);
191 snd_timer_query_t *m_Info;
208 explicit TimerParams(
const snd_timer_params_t* other);
228 snd_timer_params_t* m_Info;
243 explicit TimerStatus(
const snd_timer_status_t* other);
256 snd_timer_status_t* m_Info;
291 class TimerInputThread :
public QThread
295 TimerInputThread(
Timer* t,
int timeout)
301 virtual ~TimerInputThread() =
default;
309 QReadWriteLock m_mutex;
313 Timer(
int cls,
int scls,
int card,
int dev,
int sdev,
int openMode,
QObject* parent =
nullptr);
314 Timer(
const QString& deviceName,
int openMode,
QObject* parent =
nullptr);
315 Timer(
const QString& deviceName,
int openMode, snd_config_t* config,
QObject* parent =
nullptr);
332 void continueRunning();
334 void addAsyncTimerHandler(snd_async_callback_t callback,
void *private_data);
335 int getPollDescriptorsCount();
336 void pollDescriptors(
struct pollfd *pfds,
unsigned int space);
337 void pollDescriptorsRevents(
struct pollfd *pfds,
unsigned int nfds,
unsigned short *revents);
338 ssize_t read(
void *buffer,
size_t size);
339 snd_timer_t* getTimerHandle();
363 snd_async_handler_t *m_asyncHandler;
365 QPointer<TimerInputThread> m_thread;
368 QString m_deviceName;
369 snd_htimestamp_t m_last_time;
The QObject class is the base class of all Qt objects.
The QThread class provides platform-independent threads.
ALSA Timer events handler.
virtual void handleTimerEvent(int ticks, int msecs)=0
Timer event handler.
virtual ~TimerEventHandler()=default
Destructor.
Global timer information container.
unsigned int getFlags()
Gets the flags.
TimerGlobalInfo()
Default constructor.
unsigned int getClients()
Gets current timer clients.
int getSizeOfInfo() const
Gets the size of the ALSA timer global info object.
TimerGlobalInfo & operator=(const TimerGlobalInfo &other)
Assignment operator.
QString getId()
Gets the timer ID string.
unsigned long getMinResolution()
Gets timer minimal resolution in ns.
void setTimerId(const TimerId &tid)
Sets the timer identifier.
TimerGlobalInfo * clone()
Copy the current object.
TimerId & getTimerId()
Gets the timer identifier.
unsigned long getMaxResolution()
Gets timer maximal resolution in ns.
QString getName()
Gets the timer name.
int getCard()
Gets the card number.
unsigned long getResolution()
Gets the timer resolution in ns.
ALSA Timer identifier container.
int getDevice()
Gets the device number.
int getSlaveClass()
Gets the slave class.
int getSizeOfInfo() const
Gets the size of the ALSA timer ID object.
void setSubdevice(int subdevice)
Sets the subdevice number.
TimerId * clone()
Copy the object.
void setCard(int card)
Sets the card number.
int getClass()
Gets the class identifier.
TimerId & operator=(const TimerId &other)
Assignment operator.
int getSubdevice()
Gets the subdevice number.
void setClass(int devclass)
Set the class identifier.
void setSlaveClass(int devsclass)
Sets the Slave class.
int getCard()
Gets the card number.
void setDevice(int device)
Sets the device number.
ALSA Timer information container.
int getSizeOfInfo() const
Gets the size of the ALSA timer info object.
bool isSlave()
Check if the timer is slave (depends on another device)
QString getId()
Gets the string identifier.
long getResolution()
Gets the timer resolution (timer period in nanoseconds)
QString getName()
Gets the timer name.
Q_DECL_DEPRECATED long getTicks()
Gets the maximum timer ticks.
TimerInfo & operator=(const TimerInfo &other)
Assignment operator.
int getCard()
Gets the card number.
long getFrequency()
Gets the timer frequency in Hz.
TimerInfo * clone()
Copy the current object.
ALSA Timer parameters container.
void setFilter(unsigned int filter)
Sets the event filter.
void setEarlyEvent(bool early_event)
Sets the timer early event.
int getSizeOfInfo() const
Gets the size of the ALSA timer parameters object.
TimerParams & operator=(const TimerParams &other)
Assignment operator.
void setAutoStart(bool auto_start)
Sets the automatic start flag.
bool getExclusive()
Gets the timer's exclusive flag.
long getQueueSize()
Gets the queue size.
TimerParams()
Default constructor.
bool getEarlyEvent()
Gets the timer early event.
void setExclusive(bool exclusive)
Sets the exclusive flag.
bool getAutoStart()
Gets the automatic start flag.
void setTicks(long ticks)
Sets the timer ticks.
long getTicks()
Gets the timer ticks.
TimerParams * clone()
Copy the current object.
unsigned int getFilter()
Gets the event filter.
void setQueueSize(long queue_size)
Sets the queue size (32-1024)
ALSA Timer inquiry helper.
TimerIdList getTimers() const
Gets the list of available timers.
TimerQuery(const QString &deviceName, int openMode)
Constructor.
ALSA Timer status container.
long getLost()
Gets the master tick lost count.
TimerStatus()
Default constructor.
int getSizeOfInfo() const
Gets the size of the ALSA timer status object.
long getOverrun()
Gets the overrun count.
long getResolution()
Gets the resolution in us.
TimerStatus & operator=(const TimerStatus &other)
Assignment operator.
TimerStatus * clone()
Copy the current object.
snd_htimestamp_t getTimestamp()
Gets the high resolution time-stamp.
long getQueue()
Gets the count of used queue elements.
Timer(int cls, int scls, int card, int dev, int sdev, int openMode, QObject *parent=nullptr)
Constructor.
static TimerId bestGlobalTimerId()
Check and return the best available global TimerId in the system, meaning the timer with higher frequ...
void timerExpired(int ticks, int msecs)
This signal is emitted when the timer has expired, if there is not an event hander installed.
static Timer * bestGlobalTimer(int openMode, QObject *parent=nullptr)
Check and return the best available global Timer in the system, meaning the timer with higher frequen...
void setHandler(TimerEventHandler *h)
Sets an event handler providing a method to be called when a timer expires.
void stop()
Stop rolling the timer.
snd_timer_t * getHandle()
Gets the ALSA timer object.
QList< TimerId > TimerIdList
List of timer identifiers.
Drumstick ALSA library wrapper.