drumstick 2.9.0
C++ MIDI libraries using Qt objects, idioms, and style.
errorcheck.h
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2023, 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 3 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#ifndef ERRORCHECK_H
20#define ERRORCHECK_H
21
22extern "C" {
23#include <alsa/asoundlib.h>
24}
25
26#include <QString>
27#include <QDebug>
29
35namespace drumstick { namespace ALSA {
36
50inline int checkErrorAndThrow(int rc, const char *where)
51{
52 if (rc < 0) {
53 qDebug() << "Error code:" << rc << "(" << snd_strerror(rc) << ")";
54 qDebug() << "Location:" << where;
55 throw SequencerError(QString(where), rc);
56 }
57 return rc;
58}
59
67inline int checkWarning(int rc, const char *where)
68{
69 if (rc < 0) {
70 qWarning() << "Exception code:" << rc << "(" << snd_strerror(rc) << ")";
71 qWarning() << "Location:" << where;
72 }
73 return rc;
74}
75
80#define DRUMSTICK_ALSA_CHECK_ERROR(x) (checkErrorAndThrow((x),__PRETTY_FUNCTION__))
81
86#define DRUMSTICK_ALSA_CHECK_WARNING(x) (checkWarning((x),__PRETTY_FUNCTION__))
87
90}} // namespace drumstick::ALSA
91
92#endif // ERRORCHECK_H
Exception class for ALSA Sequencer errors.
int checkWarning(int rc, const char *where)
Check the error code for warning errors.
Definition: errorcheck.h:67
int checkErrorAndThrow(int rc, const char *where)
Checks the error code for severe errors.
Definition: errorcheck.h:50
Drumstick common.
Definition: alsaclient.cpp:68
SequencerError Exception class.