drumstick  0.5.0
alsatimer.cpp
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2010, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5  This library is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "alsatimer.h"
21 #include <QReadLocker>
22 #include <QWriteLocker>
23 #include <cmath>
24 #include <cstdio>
25 
31 namespace drumstick {
32 
89 {
90  snd_timer_info_malloc(&m_Info);
91 }
92 
97 TimerInfo::TimerInfo(const snd_timer_info_t *other)
98 {
99  snd_timer_info_malloc(&m_Info);
100  snd_timer_info_copy(m_Info, other);
101 }
102 
108 {
109  snd_timer_info_malloc(&m_Info);
110  snd_timer_info_copy(m_Info, other.m_Info);
111 }
112 
117 {
118  snd_timer_info_free(m_Info);
119 }
120 
125 TimerInfo*
127 {
128  return new TimerInfo(m_Info);
129 }
130 
135 TimerInfo&
137 {
138  snd_timer_info_copy(m_Info, other.m_Info);
139  return *this;
140 }
141 
146 bool
148 {
149  return (snd_timer_info_is_slave(m_Info) != 0);
150 }
151 
156 int
158 {
159  return snd_timer_info_get_card(m_Info);
160 }
161 
166 QString
168 {
169  return QString(snd_timer_info_get_id(m_Info));
170 }
171 
176 QString
178 {
179  return QString(snd_timer_info_get_name(m_Info));
180 }
181 
186 long
188 {
189  return snd_timer_info_get_resolution(m_Info);
190 }
191 
196 long
198 {
199  long res = getResolution();
200  if (res > 0)
201  {
202  return 1000000000L / res;
203  }
204  return 0;
205 }
206 
211 int
213 {
214  return snd_timer_info_sizeof();
215 }
216 
222 long
224 {
225  return snd_timer_info_get_ticks(m_Info);
226 }
227 
232 {
233  snd_timer_id_malloc(&m_Info);
234 }
235 
240 TimerId::TimerId(const snd_timer_id_t *other)
241 {
242  snd_timer_id_malloc(&m_Info);
243  snd_timer_id_copy(m_Info, other);
244  if (getCard() < 0)
245  setCard(0);
246  if (getDevice() < 0)
247  setDevice(0);
248  if (getSubdevice() < 0)
249  setSubdevice(0);
250 }
251 
257 {
258  snd_timer_id_malloc(&m_Info);
259  snd_timer_id_copy(m_Info, other.m_Info);
260  if (getCard() < 0)
261  setCard(0);
262  if (getDevice() < 0)
263  setDevice(0);
264  if (getSubdevice() < 0)
265  setSubdevice(0);
266 }
267 
276 TimerId::TimerId(int cls, int scls, int card, int dev, int sdev)
277 {
278  snd_timer_id_malloc(&m_Info);
279  setClass(cls);
280  setSlaveClass(scls);
281  setCard(card);
282  setDevice(dev);
283  setSubdevice(sdev);
284 }
285 
290 {
291  snd_timer_id_free(m_Info);
292 }
293 
298 TimerId*
300 {
301  return new TimerId(m_Info);
302 }
303 
309 TimerId&
311 {
312  snd_timer_id_copy(m_Info, other.m_Info);
313  if (getCard() < 0)
314  setCard(0);
315  if (getDevice() < 0)
316  setDevice(0);
317  if (getSubdevice() < 0)
318  setSubdevice(0);
319  return *this;
320 }
321 
332 void
333 TimerId::setClass(int devclass)
334 {
335  snd_timer_id_set_class(m_Info, devclass);
336 }
337 
343 int
345 {
346  return snd_timer_id_get_class(m_Info);
347 }
348 
353 void
355 {
356  snd_timer_id_set_sclass(m_Info, devsclass);
357 }
358 
363 int
365 {
366  return snd_timer_id_get_sclass(m_Info);
367 }
368 
373 void
375 {
376  snd_timer_id_set_card(m_Info, card);
377 }
378 
383 int
385 {
386  return snd_timer_id_get_card(m_Info);
387 }
388 
393 void
395 {
396  snd_timer_id_set_device(m_Info, device);
397 }
398 
403 int
405 {
406  return snd_timer_id_get_device(m_Info);
407 }
408 
413 void
414 TimerId::setSubdevice(int subdevice)
415 {
416  snd_timer_id_set_subdevice (m_Info, subdevice);
417 }
418 
423 int
425 {
426  return snd_timer_id_get_subdevice(m_Info);
427 }
428 
433 int
435 {
436  return snd_timer_id_sizeof();
437 }
438 
444 TimerQuery::TimerQuery(const QString& deviceName, int openMode)
445 {
446  CHECK_WARNING( snd_timer_query_open( &m_Info,
447  deviceName.toLocal8Bit().data(),
448  openMode ));
449  readTimers();
450 }
451 
458 TimerQuery::TimerQuery( const QString& deviceName, int openMode,
459  snd_config_t* conf )
460 {
461  CHECK_WARNING( snd_timer_query_open_lconf( &m_Info,
462  deviceName.toLocal8Bit().data(),
463  openMode, conf ));
464  readTimers();
465 }
466 
471 {
472  freeTimers();
473  snd_timer_query_close(m_Info);
474 }
475 
479 void
481 {
482  TimerId tid;
483  snd_timer_id_set_class(tid.m_Info, SND_TIMER_CLASS_NONE);
484  for(;;)
485  {
486  int rc = snd_timer_query_next_device(m_Info, tid.m_Info);
487  if ((rc < 0) || (tid.getClass() < 0)) {
488  break;
489  }
490  m_timers.append(tid);
491  }
492 }
493 
497 void
499 {
500  m_timers.clear();
501 }
502 
509 {
510  snd_timer_query_info(m_Info, m_GlobalInfo.m_Info);
511  return m_GlobalInfo;
512 }
513 
518 void
519 TimerQuery::setGlobalParams(snd_timer_gparams_t* params)
520 {
521  snd_timer_query_params(m_Info, params);
522 }
523 
528 void
529 TimerQuery::getGlobalParams(snd_timer_gparams_t* params)
530 {
531  snd_timer_query_params(m_Info, params);
532 }
533 
538 void
539 TimerQuery::getGlobalStatus(snd_timer_gstatus_t *status)
540 {
541  snd_timer_query_status(m_Info, status);
542 }
543 
548 {
549  snd_timer_ginfo_malloc(&m_Info);
550 }
551 
556 TimerGlobalInfo::TimerGlobalInfo(const snd_timer_ginfo_t* other)
557 {
558  snd_timer_ginfo_malloc(&m_Info);
559  snd_timer_ginfo_copy(m_Info, other);
560 }
561 
567 {
568  snd_timer_ginfo_malloc(&m_Info);
569  snd_timer_ginfo_copy(m_Info, other.m_Info);
570 }
571 
576 {
577  snd_timer_ginfo_free(m_Info);
578 }
579 
586 {
587  return new TimerGlobalInfo(m_Info);
588 }
589 
597 {
598  snd_timer_ginfo_copy(m_Info, other.m_Info);
599  return *this;
600 }
601 
606 void
608 {
609  m_Id = tid;
610  snd_timer_ginfo_set_tid (m_Info, m_Id.m_Info);
611 }
612 
617 TimerId&
619 {
620  m_Id = TimerId(snd_timer_ginfo_get_tid (m_Info));
621  return m_Id;
622 }
623 
628 unsigned int
630 {
631  return snd_timer_ginfo_get_flags (m_Info);
632 }
633 
638 int
640 {
641  return snd_timer_ginfo_get_card (m_Info);
642 }
643 
648 QString
650 {
651  return QString(snd_timer_ginfo_get_id (m_Info));
652 }
653 
658 QString
660 {
661  return QString(snd_timer_ginfo_get_name (m_Info));
662 }
663 
668 unsigned long
670 {
671  return snd_timer_ginfo_get_resolution (m_Info);
672 }
673 
678 unsigned long
680 {
681  return snd_timer_ginfo_get_resolution_min (m_Info);
682 }
683 
688 unsigned long
690 {
691  return snd_timer_ginfo_get_resolution_max(m_Info);
692 }
693 
698 unsigned int
700 {
701  return snd_timer_ginfo_get_clients(m_Info);
702 }
703 
708 int
710 {
711  return snd_timer_ginfo_sizeof();
712 }
713 
718 {
719  snd_timer_params_malloc (&m_Info);
720 }
721 
726 TimerParams::TimerParams(const snd_timer_params_t *other)
727 {
728  snd_timer_params_malloc (&m_Info);
729  snd_timer_params_copy (m_Info, other);
730 }
731 
737 {
738  snd_timer_params_malloc (&m_Info);
739  snd_timer_params_copy (m_Info, other.m_Info);
740 }
741 
747 {
748  snd_timer_params_free (m_Info);
749 }
750 
757 {
758  return new TimerParams(m_Info);
759 }
760 
768 {
769  snd_timer_params_copy (m_Info, other.m_Info);
770  return *this;
771 }
772 
777 void
779 {
780  snd_timer_params_set_auto_start (m_Info, auto_start ? 1 : 0);
781 }
782 
787 bool
789 {
790  return (snd_timer_params_get_auto_start (m_Info) != 0);
791 }
792 
797 void
799 {
800  snd_timer_params_set_exclusive (m_Info, exclusive ? 1 : 0);
801 }
802 
807 bool
809 {
810  return (snd_timer_params_get_exclusive (m_Info) != 0);
811 }
812 
817 void
818 TimerParams::setEarlyEvent(bool early_event)
819 {
820  snd_timer_params_set_early_event (m_Info, early_event ? 1 : 0);
821 }
822 
827 bool
829 {
830  return (snd_timer_params_get_early_event (m_Info) != 0);
831 }
832 
837 void
839 {
840  snd_timer_params_set_ticks (m_Info, ticks);
841 }
842 
847 long
849 {
850  return snd_timer_params_get_ticks (m_Info);
851 }
852 
857 void
859 {
860  snd_timer_params_set_queue_size (m_Info, queue_size);
861 }
862 
867 long
869 {
870  return snd_timer_params_get_queue_size (m_Info);
871 }
872 
877 void
878 TimerParams::setFilter(unsigned int filter)
879 {
880  snd_timer_params_set_filter (m_Info, filter);
881 }
882 
887 unsigned int
889 {
890  return snd_timer_params_get_filter (m_Info);
891 }
892 
897 int
899 {
900  return snd_timer_params_sizeof();
901 }
902 
907 {
908  snd_timer_status_malloc (&m_Info);
909 }
910 
915 TimerStatus::TimerStatus(const snd_timer_status_t *other)
916 {
917  snd_timer_status_malloc (&m_Info);
918  snd_timer_status_copy (m_Info, other);
919 }
920 
926 {
927  snd_timer_status_malloc (&m_Info);
928  snd_timer_status_copy (m_Info, other.m_Info);
929 }
930 
935 {
936  snd_timer_status_free (m_Info);
937 }
938 
945 {
946  return new TimerStatus(m_Info);
947 }
948 
956 {
957  snd_timer_status_copy (m_Info, other.m_Info);
958  return *this;
959 }
960 
965 snd_htimestamp_t
967 {
968  return snd_timer_status_get_timestamp (m_Info);
969 }
970 
975 long
977 {
978  return snd_timer_status_get_resolution (m_Info);
979 }
980 
985 long
987 {
988  return snd_timer_status_get_lost (m_Info);
989 }
990 
995 long
997 {
998  return snd_timer_status_get_overrun (m_Info);
999 }
1000 
1005 long
1007 {
1008  return snd_timer_status_get_queue (m_Info);
1009 }
1010 
1015 int
1017 {
1018  return snd_timer_status_sizeof();
1019 }
1020 
1032 Timer::Timer( const QString& deviceName, int openMode, QObject* parent )
1033  : QObject(parent),
1034  m_asyncHandler(NULL),
1035  m_handler(NULL),
1036  m_thread(NULL),
1037  m_deviceName(deviceName)
1038 {
1039  CHECK_ERROR( snd_timer_open( &m_Info, m_deviceName.toLocal8Bit().data(),
1040  openMode ));
1041 }
1042 
1055 Timer::Timer( const QString& deviceName, int openMode, snd_config_t* conf,
1056  QObject* parent )
1057  : QObject(parent),
1058  m_asyncHandler(NULL),
1059  m_handler(NULL),
1060  m_thread(NULL),
1061  m_deviceName(deviceName)
1062 {
1063  CHECK_ERROR( snd_timer_open_lconf( &m_Info,
1064  m_deviceName.toLocal8Bit().data(),
1065  openMode, conf ));
1066 }
1067 
1079 Timer::Timer( TimerId& id, int openMode, QObject* parent )
1080  : QObject(parent),
1081  m_asyncHandler(NULL),
1082  m_handler(NULL),
1083  m_thread(NULL)
1084 {
1085  m_deviceName = QString("hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1086  .arg(id.getClass())
1087  .arg(id.getSlaveClass())
1088  .arg(id.getCard())
1089  .arg(id.getDevice())
1090  .arg(id.getSubdevice());
1091  CHECK_ERROR( snd_timer_open( &m_Info,
1092  m_deviceName.toLocal8Bit().data(),
1093  openMode ));
1094 }
1095 
1111 Timer::Timer( int cls, int scls, int card, int dev, int sdev,
1112  int openMode, QObject* parent )
1113  : QObject(parent),
1114  m_asyncHandler(NULL),
1115  m_handler(NULL),
1116  m_thread(NULL)
1117 {
1118  m_deviceName = QString("hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1119  .arg(cls)
1120  .arg(scls)
1121  .arg(card)
1122  .arg(dev)
1123  .arg(sdev);
1124  CHECK_ERROR( snd_timer_open( &m_Info,
1125  m_deviceName.toLocal8Bit().data(),
1126  openMode ));
1127 }
1128 
1133 {
1134  stopEvents();
1135  if (m_thread != NULL)
1136  delete m_thread;
1137  CHECK_WARNING(snd_timer_close(m_Info));
1138 }
1139 
1145 void
1146 Timer::addAsyncTimerHandler(snd_async_callback_t callback, void *private_data)
1147 {
1148  CHECK_WARNING(snd_async_add_timer_handler(&m_asyncHandler, m_Info, callback, private_data));
1149 }
1150 
1155 snd_timer_t*
1157 {
1158  return snd_async_handler_get_timer(m_asyncHandler);
1159 }
1160 
1165 int
1167 {
1168  return snd_timer_poll_descriptors_count(m_Info);
1169 }
1170 
1176 void
1177 Timer::pollDescriptors(struct pollfd *pfds, unsigned int space)
1178 {
1179  CHECK_WARNING(snd_timer_poll_descriptors(m_Info, pfds, space));
1180 }
1181 
1188 void
1189 Timer::pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
1190 {
1191  CHECK_WARNING(snd_timer_poll_descriptors_revents(m_Info, pfds, nfds, revents));
1192 }
1193 
1198 TimerInfo&
1200 {
1201  snd_timer_info (m_Info, m_TimerInfo.m_Info);
1202  return m_TimerInfo;
1203 }
1204 
1209 void
1211 {
1212  CHECK_WARNING( snd_timer_params(m_Info, params.m_Info) );
1213 }
1214 
1219 TimerStatus&
1221 {
1222  CHECK_WARNING( snd_timer_status(m_Info, m_TimerStatus.m_Info) );
1223  return m_TimerStatus;
1224 }
1225 
1229 void
1231 {
1232  CHECK_WARNING(snd_timer_start(m_Info));
1233 }
1234 
1238 void
1240 {
1241  CHECK_WARNING(snd_timer_stop(m_Info));
1242 }
1243 
1247 void
1249 {
1250  CHECK_WARNING(snd_timer_continue(m_Info));
1251 }
1252 
1259 ssize_t
1260 Timer::read(void *buffer, size_t size)
1261 {
1262  return snd_timer_read(m_Info, buffer, size);
1263 }
1264 
1273 void
1275 {
1276  snd_timer_tread_t tr;
1277  while ( read(&tr, sizeof(tr)) == sizeof(tr) ) {
1278  int msecs = ((tr.tstamp.tv_sec - m_last_time.tv_sec) * 1000) +
1279  round((tr.tstamp.tv_nsec - m_last_time.tv_nsec) / 1000000.0);
1280  m_last_time = tr.tstamp;
1281  if ( m_handler != NULL )
1282  m_handler->handleTimerEvent(tr.val, msecs);
1283  else
1284  emit timerExpired(tr.val, msecs);
1285  }
1286 }
1287 
1292 {
1293  m_last_time = getTimerStatus().getTimestamp();
1294  if (m_thread == NULL) {
1295  m_thread = new TimerInputThread(this, 500);
1296  m_thread->start();
1297  }
1298 }
1299 
1304 {
1305  int counter = 0;
1306  if (m_thread != NULL) {
1307  m_thread->stop();
1308  while (!m_thread->wait(500) && (counter < 10)) {
1309  counter++;
1310  }
1311  if (!m_thread->isFinished()) {
1312  m_thread->terminate();
1313  }
1314  delete m_thread;
1315  }
1316 }
1317 
1324 TimerId
1326 {
1327  TimerId id;
1328  snd_timer_t* timer;
1329  snd_timer_info_t* info;
1330  long res, best_res = LONG_MAX;
1331  char timername[64];
1332  int test_devs[] = {
1333  SND_TIMER_GLOBAL_SYSTEM
1334  , SND_TIMER_GLOBAL_RTC
1335 #ifdef SND_TIMER_GLOBAL_HPET
1336  , SND_TIMER_GLOBAL_HPET
1337 #endif
1338 #ifdef SND_TIMER_GLOBAL_HRTIMER
1339  , SND_TIMER_GLOBAL_HRTIMER
1340 #endif
1341  };
1342  int max_global_timers = sizeof(test_devs)/sizeof(int);
1343  int clas = SND_TIMER_CLASS_GLOBAL;
1344  int scls = SND_TIMER_SCLASS_NONE;
1345  int card = 0;
1346  int dev = SND_TIMER_GLOBAL_SYSTEM;
1347  int sdev = 0;
1348  int err = 0;
1349  int is_slave = 0;
1350  int i;
1351  snd_timer_info_alloca(&info);
1352  // default system timer
1353  id.setClass(clas);
1354  id.setSlaveClass(scls);
1355  id.setCard(card);
1356  id.setDevice(dev);
1357  id.setSubdevice(sdev);
1358  // select a non slave timer with the lowest resolution value
1359  for( i = 0; i < max_global_timers; ++i )
1360  {
1361  dev = test_devs[i];
1362  sprintf( timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i",
1363  clas, scls, card, dev, sdev );
1364  err = snd_timer_open(&timer, timername, SND_TIMER_OPEN_NONBLOCK);
1365  if (err < 0) continue;
1366  err = snd_timer_info(timer, info);
1367  if (err == 0) {
1368  is_slave = snd_timer_info_is_slave(info);
1369  res = snd_timer_info_get_resolution(info);
1370  if ((is_slave == 0) && (best_res > res)) {
1371  best_res = res;
1372  id.setDevice(dev);
1373  }
1374  }
1375  snd_timer_close(timer);
1376  }
1377  return id;
1378 }
1379 
1387 Timer*
1388 Timer::bestGlobalTimer(int openMode, QObject* parent)
1389 {
1390  TimerId id = bestGlobalTimerId();
1391  return new Timer(id, openMode, parent);
1392 }
1393 
1397 void
1398 Timer::TimerInputThread::run()
1399 {
1400  int err, count;
1401  struct pollfd *fds;
1402  if (m_timer == NULL) return;
1403 
1404  count = m_timer->getPollDescriptorsCount();
1405  fds = (pollfd *) calloc(count, sizeof(struct pollfd));
1406  if (fds == NULL) {
1407  qWarning() << "allocation error!";
1408  return;
1409  }
1410  fds->events = POLLIN;
1411  fds->revents = 0;
1412 
1413  try {
1414  while (!stopped() && (m_timer != NULL)) {
1415  m_timer->pollDescriptors(fds, count);
1416  if ((err = poll(fds, count, m_Wait)) < 0) {
1417  qWarning() << "poll error " << err << "(" << strerror(err) << ")";
1418  return;
1419  }
1420  if (err == 0) {
1421  qWarning() << "timer time out";
1422  return;
1423  }
1424  m_timer->doEvents();
1425  }
1426  } catch (...) {
1427  qWarning() << "exception in input thread";
1428  }
1429  free(fds);
1430 }
1431 
1436 bool
1437 Timer::TimerInputThread::stopped()
1438 {
1439  QReadLocker locker(&m_mutex);
1440  return m_Stopped;
1441 }
1442 
1446 void
1447 Timer::TimerInputThread::stop()
1448 {
1449  QWriteLocker locker(&m_mutex);
1450  m_Stopped = true;
1451 }
1452 
1453 } /* namespace drumstick */
TimerGlobalInfo & operator=(const TimerGlobalInfo &other)
Assignment operator.
Definition: alsatimer.cpp:596
QString getName()
Gets the timer name.
Definition: alsatimer.cpp:177
long getResolution()
Gets the resolution in us.
Definition: alsatimer.cpp:976
TimerStatus & operator=(const TimerStatus &other)
Assignment operator.
Definition: alsatimer.cpp:955
void setDevice(int device)
Sets the device number.
Definition: alsatimer.cpp:394
void doEvents()
Internal function to deliver the timer events using one of the two available methods:
Definition: alsatimer.cpp:1274
TimerId & getTimerId()
Gets the timer identifier.
Definition: alsatimer.cpp:618
virtual ~TimerInfo()
Destructor.
Definition: alsatimer.cpp:116
void setQueueSize(long queue_size)
Sets the queue size (32-1024)
Definition: alsatimer.cpp:858
TimerId & operator=(const TimerId &other)
Assignment operator.
Definition: alsatimer.cpp:310
long getOverrun()
Gets the overrun count.
Definition: alsatimer.cpp:996
void setTicks(long ticks)
Sets the timer ticks.
Definition: alsatimer.cpp:838
void getGlobalParams(snd_timer_gparams_t *params)
Gets the global timer parameters.
Definition: alsatimer.cpp:529
static Timer * bestGlobalTimer(int openMode, QObject *parent=0)
Check and return the best available global Timer in the system, meaning the timer with higher frequen...
Definition: alsatimer.cpp:1388
snd_htimestamp_t getTimestamp()
Gets the high resolution time-stamp.
Definition: alsatimer.cpp:966
bool getEarlyEvent()
Gets the timer early event.
Definition: alsatimer.cpp:828
void setAutoStart(bool auto_start)
Sets the automatic start flag.
Definition: alsatimer.cpp:778
void pollDescriptors(struct pollfd *pfds, unsigned int space)
Gets poll descriptors.
Definition: alsatimer.cpp:1177
int getSizeOfInfo() const
Gets the size of the ALSA timer global info object.
Definition: alsatimer.cpp:709
QString getId()
Gets the timer ID string.
Definition: alsatimer.cpp:649
void setGlobalParams(snd_timer_gparams_t *params)
Sets the global parameters.
Definition: alsatimer.cpp:519
void addAsyncTimerHandler(snd_async_callback_t callback, void *private_data)
Adds an asynchronous timer handler function.
Definition: alsatimer.cpp:1146
unsigned int getClients()
Gets current timer clients.
Definition: alsatimer.cpp:699
void getGlobalStatus(snd_timer_gstatus_t *status)
Gets the global timer status.
Definition: alsatimer.cpp:539
virtual ~TimerParams()
Destructor.
Definition: alsatimer.cpp:746
TimerStatus * clone()
Copy the current object.
Definition: alsatimer.cpp:944
int getClass()
Gets the class identifier.
Definition: alsatimer.cpp:344
TimerInfo * clone()
Copy the current object.
Definition: alsatimer.cpp:126
ALSA Timer management.
Definition: alsatimer.h:267
bool getExclusive()
Gets the timer's exclusive flag.
Definition: alsatimer.cpp:808
int getSubdevice()
Gets the subdevice number.
Definition: alsatimer.cpp:424
void setCard(int card)
Sets the card number.
Definition: alsatimer.cpp:374
long getResolution()
Gets the timer resolution (timer period in nanoseconds)
Definition: alsatimer.cpp:187
The QObject class is the base class of all Qt objects.
unsigned long getResolution()
Gets the timer resolution in ns.
Definition: alsatimer.cpp:669
Classes managing ALSA Timers.
void setExclusive(bool exclusive)
Sets the exclusive flag.
Definition: alsatimer.cpp:798
int getCard()
Gets the card number.
Definition: alsatimer.cpp:157
void freeTimers()
Release the internal list of timers.
Definition: alsatimer.cpp:498
TimerGlobalInfo * clone()
Copy the current object.
Definition: alsatimer.cpp:585
QString getName()
Gets the timer name.
Definition: alsatimer.cpp:659
long getFrequency()
Gets the timer frequency in Hz.
Definition: alsatimer.cpp:197
void setClass(int devclass)
Set the class identifier.
Definition: alsatimer.cpp:333
long getQueueSize()
Gets the queue size.
Definition: alsatimer.cpp:868
TimerQuery(const QString &deviceName, int openMode)
Constructor.
Definition: alsatimer.cpp:444
ssize_t read(void *buffer, size_t size)
Read bytes from the timer handle.
Definition: alsatimer.cpp:1260
TimerId * clone()
Copy the object.
Definition: alsatimer.cpp:299
int getSlaveClass()
Gets the slave class.
Definition: alsatimer.cpp:364
TimerParams()
Default constructor.
Definition: alsatimer.cpp:717
void continueRunning()
Continue rolling the timer.
Definition: alsatimer.cpp:1248
TimerId()
Constructor.
Definition: alsatimer.cpp:231
ALSA Timer information container.
Definition: alsatimer.h:47
ALSA Timer status container.
Definition: alsatimer.h:220
ALSA Timer parameters container.
Definition: alsatimer.h:185
void pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
Gets returned events from poll descriptors.
Definition: alsatimer.cpp:1189
void start()
Start rolling the timer.
Definition: alsatimer.cpp:1230
unsigned long getMinResolution()
Gets timer minimal resolution in ns.
Definition: alsatimer.cpp:679
bool isSlave()
Check if the timer is slave (depends on another device)
Definition: alsatimer.cpp:147
virtual ~TimerGlobalInfo()
Destructor.
Definition: alsatimer.cpp:575
void setTimerId(const TimerId &tid)
Sets the timer identifier.
Definition: alsatimer.cpp:607
void stop()
Stop rolling the timer.
Definition: alsatimer.cpp:1239
void setTimerParams(const TimerParams &params)
Sets the timer parameters.
Definition: alsatimer.cpp:1210
int getCard()
Gets the card number.
Definition: alsatimer.cpp:384
TimerInfo & getTimerInfo()
Gets the timer info object.
Definition: alsatimer.cpp:1199
void setFilter(unsigned int filter)
Sets the event filter.
Definition: alsatimer.cpp:878
int getCard()
Gets the card number.
Definition: alsatimer.cpp:639
Timer(int cls, int scls, int card, int dev, int sdev, int openMode, QObject *parent=0)
Constructor.
Definition: alsatimer.cpp:1111
unsigned int getFlags()
Gets the flags.
Definition: alsatimer.cpp:629
TimerParams & operator=(const TimerParams &other)
Assignment operator.
Definition: alsatimer.cpp:767
long getTicks() __attribute__((deprecated))
Gets the maximum timer ticks.
Definition: alsatimer.cpp:223
long getLost()
Gets the master tick lost count.
Definition: alsatimer.cpp:986
TimerGlobalInfo & getGlobalInfo()
Get a TimerGlobalInfo object.
Definition: alsatimer.cpp:508
unsigned long getMaxResolution()
Gets timer maximal resolution in ns.
Definition: alsatimer.cpp:689
TimerInfo & operator=(const TimerInfo &other)
Assignment operator.
Definition: alsatimer.cpp:136
unsigned int getFilter()
Gets the event filter.
Definition: alsatimer.cpp:888
int getSizeOfInfo() const
Gets the size of the ALSA timer parameters object.
Definition: alsatimer.cpp:898
static TimerId bestGlobalTimerId()
Check and return the best available global TimerId in the system, meaning the timer with higher frequ...
Definition: alsatimer.cpp:1325
long getTicks()
Gets the timer ticks.
Definition: alsatimer.cpp:848
void setSubdevice(int subdevice)
Sets the subdevice number.
Definition: alsatimer.cpp:414
Global timer information container.
Definition: alsatimer.h:120
int getSizeOfInfo() const
Gets the size of the ALSA timer info object.
Definition: alsatimer.cpp:212
virtual ~Timer()
Destructor.
Definition: alsatimer.cpp:1132
long getQueue()
Gets the count of used queue elements.
Definition: alsatimer.cpp:1006
virtual ~TimerQuery()
Destructor.
Definition: alsatimer.cpp:470
int getPollDescriptorsCount()
Gets the count of poll descriptors.
Definition: alsatimer.cpp:1166
int getSizeOfInfo() const
Gets the size of the ALSA timer ID object.
Definition: alsatimer.cpp:434
void startEvents()
Starts the events dispatching thread.
Definition: alsatimer.cpp:1291
void readTimers()
Enumerate the available timers storing the results into an internal list.
Definition: alsatimer.cpp:480
QString getId()
Gets the string identifier.
Definition: alsatimer.cpp:167
virtual void handleTimerEvent(int ticks, int msecs)=0
Timer event handler.
TimerStatus & getTimerStatus()
Gets the timer status.
Definition: alsatimer.cpp:1220
TimerGlobalInfo()
Default constructor.
Definition: alsatimer.cpp:547
int getDevice()
Gets the device number.
Definition: alsatimer.cpp:404
void stopEvents()
Stops the events dispatching thread.
Definition: alsatimer.cpp:1303
#define CHECK_ERROR(x)
This macro calls the check error function.
bool getAutoStart()
Gets the automatic start flag.
Definition: alsatimer.cpp:788
TimerInfo()
Constructor.
Definition: alsatimer.cpp:88
#define CHECK_WARNING(x)
This macro calls the check warning function.
void setSlaveClass(int devsclass)
Sets the Slave class.
Definition: alsatimer.cpp:354
int getSizeOfInfo() const
Gets the size of the ALSA timer status object.
Definition: alsatimer.cpp:1016
void timerExpired(int ticks, int msecs)
This signal is emitted when the timer has expired, if there is not an event hander installed.
TimerStatus()
Default constructor.
Definition: alsatimer.cpp:906
virtual ~TimerId()
Destructor.
Definition: alsatimer.cpp:289
ALSA Timer identifier container.
Definition: alsatimer.h:79
virtual ~TimerStatus()
Destructor.
Definition: alsatimer.cpp:934
void setEarlyEvent(bool early_event)
Sets the timer early event.
Definition: alsatimer.cpp:818
snd_timer_t * getTimerHandle()
Gets the ALSA timer handle.
Definition: alsatimer.cpp:1156
TimerParams * clone()
Copy the current object.
Definition: alsatimer.cpp:756