Fraxinus  18.10
An IGT application
cxWebServerPluginActivator.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 
14 #include <QtPlugin>
15 #include <iostream>
16 
17 #include "cxRegisteredService.h"
18 #include <QtConcurrent>
19 #include <QNetworkAccessManager>
20 #include <QHostAddress>
21 #include <qhttpserver.h>
22 #include <qhttprequest.h>
23 #include <qhttpresponse.h>
24 #include "cxScreenVideoProvider.h"
25 
26 #include "cxPatientModelService.h"
27 #include "cxHttpRequestHandler.h"
28 #include "cxRemoteAPI.h"
29 #include "cxLogger.h"
30 
31 #include <QPixmap>
32 
33 namespace cx
34 {
35 
37 {
38  std::cout << "Created NetworkPluginActivator" << std::endl;
39 }
40 
42 {}
43 
44 void NetworkPluginActivator::start(ctkPluginContext* context)
45 {
46  int port = 8085;
47  CX_LOG_INFO() << QString("Starting REST server on port %1...").arg(port);
48  server = new QHttpServer;
49  mAPI.reset(new RemoteAPI(VisServices::create(context)));
50  mRequestHandler.reset(new HttpRequestHandler(mAPI));
51  connect(server, SIGNAL(newRequest(QHttpRequest*, QHttpResponse*)),
52  mRequestHandler.get(), SLOT(handle_request(QHttpRequest*, QHttpResponse*)));
53 
54  // let's go
55  server->listen(port);
56 
57 }
58 
59 void NetworkPluginActivator::stop(ctkPluginContext* context)
60 {
61  mRequestHandler.reset();
62  mAPI.reset();
63 
64  server->close();
65  delete server;
66  server = NULL;
67 
68  Q_UNUSED(context);
69 }
70 
71 
72 } // namespace cx
73 
74 
75 
void stop(ctkPluginContext *context)
#define CX_LOG_INFO
Definition: cxLogger.h:96
static VisServicesPtr create(ctkPluginContext *context)
void start(ctkPluginContext *context)
Namespace for all CustusX production code.