瀏覽代碼

Use ctkIllegalStateException instead of generic std::logic_error.

Sascha Zelzer 13 年之前
父節點
當前提交
d7c504bdeb

+ 2 - 2
Libs/PluginFramework/ctkPlugin.cpp

@@ -74,7 +74,7 @@ void ctkPlugin::start(const StartOptions& options)
 
   if (d->state == UNINSTALLED)
   {
-    throw std::logic_error("ctkPlugin is uninstalled");
+    throw ctkIllegalStateException("ctkPlugin is uninstalled");
   }
 
   // Initialize the activation; checks initialization of lazy
@@ -124,7 +124,7 @@ void ctkPlugin::stop(const StopOptions& options)
   //1:
   if (d->state == UNINSTALLED)
   {
-    throw std::logic_error("Plugin is uninstalled");
+    throw ctkIllegalStateException("ctkPlugin is uninstalled");
   }
 
   //2: If activating or deactivating, wait a litle

+ 6 - 6
Libs/PluginFramework/ctkPlugin.h

@@ -354,7 +354,7 @@ public:
    *         be because a code dependency could not be resolved or the
    *         <code>ctkPluginActivator</code> could not be loaded or
    *         threw an exception.
-   * @throws std::logic_error If this plugin has been uninstalled or this
+   * @throws ctkIllegalStateException If this plugin has been uninstalled or this
    *         plugin tries to change its own state.
    */
   virtual void start(const StartOptions& options = START_ACTIVATION_POLICY);
