drumstick  1.1.3
alsatimer.cpp
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2019, 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
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <cmath>
20 #include <cstdio>
21 #include <QReadLocker>
22 #include <QWriteLocker>
23 #include <drumstick/alsatimer.h>
24 
30 namespace drumstick {
31 
88 {
89  snd_timer_info_malloc(&m_Info);
90 }
91 
96 TimerInfo::TimerInfo(const snd_timer_info_t *other)
97 {
98  snd_timer_info_malloc(&m_Info);
99  snd_timer_info_copy(m_Info, other);
100 }
101 
107 {
108  snd_timer_info_malloc(&m_Info);
109  snd_timer_info_copy(m_Info, other.m_Info);
110 }
111 
116 {
117  snd_timer_info_free(m_Info);
118 }
119 
124 TimerInfo*
126 {
127  return new TimerInfo(m_Info);
128 }
129 
134 TimerInfo&
136 {
137  snd_timer_info_copy(m_Info, other.m_Info);
138  return *this;
139 }
140 
145 bool
147 {
148  return (snd_timer_info_is_slave(m_Info) != 0);
149 }
150 
155 int
157 {
158  return snd_timer_info_get_card(m_Info);
159 }
160 
165 QString
167 {
168  return QString(snd_timer_info_get_id(m_Info));
169 }
170 
175 QString
177 {
178  return QString(snd_timer_info_get_name(m_Info));
179 }
180 
185 long
187 {
188  return snd_timer_info_get_resolution(m_Info);
189 }
190 
195 long
197 {
198  long res = getResolution();
199  if (res > 0)
200  {
201  return 1000000000L / res;
202  }
203  return 0;
204 }
205 
210 int
212 {
213  return snd_timer_info_sizeof();
214 }
215 
221 long
223 {
224  return snd_timer_info_get_ticks(m_Info);
225 }
226 
231 {
232  snd_timer_id_malloc(&m_Info);
233 }
234 
239 TimerId::TimerId(const snd_timer_id_t *other)
240 {
241  snd_timer_id_malloc(&m_Info);
242  snd_timer_id_copy(m_Info, other);
243  if (getCard() < 0)
244  setCard(0);
245  if (getDevice() < 0)
246  setDevice(0);
247  if (getSubdevice() < 0)
248  setSubdevice(0);
249 }
250 
256 {
257  snd_timer_id_malloc(&m_Info);
258  snd_timer_id_copy(m_Info, other.m_Info);
259  if (getCard() < 0)
260  setCard(0);
261  if (getDevice() < 0)
262  setDevice(0);
263  if (getSubdevice() < 0)
264  setSubdevice(0);
265 }
266 
275 TimerId::TimerId(int cls, int scls, int card, int dev, int sdev)
276 {
277  snd_timer_id_malloc(&m_Info);
278  setClass(cls);
279  setSlaveClass(scls);
280  setCard(card);
281  setDevice(dev);
282  setSubdevice(sdev);
283 }
284 
289 {
290  snd_timer_id_free(m_Info);
291 }
292 
297 TimerId*
299 {
300  return new TimerId(m_Info);
301 }
302 
308 TimerId&
310 {
311  snd_timer_id_copy(m_Info, other.m_Info);
312  if (getCard() < 0)
313  setCard(0);
314  if (getDevice() < 0)
315  setDevice(0);
316  if (getSubdevice() < 0)
317  setSubdevice(0);
318  return *this;
319 }
320 
331 void
332 TimerId::setClass(int devclass)
333 {
334  snd_timer_id_set_class(m_Info, devclass);
335 }
336 
342 int
344 {
345  return snd_timer_id_get_class(m_Info);
346 }
347 
352 void
354 {
355  snd_timer_id_set_sclass(m_Info, devsclass);
356 }
357 
362 int
364 {
365  return snd_timer_id_get_sclass(m_Info);
366 }
367 
372 void
374 {
375  snd_timer_id_set_card(m_Info, card);
376 }
377 
382 int
384 {
385  return snd_timer_id_get_card(m_Info);
386 }
387 
392 void
394 {
395  snd_timer_id_set_device(m_Info, device);
396 }
397 
402 int
404 {
405  return snd_timer_id_get_device(m_Info);
406 }
407 
412 void
413 TimerId::setSubdevice(int subdevice)
414 {
415  snd_timer_id_set_subdevice (m_Info, subdevice);
416 }
417 
422 int
424 {
425  return snd_timer_id_get_subdevice(m_Info);
426 }
427 
432 int
434 {
435  return snd_timer_id_sizeof();
436 }
437 
443 TimerQuery::TimerQuery(const QString& deviceName, int openMode)
444 {
445  CHECK_WARNING( snd_timer_query_open( &m_Info,
446  deviceName.toLocal8Bit().data(),
447  openMode ));
448  readTimers();
449 }
450 
457 TimerQuery::TimerQuery( const QString& deviceName, int openMode,
458  snd_config_t* conf )
459 {
460  CHECK_WARNING( snd_timer_query_open_lconf( &m_Info,
461  deviceName.toLocal8Bit().data(),
462  openMode, conf ));
463  readTimers();
464 }
465 
470 {
471  freeTimers();
472  snd_timer_query_close(m_Info);
473 }
474 
478 void
480 {
481  TimerId tid;
482  snd_timer_id_set_class(tid.m_Info, SND_TIMER_CLASS_NONE);
483  for(;;)
484  {
485  int rc = snd_timer_query_next_device(m_Info, tid.m_Info);
486  if ((rc < 0) || (tid.getClass() < 0)) {
487  break;
488  }
489  m_timers.append(tid);
490  }
491 }
492 
496 void
498 {
499  m_timers.clear();
500 }
501 
508 {
509  snd_timer_query_info(m_Info, m_GlobalInfo.m_Info);
510  return m_GlobalInfo;
511 }
512 
517 void
518 TimerQuery::setGlobalParams(snd_timer_gparams_t* params)
519 {
520  snd_timer_query_params(m_Info, params);
521 }
522 
527 void
528 TimerQuery::getGlobalParams(snd_timer_gparams_t* params)
529 {
530  snd_timer_query_params(m_Info, params);
531 }
532 
537 void
538 TimerQuery::getGlobalStatus(snd_timer_gstatus_t *status)
539 {
540  snd_timer_query_status(m_Info, status);
541 }
542 
547 {
548  snd_timer_ginfo_malloc(&m_Info);
549 }
550 
555 TimerGlobalInfo::TimerGlobalInfo(const snd_timer_ginfo_t* other)
556 {
557  snd_timer_ginfo_malloc(&m_Info);
558  snd_timer_ginfo_copy(m_Info, other);
559 }
560 
566 {
567  snd_timer_ginfo_malloc(&m_Info);
568  snd_timer_ginfo_copy(m_Info, other.m_Info);
569 }
570 
575 {
576  snd_timer_ginfo_free(m_Info);
577 }
578 
585 {
586  return new TimerGlobalInfo(m_Info);
587 }
588 
596 {
597  snd_timer_ginfo_copy(m_Info, other.m_Info);
598  return *this;
599 }
600 
605 void
607 {
608  m_Id = tid;
609  snd_timer_ginfo_set_tid (m_Info, m_Id.m_Info);
610 }
611 
616 TimerId&
618 {
619  m_Id = TimerId(snd_timer_ginfo_get_tid (m_Info));
620  return m_Id;
621 }
622 
627 unsigned int
629 {
630  return snd_timer_ginfo_get_flags (m_Info);
631 }
632 
637 int
639 {
640  return snd_timer_ginfo_get_card (m_Info);
641 }
642 
647 QString
649 {
650  return QString(snd_timer_ginfo_get_id (m_Info));
651 }
652 
657 QString
659 {
660  return QString(snd_timer_ginfo_get_name (m_Info));
661 }
662 
667 unsigned long
669 {
670  return snd_timer_ginfo_get_resolution (m_Info);
671 }
672 
677 unsigned long
679 {
680  return snd_timer_ginfo_get_resolution_min (m_Info);
681 }
682 
687 unsigned long
689 {
690  return snd_timer_ginfo_get_resolution_max(m_Info);
691 }
692 
697 unsigned int
699 {
700  return snd_timer_ginfo_get_clients(m_Info);
701 }
702 
707 int
709 {
710  return snd_timer_ginfo_sizeof();
711 }
712 
717 {
718  snd_timer_params_malloc (&m_Info);
719 }
720 
725 TimerParams::TimerParams(const snd_timer_params_t *other)
726 {
727  snd_timer_params_malloc (&m_Info);
728  snd_timer_params_copy (m_Info, other);
729 }
730 
736 {
737  snd_timer_params_malloc (&m_Info);
738  snd_timer_params_copy (m_Info, other.m_Info);
739 }
740 
746 {
747  snd_timer_params_free (m_Info);
748 }
749 
756 {
757  return new TimerParams(m_Info);
758 }
759 
767 {
768  snd_timer_params_copy (m_Info, other.m_Info);
769  return *this;
770 }
771 
776 void
778 {
779  snd_timer_params_set_auto_start (m_Info, auto_start ? 1 : 0);
780 }
781 
786 bool
788 {
789  return (snd_timer_params_get_auto_start (m_Info) != 0);
790 }
791 
796 void
798 {
799  snd_timer_params_set_exclusive (m_Info, exclusive ? 1 : 0);
800 }
801 
806 bool
808 {
809  return (snd_timer_params_get_exclusive (m_Info) != 0);
810 }
811 
816 void
817 TimerParams::setEarlyEvent(bool early_event)
818 {
819  snd_timer_params_set_early_event (m_Info, early_event ? 1 : 0);
820 }
821 
826 bool
828 {
829  return (snd_timer_params_get_early_event (m_Info) != 0);
830 }
831 
836 void
838 {
839  snd_timer_params_set_ticks (m_Info, ticks);
840 }
841 
846 long
848 {
849  return snd_timer_params_get_ticks (m_Info);
850 }
851 
856 void
858 {
859  snd_timer_params_set_queue_size (m_Info, queue_size);
860 }
861 
866 long
868 {
869  return snd_timer_params_get_queue_size (m_Info);
870 }
871 
876 void
877 TimerParams::setFilter(unsigned int filter)
878 {
879  snd_timer_params_set_filter (m_Info, filter);
880 }
881 
886 unsigned int
888 {
889  return snd_timer_params_get_filter (m_Info);
890 }
891 
896 int
898 {
899  return snd_timer_params_sizeof();
900 }
901 
906 {
907  snd_timer_status_malloc (&m_Info);
908 }
909 
914 TimerStatus::TimerStatus(const snd_timer_status_t *other)
915 {
916  snd_timer_status_malloc (&m_Info);
917  snd_timer_status_copy (m_Info, other);
918 }
919 
925 {
926  snd_timer_status_malloc (&m_Info);
927  snd_timer_status_copy (m_Info, other.m_Info);
928 }
929 
934 {
935  snd_timer_status_free (m_Info);
936 }
937 
944 {
945  return new TimerStatus(m_Info);
946 }
947 
955 {
956  snd_timer_status_copy (m_Info, other.m_Info);
957  return *this;
958 }
959 
964 snd_htimestamp_t
966 {
967  return snd_timer_status_get_timestamp (m_Info);
968 }
969 
974 long
976 {
977  return snd_timer_status_get_resolution (m_Info);
978 }
979 
984 long
986 {
987  return snd_timer_status_get_lost (m_Info);
988 }
989 
994 long
996 {
997  return snd_timer_status_get_overrun (m_Info);
998 }
999 
1004 long
1006 {
1007  return snd_timer_status_get_queue (m_Info);
1008 }
1009 
1014 int
1016 {
1017  return snd_timer_status_sizeof();
1018 }
1019 
1031 Timer::Timer( const QString& deviceName, int openMode, QObject* parent )
1032  : QObject(parent),
1033  m_asyncHandler(NULL),
1034  m_handler(NULL),
1035  m_thread(NULL),
1036  m_deviceName(deviceName)
1037 {
1038  CHECK_ERROR( snd_timer_open( &m_Info, m_deviceName.toLocal8Bit().data(),
1039  openMode ));
1040 }
1041 
1054 Timer::Timer( const QString& deviceName, int openMode, snd_config_t* conf,
1055  QObject* parent )
1056  : QObject(parent),
1057  m_asyncHandler(NULL),
1058  m_handler(NULL),
1059  m_thread(NULL),
1060  m_deviceName(deviceName)
1061 {
1062  CHECK_ERROR( snd_timer_open_lconf( &m_Info,
1063  m_deviceName.toLocal8Bit().data(),
1064  openMode, conf ));
1065 }
1066 
1078 Timer::Timer( TimerId& id, int openMode, QObject* parent )
1079  : QObject(parent),
1080  m_asyncHandler(NULL),
1081  m_handler(NULL),
1082  m_thread(NULL)
1083 {
1084  m_deviceName = QString("hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1085  .arg(id.getClass())
1086  .arg(id.getSlaveClass())
1087  .arg(id.getCard())
1088  .arg(id.getDevice())
1089  .arg(id.getSubdevice());
1090  CHECK_ERROR( snd_timer_open( &m_Info,
1091  m_deviceName.toLocal8Bit().data(),
1092  openMode ));
1093 }
1094 
1110 Timer::Timer( int cls, int scls, int card, int dev, int sdev,
1111  int openMode, QObject* parent )
1112  : QObject(parent),
1113  m_asyncHandler(NULL),
1114  m_handler(NULL),
1115  m_thread(NULL)
1116 {
1117  m_deviceName = QString("hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1118  .arg(cls)
1119  .arg(scls)
1120  .arg(card)
1121  .arg(dev)
1122  .arg(sdev);
1123  CHECK_ERROR( snd_timer_open( &m_Info,
1124  m_deviceName.toLocal8Bit().data(),
1125  openMode ));
1126 }
1127 
1132 {
1133  stopEvents();
1134  if (m_thread != NULL)
1135  delete m_thread;
1136  CHECK_WARNING(snd_timer_close(m_Info));
1137 }
1138 
1144 void
1145 Timer::addAsyncTimerHandler(snd_async_callback_t callback, void *private_data)
1146 {
1147  CHECK_WARNING(snd_async_add_timer_handler(&m_asyncHandler, m_Info, callback, private_data));
1148 }
1149 
1154 snd_timer_t*
1156 {
1157  return snd_async_handler_get_timer(m_asyncHandler);
1158 }
1159 
1164 int
1166 {
1167  return snd_timer_poll_descriptors_count(m_Info);
1168 }
1169 
1175 void
1176 Timer::pollDescriptors(struct pollfd *pfds, unsigned int space)
1177 {
1178  CHECK_WARNING(snd_timer_poll_descriptors(m_Info, pfds, space));
1179 }
1180 
1187 void
1188 Timer::pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
1189 {
1190  CHECK_WARNING(snd_timer_poll_descriptors_revents(m_Info, pfds, nfds, revents));
1191 }
1192 
1197 TimerInfo&
1199 {
1200  snd_timer_info (m_Info, m_TimerInfo.m_Info);
1201  return m_TimerInfo;
1202 }
1203 
1208 void
1210 {
1211  CHECK_WARNING( snd_timer_params(m_Info, params.m_Info) );
1212 }
1213 
1218 TimerStatus&
1220 {
1221  CHECK_WARNING( snd_timer_status(m_Info, m_TimerStatus.m_Info) );
1222  return m_TimerStatus;
1223 }
1224 
1228 void
1230 {
1231  CHECK_WARNING(snd_timer_start(m_Info));
1232 }
1233 
1237 void
1239 {
1240  CHECK_WARNING(snd_timer_stop(m_Info));
1241 }
1242 
1246 void
1248 {
1249  CHECK_WARNING(snd_timer_continue(m_Info));
1250 }
1251 
1258 ssize_t
1259 Timer::read(void *buffer, size_t size)
1260 {
1261  return snd_timer_read(m_Info, buffer, size);
1262 }
1263 
1272 void
1274 {
1275  snd_timer_tread_t tr;
1276  while ( read(&tr, sizeof(tr)) == sizeof(tr) ) {
1277  int msecs = ((tr.tstamp.tv_sec - m_last_time.tv_sec) * 1000) +
1278  round((tr.tstamp.tv_nsec - m_last_time.tv_nsec) / 1000000.0);
1279  m_last_time = tr.tstamp;
1280  if ( m_handler != NULL )
1281  m_handler->handleTimerEvent(tr.val, msecs);
1282  else
1283  emit timerExpired(tr.val, msecs);
1284  }
1285 }
1286 
1291 {
1292  m_last_time = getTimerStatus().getTimestamp();
1293  if (m_thread == NULL) {
1294  m_thread = new TimerInputThread(this, 500);
1295  m_thread->start();
1296  }
1297 }
1298 
1303 {
1304  int counter = 0;
1305  if (m_thread != NULL) {
1306  m_thread->stop();
1307  while (!m_thread->wait(500) && (counter < 10)) {
1308  counter++;
1309  }
1310  if (!m_thread->isFinished()) {
1311  m_thread->terminate();
1312  }
1313  delete m_thread;
1314  }
1315 }
1316 
1323 TimerId
1325 {
1326  TimerId id;
1327  snd_timer_t* timer;
1328  snd_timer_info_t* info;
1329  long res, best_res = LONG_MAX;
1330  char timername[64];
1331  int test_devs[] = {
1332  SND_TIMER_GLOBAL_SYSTEM
1333  , SND_TIMER_GLOBAL_RTC
1334 #ifdef SND_TIMER_GLOBAL_HPET
1335  , SND_TIMER_GLOBAL_HPET
1336 #endif
1337 #ifdef SND_TIMER_GLOBAL_HRTIMER
1338  , SND_TIMER_GLOBAL_HRTIMER
1339 #endif
1340  };
1341  int max_global_timers = sizeof(test_devs)/sizeof(int);
1342  int clas = SND_TIMER_CLASS_GLOBAL;
1343  int scls = SND_TIMER_SCLASS_NONE;
1344  int card = 0;
1345  int dev = SND_TIMER_GLOBAL_SYSTEM;
1346  int sdev = 0;
1347  int err = 0;
1348  int is_slave = 0;
1349  int i;
1350  snd_timer_info_alloca(&info);
1351  // default system timer
1352  id.setClass(clas);
1353  id.setSlaveClass(scls);
1354  id.setCard(card);
1355  id.setDevice(dev);
1356  id.setSubdevice(sdev);
1357  // select a non slave timer with the lowest resolution value
1358  for( i = 0; i < max_global_timers; ++i )
1359  {
1360  dev = test_devs[i];
1361  sprintf( timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i",
1362  clas, scls, card, dev, sdev );
1363  err = snd_timer_open(&timer, timername, SND_TIMER_OPEN_NONBLOCK);
1364  if (err < 0) continue;
1365  err = snd_timer_info(timer, info);
1366  if (err == 0) {
1367  is_slave = snd_timer_info_is_slave(info);
1368  res = snd_timer_info_get_resolution(info);
1369  if ((is_slave == 0) && (best_res > res)) {
1370  best_res = res;
1371  id.setDevice(dev);
1372  }
1373  }
1374  snd_timer_close(timer);
1375  }
1376  return id;
1377 }
1378 
1386 Timer*
1387 Timer::bestGlobalTimer(int openMode, QObject* parent)
1388 {
1389  TimerId id = bestGlobalTimerId();
1390  return new Timer(id, openMode, parent);
1391 }
1392 
1396 void
1397 Timer::TimerInputThread::run()
1398 {
1399  int err, count;
1400  struct pollfd *fds;
1401  if (m_timer == NULL) return;
1402 
1403  count = m_timer->getPollDescriptorsCount();
1404  fds = (pollfd *) calloc(count, sizeof(struct pollfd));
1405  if (fds == NULL) {
1406  qWarning() << "allocation error!";
1407  return;
1408  }
1409  fds->events = POLLIN;
1410  fds->revents = 0;
1411 
1412  try {
1413  while (!stopped() && (m_timer != NULL)) {
1414  m_timer->pollDescriptors(fds, count);
1415  if ((err = poll(fds, count, m_Wait)) < 0) {
1416  qWarning() << "poll error " << err << "(" << strerror(err) << ")";
1417  return;
1418  }
1419  if (err == 0) {
1420  qWarning() << "timer time out";
1421  return;
1422  }
1423  m_timer->doEvents();
1424  }
1425  } catch (...) {
1426  qWarning() << "exception in input thread";
1427  }
1428  free(fds);
1429 }
1430 
1435 bool
1436 Timer::TimerInputThread::stopped()
1437 {
1438  QReadLocker locker(&m_mutex);
1439  return m_Stopped;
1440 }
1441 
1445 void
1446 Timer::TimerInputThread::stop()
1447 {
1448  QWriteLocker locker(&m_mutex);
1449  m_Stopped = true;
1450 }
1451 
1452 } /* namespace drumstick */
TimerGlobalInfo & operator=(const TimerGlobalInfo &other)
Assignment operator.
Definition: alsatimer.cpp:595
QString getName()
Gets the timer name.
Definition: alsatimer.cpp:176
long getResolution()
Gets the resolution in us.
Definition: alsatimer.cpp:975
TimerStatus & operator=(const TimerStatus &other)
Assignment operator.
Definition: alsatimer.cpp:954
void setDevice(int device)
Sets the device number.
Definition: alsatimer.cpp:393
void doEvents()
Internal function to deliver the timer events using one of the two available methods: ...
Definition: alsatimer.cpp:1273
TimerId & getTimerId()
Gets the timer identifier.
Definition: alsatimer.cpp:617
virtual ~TimerInfo()
Destructor.
Definition: alsatimer.cpp:115
void setQueueSize(long queue_size)
Sets the queue size (32-1024)
Definition: alsatimer.cpp:857
TimerId & operator=(const TimerId &other)
Assignment operator.
Definition: alsatimer.cpp:309
long getOverrun()
Gets the overrun count.
Definition: alsatimer.cpp:995
void setTicks(long ticks)
Sets the timer ticks.
Definition: alsatimer.cpp:837
void getGlobalParams(snd_timer_gparams_t *params)
Gets the global timer parameters.
Definition: alsatimer.cpp:528
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:1387
snd_htimestamp_t getTimestamp()
Gets the high resolution time-stamp.
Definition: alsatimer.cpp:965
bool getEarlyEvent()
Gets the timer early event.
Definition: alsatimer.cpp:827
void setAutoStart(bool auto_start)
Sets the automatic start flag.
Definition: alsatimer.cpp:777
void pollDescriptors(struct pollfd *pfds, unsigned int space)
Gets poll descriptors.
Definition: alsatimer.cpp:1176
int getSizeOfInfo() const
Gets the size of the ALSA timer global info object.
Definition: alsatimer.cpp:708
QString getId()
Gets the timer ID string.
Definition: alsatimer.cpp:648
void setGlobalParams(snd_timer_gparams_t *params)
Sets the global parameters.
Definition: alsatimer.cpp:518
void addAsyncTimerHandler(snd_async_callback_t callback, void *private_data)
Adds an asynchronous timer handler function.
Definition: alsatimer.cpp:1145
unsigned int getClients()
Gets current timer clients.
Definition: alsatimer.cpp:698
void getGlobalStatus(snd_timer_gstatus_t *status)
Gets the global timer status.
Definition: alsatimer.cpp:538
virtual ~TimerParams()
Destructor.
Definition: alsatimer.cpp:745
TimerStatus * clone()
Copy the current object.
Definition: alsatimer.cpp:943
int getClass()
Gets the class identifier.
Definition: alsatimer.cpp:343
TimerInfo * clone()
Copy the current object.
Definition: alsatimer.cpp:125
ALSA Timer management.
Definition: alsatimer.h:266
bool getExclusive()
Gets the timer&#39;s exclusive flag.
Definition: alsatimer.cpp:807
int getSubdevice()
Gets the subdevice number.
Definition: alsatimer.cpp:423
void setCard(int card)
Sets the card number.
Definition: alsatimer.cpp:373
long getResolution()
Gets the timer resolution (timer period in nanoseconds)
Definition: alsatimer.cpp:186
The QObject class is the base class of all Qt objects.
unsigned long getResolution()
Gets the timer resolution in ns.
Definition: alsatimer.cpp:668
Classes managing ALSA Timers.
void setExclusive(bool exclusive)
Sets the exclusive flag.
Definition: alsatimer.cpp:797
int getCard()
Gets the card number.
Definition: alsatimer.cpp:156
void freeTimers()
Release the internal list of timers.
Definition: alsatimer.cpp:497
TimerGlobalInfo * clone()
Copy the current object.
Definition: alsatimer.cpp:584
QString getName()
Gets the timer name.
Definition: alsatimer.cpp:658
long getFrequency()
Gets the timer frequency in Hz.
Definition: alsatimer.cpp:196
void setClass(int devclass)
Set the class identifier.
Definition: alsatimer.cpp:332
long getQueueSize()
Gets the queue size.
Definition: alsatimer.cpp:867
TimerQuery(const QString &deviceName, int openMode)
Constructor.
Definition: alsatimer.cpp:443
ssize_t read(void *buffer, size_t size)
Read bytes from the timer handle.
Definition: alsatimer.cpp:1259
TimerId * clone()
Copy the object.
Definition: alsatimer.cpp:298
int getSlaveClass()
Gets the slave class.
Definition: alsatimer.cpp:363
TimerParams()
Default constructor.
Definition: alsatimer.cpp:716
void continueRunning()
Continue rolling the timer.
Definition: alsatimer.cpp:1247
TimerId()
Constructor.
Definition: alsatimer.cpp:230
ALSA Timer information container.
Definition: alsatimer.h:46
ALSA Timer status container.
Definition: alsatimer.h:219
ALSA Timer parameters container.
Definition: alsatimer.h:184
void pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
Gets returned events from poll descriptors.
Definition: alsatimer.cpp:1188
void start()
Start rolling the timer.
Definition: alsatimer.cpp:1229
unsigned long getMinResolution()
Gets timer minimal resolution in ns.
Definition: alsatimer.cpp:678
bool isSlave()
Check if the timer is slave (depends on another device)
Definition: alsatimer.cpp:146
virtual ~TimerGlobalInfo()
Destructor.
Definition: alsatimer.cpp:574
void setTimerId(const TimerId &tid)
Sets the timer identifier.
Definition: alsatimer.cpp:606
void stop()
Stop rolling the timer.
Definition: alsatimer.cpp:1238
void setTimerParams(const TimerParams &params)
Sets the timer parameters.
Definition: alsatimer.cpp:1209
int getCard()
Gets the card number.
Definition: alsatimer.cpp:383
TimerInfo & getTimerInfo()
Gets the timer info object.
Definition: alsatimer.cpp:1198
void setFilter(unsigned int filter)
Sets the event filter.
Definition: alsatimer.cpp:877
int getCard()
Gets the card number.
Definition: alsatimer.cpp:638
Timer(int cls, int scls, int card, int dev, int sdev, int openMode, QObject *parent=0)
Constructor.
Definition: alsatimer.cpp:1110
unsigned int getFlags()
Gets the flags.
Definition: alsatimer.cpp:628
TimerParams & operator=(const TimerParams &other)
Assignment operator.
Definition: alsatimer.cpp:766
long getTicks() __attribute__((deprecated))
Gets the maximum timer ticks.
Definition: alsatimer.cpp:222
long getLost()
Gets the master tick lost count.
Definition: alsatimer.cpp:985
TimerGlobalInfo & getGlobalInfo()
Get a TimerGlobalInfo object.
Definition: alsatimer.cpp:507
unsigned long getMaxResolution()
Gets timer maximal resolution in ns.
Definition: alsatimer.cpp:688
TimerInfo & operator=(const TimerInfo &other)
Assignment operator.
Definition: alsatimer.cpp:135
unsigned int getFilter()
Gets the event filter.
Definition: alsatimer.cpp:887
int getSizeOfInfo() const
Gets the size of the ALSA timer parameters object.
Definition: alsatimer.cpp:897
static TimerId bestGlobalTimerId()
Check and return the best available global TimerId in the system, meaning the timer with higher frequ...
Definition: alsatimer.cpp:1324
long getTicks()
Gets the timer ticks.
Definition: alsatimer.cpp:847
void setSubdevice(int subdevice)
Sets the subdevice number.
Definition: alsatimer.cpp:413
Global timer information container.
Definition: alsatimer.h:119
int getSizeOfInfo() const
Gets the size of the ALSA timer info object.
Definition: alsatimer.cpp:211
virtual ~Timer()
Destructor.
Definition: alsatimer.cpp:1131
long getQueue()
Gets the count of used queue elements.
Definition: alsatimer.cpp:1005
virtual ~TimerQuery()
Destructor.
Definition: alsatimer.cpp:469
int getPollDescriptorsCount()
Gets the count of poll descriptors.
Definition: alsatimer.cpp:1165
int getSizeOfInfo() const
Gets the size of the ALSA timer ID object.
Definition: alsatimer.cpp:433
void startEvents()
Starts the events dispatching thread.
Definition: alsatimer.cpp:1290
void readTimers()
Enumerate the available timers storing the results into an internal list.
Definition: alsatimer.cpp:479
QString getId()
Gets the string identifier.
Definition: alsatimer.cpp:166
virtual void handleTimerEvent(int ticks, int msecs)=0
Timer event handler.
TimerStatus & getTimerStatus()
Gets the timer status.
Definition: alsatimer.cpp:1219
TimerGlobalInfo()
Default constructor.
Definition: alsatimer.cpp:546
int getDevice()
Gets the device number.
Definition: alsatimer.cpp:403
void stopEvents()
Stops the events dispatching thread.
Definition: alsatimer.cpp:1302
#define CHECK_ERROR(x)
This macro calls the check error function.
bool getAutoStart()
Gets the automatic start flag.
Definition: alsatimer.cpp:787
TimerInfo()
Constructor.
Definition: alsatimer.cpp:87
#define CHECK_WARNING(x)
This macro calls the check warning function.
void setSlaveClass(int devsclass)
Sets the Slave class.
Definition: alsatimer.cpp:353
int getSizeOfInfo() const
Gets the size of the ALSA timer status object.
Definition: alsatimer.cpp:1015
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:905
virtual ~TimerId()
Destructor.
Definition: alsatimer.cpp:288
ALSA Timer identifier container.
Definition: alsatimer.h:78
virtual ~TimerStatus()
Destructor.
Definition: alsatimer.cpp:933
void setEarlyEvent(bool early_event)
Sets the timer early event.
Definition: alsatimer.cpp:817
snd_timer_t * getTimerHandle()
Gets the ALSA timer handle.
Definition: alsatimer.cpp:1155
TimerParams * clone()
Copy the current object.
Definition: alsatimer.cpp:755