Pārlūkot izejas kodu

Cleanup DAH example host and app.

The method ctkPluginContext::getProperty() allows a cleaner
approach to instantiating the http server and registering the service
classes. The ctkDicomAppServer does not need to be exported anymore.
Sascha Zelzer 14 gadi atpakaļ
vecāks
revīzija
65432d594e

+ 3 - 3
Applications/ctkExampleHost/ctkExampleHostMain.cpp

@@ -95,13 +95,13 @@ int main(int argv, char** argc)
     }
   }
 
+  framework->start();
+
   foreach(ctkPlugin* plugin, installedPlugins)
   {
-    plugin->start(ctkPlugin::START_TRANSIENT);
+    plugin->start();
   }
 
-  framework->start();
-
 
   QMainWindow mainWindow;
   Ui::MainWindow ui;

+ 19 - 46
Applications/ctkExampleHostedApp/ctkExampleHostedAppMain.cpp

@@ -26,10 +26,6 @@
 // for testing purposes use:
 // --hostURL http://localhost:8081/host --applicationURL http://localhost:8082/app dicomapp
 
-// replace "//$" with nothing as soon as ctkDicomAppServer/ctkDicomHostService exist
-#include <ctkDicomAppServer.h>
-#include <ctkDicomHostService.h>
-#include <ctkDicomHostInterface.h>
 
 #include <QApplication>
 #include <QString>
@@ -82,7 +78,10 @@ int main(int argv, char** argc)
   qDebug() << "appURL is: " << appURL << " . Extracted port is: " << QUrl(appURL).port();
 
   // setup the plugin framework
-  ctkPluginFrameworkFactory fwFactory;
+  ctkProperties fwProps;
+  fwProps.insert("dah.hostURL", hostURL);
+  fwProps.insert("dah.appURL", appURL);
+  ctkPluginFrameworkFactory fwFactory(fwProps);
   ctkPluginFramework* framework = fwFactory.getFramework();
 
   try {
@@ -115,29 +114,25 @@ int main(int argv, char** argc)
   }
 
   // try to find the plugin and install all plugins available in 
-  // pluginPath (but do not start them)
+  // pluginPath containing the string "org_commontk_dah" (but do not start them)
+  ctkPlugin* appPlugin = 0;
   QStringList libFilter;
   libFilter << "*.dll" << "*.so" << "*.dylib";
   QDirIterator dirIter(pluginPath, libFilter, QDir::Files);
-  bool pluginFound = false;
-  QString pluginFileLocation;
-  QList<ctkPlugin*> installedPlugins;
   while(dirIter.hasNext())
   {
     try
     {
       QString fileLocation = dirIter.next();
-      if (fileLocation.contains("org_commontk_dah") && !fileLocation.contains(pluginName))
+      if (fileLocation.contains("org_commontk_dah"))
       {
         ctkPlugin* plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(fileLocation));
-        installedPlugins << plugin;
+        if (fileLocation.contains(pluginName))
+        {
+          appPlugin = plugin;
+        }
         //plugin->start(ctkPlugin::START_TRANSIENT);
       }
-      if (fileLocation.contains(pluginName))
-      {
-        pluginFound = true;
-        pluginFileLocation = fileLocation;
-      }
     }
     catch (const ctkPluginException& e)
     {
@@ -145,49 +140,27 @@ int main(int argv, char** argc)
     }
   }
 
-  try
-  {
-    foreach(ctkPlugin* plugin, installedPlugins)
-    {
-      plugin->start(ctkPlugin::START_TRANSIENT);
-    }
-  }
-  catch (const ctkPluginException& e)
-  {
-    qCritical() << e.what();
-  }
-
   // if we did not find the business logic: abort
-  if(!pluginFound)
+  if(!appPlugin)
   {
     qCritical() << "Could not find plugin.";
     qCritical() << "  Plugin name: " << pluginName;
     qCritical() << "  Plugin path: " << pluginPath;
     exit(3);
   }
-qCritical() << "app about to start 1";
-  // setup the communication infrastructure: DicomAppServer and DicomHostService
-  /*ctkDicomAppServer * appServer =*/ new ctkDicomAppServer(QUrl(appURL).port()); // accesses the app-plugin via getService("ctkDicomAppInterface");
-  ctkDicomHostInterface * hostInterface = new ctkDicomHostService(QUrl(hostURL).port(), "/HostInterface");
-  framework->getPluginContext()->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
-qCritical() << "app about to start 2";
-  // install and start the plugin with the business logic and remember pointer to start it later
-  //ctkPlugin* plugin;
+
+  // start the plugin framework
+  framework->start();
+
+  // start the plugin with the business logic
   try
   {
-    ctkPlugin* plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(pluginFileLocation));
-    plugin->start(ctkPlugin::START_TRANSIENT);
+    appPlugin->start();
   }
   catch (const ctkPluginException& e)
   {
-    qCritical() << e.what();
+    qCritical() << e;
   }
 