@@ -428,7 +428,7 @@ public:
    *        {@link #STOP_TRANSIENT}.
    * @throws ctkPluginException If this plugin's <code>ctkPluginActivator</code>
    *         threw an exception.
-   * @throws std::logic_error If this plugin has been uninstalled or this
+   * @throws ctkIllegalStateException If this plugin has been uninstalled or this
    *         plugin tries to change its own state.
    */
   virtual void stop(const StopOptions& options = 0);
@@ -488,7 +488,7 @@ public:
    * @throws ctkPluginException If the uninstall failed. This can occur if
    *         another thread is attempting to change this plugin's state and
    *         does not complete in a timely manner.
-   * @throws std::logic_error If this plugin has been uninstalled or this
+   * @throws ctkIllegalStateException If this plugin has been uninstalled or this
    *         plugin tries to change its own state.
    * @see #stop()
    */
@@ -616,7 +616,7 @@ public:
    * @return A list of the resource paths (<code>QString</code>
    *         objects) or an empty list if no entry could be found.
 
-   * @throws std::logic_error If this plugin has been
+   * @throws ctkIllegalStateException If this plugin has been
    *         uninstalled.
    */
   virtual QStringList getResourceList(const QString& path) const;
@@ -658,7 +658,7 @@ public:
    *         does not have the appropriate
    *         <code>AdminPermission[this,RESOURCE]</code>, and the Plugin
    *         Framework supports permissions.
-   * @throws std::logic_error If this plugin has been uninstalled.
+   * @throws ctkIllegalStateException If this plugin has been uninstalled.
    */
   virtual QStringList findResources(const QString& path, const QString& filePattern, bool recurse) const;
 
@@ -675,7 +675,7 @@ public:
    * @param path The path name of the resource.
    * @return A QByteArray to the resource, or a null QByteArray if no resource could be
    *         found.
-   * @throws std::logic_error If this plugin has been
+   * @throws ctkIllegalStateException If this plugin has been
    *         uninstalled.
    */
   virtual QByteArray getResource(const QString& path) const;

+ 1 - 1
Libs/PluginFramework/ctkPluginContext.cpp

@@ -40,7 +40,7 @@ ctkPluginContextPrivate::ctkPluginContextPrivate(ctkPluginPrivate* plugin)
 void ctkPluginContextPrivate::isPluginContextValid() const
 {
   if (!plugin) {
-    throw std::logic_error("This plugin context is no longer valid");
+    throw ctkIllegalStateException("This plugin context is no longer valid");
   }
 }
 

+ 15 - 15
Libs/PluginFramework/ctkPluginContext.h

@@ -120,7 +120,7 @@ public:
    *
    * @return The <code>ctkPlugin</code> object associated with this
    *         <code>ctkPluginContext</code>.
-   * @throws std::logic_error If this ctkPluginContext is no
+   * @throws ctkIllegalStateException If this ctkPluginContext is no
    *         longer valid.
    */
   QSharedPointer<ctkPlugin> getPlugin() const;
@@ -209,7 +209,7 @@ public:
    *         <code>properties</code> contains case variants of the same key
    *         name.
    *         </ul>
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    * @see ctkServiceRegistration
    * @see ctkServiceFactory
    */
@@ -233,7 +233,7 @@ public:
    * @return A ctkServiceRegistration object for use by the plugin
    *         registering the service to update the service's properties or to
    *         unregister the service.
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    * @see registerService(const QStringList&, QObject*, const ctkDictionary&)
    */
   ctkServiceRegistration registerService(const char* clazz, QObject* service, const ctkDictionary& properties = ctkDictionary());
@@ -293,7 +293,7 @@ public:
    *         search.
    * @throws std::invalid_argument If the specified <code>filter</code>
    *         contains an invalid filter expression that cannot be parsed.
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    */
   QList<ctkServiceReference> getServiceReferences(const QString& clazz, const QString& filter = QString());
 
@@ -314,7 +314,7 @@ public:
    *         search.
    * @throws std::invalid_argument If the specified <code>filter</code>
    *         contains an invalid filter expression that cannot be parsed.
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    * @see getServiceReferences(const QString&, const QString&)
    */
   template<class S>
@@ -351,7 +351,7 @@ public:
    * @param clazz The class name with which the service was registered.
    * @return A <code>ctkServiceReference</code> object, or <code>0</code> if
    *         no services are registered which implement the named class.
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    * @throws ctkServiceException It no service was registered under the given class name.
    * @see #getServiceReferences(const QString&, const QString&)
    */
@@ -367,7 +367,7 @@ public:
    *
    * @return A <code>ctkServiceReference</code> object, or <code>0</code> if
    *         no services are registered which implement the named class.
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    * @throws ctkServiceException It no service was registered under the given class name.
    * @see #getServiceReference(const QString&)
    * @see #getServiceReferences(const QString&)
@@ -429,7 +429,7 @@ public:
    *         <code>ctkServiceFactory</code> does not implement the classes under
    *         which it was registered or the <code>ctkServiceFactory</code> threw
    *         an exception.
-   * @throws std::logic_error If this ctkPluginContext is no
+   * @throws ctkIllegalStateException If this ctkPluginContext is no
    *         longer valid.
    * @throws std::invalid_argument If the specified
    *         <code>ctkServiceReference</code> was not created by the same
@@ -453,7 +453,7 @@ public:
    *         <code>ctkServiceFactory</code> does not implement the classes under
    *         which it was registered, the <code>ctkServiceFactory</code> threw
    *         an exception or the service could not be casted to the desired type.
-   * @throws std::logic_error If this ctkPluginContext is no
+   * @throws ctkIllegalStateException If this ctkPluginContext is no
    *         longer valid.
    * @throws std::invalid_argument If the specified
    *         <code>ctkServiceReference</code> was not created by the same
@@ -500,7 +500,7 @@ public:
    * @return <code>false</code> if the context plugin's use count for the
    *         service is zero or if the service has been unregistered;
    *         <code>true</code> otherwise.
-   * @throws std::logic_error If this ctkPluginContext is no
+   * @throws ctkIllegalStateException If this ctkPluginContext is no
    *         longer valid.
    * @throws std::invalid_argument If the specified
    *         <code>ctkServiceReference</code> was not created by the same
@@ -530,7 +530,7 @@ public:
    * @param filename A relative name to the file or directory to be accessed.
    * @return A <code>QFileInfo</code> object that represents the requested file
    *         or directory.
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    */
   QFileInfo getDataFile(const QString& filename);
 
@@ -590,7 +590,7 @@ public:
    * @return The <code>ctkPlugin</code> object of the installed plugin.
    * @throws ctkPluginException If the I/O device cannot be read or the
    *         installation failed.
-   * @throws std::logic_error If this ctkPluginContext is no longer valid.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
    */
   QSharedPointer<ctkPlugin> installPlugin(const QUrl& location, QIODevice* input = 0);
 
@@ -606,7 +606,7 @@ public:
    *        Qt::QueuedConnection, or Qt::BlockingQueuedConnection is allowed.
    * @returns <code>true</code> if the connection was successfull;
    *          <code>false</code> otherwise.
-   * @throws std::logic_error If this ctkPluginContext is no
+   * @throws ctkIllegalStateException If this ctkPluginContext is no
    *         longer valid.
    * @see ctkPluginEvent
    * @see ctkEventBus
@@ -623,7 +623,7 @@ public:
    * @param type The Qt connection type.
    * @returns <code>true</code> if the connection was successfull;
    *          <code>false</code> otherwise.
-   * @throws std::logic_error If this ctkPluginContext is no
+   * @throws ctkIllegalStateException If this ctkPluginContext is no
    *         longer valid.
    * @see ctkPluginFrameworkEvent
    * @see ctkEventBus
@@ -675,7 +675,7 @@ public:
    * @param filter The filter criteria.
    * @throws std::invalid_argument If <code>filter</code> contains an
    *         invalid filter string that cannot be parsed.
-   * @throws std::logic_error If this ctkPluginContext is no
+   * @throws ctkIllegalStateException If this ctkPluginContext is no
    *         longer valid.
    * @see ctkServiceEvent
    * @see disconnectServiceListener()

+ 2 - 2
Libs/PluginFramework/ctkPluginFramework.cpp

@@ -55,7 +55,7 @@ void ctkPluginFramework::init()
   case ctkPlugin::ACTIVE:
     return;
   default:
-    throw std::logic_error("INTERNAL ERROR, Illegal state");
+    throw ctkIllegalStateException("INTERNAL ERROR, Illegal state");
   }
   d->init();
 }
