Use BOOST_SCOPE_EXIT

This commit is contained in:
Jonas Kvinge 2018-06-12 00:26:08 +02:00
parent c4e64b591d
commit 416beb6b8e
2 changed files with 15 additions and 18 deletions

View File

@ -22,6 +22,7 @@
#include <stdio.h>
#include <errno.h>
#include <alsa/asoundlib.h>
#include <boost/scope_exit.hpp>
#include <QList>
#include <QVariant>
@ -41,20 +42,13 @@ AlsaDeviceFinder::AlsaDeviceFinder()
QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
QList<Device> ret;
int result = -1;
int card = -1;
int dev = -1;
snd_ctl_card_info_t *cardinfo;
snd_pcm_info_t *pcminfo;
snd_ctl_t *handle;
snd_ctl_card_info_alloca(&cardinfo);
snd_pcm_info_alloca(&pcminfo);
snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK);
int card = -1;
snd_ctl_card_info_t* cardinfo;
snd_ctl_card_info_alloca(&cardinfo);
while (true) {
result = snd_card_next(&card);
@ -64,10 +58,10 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
}
if (card < 0) break;
char name[32];
sprintf(name, "hw:%d", card);
result = snd_ctl_open(&handle, name, 0);
char str[32];
snd_ctl_t* handle;
snprintf(str, 31, "hw:%d", card);
result = snd_ctl_open(&handle, str, 0);
if (result < 0) {
qLog(Error) << "Unable to open soundcard" << card << ":" << snd_strerror(result);
continue;
@ -75,11 +69,14 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
result = snd_ctl_card_info(handle, cardinfo);
if (result < 0) {
qLog(Error) << "Control hardware failure for card" << card << ":" << snd_strerror(result);
snd_ctl_close(handle);
BOOST_SCOPE_EXIT(&handle) { snd_ctl_close(handle); }
BOOST_SCOPE_EXIT_END
continue;
}
dev = -1;
int dev = -1;
snd_pcm_info_t* pcminfo;
snd_pcm_info_alloca(&pcminfo);
while (true) {
result = snd_ctl_pcm_next_device(handle, &dev);
@ -106,7 +103,8 @@ QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() {
ret.append(device);
}
snd_ctl_close(handle);
BOOST_SCOPE_EXIT(&handle) { snd_ctl_close(handle); }
BOOST_SCOPE_EXIT_END
}
snd_config_update_free_global();

View File

@ -150,7 +150,6 @@ void StatusView::CreateWidget() {
//qLog(Debug) << __PRETTY_FUNCTION__;
setLayout(layout_);
//setStyleSheet("background-color: white;");
layout_->setSizeConstraint(QLayout::SetMinAndMaxSize);
layout_->setContentsMargins(0, 0, 0, 0);