-qCritical() << "app about to start 3";
-  framework->start();
-qCritical() << "app about to start 4";
-  //QWidget placeholder;
-  //placeholder.show();
-
   return app.exec();
 }

+ 1 - 2
Plugins/org.commontk.dah.app/CMakeLists.txt

@@ -7,14 +7,13 @@ SET(PLUGIN_SRCS
   ctkDicomAbstractApp.cpp
   ctkDicomAppPlugin.cpp
   ctkDicomAppServer.cpp
-  ctkDicomAppServerPrivate.cpp
   ctkDicomHostService.cpp
 )
 
 # Files which should be processed by Qts moc
 SET(PLUGIN_MOC_SRCS
   ctkDicomAppPlugin_p.h
-  ctkDicomAppServerPrivate.h
+  ctkDicomAppServer_p.h
 )
 
 # Qt Designer files which should be processed by Qts uic

+ 30 - 1
Plugins/org.commontk.dah.app/ctkDicomAppPlugin.cpp

@@ -21,13 +21,18 @@
 
 
 #include "ctkDicomAppPlugin_p.h"
+#include "ctkDicomAppServer_p.h"
+#include "ctkDicomHostService_p.h"
 
 #include <QtPlugin>
+#include <QStringList>
+
+#include <stdexcept>
 
 ctkDicomAppPlugin* ctkDicomAppPlugin::instance = 0;
 
 ctkDicomAppPlugin::ctkDicomAppPlugin()
-  : context(0)
+  : context(0), appServer(0), hostInterface(0)
 {
 
 }
@@ -41,11 +46,35 @@ void ctkDicomAppPlugin::start(ctkPluginContext* context)
 {
   instance = this;
   this->context = context;
+
+
+  QUrl appURL(context->getProperty("dah.appURL").toString());
+  if (!appURL.isValid())
+  {
+    throw std::runtime_error("The plugin framework does not contain a valid \"dah.appURL\" property");
+  }
+
+  QUrl hostURL(context->getProperty("dah.hostURL").toString());
+  if (!hostURL.isValid())
+  {
+    throw std::runtime_error("The plugin framework does not contain a valid \"dah.hostURL\" property");
+  }
+
+  // start the application server
+  appServer = new ctkDicomAppServer(appURL.port());
+
+  // register the host service, providing callbacks to the hosting application
+  hostInterface = new ctkDicomHostService(QUrl(hostURL).port(), "/HostInterface");
+  context->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
+
 }
 
 void ctkDicomAppPlugin::stop(ctkPluginContext* context)
 {
   Q_UNUSED(context)
+
+  delete appServer;
+  delete hostInterface;
 }
 
 ctkDicomAppPlugin* ctkDicomAppPlugin::getInstance()

+ 5 - 0
Plugins/org.commontk.dah.app/ctkDicomAppPlugin_p.h

@@ -25,6 +25,9 @@
 
 #include <ctkPluginActivator.h>
 
+class ctkDicomAppServer;
+class ctkDicomHostInterface;
+
 class ctkDicomAppPlugin :
   public QObject, public ctkPluginActivator
 {
@@ -49,6 +52,8 @@ private:
   static ctkDicomAppPlugin* instance;
   ctkPluginContext* context;
 
+  ctkDicomAppServer* appServer;
+  ctkDicomHostInterface* hostInterface;
 
 }; // ctkDicomAppPlugin
 

+ 73 - 5
Plugins/org.commontk.dah.app/ctkDicomAppServer.cpp

@@ -19,15 +19,83 @@
 
 =============================================================================*/
 
-#include "ctkDicomAppServer.h"
 
-#include "ctkDicomAppServerPrivate.h"
+#include "ctkDicomAppServer_p.h"
+#include "ctkDicomAppPlugin_p.h"
+#include "ctkAppSoapMessageProcessor.h"
 
-ctkDicomAppServer::ctkDicomAppServer(int port)
-  : d_ptr(new ctkDicomAppServerPrivate(port))
+#include <ctkDicomAppHostingTypesHelper.h>
+#include <ctkDicomAppInterface.h>
+#include <ctkExchangeSoapMessageProcessor.h>
+
+#include <ctkServiceReference.h>
+
+#include <QHostAddress>
+
+#include <stdexcept>
+
+
+ctkDicomAppServer::ctkDicomAppServer(int port) :
+      port(port), appInterface(0)
 {
+  connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
+          this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
+  connect(&server, SIGNAL(incomingWSDLMessage(QString,QString*)),
+          this, SLOT(incomingWSDLMessage(QString,QString*)));
+
+  if (!server.listen(QHostAddress::LocalHost, this->port))
+  {
+    qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
+  }
+}
 
