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