/usr/include/drumstick/alsatimer.h is in libdrumstick-dev 0.5.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | /*
MIDI Sequencer C++ library
Copyright (C) 2006-2010, Pedro Lopez-Cabanillas <plcl@users.sf.net>
This library 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 library 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef DRUMSTICK_ALSATIMER_H
#define DRUMSTICK_ALSATIMER_H
#include "drumstickcommon.h"
#include <QList>
#include <QThread>
#include <QReadWriteLock>
#include <QPointer>
/**
* @file alsatimer.h
* Classes managing ALSA Timers
* @defgroup ALSATimer ALSA Timers
* @{
*/
namespace drumstick {
class TimerQuery;
class TimerId;
class TimerGlobalInfo;
/**
* ALSA Timer information container.
*
* This class is used to hold properties about ALSA Timers.
*/
class DRUMSTICK_EXPORT TimerInfo
{
friend class Timer;
public:
TimerInfo();
TimerInfo(const TimerInfo& other);
TimerInfo(const snd_timer_info_t* other);
virtual ~TimerInfo();
TimerInfo* clone();
TimerInfo& operator=(const TimerInfo& other);
int getSizeOfInfo() const;
bool isSlave();
int getCard();
QString getId();
QString getName();
long getResolution();
long getFrequency();
protected:
long getTicks() __attribute__((deprecated));
private:
snd_timer_info_t *m_Info;
};
/**
* ALSA Timer identifier container.
*
* This class provides an unique identifier for a Timer.
*/
class DRUMSTICK_EXPORT TimerId
{
friend class TimerQuery;
friend class TimerGlobalInfo;
friend class QueueTimer;
public:
TimerId();
TimerId(const TimerId& other);
TimerId(const snd_timer_id_t *other);
TimerId(int cls, int scls, int card, int dev, int sdev);
virtual ~TimerId();
TimerId* clone();
TimerId& operator=(const TimerId& other);
int getSizeOfInfo() const;
void setClass(int devclass);
int getClass();
void setSlaveClass(int devsclass);
int getSlaveClass();
void setCard(int card);
int getCard();
void setDevice(int device);
int getDevice();
void setSubdevice(int subdevice);
int getSubdevice();
private:
snd_timer_id_t *m_Info;
};
/**
* List of timer identifiers
*/
typedef QList<TimerId> TimerIdList;
/**
* Global timer information container.
*
* This class provides global timer parameters.
*/
class DRUMSTICK_EXPORT TimerGlobalInfo
{
friend class TimerQuery;
public:
TimerGlobalInfo();
TimerGlobalInfo(const TimerGlobalInfo& other);
TimerGlobalInfo(const snd_timer_ginfo_t* other);
virtual ~TimerGlobalInfo();
TimerGlobalInfo* clone();
TimerGlobalInfo& operator=(const TimerGlobalInfo& other);
int getSizeOfInfo() const;
void setTimerId(const TimerId& tid);
TimerId& getTimerId();
unsigned int getFlags();
int getCard();
QString getId();
QString getName();
unsigned long getResolution();
unsigned long getMinResolution();
unsigned long getMaxResolution();
unsigned int getClients();
private:
snd_timer_ginfo_t* m_Info;
TimerId m_Id;
};
/**
* ALSA Timer inquiry helper.
*
* This class provides a mechanism to enumerate the available system timers.
*/
class DRUMSTICK_EXPORT TimerQuery
{
public:
TimerQuery(const QString& deviceName, int openMode);
TimerQuery(const QString& deviceName, int openMode, snd_config_t* conf);
virtual ~TimerQuery();
/**
* Gets the list of available timers
* @return List of TimerId objects
*/
TimerIdList getTimers() const { return m_timers; }
TimerGlobalInfo& getGlobalInfo();
void setGlobalParams(snd_timer_gparams_t* params);
void getGlobalParams(snd_timer_gparams_t* params);
void getGlobalStatus(snd_timer_gstatus_t* status);
protected:
void readTimers();
void freeTimers();
private:
snd_timer_query_t *m_Info;
TimerIdList m_timers;
TimerGlobalInfo m_GlobalInfo;
};
/**
* ALSA Timer parameters container.
*
* This class provides several parameters about a Timer.
*/
class DRUMSTICK_EXPORT TimerParams
{
friend class Timer;
public:
TimerParams();
TimerParams(const TimerParams& other);
TimerParams(const snd_timer_params_t* other);
virtual ~TimerParams();
TimerParams* clone();
TimerParams& operator=(const TimerParams& other);
int getSizeOfInfo() const;
void setAutoStart(bool auto_start);
bool getAutoStart();
void setExclusive(bool exclusive);
bool getExclusive();
void setEarlyEvent(bool early_event);
bool getEarlyEvent();
void setTicks(long ticks);
long getTicks();
void setQueueSize(long queue_size);
long getQueueSize();
void setFilter(unsigned int filter);
unsigned int getFilter();
private:
snd_timer_params_t* m_Info;
};
/**
* ALSA Timer status container.
*
* This class provides some status information about a Timer.
*/
class DRUMSTICK_EXPORT TimerStatus
{
friend class Timer;
public:
TimerStatus();
TimerStatus(const TimerStatus& other);
TimerStatus(const snd_timer_status_t* other);
virtual ~TimerStatus();
TimerStatus* clone();
TimerStatus& operator=(const TimerStatus& other);
int getSizeOfInfo() const;
snd_htimestamp_t getTimestamp();
long getResolution();
long getLost();
long getOverrun();
long getQueue();
private:
snd_timer_status_t* m_Info;
};
/**
* ALSA Timer events handler.
*
* This abstract class is used to define an interface that other class can
* implement to receive timer events.
*/
class DRUMSTICK_EXPORT TimerEventHandler
{
public:
/** Destructor */
virtual ~TimerEventHandler() {}
/**
* Timer event handler. This method is called when the timer expires.
* @param ticks The time in ticks.
* @param msecs The time in milliseconds.
*/
virtual void handleTimerEvent(int ticks, int msecs) = 0;
};
/**
* ALSA Timer management.
*
* This class represents an ALSA timer object.
*/
class DRUMSTICK_EXPORT Timer : public QObject
{
Q_OBJECT
private:
/**
* This class manages timer events input from ALSA
*/
class TimerInputThread : public QThread
{
public:
/** Constructor */
TimerInputThread(Timer* t, int timeout)
: QThread(),
m_timer(t),
m_Wait(timeout),
m_Stopped(false) {}
/** Destructor */
virtual ~TimerInputThread() {}
virtual void run();
bool stopped();
void stop();
private:
Timer* m_timer;
int m_Wait;
bool m_Stopped;
QReadWriteLock m_mutex;
};
public:
Timer(int cls, int scls, int card, int dev, int sdev, int openMode, QObject* parent = 0);
Timer(const QString& deviceName, int openMode, QObject* parent = 0);
Timer(const QString& deviceName, int openMode, snd_config_t* config, QObject* parent = 0);
Timer(TimerId& id, int openMode, QObject* parent = 0);
virtual ~Timer();
static TimerId bestGlobalTimerId();
static Timer* bestGlobalTimer(int openMode, QObject* parent = 0);
/**
* Gets the ALSA timer object.
* @return ALSA timer object pointer.
*/
snd_timer_t* getHandle() { return m_Info; }
TimerInfo& getTimerInfo();
TimerStatus& getTimerStatus();
void setTimerParams(const TimerParams& params);
void start();
void stop();
void continueRunning();
void addAsyncTimerHandler(snd_async_callback_t callback, void *private_data);
int getPollDescriptorsCount();
void pollDescriptors(struct pollfd *pfds, unsigned int space);
void pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
ssize_t read(void *buffer, size_t size);
snd_timer_t* getTimerHandle();
/**
* Sets an event handler providing a method to be called when a timer expires.
* @param h A TimerEventHandler instance.
*/
void setHandler(TimerEventHandler* h) { m_handler = h; }
void startEvents();
void stopEvents();
protected:
void doEvents();
signals:
/**
* This signal is emitted when the timer has expired, if there is not an
* event hander installed.
*
* @param ticks The time in ticks.
* @param msecs The time in milliseconds.
*/
void timerExpired(int ticks, int msecs);
private:
snd_timer_t *m_Info;
snd_async_handler_t *m_asyncHandler;
TimerEventHandler* m_handler;
QPointer<TimerInputThread> m_thread;
TimerInfo m_TimerInfo;
TimerStatus m_TimerStatus;
QString m_deviceName;
snd_htimestamp_t m_last_time;
};
} /* namespace drumstick */
/** @} */
#endif /* DRUMSTICK_ALSATIMER_H */
|