Forráskód Böngészése

ENH: adapted order of startup of communication infrastructure and business logic

ivowolf 15 éve
szülő
commit
167cb2c092

+ 1 - 1
Applications/ctkExampleHost/ctkHostAppExampleWidget.cpp

@@ -26,7 +26,7 @@ void ctkHostAppExampleWidget::startButtonClicked()
     qDebug() << "start button clicked";
     if (host)
     {
-      // host->StartApplication(appFileName);
+      host->StartApplication(appFileName);
     }
 }
 

+ 9 - 8
Applications/ctkExampleHostedApp/ctkExampleHostedAppMain.cpp

@@ -148,7 +148,13 @@ int main(int argv, char** argc)
     exit(3);
   }
 
-  // start the plugin with the business logic
+  // 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());
+//$  framework->getPluginContext()->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
+
+  // install and start the plugin with the business logic and remember pointer to start it later
+  ctkPlugin* plugin;
   try
   {
     ctkPlugin* plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(pluginFileLocation));
@@ -159,15 +165,10 @@ int main(int argv, char** argc)
     qCritical() << e.what();
   }
 
-  // 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());
-//$  framework->getPluginContext()->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
-
   framework->start();
 
-  QWidget placeholder;
-  placeholder.show();
+  //QWidget placeholder;
+  //placeholder.show();
 
   return app.exec();
 }

+ 12 - 9
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServerPrivate.cpp

@@ -41,15 +41,6 @@ ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(int port) :
   {
     qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
   }
-
-  ctkPluginContext* context = ctkDicomWG23AppPlugin::getInstance()->getPluginContext();
-  ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomAppInterface");
-  if (!serviceRef)
-  {
-    // this will change after merging changes from branch plugin_framework
-    throw std::runtime_error("No Dicom App Service found");
-  }
-  appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
 }
 
 void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
@@ -60,6 +51,18 @@ void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
 
   qDebug() << "Received soap method request: " << methodName;
 
+  if(appInterface == NULL)
+  {
+    ctkPluginContext* context = ctkDicomWG23AppPlugin::getInstance()->getPluginContext();
+    ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomAppInterface");
+    if (!serviceRef)
+    {
+      // this will change after merging changes from branch plugin_framework
+      throw std::runtime_error("No Dicom App Service found");
+    }
+    appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
+  }
+
   if (methodName == "getState")
   {
     processGetState(message, reply);

+ 16 - 1
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppLogic.cpp

@@ -29,6 +29,14 @@
 ctkExampleDicomAppLogic::ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface> host)
   : host(host)
 {
+  try
+  {
+    host->notifyStateChanged(ctkDicomWG23::IDLE);
+  }
+  catch (const std::runtime_error& e)
+  {
+    qCritical() << e.what();
+  }
 }
 
 ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
@@ -59,5 +67,12 @@ bool ctkExampleDicomAppLogic::bringToFront(const QRect& requestedScreenArea)
 void ctkExampleDicomAppLogic::do_something()
 {
   QRect preferred;
-  QRect rect = host->getAvailableScreen(preferred);
+  try
+  {
+    QRect rect = host->getAvailableScreen(preferred);
+  }
+  catch (const std::runtime_error& e)
+  {
+    qCritical() << e.what();
+  }
 }