Преглед на файлове

Added ctkServiceEvent class.

Sascha Zelzer преди 14 години
родител
ревизия
7c60039646
променени са 2 файла, в които са добавени 249 реда и са изтрити 0 реда
  1. 99 0
      Libs/PluginFramework/ctkServiceEvent.cpp
  2. 150 0
      Libs/PluginFramework/ctkServiceEvent.h

+ 99 - 0
Libs/PluginFramework/ctkServiceEvent.cpp

@@ -0,0 +1,99 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 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 "ctkServiceEvent.h"
+
+class ctkServiceEventData : public QSharedData
+{
+public:
+
+  ctkServiceEventData(ctkServiceEvent::Type type, const ctkServiceReference& reference)
+    : type(type), reference(reference)
+  {
+
+  }
+
+  ctkServiceEventData(const ctkServiceEventData& other)
+    : QSharedData(other), type(other.type), reference(other.reference)
+  {
+
+  }
+
+  const ctkServiceEvent::Type type;
+  const ctkServiceReference reference;
+};
+
+
+ctkServiceEvent::ctkServiceEvent()
+  : d(0)
+{
+
+}
+
+ctkServiceEvent::~ctkServiceEvent()
+{
+
+}
+
+ctkServiceEvent::ctkServiceEvent(Type type, const ctkServiceReference& reference)
+  : d(new ctkServiceEventData(type, reference))
+{
+
+}
+
+ctkServiceEvent::ctkServiceEvent(const ctkServiceEvent& other)
+  : d(other.d)
+{
+
+}
+
+ctkServiceReference ctkServiceEvent::getServiceReference() const
+{
+  return d->reference;
+}
+
+ctkServiceEvent::Type ctkServiceEvent::getType() const
+{
+  return d->type;
+}
+
+QDebug operator<<(QDebug dbg, ctkServiceEvent::Type type)
+{
+  switch(type)
+  {
+  case ctkServiceEvent::MODIFIED:
+    dbg.nospace() << "MODIFIED";
+    break;
+  case ctkServiceEvent::MODIFIED_ENDMATCH:
+    dbg.nospace() << "MODIFIED_ENDMATCH";
+    break;
+  case ctkServiceEvent::REGISTERED:
+    dbg.nospace() << "REGISTERED";
+    break;
+  case ctkServiceEvent::UNREGISTERING:
+    dbg.nospace() << "UNREGISTERING";
+    break;
+  default:
+    dbg.nospace() << "unknown event type " << static_cast<int>(type);
+  }
+
+  return dbg.maybeSpace();
+}

+ 150 - 0
Libs/PluginFramework/ctkServiceEvent.h

@@ -0,0 +1,150 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 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 CTKSERVICEEVENT_H
+#define CTKSERVICEEVENT_H
+
+#include <QSharedDataPointer>
+#include <QDebug>
+
+#include "CTKPluginFrameworkExport.h"
+
+#include "ctkServiceReference.h"
+
+class ctkServiceEventData;
+
+/**
+ * An event from the Plugin Framework describing a service lifecycle change.
+ * <p>
+ * <code>ctkServiceEvent</code> objects are delivered to
+ * slots connected via ctkPluginContext::connectServiceListener() when a
+ * change occurs in this service's lifecycle. A type code is used to identify
+ * the event type for future extendability.
+ */
+class CTK_PLUGINFW_EXPORT ctkServiceEvent
+{
+
+  QSharedDataPointer<ctkServiceEventData> d;
+
+public:
+
+  enum Type {
+
+    /**
+     * This service has been registered.
+     * <p>
+     * This event is synchronously delivered <strong>after</strong> the service
+     * has been registered with the Framework.
+     *
+     * @see ctkPluginContext#registerService()
+     */
+    REGISTERED = 0x00000001,
+
+    /**
+     * The properties of a registered service have been modified.
+     * <p>
+     * This event is synchronously delivered <strong>after</strong> the service
+     * properties have been modified.
+     *
+     * @see ctkServiceRegistration#setProperties
+     */
+    MODIFIED = 0x00000002,
+
+    /**
+     * This service is in the process of being unregistered.
+     * <p>
+     * This event is synchronously delivered <strong>before</strong> the service
+     * has completed unregistering.
+     *
+     * <p>
+     * If a plugin is using a service that is <code>UNREGISTERING</code>, the
+     * plugin should release its use of the service when it receives this event.
+     * If the plugin does not release its use of the service when it receives
+     * this event, the Framework will automatically release the plugin's use of
+     * the service while completing the service unregistration operation.
+     *
+     * @see ctkServiceRegistration#unregister
+     * @see ctkPluginContext#ungetService
+     */
+    UNREGISTERING		= 0x00000004,
+
+    /**
+     * The properties of a registered service have been modified and the new
+     * properties no longer match the listener's filter.
+     * <p>
+     * This event is synchronously delivered <strong>after</strong> the service
+     * properties have been modified. This event is only delivered to slots
+     * which were added with a non-<code>null</code> filter where the filter
+     * matched the service properties prior to the modification but the filter
+     * does not match the modified service properties.
+     *
+     * @see ctkServiceRegistration#setProperties
+     */
+    MODIFIED_ENDMATCH	= 0x00000008
+
+  };
+
+  /**
+   * Default constructor for use with the Qt meta object system.
+   */
+  ctkServiceEvent();
+
+  ~ctkServiceEvent();
+
+  /**
+   * Creates a new service event object.
+   *
+   * @param type The event type.
+   * @param reference A <code>ServiceReference</code> object to the service
+   *        that had a lifecycle change.
+   */
+  ctkServiceEvent(Type type, const ctkServiceReference& plugin);
+
+  ctkServiceEvent(const ctkServiceEvent& other);
+
+  /**
+   * Returns a reference to the service that had a change occur in its
+   * lifecycle.
+   * <p>
+   * This reference is the source of the event.
+   *
+   * @return Reference to the service that had a lifecycle change.
+   */
+  ctkServiceReference getServiceReference() const;
+
+  /**
+   * Returns the type of event. The event type values are:
+   * <ul>
+   * <li>{@link #REGISTERED} </li>
+   * <li>{@link #MODIFIED} </li>
+   * <li>{@link #MODIFIED_ENDMATCH} </li>
+   * <li>{@link #UNREGISTERING} </li>
+   * </ul>
+   *
+   * @return Type of service lifecycle change.
+   */
+  Type getType() const;
+
+};
+
+QDebug CTK_PLUGINFW_EXPORT operator<<(QDebug dbg, ctkServiceEvent::Type type);
+
+#endif // CTKSERVICEEVENT_H