-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBusPODProxy.cpp
93 lines (85 loc) · 2.12 KB
/
DBusPODProxy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* File: DBusPODProxy.cpp
* Author: Saleem Edah-Tally - [email protected]
* License : GPL V2
*
* Created on 10 décembre 2017, 18:51
*/
#include "DBusPODProxy.h"
#include "globals.h"
#include <iostream>
#include <thread>
using namespace std;
#include "DBusMprisProxy.h"
DBusMprisProxy * g_MprisProxy;
extern string g_backend;
extern uint g_rewind;
extern uint g_fastforward;
extern uint g_play;
extern bool g_verbose;
/**
* Controls playback of an MPRIS compliant media player.
* @param connection
* @param service
*/
DBusPODProxy::DBusPODProxy(DBus::Connection &connection, const char * service)
: DBus::ObjectProxy(connection, "/pedal/event", service)
{
thread t(Entry);
t.detach();
string mpris_service("org.mpris.MediaPlayer2.");
mpris_service += g_backend;
g_MprisProxy = new DBusMprisProxy(connection, mpris_service.c_str());
}
DBusPODProxy::~DBusPODProxy()
{
DBus::default_dispatcher->leave();
delete g_MprisProxy;
}
void DBusPODProxy::OnPedalEvent(const int32_t& code)
{
if (g_verbose)
cout << code << endl;
try
{
// Stop evenything whenever a pedal whenever occurs
g_MprisProxy->Reset();
g_MprisProxy->Pause();
// switch case does not compile here
if ((uint) code == g_rewind)
{
g_MprisProxy->Rewind(FFR_STEP);
}
else if ((uint) code == g_rewind + g_play)
{
g_MprisProxy->Rewind(FFR_STEP_QUICK);
}
else if ((uint) code == g_fastforward)
{
g_MprisProxy->FastForward(FFR_STEP);
}
else if ((uint) code == g_fastforward + g_play)
{
g_MprisProxy->FastForward(FFR_STEP_QUICK);
}
else if ((uint) code == g_play)
{
g_MprisProxy->AutoRewind();
g_MprisProxy->Play();
}
else
{
g_MprisProxy->Reset();
g_MprisProxy->Pause();
}
}
catch (DBus::Error e)
{
cout << e.message() << _NL_ << e.name() << endl;
}
}
int DBusPODProxy::Entry()
{
DBus::default_dispatcher->enter(); // IS BLOCKING
return 0;
}