Skip to content

Commit 620c499

Browse files
committed
m6: improve error checking
This way we can properly return an error and exit if something goes wrong in the setup. Signed-off-by: Felipe Contreras <[email protected]>
1 parent 7aa4496 commit 620c499

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

m6_main.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,46 @@
1414
Listener::Listener(QObject *parent)
1515
{
1616
setParent(parent);
17+
}
1718

19+
bool Listener::init(void)
20+
{
1821
registry = MafwRegistry::instance();
1922
shared = MafwShared::instance();
2023
shared->initTracking(registry);
2124

2225
renderer = registry->renderer("mafw_gst_renderer");
2326

24-
connect(renderer, SIGNAL(mediaChanged(int, const MafwContent&)),
25-
this, SLOT(next(void)));
27+
if (!connect(renderer, SIGNAL(mediaChanged(int, const MafwContent&)),
28+
this, SLOT(next(void))))
29+
goto fail;
2630

27-
connect(renderer, SIGNAL(stateChanged(MafwRenderer::State)),
28-
this, SLOT(state_changed(MafwRenderer::State)));
31+
if (!connect(renderer, SIGNAL(stateChanged(MafwRenderer::State)),
32+
this, SLOT(state_changed(MafwRenderer::State))))
33+
goto fail;
2934

30-
connect(renderer, SIGNAL(metadataChanged(const QString&, const QList<QVariant>&)),
31-
this, SLOT(metadata_changed(const QString&, const QList<QVariant>&)));
35+
if (!connect(renderer, SIGNAL(metadataChanged(const QString&, const QList<QVariant>&)),
36+
this, SLOT(metadata_changed(const QString&, const QList<QVariant>&))))
37+
goto fail;
3238

3339
tk_factory = new MafwTrackerModelFactory();
3440
tk_factory->init();
3541

3642
tk_conn = tk_factory->trackerConnection();
37-
connect(tk_conn, SIGNAL(musicFavorited(const QSet<int>&)),
38-
this, SLOT(favorited(const QSet<int>&)));
39-
connect(tk_conn, SIGNAL(musicUnfavorited(const QSet<int>&)),
40-
this, SLOT(unfavorited(const QSet<int>&)));
43+
if (!connect(tk_conn, SIGNAL(musicFavorited(const QSet<int>&)),
44+
this, SLOT(favorited(const QSet<int>&))))
45+
goto tk_fail;
46+
47+
if (!connect(tk_conn, SIGNAL(musicUnfavorited(const QSet<int>&)),
48+
this, SLOT(unfavorited(const QSet<int>&))))
49+
goto tk_fail;
50+
51+
return true;
52+
fail:
53+
QCoreApplication::exit(-1);
54+
return false;
55+
tk_fail:
56+
return false;
4157
}
4258

4359
void Listener::next(void)
@@ -124,8 +140,14 @@ int main(int argc, char *argv[])
124140
QCoreApplication a(argc, argv);
125141
Listener listener(&a);
126142

143+
if (!listener.init()) {
144+
r = -1;
145+
goto leave;
146+
}
147+
127148
r = a.exec();
128149

150+
leave:
129151
hp_deinit();
130152

131153
return r;

m6_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Listener : public QObject
1414

1515
public:
1616
Listener(QObject *parent = NULL);
17+
bool init(void);
1718

1819
private slots:
1920
void next(void);

0 commit comments

Comments
 (0)