@@ -83,7 +83,7 @@ void ctkPluginFramework::start(const ctkPlugin::StartOptions& options)
     case ACTIVE:
       return;
     default:
-      throw std::logic_error("INTERNAL ERROR, Illegal state");
+      throw ctkIllegalStateException("INTERNAL ERROR, Illegal state");
     }
 
     pluginsToStart = d->fwCtx->storage->getStartOnLaunchPlugins();

+ 2 - 2
Libs/PluginFramework/ctkPluginPrivate.cpp

@@ -294,8 +294,8 @@ void ctkPluginPrivate::finalizeActivation()
     // Don't allow it.
     throw ctkPluginException("start called from ctkPluginActivator::stop",
                              ctkPluginException::ACTIVATOR_ERROR);
-      case ctkPlugin::UNINSTALLED:
-    throw std::logic_error("ctkPlugin is in UNINSTALLED state");
+  case ctkPlugin::UNINSTALLED:
+    throw ctkIllegalStateException("ctkPlugin is in UNINSTALLED state");
   }
 }
 

+ 1 - 1
Libs/PluginFramework/ctkPluginTracker.h

@@ -102,7 +102,7 @@ public:
    * <code>ctkPluginTracker</code> was created are now tracked by this
    * <code>ctkPluginTracker</code>.
    *
-   * @throws std::logic_error If the <code>ctkPluginContext</code>
+   * @throws ctkIllegalStateException If the <code>ctkPluginContext</code>
    *         with which this <code>ctkPluginTracker</code> was created is no
    *         longer valid.
    */

+ 16 - 28
Libs/PluginFramework/ctkPlugins.cpp

@@ -33,6 +33,15 @@
 #include <QUrl>
 
 //----------------------------------------------------------------------------
