-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathconnectionlistener.cpp
65 lines (52 loc) · 2.21 KB
/
connectionlistener.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
#include "moonlight.hpp"
#include "ppapi/c/ppb_input_event.h"
#include "ppapi/cpp/input_event.h"
#include "ppapi/cpp/mouse_lock.h"
void MoonlightInstance::ClStageStarting(int stage) {
pp::Var response(std::string("ProgressMsg: Starting ") + std::string(LiGetStageName(stage)) + std::string("..."));
g_Instance->PostMessage(response);
}
void MoonlightInstance::ClStageFailed(int stage, int errorCode) {
pp::Var response(
std::string("DialogMsg: ") +
std::string(LiGetStageName(stage)) +
std::string(" failed (error ") +
std::to_string(errorCode) +
std::string(")"));
g_Instance->PostMessage(response);
}
void MoonlightInstance::ClConnectionStarted(void) {
pp::Module::Get()->core()->CallOnMainThread(0,
g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::OnConnectionStarted));
}
void MoonlightInstance::ClConnectionTerminated(int errorCode) {
// Teardown the connection
LiStopConnection();
pp::Module::Get()->core()->CallOnMainThread(0,
g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::OnConnectionStopped), (uint32_t)errorCode);
}
void MoonlightInstance::ClDisplayMessage(const char* message) {
pp::Var response(std::string("DialogMsg: ") + std::string(message));
g_Instance->PostMessage(response);
}
void MoonlightInstance::ClDisplayTransientMessage(const char* message) {
pp::Var response(std::string("TransientMsg: ") + std::string(message));
g_Instance->PostMessage(response);
}
void MoonlightInstance::ClLogMessage(const char* format, ...) {
va_list va;
char message[1024];
va_start(va, format);
vsnprintf(message, sizeof(message), format, va);
va_end(va);
pp::Var response(std::string("LogMsg: ") + std::string(message));
g_Instance->PostMessage(response);
}
CONNECTION_LISTENER_CALLBACKS MoonlightInstance::s_ClCallbacks = {
.stageStarting = MoonlightInstance::ClStageStarting,
.stageFailed = MoonlightInstance::ClStageFailed,
.connectionStarted = MoonlightInstance::ClConnectionStarted,
.connectionTerminated = MoonlightInstance::ClConnectionTerminated,
.logMessage = MoonlightInstance::ClLogMessage,
.rumble = MoonlightInstance::ClControllerRumble,
};