MythTV  master
mythhttpinstance.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mthread.h"
4 #include "http/mythhttproot.h"
5 #include "http/mythhttpserver.h"
6 
8 {
9  static MythHTTPInstance s_instance;
10  return s_instance;
11 }
12 
14  : m_httpServer(new MythHTTPServer),
15  m_httpServerThread(new MThread("HTTPServer"))
16 {
17  // We need to register some types and this should always be hit at least once
18  // before they are needed
19  qRegisterMetaType<HTTPHandler>();
20  qRegisterMetaType<HTTPHandlers>();
21  qRegisterMetaType<HTTPServices>();
22  qRegisterMetaType<DataPayload>();
23  qRegisterMetaType<DataPayloads>();
24  qRegisterMetaType<StringPayload>();
25 
26  m_httpServer->moveToThread(m_httpServerThread->qthread());
28  do { QThread::usleep(50); } while (!m_httpServerThread->qthread()->isRunning());
29 }
30 
32 {
34  {
37  }
38  delete m_httpServerThread;
39  delete m_httpServer;
40 }
41 
48 {
50  {
54  Instance().m_httpServerThread = nullptr;
55  }
56 
57  delete Instance().m_httpServer;
58  Instance().m_httpServer = nullptr;
59 }
60 
66 {
67  emit Instance().m_httpServer->EnableHTTP(Enable);
68 }
69 
75 void MythHTTPInstance::AddPaths(const QStringList &Paths)
76 {
77  emit Instance().m_httpServer->AddPaths(Paths);
78 }
79 
82 void MythHTTPInstance::RemovePaths(const QStringList &Paths)
83 {
84  emit Instance().m_httpServer->RemovePaths(Paths);
85 }
86 
93 {
94  emit Instance().m_httpServer->AddHandlers(Handlers);
95 }
96 
98 {
99  emit Instance().m_httpServer->RemoveHandlers(Handlers);
100 }
101 
103 {
104  emit Instance().m_httpServer->AddServices(Services);
105 }
106 
108 {
109  emit Instance().m_httpServer->RemoveServices(Services);
110 }
111 
113 {
114  emit Instance().m_httpServer->AddErrorPageHandler(Handler);
115 }
116 
120 {
123 }
124 
126 {
128 }
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:283
MThread::quit
void quit(void)
calls exit(0)
Definition: mthread.cpp:295
MThread::wait
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
MythHTTPInstance
Definition: mythhttpinstance.h:11
MythHTTPServer::EnableHTTP
void EnableHTTP(bool Enable)
mythhttpinstance.h
MythHTTPServer::RemovePaths
void RemovePaths(const QStringList &Paths)
MythHTTPScopedInstance::MythHTTPScopedInstance
MythHTTPScopedInstance(const HTTPHandlers &Handlers)
A convenience class to manage the lifetime of a MythHTTPInstance.
Definition: mythhttpinstance.cpp:119
MythHTTPServer::AddErrorPageHandler
void AddErrorPageHandler(const HTTPHandler &Handler)
MythHTTPServer::AddHandlers
void AddHandlers(const HTTPHandlers &Handlers)
MythHTTPServer::AddPaths
void AddPaths(const QStringList &Paths)
MythHTTPInstance::AddPaths
static void AddPaths(const QStringList &Paths)
Add path(s) for the MythHTTPServer instance to handle.
Definition: mythhttpinstance.cpp:75
MythHTTPInstance::Addservices
static void Addservices(const HTTPServices &Services)
Definition: mythhttpinstance.cpp:102
MythHTTPScopedInstance::~MythHTTPScopedInstance
~MythHTTPScopedInstance()
Definition: mythhttpinstance.cpp:125
MThread::qthread
QThread * qthread(void)
Returns the thread, this will always return the same pointer no matter how often you restart the thre...
Definition: mthread.cpp:233
MythHTTPInstance::RemoveServices
static void RemoveServices(const HTTPServices &Services)
Definition: mythhttpinstance.cpp:107
MythHTTPInstance::AddHandlers
static void AddHandlers(const HTTPHandlers &Handlers)
Add function handlers for specific paths.
Definition: mythhttpinstance.cpp:92
MythHTTPInstance::Instance
static MythHTTPInstance & Instance()
Definition: mythhttpinstance.cpp:7
MythHTTPInstance::~MythHTTPInstance
~MythHTTPInstance()
Definition: mythhttpinstance.cpp:31
MythHTTPInstance::RemovePaths
static void RemovePaths(const QStringList &Paths)
Remove path(s) from the MythHTTPServer instance.
Definition: mythhttpinstance.cpp:82
mythhttpserver.h
MythHTTPInstance::m_httpServerThread
MThread * m_httpServerThread
Definition: mythhttpinstance.h:32
mythhttproot.h
MythHTTPInstance::m_httpServer
MythHTTPServer * m_httpServer
Definition: mythhttpinstance.h:31
MythHTTPServer::RemoveHandlers
void RemoveHandlers(const HTTPHandlers &Handlers)
MythHTTPInstance::StopHTTPService
static void StopHTTPService()
Stop and delete the MythHTTPServer instance.
Definition: mythhttpinstance.cpp:47
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
mthread.h
MythHTTPServer
Definition: mythhttpserver.h:12
MythHTTPInstance::EnableHTTPService
static void EnableHTTPService(bool Enable=true)
Signals to the MythHTTPServer instance whether to start or stop listening.
Definition: mythhttpinstance.cpp:65
MythHTTPServer::AddServices
void AddServices(const HTTPServices &Services)
HTTPServices
std::vector< HTTPService > HTTPServices
Definition: mythhttptypes.h:54
MythHTTPServer::RemoveServices
void RemoveServices(const HTTPServices &Services)
MythHTTPInstance::RemoveHandlers
static void RemoveHandlers(const HTTPHandlers &Handlers)
Definition: mythhttpinstance.cpp:97
HTTPHandler
std::pair< QString, HTTPFunction > HTTPHandler
Definition: mythhttptypes.h:46
MythHTTPInstance::MythHTTPInstance
MythHTTPInstance()
Definition: mythhttpinstance.cpp:13
HTTPHandlers
std::vector< HTTPHandler > HTTPHandlers
Definition: mythhttptypes.h:47
MythHTTPInstance::AddErrorPageHandler
static void AddErrorPageHandler(const HTTPHandler &Handler)
Definition: mythhttpinstance.cpp:112