+void ctkPlugins::checkIllegalState() const
+{
+  if (!fwCtx)
+  {
+    throw ctkIllegalStateException("This framework instance is not active");
+  }
+}
+
+//----------------------------------------------------------------------------
 ctkPlugins::ctkPlugins(ctkPluginFrameworkContext* fw)
 {
   fwCtx = fw;
@@ -50,10 +59,7 @@ void ctkPlugins::clear()
 //----------------------------------------------------------------------------
 QSharedPointer<ctkPlugin> ctkPlugins::install(const QUrl& location, QIODevice* in)
 {
-  if (!fwCtx)
-  { // This ctkPlugins instance has been closed!
-    throw std::logic_error("ctkPlugins::install(location, inputStream) called on closed plugins object.");
-  }
+  checkIllegalState();
 
   QSharedPointer<ctkPlugin> res;
   {
@@ -148,10 +154,7 @@ void ctkPlugins::remove(const QUrl& location)
 //----------------------------------------------------------------------------
 QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(int id) const
 {
-  if (!fwCtx)
-  { // This plugins instance has been closed!
-    throw std::logic_error("ctkPlugins::getPlugin(id) called on closed plugins object.");
-  }
+  checkIllegalState();
 
   {
     QReadLocker lock(&pluginsLock);
@@ -172,10 +175,7 @@ QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(int id) const
 //----------------------------------------------------------------------------
 QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(const QString& location) const
 {
-  if (!fwCtx)
-  { // This plugins instance has been closed!
-    throw std::logic_error("ctkPlugins::getPlugin(location) called on closed plugins object.");
-  }
+  checkIllegalState();
 
   QReadLocker lock(&pluginsLock);
   QHash<QString, QSharedPointer<ctkPlugin> >::const_iterator it = plugins.find(location);
@@ -186,10 +186,7 @@ QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(const QString& location) const
 //----------------------------------------------------------------------------
 QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(const QString& name, const ctkVersion& version) const
 {
-  if (!fwCtx)
-  { // This ctkPlugins instance has been closed!
-    throw std::logic_error("ctkPlugins::getPlugin(name, version) called on closed plugins object.");
-  }
+  checkIllegalState();
 
   {
     QReadLocker lock(&pluginsLock);
@@ -210,10 +207,7 @@ QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(const QString& name, const ctkVe
 //----------------------------------------------------------------------------
 QList<QSharedPointer<ctkPlugin> > ctkPlugins::getPlugins() const
 {
-  if (!fwCtx)
-  { // This plugins instance has been closed!
-    throw std::logic_error("ctkPlugins::getPlugins() called on closed plugins object.");
-  }
+  checkIllegalState();
 
   {
     QReadLocker lock(&pluginsLock);
@@ -245,10 +239,7 @@ QList<ctkPlugin*> ctkPlugins::getPlugins(const QString& name) const
 //----------------------------------------------------------------------------
 QList<ctkPlugin*> ctkPlugins::getPlugins(const QString& name, const ctkVersionRange& range) const
 {
-  if (!fwCtx)
-  { // This plugins instance has been closed!
-    throw std::logic_error("ctkPlugins::getPlugins(name, versionRange) called on closed plugins object.");
-  }
+  checkIllegalState();
 
   QList<ctkPlugin*> pluginsWithName = getPlugins(name);
   QList<ctkPlugin*> res;
@@ -276,10 +267,7 @@ QList<ctkPlugin*> ctkPlugins::getPlugins(const QString& name, const ctkVersionRa
 //----------------------------------------------------------------------------
 QList<ctkPlugin*> ctkPlugins::getActivePlugins() const
 {
-  if (!fwCtx)
-  { // This plugins instance has been closed!
-    throw std::logic_error("ctkPlugins::getActivePlugins() called on closed plugins object.");
-  }
+  checkIllegalState();
 
   QList<ctkPlugin*> slist;
   {

+ 2 - 0
Libs/PluginFramework/ctkPlugins_p.h

@@ -67,6 +67,8 @@ private:
    */
   QMutex objectLock;
 
+  void checkIllegalState() const;
+
 public:
 
   /**

+ 4 - 0
Libs/PluginFramework/ctkRuntimeException.h

@@ -53,4 +53,8 @@ private:
   QString  cause;
 };
 
+/**
+ * \ingroup PluginFramework
+ */
+typedef ctkRuntimeException ctkIllegalStateException;
 #endif // CTKRUNTIMEEXCEPTION_H

+ 6 - 6
Libs/PluginFramework/ctkServiceRegistration.cpp

@@ -94,8 +94,8 @@ ctkServiceReference ctkServiceRegistration::getReference() const
 {
   Q_D(const ctkServiceRegistration);
 
-  if (!d) throw std::logic_error("ctkServiceRegistration object invalid");
-  if (!d->available) throw std::logic_error("Service is unregistered");
+  if (!d) throw ctkIllegalStateException("ctkServiceRegistration object invalid");
+  if (!d->available) throw ctkIllegalStateException("Service is unregistered");
 
   return d->reference;
 }
@@ -104,7 +104,7 @@ ctkServiceReference ctkServiceRegistration::getReference() const
 void ctkServiceRegistration::setProperties(const ctkDictionary& props)
 {
   Q_D(ctkServiceRegistration);
-  if (!d) throw std::logic_error("ctkServiceRegistration object invalid");
+  if (!d) throw ctkIllegalStateException("ctkServiceRegistration object invalid");
 
   QMutexLocker lock(&d->eventLock);
 
@@ -130,7 +130,7 @@ void ctkServiceRegistration::setProperties(const ctkDictionary& props)
     }
     else
     {
-      throw std::logic_error("Service is unregistered");
+      throw ctkIllegalStateException("Service is unregistered");
     }
   }
   d->plugin->fwCtx->listeners.serviceChanged(
@@ -146,7 +146,7 @@ void ctkServiceRegistration::setProperties(const ctkDictionary& props)
 void ctkServiceRegistration::unregister()
 {
   Q_D(ctkServiceRegistration);
-  if (!d) throw std::logic_error("ctkServiceRegistration object invalid");
+  if (!d) throw ctkIllegalStateException("ctkServiceRegistration object invalid");
 
   if (d->unregistering) return; // Silently ignore redundant unregistration.
   {
@@ -163,7 +163,7 @@ void ctkServiceRegistration::unregister()
     }
     else
     {
-      throw std::logic_error("Service is unregistered");
+      throw ctkIllegalStateException("Service is unregistered");
     }
   }
 

+ 3 - 3
Libs/PluginFramework/ctkServiceRegistration.h

@@ -79,7 +79,7 @@ public:
    * The <code>ctkServiceReference</code> object may be shared with other
    * plugins.
    *
-   * @throws std::logic_error If this
+   * @throws ctkIllegalStateException If this
    *         <code>ctkServiceRegistration</code> object has already been
    *         unregistered or if it is invalid.
    * @return <code>ctkServiceReference</code> object.
@@ -106,7 +106,7 @@ public:
    *        be made to this object after calling this method. To update the
    *        service's properties this method should be called again.
    *
-   * @throws std::logic_error If this <code>ctkServiceRegistration</code>
+   * @throws ctkIllegalStateException If this <code>ctkServiceRegistration</code>
    *         object has already been unregistered or if it is invalid.
    * @throws std::invalid_argument If <code>properties</code> contains
    *         case variants of the same key name.
@@ -138,7 +138,7 @@ public:
    * the service object for the plugin.
    * </ol>
    *
-   * @throws std::logic_error If this
+   * @throws ctkIllegalStateException If this
    *         <code>ctkServiceRegistration</code> object has already been
    *         unregistered or if it is invalid.
    * @see ctkPluginContext#ungetService

+ 1 - 1
Libs/PluginFramework/ctkServiceTracker.h

@@ -171,7 +171,7 @@ public:
    * <code>ctkServiceTracker</code> was created are now tracked by this
    * <code>ctkServiceTracker</code>.
    *
-   * @throws std::logic_error If the <code>ctkPluginContext</code>
+   * @throws ctkIllegalStateException If the <code>ctkPluginContext</code>
    *         with which this <code>ctkServiceTracker</code> was created is no
    *         longer valid.
    */