MythTV master
mythhttpinstance.cpp
Go to the documentation of this file.
1// MythTV
2#include "mthread.h"
4#include "http/mythhttproot.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 QThread::usleep(50);
29 while (!m_httpServerThread->qthread()->isRunning())
30 {
31 QThread::usleep(50);
32 }
33}
34
36{
38 {
41 }
42 delete m_httpServerThread;
43 delete m_httpServer;
44}
45
52{
54 {
58 Instance().m_httpServerThread = nullptr;
59 }
60
61 delete Instance().m_httpServer;
62 Instance().m_httpServer = nullptr;
63}
64
70{
71 emit Instance().m_httpServer->EnableHTTP(Enable);
72}
73
79void MythHTTPInstance::AddPaths(const QStringList &Paths)
80{
81 emit Instance().m_httpServer->AddPaths(Paths);
82}
83
86void MythHTTPInstance::RemovePaths(const QStringList &Paths)
87{
88 emit Instance().m_httpServer->RemovePaths(Paths);
89}
90
97{
98 emit Instance().m_httpServer->AddHandlers(Handlers);
99}
100
102{
103 emit Instance().m_httpServer->RemoveHandlers(Handlers);
104}
105
107{
108 emit Instance().m_httpServer->AddServices(Services);
109}
110
112{
113 emit Instance().m_httpServer->RemoveServices(Services);
114}
115
117{
119}
120
124{
127}
128
130{
132}
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:283
void quit(void)
calls exit(0)
Definition: mthread.cpp:295
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
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
static void AddErrorPageHandler(const HTTPHandler &Handler)
static void Addservices(const HTTPServices &Services)
static void RemoveHandlers(const HTTPHandlers &Handlers)
static void StopHTTPService()
Stop and delete the MythHTTPServer instance.
static void EnableHTTPService(bool Enable=true)
Signals to the MythHTTPServer instance whether to start or stop listening.
MythHTTPServer * m_httpServer
static void RemovePaths(const QStringList &Paths)
Remove path(s) from the MythHTTPServer instance.
static void AddPaths(const QStringList &Paths)
Add path(s) for the MythHTTPServer instance to handle.
static void AddHandlers(const HTTPHandlers &Handlers)
Add function handlers for specific paths.
static MythHTTPInstance & Instance()
MThread * m_httpServerThread
static void RemoveServices(const HTTPServices &Services)
MythHTTPScopedInstance(const HTTPHandlers &Handlers)
A convenience class to manage the lifetime of a MythHTTPInstance.
void RemoveServices(const HTTPServices &Services)
void RemovePaths(const QStringList &Paths)
void EnableHTTP(bool Enable)
void AddHandlers(const HTTPHandlers &Handlers)
void AddServices(const HTTPServices &Services)
void AddErrorPageHandler(const HTTPHandler &Handler)
void RemoveHandlers(const HTTPHandlers &Handlers)
void AddPaths(const QStringList &Paths)
std::vector< HTTPHandler > HTTPHandlers
Definition: mythhttptypes.h:48
std::vector< HTTPService > HTTPServices
Definition: mythhttptypes.h:55
std::pair< QString, HTTPFunction > HTTPHandler
Definition: mythhttptypes.h:47