+void ctkDicomAppServer::incomingWSDLMessage(
+  const QString& message, QString* reply)
+{
+  if (message == "?wsdl")
+  {
+    QFile wsdlfile(":/dah/ApplicationService.wsdl");
+    wsdlfile.open(QFile::ReadOnly | QFile::Text);
+    if(wsdlfile.isOpen())
+    {
+      QTextStream textstream(&wsdlfile);
+      *reply = textstream.readAll();
+      QString actualURL="http://localhost:";
+      actualURL+=QString::number(port)+"/ApplicationInterface"; // FIXME: has to be replaced by url provided by host
+      reply->replace("REPLACE_WITH_ACTUAL_URL",actualURL);
+      reply->replace("ApplicationService_schema1.xsd",actualURL+"?xsd=1");
+      //reply->replace("<soap:body use=\"literal\"/>","<soap:body use=\"literal\"></soap:body>");
+    }
+  }
+  else if (message == "?xsd=1")
+  {
+    QFile wsdlfile(":/dah/HostService_schema1.xsd");
+    wsdlfile.open(QFile::ReadOnly | QFile::Text);
+    if(wsdlfile.isOpen())
+    {
+      QTextStream textstream(&wsdlfile);
+      *reply = textstream.readAll();
+    }
+  }
 }
-ctkDicomAppServer::~ctkDicomAppServer()
+
+void ctkDicomAppServer::incomingSoapMessage(
+  const QtSoapMessage& message,
+  QtSoapMessage* reply)
+
 {
+  if(appInterface == NULL)
+  {
+    ctkPluginContext* context = ctkDicomAppPlugin::getInstance()->getPluginContext();
+    ctkServiceReference serviceRef = context->getServiceReference("ctkDicomAppInterface");
+    appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
+    
+    ctkAppSoapMessageProcessor* appProcessor = new ctkAppSoapMessageProcessor( appInterface );
+    processors.push_back(appProcessor);
+    ctkExchangeSoapMessageProcessor* exchangeProcessor = new ctkExchangeSoapMessageProcessor( appInterface );
+    processors.push_back(exchangeProcessor);
+  }
+
+  processors.process(message, reply);
 }
+

+ 0 - 46
Plugins/org.commontk.dah.app/ctkDicomAppServer.h

@@ -1,46 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) German Cancer Research Center,
-    Division of Medical and Biological Informatics
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-=============================================================================*/
-
-
-#ifndef CTKDICOMAPPPSERVER_H
-#define CTKDICOMAPPPSERVER_H
-
-class ctkDicomAppInterface;
-
-#include <QScopedPointer>
-#include <org_commontk_dah_app_Export.h>
-
-class ctkDicomAppServerPrivate;
-
-class org_commontk_dah_app_EXPORT ctkDicomAppServer
-{
-
-public:
-  ctkDicomAppServer(int port);
-  ~ctkDicomAppServer();
-
-private:
-  Q_DECLARE_PRIVATE(ctkDicomAppServer)
-
-  const QScopedPointer<ctkDicomAppServerPrivate> d_ptr;
-};
-
-#endif // CTKDICOMAPPPSERVER_H

+ 0 - 99
Plugins/org.commontk.dah.app/ctkDicomAppServerPrivate.cpp

