Explorar el Código

If the web server can't start it should not be a fatal error.

Fixes #44
Tobias Hieta hace 9 años
padre
commit
cbfb121f8d

+ 0 - 4
src/ComponentManager.cpp

@@ -55,10 +55,6 @@ void ComponentManager::initialize()
   // might have some settings
   //
   registerComponent(&SettingsComponent::Get());
-
-  m_server = new HttpServer(this);
-  m_server->start();
-
   registerComponent(&SystemComponent::Get());
   registerComponent(&InputComponent::Get());
   registerComponent(&DisplayComponent::Get());

+ 4 - 0
src/remote/RemoteComponent.cpp

@@ -39,6 +39,10 @@ RemoteComponent::RemoteComponent(QObject* parent) : ComponentBase(parent), m_com
 /////////////////////////////////////////////////////////////////////////////////////////
 bool RemoteComponent::componentInitialize()
 {
+  m_server = new HttpServer(this);
+  if (!m_server->start())
+    return false;
+
   m_gdmManager->startAnnouncing();
 
   // check for timed out subscribers

+ 1 - 0
src/remote/RemoteComponent.h

@@ -57,6 +57,7 @@ private:
   void handleSubscription(QHttpRequest * request, QHttpResponse * response, bool poll=false);
   void subscribeToWeb(bool subscribe);
 
+  HttpServer* m_server;
   GDMManager* m_gdmManager;
 
   quint64 m_commandId;

+ 8 - 2
src/server/HTTPServer.cpp

@@ -20,11 +20,17 @@ HttpServer::HttpServer(QObject* parent) : QObject(parent)
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
-void HttpServer::start()
+bool HttpServer::start()
 {
   connect(m_server, &QHttpServer::newRequest, this, &HttpServer::handleRequest);
   if (!m_server->listen(QHostAddress::AnyIPv4, m_port))
-    throw FatalException(tr("Could not start local web server:") + "<br>" + m_server->errorString());
+  {
+    QLOG_WARN() << "Failed to listen to remote control web server. Remote controlling from apps disabled.";
+    return false;
+  }
+
+  QLOG_DEBUG() << "Listening to port:" << m_port;
+  return true;
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////

+ 1 - 1
src/server/HTTPServer.h

@@ -13,7 +13,7 @@ class HttpServer : public QObject
   Q_OBJECT
 public:
   HttpServer(QObject* parent);
-  void start();
+  bool start();
 
 private slots:
   void handleRequest(QHttpRequest *request, QHttpResponse *response);