19#ifndef DRUMSTICK_ALSATIMER_H
20#define DRUMSTICK_ALSATIMER_H
23 #include <alsa/asoundlib.h>
29#include <QReadWriteLock>
60 explicit TimerInfo(
const snd_timer_info_t* other);
74 long getTicks() __attribute__((deprecated));
77 snd_timer_info_t *m_Info;
87 friend class TimerQuery;
88 friend class TimerGlobalInfo;
89 friend class QueueTimer;
94 explicit TimerId(
const snd_timer_id_t *other);
95 TimerId(
int cls,
int scls,
int card,
int dev,
int sdev);
113 snd_timer_id_t *m_Info;
128 friend class TimerQuery;
151 snd_timer_ginfo_t* m_Info;
163 TimerQuery(
const QString& deviceName,
int openMode);
164 TimerQuery(
const QString& deviceName,
int openMode, snd_config_t* conf);
172 void setGlobalParams(snd_timer_gparams_t* params);
173 void getGlobalParams(snd_timer_gparams_t* params);
174 void getGlobalStatus(snd_timer_gstatus_t* status);
181 snd_timer_query_t *m_Info;
198 explicit TimerParams(
const snd_timer_params_t* other);
218 snd_timer_params_t* m_Info;
233 explicit TimerStatus(
const snd_timer_status_t* other);
246 snd_timer_status_t* m_Info;
281 class TimerInputThread :
public QThread
285 TimerInputThread(
Timer* t,
int timeout)
291 virtual ~TimerInputThread() =
default;
299 QReadWriteLock m_mutex;
303 Timer(
int cls,
int scls,
int card,
int dev,
int sdev,
int openMode,
QObject* parent =
nullptr);
304 Timer(
const QString& deviceName,
int openMode,
QObject* parent =
nullptr);
305 Timer(
const QString& deviceName,
int openMode, snd_config_t* config,
QObject* parent =
nullptr);
322 void continueRunning();
324 void addAsyncTimerHandler(snd_async_callback_t callback,
void *private_data);
325 int getPollDescriptorsCount();
326 void pollDescriptors(
struct pollfd *pfds,
unsigned int space);
327 void pollDescriptorsRevents(
struct pollfd *pfds,
unsigned int nfds,
unsigned short *revents);
328 ssize_t read(
void *buffer,
size_t size);
329 snd_timer_t* getTimerHandle();
353 snd_async_handler_t *m_asyncHandler;
355 QPointer<TimerInputThread> m_thread;
358 QString m_deviceName;
359 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.
long getTicks() __attribute__((deprecated))
Gets the maximum timer ticks.
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.
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 visibility macros.
Drumstick ALSA library wrapper.