MythTV
master
mythtv
libs
libmythprotoserver
requesthandler
messagehandler.cpp
Go to the documentation of this file.
1
#include "
libmythbase/mythcorecontext.h
"
2
#include "
libmythbase/mythevent.h
"
3
#include "
libmythbase/mythlogging.h
"
4
5
#include "
requesthandler/messagehandler.h
"
6
7
MessageHandler::MessageHandler
(
void
)
8
{
9
if
(!
gCoreContext
)
10
{
11
LOG
(VB_GENERAL, LOG_ERR,
"MessageHandler started with no CoreContext!"
);
12
return
;
13
}
14
gCoreContext
->
addListener
(
this
);
15
}
16
17
void
MessageHandler::customEvent
(QEvent *e)
18
{
19
if
(e->type() !=
MythEvent::kMythEventMessage
)
20
return
;
21
22
if
(!
gCoreContext
->
IsMasterBackend
())
23
// only master backend should forward events
24
return
;
25
26
//MythEvent *me = static_cast<MythEvent *>(e);
27
28
// TODO: actually do something
29
// right now, this really doesnt need to do anything, but at such time as
30
// the backend's mainserver.cpp is migrated over, this will need to
31
// its message passing behavior
32
}
33
34
bool
MessageHandler::HandleQuery
(
SocketHandler
*socket, QStringList &commands,
35
QStringList &slist)
36
{
37
const
QString& command = commands[0];
38
bool
res =
false
;
39
40
if
(command ==
"MESSAGE"
)
41
res =
HandleInbound
(socket, slist);
42
else
if
(command ==
"BACKEND_MESSAGE"
)
43
res =
HandleOutbound
(socket, slist);
44
45
return
res;
46
}
47
48
// inbound events from clients
49
bool
MessageHandler::HandleInbound
(
SocketHandler
*sock, QStringList &slist)
50
{
51
QStringList res;
52
if
(slist.size() < 2)
53
{
54
res <<
"ERROR"
<<
"Insufficient Length"
;
55
sock->
WriteStringList
(res);
56
return
true
;
57
}
58
59
const
QString& message = slist[1];
60
QStringList extra_data;
61
for
(
uint
i = 2; i < (
uint
) slist.size(); i++)
62
extra_data.push_back(slist[i]);
63
64
if
(extra_data.empty())
65
{
66
MythEvent
me(message);
67
gCoreContext
->
dispatch
(me);
68
}
69
else
70
{
71
MythEvent
me(message, extra_data);
72
gCoreContext
->
dispatch
(me);
73
}
74
75
res <<
"OK"
;
76
sock->
WriteStringList
(res);
77
return
true
;
78
}
79
94
bool
MessageHandler::HandleOutbound
(
SocketHandler
*
/*sock*/
, QStringList &slist)
95
{
96
QStringList::const_iterator iter = slist.cbegin();
97
QString message = *(iter++);
98
QStringList extra_data( *(iter++) );
99
++iter;
100
for
(; iter != slist.cend(); ++iter)
101
extra_data << *iter;
102
MythEvent
me(message, extra_data);
103
gCoreContext
->
dispatch
(me);
104
return
true
;
105
}
106
MessageHandler::customEvent
void customEvent(QEvent *e) override
Definition:
messagehandler.cpp:17
MessageHandler::MessageHandler
MessageHandler(void)
Definition:
messagehandler.cpp:7
MessageHandler::HandleOutbound
static bool HandleOutbound(SocketHandler *sock, QStringList &slist)
Handle an asynchronous message received from the master backend.
Definition:
messagehandler.cpp:94
MessageHandler::HandleInbound
static bool HandleInbound(SocketHandler *sock, QStringList &slist)
Definition:
messagehandler.cpp:49
MessageHandler::HandleQuery
bool HandleQuery(SocketHandler *socket, QStringList &commands, QStringList &slist) override
Definition:
messagehandler.cpp:34
MythCoreContext::dispatch
void dispatch(const MythEvent &event)
Definition:
mythcorecontext.cpp:1746
MythCoreContext::IsMasterBackend
bool IsMasterBackend(void)
is this the actual MBE process
Definition:
mythcorecontext.cpp:702
MythEvent
This class is used as a container for messages.
Definition:
mythevent.h:17
MythEvent::kMythEventMessage
static const Type kMythEventMessage
Definition:
mythevent.h:79
MythObservable::addListener
void addListener(QObject *listener)
Add a listener to the observable.
Definition:
mythobservable.cpp:38
SocketHandler
Definition:
sockethandler.h:17
SocketHandler::WriteStringList
bool WriteStringList(const QStringList &strlist)
Definition:
sockethandler.cpp:25
uint
unsigned int uint
Definition:
compat.h:68
messagehandler.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition:
mythcorecontext.cpp:57
mythcorecontext.h
mythevent.h
mythlogging.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition:
mythlogging.h:39
Generated on Mon Dec 15 2025 03:16:12 for MythTV by
1.9.4