@@ -1,99 +0,0 @@
-/*=============================================================================
-
-  Library: CTK
-
-  Copyright (c) German Cancer Research Center,
-    Division of Medical and Biological Informatics
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-=============================================================================*/
-
-
-#include "ctkDicomAppServerPrivate.h"
-
-#include <ctkDicomAppInterface.h>
-#include <ctkServiceReference.h>
-
-#include <QHostAddress>
-
-#include <stdexcept>
-#include <ctkDicomAppHostingTypesHelper.h>
-#include <ctkDicomAppPlugin_p.h>
-
-#include <ctkExchangeSoapMessageProcessor.h>
-#include "ctkAppSoapMessageProcessor.h"
-
-ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(int port) :
-      port(port), appInterface(0)
-{
-  connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
-          this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
-  connect(&server, SIGNAL(incomingWSDLMessage(QString,QString*)),
-          this, SLOT(incomingWSDLMessage(QString,QString*)));
-
-  if (!server.listen(QHostAddress::LocalHost, this->port))
-  {
-    qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
-  }
-}
-
-void ctkDicomAppServerPrivate::incomingWSDLMessage(
-  const QString& message, QString* reply)
-{
-  if (message == "?wsdl")
-  {
-    QFile wsdlfile(":/dah/ApplicationService.wsdl");
-    wsdlfile.open(QFile::ReadOnly | QFile::Text);
-    if(wsdlfile.isOpen())
-    {
-      QTextStream textstream(&wsdlfile);
-      *reply = textstream.readAll();
-      QString actualURL="http://localhost:";
-      actualURL+=QString::number(port)+"/ApplicationInterface"; // FIXME: has to be replaced by url provided by host
-      reply->replace("REPLACE_WITH_ACTUAL_URL",actualURL);
-      reply->replace("ApplicationService_schema1.xsd",actualURL+"?xsd=1");
-      //reply->replace("<soap:body use=\"literal\"/>","<soap:body use=\"literal\"></soap:body>");
-    }
-  }
-  else if (message == "?xsd=1")
-  {
-    QFile wsdlfile(":/dah/HostService_schema1.xsd");
-    wsdlfile.open(QFile::ReadOnly | QFile::Text);
-    if(wsdlfile.isOpen())
-    {
-      QTextStream textstream(&wsdlfile);
-      *reply = textstream.readAll();
-    }
-  }
-}
-void ctkDicomAppServerPrivate::incomingSoapMessage(
-  const QtSoapMessage& message,
-  QtSoapMessage* reply)
-
-{
-  if(appInterface == NULL)
-  {
-    ctkPluginContext* context = ctkDicomAppPlugin::getInstance()->getPluginContext();
-    ctkServiceReference serviceRef = context->getServiceReference("ctkDicomAppInterface");
-    appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
-    
-    ctkAppSoapMessageProcessor* appProcessor = new ctkAppSoapMessageProcessor( appInterface );
-    processors.push_back(appProcessor);
-    ctkExchangeSoapMessageProcessor* exchangeProcessor = new ctkExchangeSoapMessageProcessor( appInterface );
-    processors.push_back(exchangeProcessor);
-  }
-
-  processors.process(message, reply);
-}
-

+ 8 - 9
Plugins/org.commontk.dah.app/ctkDicomAppServerPrivate.h

@@ -20,8 +20,8 @@
 =============================================================================*/
 
 
-#ifndef CTKDICOMAPPSERVERPRIVATE_H
-#define CTKDICOMAPPSERVERPRIVATE_H
+#ifndef CTKDICOMAPPPSERVER_P_H
+#define CTKDICOMAPPPSERVER_P_H
 
 #include <QObject>
 #include <QtSoapMessage>
@@ -31,15 +31,12 @@
 
 class ctkDicomAppInterface;
 
-class ctkDicomAppServerPrivate : public QObject
+class ctkDicomAppServer : public QObject
 {
   Q_OBJECT
 
 public:
-  ctkDicomAppServerPrivate(int port);
-
-  ctkSimpleSoapServer server;
-  int port;
+  ctkDicomAppServer(int port);
 
 public slots:
 
@@ -50,8 +47,10 @@ public slots:
 private:
 
   ctkSoapMessageProcessorList processors;
-  ctkDicomAppInterface* appInterface;
+  ctkSimpleSoapServer server;
+  int port;
 
+  ctkDicomAppInterface* appInterface;
 };
 
-#endif // CTKDICOMAPPSERVERPRIVATE_H
+#endif // CTKDICOMAPPPSERVER_P_H

+ 5 - 6
Plugins/org.commontk.dah.app/ctkDicomHostService.h

@@ -20,14 +20,13 @@
 =============================================================================*/
 
 
-#ifndef CTKDICOMHOSTSERVICE_H
-#define CTKDICOMHOSTSERVICE_H
+#ifndef CTKDICOMHOSTSERVICE_P_H
+#define CTKDICOMHOSTSERVICE_P_H
 
 #include <ctkDicomHostInterface.h>
 #include <ctkDicomExchangeService.h>
-#include <org_commontk_dah_app_Export.h>
 
-class org_commontk_dah_app_EXPORT ctkDicomHostService : public ctkDicomHostInterface
+class ctkDicomHostService : public ctkDicomHostInterface
 {
 
 public:
@@ -42,7 +41,7 @@ public:
 
   // Exchange methods
   bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
-  QList<ctkDicomAppHosting::ObjectLocator>* getData(
+  QList<ctkDicomAppHosting::ObjectLocator> getData(
     QList<QUuid> objectUUIDs, 
     QList<QString> acceptableTransferSyntaxUIDs, 
     bool includeBulkData);
@@ -55,4 +54,4 @@ private:
 
 };
 
-#endif // CTKDICOMHOSTSERVICE_H
+#endif // CTKDICOMHOSTSERVICE_P_H

+ 1 - 0
Plugins/org.commontk.dah.app/manifest_headers.cmake

@@ -1 +1,2 @@
 SET(Require-Plugin org.commontk.dah.core)
+SET(Plugin-ActivationPolicy "eager")

+ 1 - 0
Plugins/org.commontk.dah.exampleapp/manifest_headers.cmake

@@ -1 +1,2 @@
 SET(Require-Plugin org.commontk.dah.app)
+SET(Plugin-ActivationPolicy "eager")