MythTV master
messagehandler.cpp
Go to the documentation of this file.
4
6
8{
9 if (!gCoreContext)
10 {
11 LOG(VB_GENERAL, LOG_ERR, "MessageHandler started with no CoreContext!");
12 return;
13 }
15}
16
18{
19 if (e->type() != MythEvent::kMythEventMessage)
20 return;
21
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
34bool 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
49bool 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);
68 }
69 else
70 {
71 MythEvent me(message, extra_data);
73 }
74
75 res << "OK";
76 sock->WriteStringList(res);
77 return true;
78}
79
94bool 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);
104 return true;
105}
106
void customEvent(QEvent *e) override
static bool HandleOutbound(SocketHandler *sock, QStringList &slist)
Handle an asynchronous message received from the master backend.
static bool HandleInbound(SocketHandler *sock, QStringList &slist)
bool HandleQuery(SocketHandler *socket, QStringList &commands, QStringList &slist) override
void dispatch(const MythEvent &event)
bool IsMasterBackend(void)
is this the actual MBE process
This class is used as a container for messages.
Definition: mythevent.h:17
static const Type kMythEventMessage
Definition: mythevent.h:79
void addListener(QObject *listener)
Add a listener to the observable.
bool WriteStringList(const QStringList &strlist)
unsigned int uint
Definition: compat.h:68
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39