2016-06-04 10:50:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2016-06-05 21:16:13 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
The :mod:`http` module contains the API web server. This is a lightweight web server used by remotes to interact
|
|
|
|
with OpenLP. It uses JSON to communicate with the remotes.
|
|
|
|
"""
|
|
|
|
|
2016-06-05 16:20:39 +00:00
|
|
|
import logging
|
|
|
|
|
2016-06-05 21:16:13 +00:00
|
|
|
from PyQt5 import QtCore
|
2016-06-10 16:16:35 +00:00
|
|
|
from waitress import serve
|
2016-06-05 21:16:13 +00:00
|
|
|
|
2016-06-10 16:16:35 +00:00
|
|
|
from openlp.core.api import application
|
2016-06-05 21:16:13 +00:00
|
|
|
from openlp.core.common import RegistryProperties, OpenLPMixin
|
2016-06-04 10:50:43 +00:00
|
|
|
|
2016-06-05 16:20:39 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2016-06-04 10:50:43 +00:00
|
|
|
|
2016-06-06 19:56:38 +00:00
|
|
|
class HttpThread(QtCore.QObject):
|
2016-06-05 05:49:27 +00:00
|
|
|
"""
|
2016-06-05 21:16:13 +00:00
|
|
|
A special Qt thread class to allow the HTTP server to run at the same time as the UI.
|
|
|
|
"""
|
2016-06-06 19:56:38 +00:00
|
|
|
def __init__(self):
|
2016-06-05 21:16:13 +00:00
|
|
|
"""
|
|
|
|
Constructor for the thread class.
|
2016-06-04 10:50:43 +00:00
|
|
|
|
2016-06-05 21:16:13 +00:00
|
|
|
:param server: The http server class.
|
|
|
|
"""
|
2016-06-06 19:56:38 +00:00
|
|
|
super().__init__()
|
2016-06-04 10:50:43 +00:00
|
|
|
|
2016-06-06 19:56:38 +00:00
|
|
|
def start(self):
|
2016-06-04 10:50:43 +00:00
|
|
|
"""
|
2016-06-05 21:16:13 +00:00
|
|
|
Run the thread.
|
2016-06-04 10:50:43 +00:00
|
|
|
"""
|
2016-06-10 16:16:35 +00:00
|
|
|
serve(application, host='0.0.0.0', port=4318)
|
2016-06-05 21:16:13 +00:00
|
|
|
|
|
|
|
def stop(self):
|
2016-06-06 19:56:38 +00:00
|
|
|
pass
|
2016-06-05 05:49:27 +00:00
|
|
|
|
2016-06-05 21:16:13 +00:00
|
|
|
|
|
|
|
class OpenLPHttpServer(RegistryProperties, OpenLPMixin):
|
|
|
|
"""
|
|
|
|
Wrapper round a server instance
|
|
|
|
"""
|
2016-06-06 19:56:38 +00:00
|
|
|
def __init__(self):
|
2016-06-04 19:32:50 +00:00
|
|
|
"""
|
2016-06-05 21:16:13 +00:00
|
|
|
Initialise the http server, and start the server of the correct type http / https
|
2016-06-04 19:32:50 +00:00
|
|
|
"""
|
2016-06-05 21:16:13 +00:00
|
|
|
super(OpenLPHttpServer, self).__init__()
|
2016-06-06 19:56:38 +00:00
|
|
|
self.thread = QtCore.QThread()
|
|
|
|
self.worker = HttpThread()
|
|
|
|
self.worker.moveToThread(self.thread)
|
|
|
|
self.thread.started.connect(self.worker.start)
|
|
|
|
self.thread.start()
|