diff --git a/BlueBerry/Bundles/org.blueberry.core.commands/src/berryCommand.cpp b/BlueBerry/Bundles/org.blueberry.core.commands/src/berryCommand.cpp
index c1bfc88bd3..0517b35522 100644
--- a/BlueBerry/Bundles/org.blueberry.core.commands/src/berryCommand.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.commands/src/berryCommand.cpp
@@ -1,559 +1,559 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryCommand.h"
#include "berryIParameter.h"
#include "berryITypedParameter.h"
#include "berryIHandler.h"
#include "berryIHandlerListener.h"
#include "berryIParameterValueConverter.h"
#include "berryHandlerEvent.h"
#include "berryCommandEvent.h"
#include "berryExecutionEvent.h"
#include "berryCommandCategory.h"
#include "berryState.h"
#include "util/berryCommandTracing.h"
#include "internal/berryCommandUtils.h"
#include
* This class is not intended to be extended by clients.
*
* The parameters for a command. This interface will only be consulted if the
* parameters need to be displayed to the user. Otherwise, they will be ignored.
*
* An event fired from a
* An event fired from a
* This class is not intended to be extended by clients.
*
* A property tester implements the property tests enumerated in the property
* tester extension point. For the following property test extension
* null
.
*
*/
void Command::RemoveExecutionListener(IExecutionListener* executionListener)
{
if (!executionListener)
{
throw Poco::NullPointerException(
"Cannot remove a null execution listener");
}
executionEvents.RemoveListener(executionListener);
}
void Command::RemoveState(const QString& stateId)
{
if (IObjectWithState::Pointer stateHandler = handler.CastCommand
.
* true
, iff the category property changed.
* @param definedChanged
* true
, iff the defined property changed.
* @param descriptionChanged
* true
, iff the description property changed.
* @param handledChanged
* true
, iff the handled property changed.
* @param nameChanged
* true
, iff the name property changed.
* @param parametersChanged
* true
if the parameters have changed;
* false
otherwise.
* @param returnTypeChanged
* true
iff the return type property changed;
* false
otherwise.
* @param helpContextIdChanged
* true
iff the help context identifier changed;
* false
otherwise.
* @param enabledChanged
* true
iff the comand enablement changed;
* false
otherwise.
* @since 3.3
*/
CommandEvent(const SmartPointernull
.
*/
SmartPointertrue
, iff the category property changed.
*/
bool IsCategoryChanged() const;
/**
* Returns whether or not the handled property changed.
*
* @return true
, iff the handled property changed.
*/
bool IsHandledChanged() const;
/**
* Returns whether or not the help context identifier changed.
*
* @return true
, iff the help context identifier changed.
* @since 3.2
*/
bool IsHelpContextIdChanged() const;
/**
* Returns whether or not the parameters have changed.
*
* @return true
, iff the parameters property changed.
*/
bool IsParametersChanged() const;
/**
* Returns whether or not the return type property changed.
*
* @return true
, iff the return type property changed.
* @since 3.2
*/
bool IsReturnTypeChanged() const;
/**
* Return whether the enable property changed.
*
* @return true
iff the comand enablement changed
* @since 3.3
*/
bool IsEnabledChanged() const;
private:
/**
* The bit used to represent whether the command has changed its category.
*/
- static const int CHANGED_CATEGORY; // = LAST_USED_BIT << 1;
+ static int CHANGED_CATEGORY(); // = LAST_USED_BIT << 1;
/**
* The bit used to represent whether the command has changed its handler.
*/
- static const int CHANGED_HANDLED; // = LAST_USED_BIT << 2;
+ static int CHANGED_HANDLED(); // = LAST_USED_BIT << 2;
/**
* The bit used to represent whether the command has changed its parameters.
*/
- static const int CHANGED_PARAMETERS; // = LAST_USED_BIT << 3;
+ static int CHANGED_PARAMETERS(); // = LAST_USED_BIT << 3;
/**
* The bit used to represent whether the command has changed its return
* type.
*
* @since 3.2
*/
- static const int CHANGED_RETURN_TYPE; // = LAST_USED_BIT << 4;
+ static int CHANGED_RETURN_TYPE(); // = LAST_USED_BIT << 4;
/**
* The bit used to represent whether the command has changed its help
* context identifier.
*
* @since 3.2
*/
- static const int CHANGED_HELP_CONTEXT_ID; // = LAST_USED_BIT << 5;
+ static int CHANGED_HELP_CONTEXT_ID(); // = LAST_USED_BIT << 5;
/**
* The bit used to represent whether this commands active handler has
* changed its enablement state.
*
* @since 3.3
*/
- static const int CHANGED_ENABLED; // = LAST_USED_BIT << 6;
+ static int CHANGED_ENABLED(); // = LAST_USED_BIT << 6;
/**
* The command that has changed; this value is never null
.
*/
const SmartPointerString
)
* to the actual value of the parameter (String
).
*/
virtual QHashNamedHandleObject
. This provides
* notification of changes to the defined state, the name and the description.
* true
, iff the defined property changed.
*/
bool IsDefinedChanged() const;
protected:
/**
* The bit used to represent whether the category has changed its defined
* state.
*/
- static const int CHANGED_DEFINED; // = 1;
+ static int CHANGED_DEFINED(); // = 1;
/**
* The last used bit so that subclasses can add more properties.
*/
- static const int LAST_BIT_USED_ABSTRACT_HANDLE; // = CHANGED_DEFINED;
+ static int LAST_BIT_USED_ABSTRACT_HANDLE(); // = CHANGED_DEFINED;
/**
* Constructs a new instance of AbstractHandleObjectEvent
.
*
* @param definedChanged
* true
, iff the defined property changed.
*/
AbstractHandleObjectEvent(bool definedChanged);
};
}
#endif /* BERRYABSTRACTHANDLEOBJECTEVENT_H_ */
diff --git a/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.cpp b/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.cpp
index 266ab314a4..b6d8c7e9cb 100755
--- a/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.cpp
@@ -1,51 +1,51 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryAbstractNamedHandleEvent.h"
namespace berry
{
-const int AbstractNamedHandleEvent::CHANGED_DESCRIPTION = AbstractNamedHandleEvent::LAST_BIT_USED_ABSTRACT_HANDLE << 1;
-const int AbstractNamedHandleEvent::CHANGED_NAME = AbstractNamedHandleEvent::LAST_BIT_USED_ABSTRACT_HANDLE << 2;
-const int AbstractNamedHandleEvent::LAST_USED_BIT = AbstractNamedHandleEvent::CHANGED_NAME;
+int AbstractNamedHandleEvent::CHANGED_DESCRIPTION() { static int i = AbstractNamedHandleEvent::LAST_BIT_USED_ABSTRACT_HANDLE() << 1; return i; }
+int AbstractNamedHandleEvent::CHANGED_NAME() { static int i = AbstractNamedHandleEvent::LAST_BIT_USED_ABSTRACT_HANDLE() << 2; return i; }
+int AbstractNamedHandleEvent::LAST_USED_BIT() { static int i = AbstractNamedHandleEvent::CHANGED_NAME(); return i; }
bool AbstractNamedHandleEvent::IsDescriptionChanged() const
{
- return ((changedValues & CHANGED_DESCRIPTION) != 0);
+ return ((changedValues & CHANGED_DESCRIPTION()) != 0);
}
bool AbstractNamedHandleEvent::IsNameChanged() const
{
- return ((changedValues & CHANGED_NAME) != 0);
+ return ((changedValues & CHANGED_NAME()) != 0);
}
AbstractNamedHandleEvent::AbstractNamedHandleEvent(bool definedChanged,
bool descriptionChanged, bool nameChanged) :
AbstractHandleObjectEvent(definedChanged)
{
if (descriptionChanged)
{
- changedValues |= CHANGED_DESCRIPTION;
+ changedValues |= CHANGED_DESCRIPTION();
}
if (nameChanged)
{
- changedValues |= CHANGED_NAME;
+ changedValues |= CHANGED_NAME();
}
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.h b/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.h
index 45136e9200..3231de1f9a 100755
--- a/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.h
+++ b/BlueBerry/Bundles/org.blueberry.core.commands/src/common/berryAbstractNamedHandleEvent.h
@@ -1,87 +1,87 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYABSTRACTNAMEDHANDLEEVENT_H_
#define BERRYABSTRACTNAMEDHANDLEEVENT_H_
#include "berryAbstractHandleObjectEvent.h"
namespace berry {
/**
* NamedHandleObject
. This provides
* notification of changes to the defined state, the name and the description.
* true
, iff the description property changed.
*/
bool IsDescriptionChanged() const;
/**
* Returns whether or not the name property changed.
*
* @return true
, iff the name property changed.
*/
bool IsNameChanged() const;
protected:
/**
* The bit used to represent whether the category has changed its
* description.
*/
- static const int CHANGED_DESCRIPTION; // = LAST_BIT_USED_ABSTRACT_HANDLE << 1;
+ static int CHANGED_DESCRIPTION(); // = LAST_BIT_USED_ABSTRACT_HANDLE << 1;
/**
* The bit used to represent whether the category has changed its name.
*/
- static const int CHANGED_NAME; // = LAST_BIT_USED_ABSTRACT_HANDLE << 2;
+ static int CHANGED_NAME(); // = LAST_BIT_USED_ABSTRACT_HANDLE << 2;
/**
* The last used bit so that subclasses can add more properties.
*/
- static const int LAST_USED_BIT; // = CHANGED_NAME;
+ static int LAST_USED_BIT(); // = CHANGED_NAME;
/**
* Constructs a new instance of AbstractHandleObjectEvent
.
*
* @param definedChanged
* true
, iff the defined property changed.
* @param descriptionChanged
* true
, iff the description property changed.
* @param nameChanged
* true
, iff the name property changed.
*/
AbstractNamedHandleEvent(bool definedChanged,
bool descriptionChanged, bool nameChanged);
};
}
#endif /* BERRYABSTRACTNAMEDHANDLEEVENT_H_ */
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/files.cmake b/BlueBerry/Bundles/org.blueberry.core.expressions/files.cmake
index a38c51dd5b..8d410d5d88 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/files.cmake
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/files.cmake
@@ -1,59 +1,63 @@
set(MOC_H_FILES
+ src/berryPropertyTester.h
+
+ src/internal/berryPlatformPropertyTester.h
src/internal/berryExpressionPlugin.h
)
set(CACHED_RESOURCE_FILES
plugin.xml
)
set(SRC_CPP_FILES
berryElementHandler.cpp
berryEvaluationContext.cpp
berryEvaluationResult.cpp
berryExpression.cpp
berryExpressionConverter.cpp
berryExpressionInfo.cpp
berryExpressionTagNames.cpp
berryICountable.h
berryIEvaluationContext.cpp
berryIIterable.cpp
berryIPropertyTester.cpp
berryIVariableResolver.cpp
berryPropertyTester.cpp
)
set(INTERNAL_CPP_FILES
berryAdaptExpression.cpp
berryAndExpression.cpp
berryCompositeExpression.cpp
berryCountExpression.cpp
berryDefaultVariable.cpp
berryDefinitionRegistry.cpp
berryEnablementExpression.cpp
berryEqualsExpression.cpp
berryExpressionPlugin.cpp
berryExpressions.cpp
berryExpressionStatus.cpp
berryInstanceofExpression.cpp
berryIterateExpression.cpp
berryNotExpression.cpp
berryOrExpression.cpp
+ berryPlatformPropertyTester.cpp
berryProperty.cpp
berryPropertyTesterDescriptor.cpp
berryReferenceExpression.cpp
berryResolveExpression.cpp
berryStandardElementHandler.cpp
berrySystemTestExpression.cpp
berryTestExpression.cpp
berryTypeExtension.cpp
berryTypeExtensionManager.cpp
berryWithExpression.cpp
)
foreach(file ${SRC_CPP_FILES})
set(CPP_FILES ${CPP_FILES} src/${file})
endforeach(file ${SRC_CPP_FILES})
foreach(file ${INTERNAL_CPP_FILES})
set(CPP_FILES ${CPP_FILES} src/internal/${file})
endforeach(file ${INTERNAL_CPP_FILES})
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/plugin.xml b/BlueBerry/Bundles/org.blueberry.core.expressions/plugin.xml
index 2bb386d815..a05b11cb6e 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/plugin.xml
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/plugin.xml
@@ -1,7 +1,17 @@
true
if the default variable is accessed
* by the expression tree.
*
* @return whether the default variable is accessed or not
*/
bool HasDefaultVariableAccess() const;
/**
* Marks the default variable as accessed.
*/
void MarkDefaultVariableAccessed();
/**
* Returns true
if the system property is accessed
* by the expression tree.
*
* @return whether the system property is accessed or not
*/
bool HasSystemPropertyAccess() const;
/**
* Marks the system property as accessed.
*/
void MarkSystemPropertyAccessed();
/**
* Returns the set off accessed variables.
*
* @return the set off accessed variables
*/
QSetnull
if
* all expressions implement the method.
*
* @return the set of expression types which don't implement the
* computeReevaluationInfo
method.
*/
QSetorg.blueberry.core.expresssions.propertyTesters
*
must extend PropertyTester
.
*
* <propertyTester
* namespace="org.blueberry.jdt.core"
* id="org.blueberry.jdt.core.IPackageFragmentTester"
* properties="isDefaultPackage"
* type="org.blueberry.jdt.core.IPackageFragment"
* class="org.blueberry.demo.MyPackageFragmentTester">
* </propertyTester>
*
* the corresponding implementation class looks like:
*
* public class MyPackageFragmentTester {
* public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
* IPackageFragment fragement= (IPackageFragment)receiver;
* if ("isDefaultPackage".equals(property)) {
* return expectedValue == null
* ? fragement.isDefaultPackage()
* : fragement.isDefaultPackage() == ((Boolean)expectedValue).booleanValue();
* }
* Assert.isTrue(false);
* return false;
* }
* }
*
* The property can then be used in a test expression as follows:
*
* <instanceof value="org.blueberry.core.IPackageFragment"/>
* <test property="org.blueberry.jdt.core.isDefaultPackage"/>
*
*
* There is no guarantee that the same instance of a property tester is used * to handle <test property="..."/> requests. So property testers * should always be implemented in a stateless fashion. *
- * @since 3.0 */ -class BERRY_EXPRESSIONS PropertyTester : public IPropertyTester +class BERRY_EXPRESSIONS PropertyTester : public QObject, public IPropertyTester { + Q_OBJECT + Q_INTERFACES(berry::IPropertyTester) private: IConfigurationElement::Pointer fConfigElement; QString fNamespace; QString fProperties; public: /** * Initialize the property tester with the given name space and property. ** Note: this method is for internal use only. Clients must not call * this method. *
* @param descriptor the descriptor object for this tester */ void InternalInitialize(PropertyTesterDescriptor::Pointer descriptor); /** * Note: this method is for internal use only. Clients must not call * this method. * * @return the property tester descriptor */ PropertyTesterDescriptor::Pointer InternalCreateDescriptor(); /** * {@inheritDoc} */ bool Handles(const QString& namespaze, const QString& property); /** * {@inheritDoc} */ bool IsInstantiated(); /** * {@inheritDoc} */ bool IsDeclaringPluginActive(); /** * {@inheritDoc} */ IPropertyTester* Instantiate(); }; } // namespace berry #endif /*BERRYPROPERTYTESTER_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryCompositeExpression.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryCompositeExpression.cpp index b8a0266b37..dee8cd0d7e 100644 --- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryCompositeExpression.cpp +++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryCompositeExpression.cpp @@ -1,82 +1,82 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryCompositeExpression.h" -#include "Poco/Hash.h" +#includeIIterable
. If a corresponding adapter can't be found an
* exception is thrown. If the corresponding adapter isn't loaded yet, null
is returned.
*
* @param var the variable to turn into an IIterable
* @param expression the expression referring to the variable
*
* @return the IIterable
or null if a corresponding adapter isn't loaded yet
*
* @throws CoreException if the var can't be adapted to an IIterable
*/
static IIterable::ConstPointer GetAsIIterable(Object::ConstPointer var, Expression::ConstPointer expression);
/**
* Converts the given variable into an ICountable
. If a corresponding adapter can't be found an
* exception is thrown. If the corresponding adapter isn't loaded yet, null
is returned.
*
* @param var the variable to turn into an ICountable
* @param expression the expression referring to the variable
*
* @return the ICountable
or null if a corresponding adapter isn't loaded yet
*
* @throws CoreException if the var can't be adapted to an ICountable
*/
static ICountable::ConstPointer GetAsICountable(Object::ConstPointer var, Expression::ConstPointer expression);
static bool GetOptionalBooleanAttribute(SmartPointer element, const QString& attributeName);
static bool GetOptionalBooleanAttribute(Poco::XML::Element* element, const QString& attributeName);
//---- Argument parsing --------------------------------------------
static QList GetArguments(const SmartPointer& element,
const QString& attributeName);
static QList GetArguments(Poco::XML::Element* element,
const QString& attributeName);
static QList ParseArguments(const QString& args);
static Object::Pointer ConvertArgument(const QString& arg);
static QString UnEscapeString(const QString& str);
};
}
#endif /*BERRYEXPRESSIONS_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.cpp
index b23c0be84c..7f84ffa3e1 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.cpp
@@ -1,61 +1,60 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryNotExpression.h"
#include
-#include
namespace berry {
-const std::size_t NotExpression::HASH_INITIAL = Poco::hash("berry::NotExpression");
+const uint NotExpression::HASH_INITIAL = qHash("berry::NotExpression");
NotExpression::NotExpression(Expression::Pointer expression)
{
poco_assert(expression.IsNotNull());
fExpression= expression;
}
EvaluationResult::ConstPointer
NotExpression::Evaluate(IEvaluationContext* context) const
{
return fExpression->Evaluate(context)->Not();
}
void
NotExpression::CollectExpressionInfo(ExpressionInfo* info) const
{
fExpression->CollectExpressionInfo(info);
}
bool
NotExpression::operator==(const Object* object) const
{
if (const NotExpression* that = dynamic_cast(object))
{
return this->fExpression == that->fExpression;
}
return false;
}
uint
NotExpression::ComputeHashCode() const
{
return HASH_INITIAL * HASH_FACTOR + fExpression->HashCode();
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.h
index 8f5e920418..297ab15e99 100755
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.h
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryNotExpression.h
@@ -1,53 +1,53 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef __BERRY_NOT_EXPRESSION_H__
#define __BERRY_NOT_EXPRESSION_H__
#include "berryExpression.h"
namespace berry {
class NotExpression : public Expression {
private:
/**
* The seed for the hash code for all not expressions.
*/
- static const std::size_t HASH_INITIAL;
+ static const uint HASH_INITIAL;
Expression::Pointer fExpression;
public:
NotExpression(Expression::Pointer expression);
EvaluationResult::ConstPointer Evaluate(IEvaluationContext* context) const;
void CollectExpressionInfo(ExpressionInfo* info) const;
bool operator==(const Object* object) const;
protected:
uint ComputeHashCode() const;
};
} // namespace berry
#endif // __BERRY_NOT_EXPRESSION_H__
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPlatformPropertyTester.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPlatformPropertyTester.cpp
new file mode 100644
index 0000000000..f66a912071
--- /dev/null
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPlatformPropertyTester.cpp
@@ -0,0 +1,92 @@
+/*===================================================================
+
+BlueBerry Platform
+
+Copyright (c) German Cancer Research Center,
+Division of Medical and Biological Informatics.
+All rights reserved.
+
+This software is distributed WITHOUT ANY WARRANTY; without
+even the implied warranty of MERCHANTABILITY or FITNESS FOR
+A PARTICULAR PURPOSE.
+
+See LICENSE.txt or http://www.mitk.org for details.
+
+===================================================================*/
+
+#include "berryPlatformPropertyTester.h"
+
+#include "berryPlatform.h"
+#include
+#include
+
+#include
+
+
+namespace berry {
+
+const QString PlatformPropertyTester::PROPERTY_PRODUCT = "product";
+const QString PlatformPropertyTester::PROPERTY_IS_PLUGIN_INSTALLED = "isPluginInstalled";
+const QString PlatformPropertyTester::PROPERTY_PLUGIN_STATE = "pluginState";
+
+
+bool PlatformPropertyTester::Test(Object::ConstPointer receiver, const QString &property,
+ const QList &args, Object::Pointer expectedValue)
+{
+ if (ObjectTypeInfo::ConstPointer typeInfo = receiver.Cast())
+ {
+ if (!(*typeInfo == Reflection::TypeInfo::New()))
+ {
+ return false;
+ }
+
+ if (PROPERTY_PRODUCT == property)
+ {
+ IProduct* product= Platform::GetProduct();
+ if (product != nullptr)
+ {
+ return product->GetId() == expectedValue->ToString();
+ }
+ return false;
+ }
+ else if (PROPERTY_IS_PLUGIN_INSTALLED == property && !args.isEmpty() && args[0].Cast())
+ {
+ return !Platform::GetPlugin(args[0]->ToString()).isNull();
+ }
+ else if (PROPERTY_PLUGIN_STATE == property &&
+ !args.isEmpty() && args[0].Cast())
+ {
+ QSharedPointer p = Platform::GetPlugin(args[0]->ToString());
+ if (!p.isNull())
+ {
+ return PluginState(p->getState(), expectedValue->ToString());
+ }
+ return false;
+ }
+ }
+ return false;
+}
+
+bool PlatformPropertyTester::PluginState(ctkPlugin::State pluginState, const QString& expectedValue)
+{
+ switch (pluginState)
+ {
+ case ctkPlugin::UNINSTALLED:
+ return expectedValue == QString("UNINSTALLED");
+ case ctkPlugin::INSTALLED:
+ return expectedValue == QString("INSTALLED");
+ case ctkPlugin::RESOLVED:
+ return expectedValue == QString("RESOLVED");
+ case ctkPlugin::STARTING:
+ return expectedValue == QString("STARTING");
+ case ctkPlugin::STOPPING:
+ return expectedValue == QString("STOPPING");
+ case ctkPlugin::ACTIVE:
+ return expectedValue == QString("ACTIVE");
+ default:
+ return false;
+ }
+ return false;
+}
+
+}
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPlatformPropertyTester.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPlatformPropertyTester.h
new file mode 100644
index 0000000000..3de27e2a75
--- /dev/null
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPlatformPropertyTester.h
@@ -0,0 +1,59 @@
+/*===================================================================
+
+BlueBerry Platform
+
+Copyright (c) German Cancer Research Center,
+Division of Medical and Biological Informatics.
+All rights reserved.
+
+This software is distributed WITHOUT ANY WARRANTY; without
+even the implied warranty of MERCHANTABILITY or FITNESS FOR
+A PARTICULAR PURPOSE.
+
+See LICENSE.txt or http://www.mitk.org for details.
+
+===================================================================*/
+
+#ifndef BERRYPLATFORMPROPERTYTESTER_H
+#define BERRYPLATFORMPROPERTYTESTER_H
+
+#include
+
+#include
+
+namespace berry {
+
+/**
+ * A property tester for testing platform properties. Can test whether or
+ * not a given plugin is installed in the running environment, as well as
+ * the id of the currently active product.
+ *
+ * For example:
+ * <test property="org.blueberry.core.runtime.product" value="org.mitk.qt.Workbench"/>
+ * <test property="org.blueberry.core.runtime.isPluginInstalled" args="org.blueberry.core.expressions"/>
+ * <test property="org.blueberry.core.runtime.pluginState" args="org.blueberry.core.expressions" value="ACTIVE"/>
+ *
+ */
+class PlatformPropertyTester : public PropertyTester
+{
+ Q_OBJECT
+private:
+
+ static const QString PROPERTY_PRODUCT; // = "product";
+ static const QString PROPERTY_IS_PLUGIN_INSTALLED; // = "isPluginInstalled";
+ static const QString PROPERTY_PLUGIN_STATE; // = "pluginState";
+
+public:
+
+ bool Test(Object::ConstPointer receiver, const QString& property,
+ const QList& args, Object::Pointer expectedValue);
+
+private:
+
+ bool PluginState(ctkPlugin::State pluginState, const QString &expectedValue);
+
+};
+
+}
+
+#endif // BERRYPLATFORMPROPERTYTESTER_H
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.cpp
index 267a218754..3ea8bafffd 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.cpp
@@ -1,84 +1,86 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryProperty.h"
-#include
-#include
+#include
namespace berry {
-Property::Property(Object::ConstPointer type,
+Property::Property(const Reflection::TypeInfo& typeInfo,
const QString &namespaze, const QString &name)
- : fType(type), fNamespace(namespaze), fName(name)
+ : fType(typeInfo), fNamespace(namespaze), fName(name)
{
}
void Property::SetPropertyTester(IPropertyTester::Pointer tester)
{
- poco_check_ptr(tester);
-
- fTester= tester;
+ assert(tester.GetPointer() != 0);
+ fTester = tester;
}
-bool Property::IsInstantiated()
+bool Property::IsInstantiated() const
{
return fTester->IsInstantiated();
}
-bool Property::IsDeclaringPluginActive()
+bool Property::IsDeclaringPluginActive() const
{
return fTester->IsDeclaringPluginActive();
}
-bool Property::IsValidCacheEntry(bool forcePluginActivation)
+bool Property::IsValidCacheEntry(bool forcePluginActivation) const
{
if (forcePluginActivation)
{
return this->IsInstantiated() && this->IsDeclaringPluginActive();
}
else
{
return (this->IsInstantiated() && this->IsDeclaringPluginActive()) ||
(!this->IsInstantiated() && !this->IsDeclaringPluginActive());
}
}
bool Property::Test(Object::ConstPointer receiver, const QList& args,
Object::Pointer expectedValue)
{
return fTester->Test(receiver, fName, args, expectedValue);
}
-bool Property::operator==(Property& obj)
+bool Property::operator==(const Object* obj) const
{
- return fType == obj.fType && fNamespace == obj.fNamespace &&
- fName == obj.fName;
- }
+ if (const Property* other = dynamic_cast(obj))
+ {
+ return fType == other->fType && fNamespace == other->fNamespace &&
+ fName == other->fName;
+ }
+ return false;
+}
-bool Property::operator==(Property* obj)
+bool Property::operator<(const Object* obj) const
{
- return this->operator==(*obj);
+ return this->HashCode() < obj->HashCode();
}
-int Property::HashCode()
+uint Property::HashCode() const
{
- return (int) ((Poco::Hash()(typeid(fType).name()) << 16) |
- (Poco::Hash()(fNamespace.toStdString()) << 8) |
- Poco::Hash()(fName.toStdString()));
+ return qHash(fType.GetName()) << 16 |
+ qHash(fNamespace) << 8 |
+ qHash(fName);
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.h
index 9ca3b844d1..8e850560ac 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.h
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryProperty.h
@@ -1,71 +1,70 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYPROPERTY_H_
#define BERRYPROPERTY_H_
#include "berryIPropertyTester.h"
#include "berryObject.h"
#include "Poco/SharedPtr.h"
#include "Poco/Any.h"
#include
#include
namespace berry {
-class Property {
+class Property : public Object {
public:
- typedef Property Self;
- typedef Poco::SharedPtr Pointer;
- typedef Poco::SharedPtr ConstPointer;
+
+ berryObjectMacro(Property)
private:
- Object::ConstPointer fType;
+ Reflection::TypeInfo fType;
QString fNamespace;
QString fName;
IPropertyTester::Pointer fTester;
friend class TypeExtensionManager;
- /* package */ Property(Object::ConstPointer type,
+ /* package */ Property(const Reflection::TypeInfo& typeInfo,
const QString& namespaze, const QString& name);
/* package */ void SetPropertyTester(IPropertyTester::Pointer tester);
public:
- bool IsInstantiated();
+ bool IsInstantiated() const;
- bool IsDeclaringPluginActive();
+ bool IsDeclaringPluginActive() const;
- bool IsValidCacheEntry(bool forcePluginActivation);
+ bool IsValidCacheEntry(bool forcePluginActivation) const;
bool Test(Object::ConstPointer receiver, const QList& args,
Object::Pointer expectedValue);
- bool operator==(Property& obj);
+ bool operator==(const Object* obj) const;
- bool operator==(Property* obj);
+ bool operator<(const Object* obj) const;
- int HashCode();
+ uint HashCode() const;
};
} // namespace berry
#endif /*BERRYPROPERTY_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPropertyCache.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPropertyCache.h
index b52d704abd..cb18b8b413 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPropertyCache.h
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryPropertyCache.h
@@ -1,52 +1,60 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYPROPERTYCACHE_H_
#define BERRYPROPERTYCACHE_H_
#include "Poco/LRUCache.h"
#include "berryProperty.h"
namespace berry {
class PropertyCache {
private:
- Poco::LRUCache fCache;
+
+ struct PropertyHandle
+ {
+ Property* m_Property;
+ };
+
+ Poco::LRUCache fCache;
public:
PropertyCache(const int cacheSize) : fCache(cacheSize) {
}
Property::Pointer Get(Property::Pointer key) {
- return fCache.get(key);
+ Poco::SharedPtr value = fCache.get(key);
+ return value.isNull() ? Property::Pointer(0) : Property::Pointer(value->m_Property);
}
void Put(Property::Pointer method) {
- fCache.add(method, method);
+ PropertyHandle handle = { method.GetPointer() };
+ fCache.add(method, handle);
}
void Remove(Property::Pointer method) {
fCache.remove(method);
}
};
} // namespace berry
#endif /*BERRYPROPERTYCACHE_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.cpp
index cc87312074..dbba850507 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.cpp
@@ -1,96 +1,94 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryReferenceExpression.h"
#include "berryExpressions.h"
#include
#include
-#include "Poco/Hash.h"
-
namespace berry {
-const QString ReferenceExpression::ATT_DEFINITION_ID= "definitionId";
-const std::size_t ReferenceExpression::HASH_INITIAL= Poco::Hash()("berry::ReferenceExpression");
+const QString ReferenceExpression::ATT_DEFINITION_ID = "definitionId";
+const uint ReferenceExpression::HASH_INITIAL= qHash(QString("berry::ReferenceExpression"));
DefinitionRegistry ReferenceExpression::fgDefinitionRegistry = DefinitionRegistry();
DefinitionRegistry&
ReferenceExpression::GetDefinitionRegistry()
{
return fgDefinitionRegistry;
}
ReferenceExpression::ReferenceExpression(const QString &definitionId)
{
fDefinitionId= definitionId;
}
ReferenceExpression::ReferenceExpression(IConfigurationElement::Pointer element)
{
fDefinitionId = element->GetAttribute(ATT_DEFINITION_ID);
Expressions::CheckAttribute(ATT_DEFINITION_ID, fDefinitionId);
}
ReferenceExpression::ReferenceExpression(Poco::XML::Element* element)
{
fDefinitionId = QString::fromStdString(element->getAttribute(ATT_DEFINITION_ID.toStdString()));
Expressions::CheckAttribute(ATT_DEFINITION_ID, fDefinitionId.size() > 0 ? fDefinitionId : QString());
}
EvaluationResult::ConstPointer
ReferenceExpression::Evaluate(IEvaluationContext* context) const
{
Expression::Pointer expr= GetDefinitionRegistry().GetExpression(fDefinitionId);
return expr->Evaluate(context);
}
void
ReferenceExpression::CollectExpressionInfo(ExpressionInfo* info) const
{
Expression::Pointer expr;
try
{
expr= GetDefinitionRegistry().GetExpression(fDefinitionId);
}
catch (const CoreException& /*e*/)
{
// We didn't find the expression definition. So no
// expression info can be collected.
return;
}
expr->CollectExpressionInfo(info);
}
bool
ReferenceExpression::operator==(const Object* object) const
{
if (const ReferenceExpression* that = dynamic_cast(object))
{
return this->fDefinitionId == that->fDefinitionId;
}
return false;
}
uint
ReferenceExpression::ComputeHashCode() const
{
- return HASH_INITIAL * HASH_FACTOR + Poco::Hash()(fDefinitionId.toStdString());
+ return HASH_INITIAL * HASH_FACTOR + qHash(fDefinitionId);
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.h
index 2bf6021639..f7a30d572e 100755
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.h
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryReferenceExpression.h
@@ -1,72 +1,72 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef __BERRY_REFERENCE_EXPRESSION_H__
#define __BERRY_REFERENCE_EXPRESSION_H__
#include "berryDefinitionRegistry.h"
#include "Poco/DOM/Element.h"
namespace berry {
/**
* This class makes use of the org.blueberry.core.expressions.definitions
* extension point to evaluate the current context against pre-defined
* expressions. It provides core expression re-use.
*/
class ReferenceExpression : public Expression {
private:
// consider making this a more general extension manager
// for now it's just part of the reference expression
static DefinitionRegistry fgDefinitionRegistry;
static DefinitionRegistry& GetDefinitionRegistry();
static const QString ATT_DEFINITION_ID;
/**
* The seed for the hash code for all equals expressions.
*/
- static const std::size_t HASH_INITIAL;
+ static const uint HASH_INITIAL;
QString fDefinitionId;
public:
ReferenceExpression(const QString& definitionId);
ReferenceExpression(SmartPointer element);
ReferenceExpression(Poco::XML::Element* element);
EvaluationResult::ConstPointer Evaluate(IEvaluationContext* context) const;
void CollectExpressionInfo(ExpressionInfo* info) const;
bool operator==(const Object* object) const;
protected:
uint ComputeHashCode() const;
};
} // namespace berry
#endif // __BERRY_REFERENCE_EXPRESSION_H__
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.cpp
index 97a48c8965..102216e58c 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.cpp
@@ -1,190 +1,189 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryTestExpression.h"
#include "berryExpressions.h"
#include "berryExpressionStatus.h"
#include "berryPlatform.h"
#include "berryCoreException.h"
#include
#include
namespace berry {
const QChar TestExpression::PROP_SEP = '.';
const QString TestExpression::ATT_PROPERTY = "property";
const QString TestExpression::ATT_ARGS = "args";
const QString TestExpression::ATT_FORCE_PLUGIN_ACTIVATION = "forcePluginActivation";
-TypeExtensionManager TestExpression::fgTypeExtensionManager("propertyTesters");
-
const uint TestExpression::HASH_INITIAL= qHash("berry::TextExpression");
+TypeExtensionManager& TestExpression::GetTypeExtensionManager()
+{
+ static TypeExtensionManager mgr("propertyTesters");
+ return mgr;
+}
TestExpression::TestExpression(const IConfigurationElement::Pointer& element)
{
QString property = element->GetAttribute(ATT_PROPERTY);
int pos = property.lastIndexOf(PROP_SEP);
if (pos == -1)
{
IStatus::Pointer status(new ExpressionStatus(
ExpressionStatus::NO_NAMESPACE_PROVIDED,
"The property attribute of the test expression must be qualified by a name space.",
BERRY_STATUS_LOC));
throw CoreException(status);
}
fNamespace = property.left(pos);
fProperty = property.mid(pos + 1);
fArgs = Expressions::GetArguments(element, ATT_ARGS);
fExpectedValue = Expressions::ConvertArgument(element->GetAttribute(ATT_VALUE));
fForcePluginActivation = Expressions::GetOptionalBooleanAttribute(element, ATT_FORCE_PLUGIN_ACTIVATION);
}
TestExpression::TestExpression(Poco::XML::Element* element)
{
QString property= QString::fromStdString(element->getAttribute(ATT_PROPERTY.toStdString()));
int pos = property.lastIndexOf(PROP_SEP);
if (pos == -1)
{
IStatus::Pointer status(new ExpressionStatus(
ExpressionStatus::NO_NAMESPACE_PROVIDED,
"The property attribute of the test expression must be qualified by a name space.",
BERRY_STATUS_LOC));
throw CoreException(status);
}
fNamespace = property.left(pos);
fProperty = property.mid(pos + 1);
fArgs = Expressions::GetArguments(element, ATT_ARGS);
std::string value = element->getAttribute(ATT_VALUE.toStdString());
fExpectedValue = Expressions::ConvertArgument(value.size() > 0 ? QString::fromStdString(value) : QString());
fForcePluginActivation = Expressions::GetOptionalBooleanAttribute(element, ATT_FORCE_PLUGIN_ACTIVATION);
}
TestExpression::TestExpression(const QString& namespaze, const QString& property,
const QList& args, Object::Pointer expectedValue)
: fNamespace(namespaze), fProperty(property), fArgs(args),
fExpectedValue(expectedValue), fForcePluginActivation(false)
{
}
TestExpression::TestExpression(const QString &namespaze, const QString &property, const QList& args,
Object::Pointer expectedValue, bool forcePluginActivation)
: fNamespace(namespaze), fProperty(property), fArgs(args),
fExpectedValue(expectedValue), fForcePluginActivation(forcePluginActivation)
{
}
EvaluationResult::ConstPointer
TestExpression::Evaluate(IEvaluationContext* context) const
{
Object::ConstPointer element(context->GetDefaultVariable());
if (typeid(Platform) == typeid(element.GetPointer()))
{
QString str = Platform::GetProperty(fProperty);
if (str.isEmpty())
{
return EvaluationResult::FALSE_EVAL;
}
- ObjectString::Pointer var = fArgs[0].Cast();
- if (var)
- return EvaluationResult::ValueOf(static_cast(*var) == str);
-
- return EvaluationResult::FALSE_EVAL;
+ return EvaluationResult::ValueOf(str == fArgs[0]->ToString());
}
- Property::Pointer property= fgTypeExtensionManager.GetProperty(element, fNamespace, fProperty, context->GetAllowPluginActivation() && fForcePluginActivation);
+ Property::Pointer property= GetTypeExtensionManager().GetProperty(element, fNamespace, fProperty, context->GetAllowPluginActivation() && fForcePluginActivation);
if (!property->IsInstantiated())
return EvaluationResult::NOT_LOADED;
return EvaluationResult::ValueOf(property->Test(element, fArgs, fExpectedValue));
}
void
TestExpression::CollectExpressionInfo(ExpressionInfo* info) const
{
info->MarkDefaultVariableAccessed();
info->AddAccessedPropertyName(fNamespace + PROP_SEP + fProperty);
}
bool
TestExpression::operator==(const Object* object) const
{
if (const TestExpression* that = dynamic_cast(object))
{
return this->fNamespace == that->fNamespace &&
this->fProperty == that->fProperty &&
this->fForcePluginActivation == that->fForcePluginActivation &&
this->Equals(this->fArgs, that->fArgs) &&
this->fExpectedValue == that->fExpectedValue;
}
return false;
}
uint TestExpression::ComputeHashCode() const
{
return HASH_INITIAL * HASH_FACTOR + this->HashCode(fArgs)
- * HASH_FACTOR + fExpectedValue->HashCode()
+ * HASH_FACTOR + (fExpectedValue.IsNull() ? 0 : fExpectedValue->HashCode())
* HASH_FACTOR + qHash(fNamespace)
* HASH_FACTOR + qHash(fProperty)
* HASH_FACTOR + (fForcePluginActivation ? 1 : 0);
}
QString
TestExpression::ToString() const
{
QString args("");
for (int i= 0; i < fArgs.size(); i++)
{
Object::Pointer arg= fArgs[i];
ObjectString::Pointer strarg = arg.Cast();
if (strarg)
{
args.append('\'');
args.append(static_cast(*strarg));
args.append('\'');
}
else
{
args.append(arg->ToString());
}
if (i < fArgs.size() - 1)
args.append(", ");
}
return "ToString() + "\"" : "\"") +
" plug-in activation: " + (fForcePluginActivation ? "eager" : "lazy") + "/>";
}
//---- testing ---------------------------------------------------
bool
TestExpression::TestGetForcePluginActivation()
{
return fForcePluginActivation;
}
TypeExtensionManager&
TestExpression::TestGetTypeExtensionManager()
{
- return fgTypeExtensionManager;
+ return GetTypeExtensionManager();
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.h
index f8807fc433..d887c69ea9 100755
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.h
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTestExpression.h
@@ -1,93 +1,93 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef __BERRY_TEST_EXPRESSION_H__
#define __BERRY_TEST_EXPRESSION_H__
#include "berryExpression.h"
#include "berryTypeExtensionManager.h"
#include "berryObject.h"
#include "Poco/DOM/Element.h"
namespace berry {
struct IConfigurationElement;
class TestExpression : public Expression {
private:
QString fNamespace;
QString fProperty;
QList fArgs;
Object::Pointer fExpectedValue;
bool fForcePluginActivation;
static const QChar PROP_SEP;
static const QString ATT_PROPERTY;
static const QString ATT_ARGS;
static const QString ATT_FORCE_PLUGIN_ACTIVATION;
/**
* The seed for the hash code for all test expressions.
*/
static const uint HASH_INITIAL;
- static TypeExtensionManager fgTypeExtensionManager;
+ static TypeExtensionManager& GetTypeExtensionManager();
public:
TestExpression(const SmartPointer& element);
TestExpression(Poco::XML::Element* element);
TestExpression(const QString& namespaze, const QString& property,
const QList& args, Object::Pointer expectedValue);
TestExpression(const QString& namespaze, const QString& property,
const QList& args, Object::Pointer expectedValue,
bool forcePluginActivation);
EvaluationResult::ConstPointer Evaluate(IEvaluationContext* context) const;
void CollectExpressionInfo(ExpressionInfo* info) const;
bool operator==(const Object* object) const;
protected:
uint ComputeHashCode() const;
//---- Debugging ---------------------------------------------------
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public:
QString ToString() const;
//---- testing ---------------------------------------------------
bool TestGetForcePluginActivation();
static TypeExtensionManager& TestGetTypeExtensionManager();
};
} // namespace berry
#endif // __BERRY_TEST_EXPRESSION_H__
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.cpp
index 79459c51fd..2a34b47828 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.cpp
@@ -1,123 +1,157 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryTypeExtension.h"
#include "berryTypeExtensionManager.h"
#include "berryPropertyTesterDescriptor.h"
#include "berryPropertyTester.h"
#include "berryExpressionStatus.h"
#include
namespace berry {
-
-TypeExtension::TypeExtension(const QString& typeInfo)
- : fTypeInfo(typeInfo), fExtendersLoaded(false), fExtendsLoaded(false)
+TypeExtension::TypeExtension()
+ : fExtendersLoaded(false)
+ , fInheritsLoaded(false)
{
+ // special constructor to create the CONTINUE instance
+}
+TypeExtension::TypeExtension(const Reflection::TypeInfo& typeInfo)
+ : fTypeInfo(typeInfo)
+ , fExtendersLoaded(false)
+ , fInheritsLoaded(false)
+{
}
IPropertyTester::Pointer TypeExtension::FindTypeExtender(
TypeExtensionManager& manager, const QString& namespaze, const QString& method,
bool staticMethod, bool forcePluginActivation)
{
if (!fExtendersLoaded)
{
- fExtenders = manager.LoadTesters(fTypeInfo);
+ fExtenders = manager.LoadTesters(fTypeInfo.GetName());
fExtendersLoaded = true;
}
IPropertyTester::Pointer result;
// handle extenders associated with this type extender
for (int i= 0; i < fExtenders.size(); i++)
{
IPropertyTester::Pointer extender = fExtenders[i];
if (extender.IsNull() || !extender->Handles(namespaze, method))
continue;
if (extender->IsInstantiated())
{
// There is no need to check for an active plug-in here. If a plug-in
// gets uninstalled we receive an registry event which will flush the whole
// type extender cache and will reinstantiate the testers. However Bundle#stop
// isn't handled by this. According to bug https://bugs.blueberry.org/bugs/show_bug.cgi?id=130338
// we don't have to support stop in 3.2. If we have to in the future we have to
// reactivate the stopped plug-in if we are in forcePluginActivation mode.
return extender;
}
else
{
if (extender->IsDeclaringPluginActive() || forcePluginActivation)
{
PropertyTesterDescriptor::Pointer descriptor = extender.Cast();
if (!descriptor.IsNull())
{
try
{
IPropertyTester::Pointer inst(descriptor->Instantiate());
inst.Cast()->InternalInitialize(descriptor);
fExtenders[i]= extender = inst;
return extender;
}
catch (const CoreException& e)
{
fExtenders[i] = IPropertyTester::Pointer();
throw e;
}
}
else
{
fExtenders[i]= IPropertyTester::Pointer();
IStatus::Pointer status(new ExpressionStatus(ExpressionStatus::TYPE_EXTENDER_INCORRECT_TYPE,
"The implementation class is not a sub type of berry::PropertyTester",
BERRY_STATUS_LOC));
throw CoreException(status);
}
}
else
{
return extender;
}
}
}
// there is no inheritance for static methods
if (staticMethod)
return CONTINUE_::Pointer(new CONTINUE_());
// handle inheritance chain
- // TODO Reflection
-// if (!fExtendsLoaded) {
-// fExtends.clear();
-// Object::ExtTypeInfo types(fTypeInfo);
-// while (!types.m_TypeNames.empty()) {
-// types.m_TypeNames.pop_back();
-// types.m_TypeInfos.pop_back();
-// fExtends.push_back(manager.Get(types));
-// }
-// fExtendsLoaded = true;
-// }
-// for (unsigned int i= 0; i < fExtends.size(); i++) {
-// result = fExtends[i]->FindTypeExtender(manager, namespaze, method, staticMethod, forcePluginActivation);
-// if (result.Cast().IsNull())
-// return result;
-// }
+ if (!fInheritsLoaded)
+ {
+ fInherits.clear();
+ QList superClasses = fTypeInfo.GetSuperclasses();
+ foreach(const Reflection::TypeInfo& superClass, superClasses)
+ {
+ fInherits.push_back(manager.Get(superClass));
+ }
+ fInheritsLoaded = true;
+ }
+ foreach(const TypeExtension::Pointer& typeExtension, fInherits)
+ {
+ result = typeExtension->FindTypeExtender(manager, namespaze, method, staticMethod, forcePluginActivation);
+ if (result.Cast().IsNull())
+ {
+ return result;
+ }
+ }
+ return CONTINUE_::Pointer(new CONTINUE_());
+}
+
+bool TypeExtension::CONTINUE_::Handles(const QString&, const QString&) {
+ return false;
+}
+
+bool TypeExtension::CONTINUE_::IsInstantiated() {
+ return true;
+}
+
+bool TypeExtension::CONTINUE_::IsDeclaringPluginActive() {
+ return true;
+}
+
+IPropertyTester*TypeExtension::CONTINUE_::Instantiate() {
+ return this;
+}
+
+bool TypeExtension::CONTINUE_::Test(Object::ConstPointer, const QString&, const QList&, Object::Pointer) {
+ return false;
+}
+
+IPropertyTester::Pointer END_POINT_::FindTypeExtender(TypeExtensionManager&, const QString&, const QString&, bool, bool)
+{
return CONTINUE_::Pointer(new CONTINUE_());
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.h
index 47e044eec7..6f37bc6227 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.h
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtension.h
@@ -1,109 +1,91 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYTYPEEXTENSION_H_
#define BERRYTYPEEXTENSION_H_
#include
#include
#include "berryIPropertyTester.h"
namespace berry {
class TypeExtensionManager;
class END_POINT_;
class TypeExtension : public Object {
public:
- berryObjectMacro(TypeExtension);
+ berryObjectMacro(TypeExtension)
private:
/* the type this extension is extending */
- QString fTypeInfo;
+ Reflection::TypeInfo fTypeInfo;
/* the list of associated extenders */
QList fExtenders;
bool fExtendersLoaded;
/* the extensions associated with fType
's super classes */
- QList fExtends;
- bool fExtendsLoaded;
-
- TypeExtension() : fExtendersLoaded(false), fExtendsLoaded(false) {
- // special constructor to create the CONTINUE instance
- }
+ QList fInherits;
+ bool fInheritsLoaded;
+ TypeExtension();
protected:
friend class TypeExtensionManager;
/* a special property tester instance that is used to signal that method searching has to continue */
- /* package */ class CONTINUE_ : public IPropertyTester {
-
- public:
-
- berryObjectMacro(CONTINUE_);
-
- bool Handles(const QString& /*namespaze*/, const QString& /*method*/) {
- return false;
- }
- bool IsInstantiated() {
- return true;
- }
- bool IsDeclaringPluginActive() {
- return true;
- }
- IPropertyTester* Instantiate() {
- return this;
- }
- bool Test(Object::ConstPointer /*receiver*/, const QString& /*method*/,
- const QList& /*args*/, Object::Pointer /*expectedValue*/) {
- return false;
- }
- };
-
- static const CONTINUE_ CONTINUE;
- static const END_POINT_ END_POINT;
-
- /* package */
- TypeExtension(const QString &typeInfo);
-
- /* package */
- IPropertyTester::Pointer FindTypeExtender(TypeExtensionManager& manager,
- const QString &namespaze, const QString &method,
- bool staticMethod, bool forcePluginActivation);
+ class CONTINUE_ : public IPropertyTester {
+
+ public:
+
+ berryObjectMacro(CONTINUE_)
+
+ bool Handles(const QString& /*namespaze*/, const QString& /*method*/);
+ bool IsInstantiated();
+ bool IsDeclaringPluginActive();
+ IPropertyTester* Instantiate();
+ bool Test(Object::ConstPointer /*receiver*/, const QString& /*method*/,
+ const QList& /*args*/, Object::Pointer /*expectedValue*/);
+ };
+
+ static const CONTINUE_ CONTINUE;
+ static const END_POINT_ END_POINT;
+
+ TypeExtension(const Reflection::TypeInfo& typeInfo);
+
+ IPropertyTester::Pointer FindTypeExtender(TypeExtensionManager& manager,
+ const QString &namespaze, const QString &method,
+ bool staticMethod, bool forcePluginActivation);
};
/* a special type extension instance that marks the end of an evaluation chain */
class END_POINT_ : public TypeExtension
{
protected:
IPropertyTester::Pointer FindTypeExtender(TypeExtensionManager& /*manager*/,
- const QString& /*namespaze*/, const QString& /*name*/,
- bool /*staticMethod*/, bool /*forcePluginActivation*/)
- {
- return CONTINUE_::Pointer(new CONTINUE_());
- }
+ const QString& /*namespaze*/, const QString& /*name*/,
+ bool /*staticMethod*/, bool /*forcePluginActivation*/);
};
} // namespace berry
#endif /*BERRYTYPEEXTENSION_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.cpp b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.cpp
index 139559f5a9..bb418d8a67 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.cpp
@@ -1,167 +1,199 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryLog.h"
#include "berryTypeExtensionManager.h"
#include "berryExpressions.h"
#include "berryExpressionStatus.h"
#include "berryPropertyTesterDescriptor.h"
#include "berryPlatform.h"
#include "berryCoreException.h"
#include
#include
namespace berry {
+ /**
+ * Tells whether this class is in debug mode.
+ */
+ bool TypeExtensionManager::DEBUG = false;
+
const QString TypeExtensionManager::TYPE= "type";
TypeExtensionManager::TypeExtensionManager(const QString& extensionPoint)
: fExtensionPoint(extensionPoint)
{
- //Platform.getExtensionRegistry().addRegistryChangeListener(this);
+ Platform::GetExtensionRegistry()->AddListener(this);
this->InitializeCaches();
}
Property::Pointer TypeExtensionManager::GetProperty(Object::ConstPointer receiver,
const QString& namespaze, const QString& method)
{
return GetProperty(receiver, namespaze, method, false);
}
/*synchronized*/Property::Pointer
TypeExtensionManager::GetProperty(
Object::ConstPointer receiver, const QString& namespaze,
const QString& method, bool forcePluginActivation)
{
std::clock_t start= 0;
if (Expressions::TRACING)
- start = std::clock();
+ {
+ start = std::clock();
+ }
// if we call a static method than the receiver is the class object
//Class clazz= receiver instanceof Class ? (Class)receiver : receiver.getClass();
- Property::Pointer result(new Property(receiver, namespaze, method));
+ Property::Pointer result(new Property(receiver->GetTypeInfo(), namespaze, method));
Property::Pointer cached(fPropertyCache->Get(result));
- if (!cached.isNull())
+ if (!cached.IsNull())
{
if (cached->IsValidCacheEntry(forcePluginActivation))
{
if (Expressions::TRACING)
{
BERRY_INFO << "[Type Extension] - method "
- << receiver->ToString() << "#" << method.toStdString()
+ << receiver->GetClassName() << "#" << method.toStdString()
<< " found in cache: "
<< (double(std::clock() - start))/(CLOCKS_PER_SEC/1000) << " ms.";
}
return cached;
}
// The type extender isn't loaded in the cached method but can be loaded
// now. So remove method from cache and do the normal look up so that the
// implementation class gets loaded.
fPropertyCache->Remove(cached);
}
- TypeExtension::Pointer extension(this->Get(receiver->GetClassName()));
+ TypeExtension::Pointer extension(this->Get(receiver->GetTypeInfo()));
IPropertyTester::Pointer extender(extension->FindTypeExtender(*this, namespaze, method, false /*receiver instanceof Class*/, forcePluginActivation));
if (!extender.Cast().IsNull() || extender.IsNull())
{
QString msg("Unknown method for ");
msg.append(receiver->GetClassName());
IStatus::Pointer status(new ExpressionStatus(ExpressionStatus::TYPE_EXTENDER_UNKOWN_METHOD,
QString("No property tester contributes a property %1 to type %2")
.arg(namespaze + "::" + method).arg(receiver->GetClassName()),
BERRY_STATUS_LOC));
throw CoreException(status);
}
result->SetPropertyTester(extender);
fPropertyCache->Put(result);
if (Expressions::TRACING)
{
BERRY_INFO << "[Type Extension] - method "
- << typeid(receiver).name() << "#" << method
+ << receiver->GetClassName() << "#" << method
<< " not found in cache: "
<< (double(std::clock() - start))/(CLOCKS_PER_SEC/1000) << " ms.";
}
return result;
}
- /* package */TypeExtension::Pointer
- TypeExtensionManager::Get(const QString& type)
+ TypeExtension::Pointer TypeExtensionManager::Get(const Reflection::TypeInfo& typeInfo)
{
- TypeExtension::Pointer result(fTypeExtensionMap[type]);
+ TypeExtension::Pointer result(fTypeExtensionMap[typeInfo.GetName()]);
if (result.IsNull())
{
- result = new TypeExtension(type);
- fTypeExtensionMap[type] = result;
+ result = new TypeExtension(typeInfo);
+ fTypeExtensionMap[typeInfo.GetName()] = result;
}
return result;
}
QList TypeExtensionManager::LoadTesters(const QString& typeName)
{
if (fConfigurationElementMap.isEmpty())
{
IExtensionRegistry* registry = Platform::GetExtensionRegistry();
QList ces(
registry->GetConfigurationElementsFor(QString("org.blueberry.core.expressions.") + fExtensionPoint));
for (int i= 0; i < ces.size(); i++)
{
IConfigurationElement::Pointer config(ces[i]);
QString typeAttr = config->GetAttribute(TYPE);
fConfigurationElementMap[typeAttr].push_back(config);
}
}
//std::string typeName= type.getName();
QList typeConfigs = fConfigurationElementMap.take(typeName);
QList result;
for (int i= 0; i < typeConfigs.size(); i++)
{
IConfigurationElement::Pointer config(typeConfigs[i]);
try
{
IPropertyTester::Pointer descr(new PropertyTesterDescriptor(config));
result.push_back(descr);
}
- catch (const CoreException& /*e*/)
+ catch (const CoreException& e)
{
//TODO
//ExpressionPlugin.getDefault().getLog().log(e.getStatus());
+ BERRY_ERROR << e.what();
IPropertyTester::Pointer nullTester(new NULL_PROPERTY_TESTER_());
result.push_back(nullTester);
}
}
return result;
}
/*synchronized*/void TypeExtensionManager::InitializeCaches()
{
fPropertyCache = new PropertyCache(1000);
fConfigurationElementMap.clear();
fTypeExtensionMap.clear();
}
+ void TypeExtensionManager::Added(const QList >& /*extensions*/)
+ {
+ this->InitializeCaches();
+ }
+
+ void TypeExtensionManager::Removed(const QList >& /*extensions*/)
+ {
+ this->InitializeCaches();
+ }
+
+ void TypeExtensionManager::Added(const QList >& /*extensionPoints*/)
+ {
+ this->InitializeCaches();
+ }
+
+ void TypeExtensionManager::Removed(const QList >& /*extensionPoints*/)
+ {
+ this->InitializeCaches();
+ }
+
TypeExtensionManager::~TypeExtensionManager()
{
+ IExtensionRegistry* registry = Platform::GetExtensionRegistry();
+ if (registry)
+ {
+ registry->RemoveListener(this);
+ }
if (fPropertyCache) delete fPropertyCache;
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.h b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.h
index 144bd59507..8388e430ec 100644
--- a/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.h
+++ b/BlueBerry/Bundles/org.blueberry.core.expressions/src/internal/berryTypeExtensionManager.h
@@ -1,125 +1,127 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYTYPEEXTENSIONMANAGER_H_
#define BERRYTYPEEXTENSIONMANAGER_H_
#include "berryIPropertyTester.h"
#include "berryTypeExtension.h"
#include "berryPropertyCache.h"
#include "berryProperty.h"
#include
+#include
#include
#include
namespace berry {
-class TypeExtensionManager { // implements IRegistryChangeListener {
+class TypeExtensionManager : private IRegistryEventListener
+{
private:
QString fExtensionPoint;
static const QString TYPE;
class NULL_PROPERTY_TESTER_ : public IPropertyTester
{
public:
bool Handles(const QString& /*namespaze*/, const QString& /*property*/)
{
return false;
}
bool IsInstantiated()
{
return true;
}
bool IsDeclaringPluginActive()
{
return true;
}
IPropertyTester* Instantiate()
{
return this;
}
bool Test(Object::ConstPointer, const QString& /*property*/,
const QList& /*args*/, Object::Pointer /*expectedValue*/)
{
return false;
}
};
static const NULL_PROPERTY_TESTER_ NULL_PROPERTY_TESTER;
/*
* Map containing all already created type extension object.
*/
QHash fTypeExtensionMap;
/*
* Table containing mapping of class name to configuration element
*/
QHash > fConfigurationElementMap;
/*
* A cache to give fast access to the last 1000 method invocations.
*/
PropertyCache* fPropertyCache;
public:
+ static bool DEBUG;
+
TypeExtensionManager(const QString& extensionPoint);
~TypeExtensionManager();
Property::Pointer GetProperty(Object::ConstPointer receiver,
const QString& namespaze, const QString& method);
/*synchronized*/Property::Pointer GetProperty(Object::ConstPointer receiver,
const QString& namespaze, const QString& method, bool forcePluginActivation);
protected:
friend class TypeExtension;
/*
* This method doesn't need to be synchronized since it is called
* from withing the getProperty method which is synchronized
*/
- /* package */TypeExtension::Pointer Get(const QString& type);
+ TypeExtension::Pointer Get(const Reflection::TypeInfo& typeInfo);
/*
* This method doesn't need to be synchronized since it is called
* from withing the getProperty method which is synchronized
*/
- /* package */QList LoadTesters(const QString& typeName);
-
- // public void registryChanged(IRegistryChangeEvent event) {
- // IExtensionDelta[] deltas= event.getExtensionDeltas(ExpressionPlugin.getPluginId(), fExtensionPoint);
- // if (deltas.length > 0) {
- // initializeCaches();
- // }
- // }
+ QList LoadTesters(const QString& typeName);
private:
/*synchronized*/void InitializeCaches();
+
+ virtual void Added(const QList >& extensions);
+ virtual void Removed(const QList >& extensions);
+ virtual void Added(const QList >& extensionPoints);
+ virtual void Removed(const QList >& extensionPoints);
};
}
#endif /*BERRYTYPEEXTENSIONMANAGER_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.jobs/src/berryIJobChangeListener.h b/BlueBerry/Bundles/org.blueberry.core.jobs/src/berryIJobChangeListener.h
index 24ab1c42b7..680871ee7a 100644
--- a/BlueBerry/Bundles/org.blueberry.core.jobs/src/berryIJobChangeListener.h
+++ b/BlueBerry/Bundles/org.blueberry.core.jobs/src/berryIJobChangeListener.h
@@ -1,159 +1,157 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYIJOBCHANGELISTENER_H_
#define BERRYIJOBCHANGELISTENER_H_
#include "berryIJobChangeEvent.h"
namespace berry
{
/**
* Callback interface for clients interested in being notified when jobs change state.
*
* A single job listener instance can be added either to the job manager, for notification
* of all scheduled jobs, or to any set of individual jobs. A single listener instance should
* not be added to both the job manager, and to individual jobs (such a listener may
* receive duplicate notifications).
*
* Clients should not rely on the result of the Job#GetState()
* method on jobs for which notification is occurring. Listeners are notified of
* all job state changes, but whether the state change occurs before, during, or
* after listeners are notified is unspecified.
*
* Clients may implement this interface.
*
* @see IJobManager#AddJobChangeListener(IJobChangeListener::Pointer)
* @see IJobManager#RemoveJobChangeListener(IJobChangeListener::Pointer)
* @see Job#AddJobChangeListener(IJobChangeListener::Pointer)
* @see Job#GetState()
* @see Job#RemoveJobChangeListener(IJobChangeListener::Pointer)
*/
struct BERRY_JOBS IJobChangeListener
{
- berryObjectMacro(berry::IJobChangeListener)
-
struct BERRY_JOBS Events
{
typedef Message1 JobChangeEventType;
enum Type
{
NONE = 0x00000000,
ABOUT_TO_RUN = 0x00000001,
AWAKE = 0x00000002,
DONE = 0x00000004,
RUNNING = 0x00000008,
SCHEDULED = 0x00000010,
SLEEPING = 0x00000020,
ALL = 0xffffffff
};
Q_DECLARE_FLAGS(Types, Type)
JobChangeEventType jobAboutToRun;
JobChangeEventType jobAwake;
JobChangeEventType jobDone;
JobChangeEventType jobRunning;
JobChangeEventType jobScheduled;
JobChangeEventType jobSleeping;
void AddListener(IJobChangeListener* listener);
void RemoveListener(IJobChangeListener* listener);
void SetExceptionHandler(const AbstractExceptionHandler& handler);
typedef MessageDelegate1
Delegate;
};
virtual Events::Types GetEventTypes() = 0;
/**
* Notification that a job is about to be run. Listeners are allowed to sleep, cancel,
* or change the priority of the job before it is started (and as a result may prevent
* the run from actually occurring).
*
* @param event the event details
*/
virtual void AboutToRun(const IJobChangeEvent::ConstPointer& /*event*/)
{
}
/**
* Notification that a job was previously sleeping and has now been rescheduled
* to run.
*
* @param event the event details
*/
virtual void Awake(const IJobChangeEvent::ConstPointer& /*event*/)
{
}
/**
* Notification that a job has completed execution, either due to cancelation, successful
* completion, or failure. The event status object indicates how the job finished,
* and the reason for failure, if applicable.
*
* @param event the event details
*/
virtual void Done(const IJobChangeEvent::ConstPointer& /*event*/)
{
}
/**
* Notification that a job has started running.
*
* @param event the event details
*/
virtual void Running(const IJobChangeEvent::ConstPointer& /*event*/)
{
}
/**
* Notification that a job is being added to the queue of scheduled jobs.
* The event details includes the scheduling delay before the job should start
* running.
*
* @param event the event details, including the job instance and the scheduling
* delay
*/
virtual void Scheduled(const IJobChangeEvent::ConstPointer& /*event*/)
{
}
/**
* Notification that a job was waiting to run and has now been put in the
* sleeping state.
*
* @param event the event details
*/
virtual void Sleeping(const IJobChangeEvent::ConstPointer& /*event*/)
{
}
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS(berry::IJobChangeListener::Events::Types)
#endif /* BERRYIJOBCHANGELISTENER_H_ */
diff --git a/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryJobListeners.cpp b/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryJobListeners.cpp
index a80f9e9311..b863335a2a 100644
--- a/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryJobListeners.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryJobListeners.cpp
@@ -1,164 +1,165 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryJobListeners.h"
#include "berryJobManager.h"
#include "berryJob.h"
#include "berryOperationCanceledException.h"
#include "berryLog.h"
#include
namespace berry
{
struct AboutToRunDoit: public JobListeners::IListenerDoit
{
void Notify(const IJobChangeListener::Events& events,
const IJobChangeEvent::ConstPointer& event) const
{
events.jobAboutToRun(event);
}
};
struct AwakeDoit: public JobListeners::IListenerDoit
{
void Notify(const IJobChangeListener::Events& events,
const IJobChangeEvent::ConstPointer& event) const
{
events.jobAwake(event);
}
};
struct DoneDoit: public JobListeners::IListenerDoit
{
void Notify(const IJobChangeListener::Events& events,
const IJobChangeEvent::ConstPointer& event) const
{
events.jobDone(event);
}
};
struct RunningDoit: public JobListeners::IListenerDoit
{
void Notify(const IJobChangeListener::Events& events,
const IJobChangeEvent::ConstPointer& event) const
{
events.jobRunning(event);
}
};
struct ScheduledDoit: public JobListeners::IListenerDoit
{
void Notify(const IJobChangeListener::Events& events,
const IJobChangeEvent::ConstPointer& event) const
{
events.jobScheduled(event);
}
};
struct SleepingDoit: public JobListeners::IListenerDoit
{
void Notify(const IJobChangeListener::Events& events,
const IJobChangeEvent::ConstPointer& event) const
{
events.jobSleeping(event);
}
};
JobListeners::JobListeners()
: aboutToRun(new AboutToRunDoit())
, awake(new AwakeDoit())
, done(new DoneDoit())
, running(new RunningDoit())
, scheduled(new ScheduledDoit())
, sleeping(new SleepingDoit())
{
}
JobListeners::~JobListeners()
{
delete aboutToRun;
delete awake;
delete done;
delete running;
delete scheduled;
delete sleeping;
}
JobChangeEvent::Pointer JobListeners::NewEvent(Job::Pointer job)
{
JobChangeEvent::Pointer instance(new JobChangeEvent());
instance->job = job;
return instance;
}
JobChangeEvent::Pointer JobListeners::NewEvent(Job::Pointer job, IStatus::Pointer result)
{
JobChangeEvent::Pointer instance(new JobChangeEvent());
instance->job = job;
instance->result = result;
return instance;
}
JobChangeEvent::Pointer JobListeners::NewEvent(Job::Pointer job, Poco::Timestamp::TimeDiff delay)
{
JobChangeEvent::Pointer instance(new JobChangeEvent());
instance->job = job;
instance->delay = delay;
return instance;
}
void JobListeners::DoNotify(const IListenerDoit* doit,
const IJobChangeEvent::ConstPointer& event)
{
//notify all global listeners
doit->Notify(global, event);
//notify all local listeners
const IJobChangeListener::Events& events =
event->GetJob().Cast ()->GetListeners();
doit->Notify(events, event);
}
void JobListeners::HandleException(const std::exception& e)
{
//this code is roughly copied from InternalPlatform.run(ISafeRunnable),
//but in-lined here for performance reasons
- try
+ if(dynamic_cast(&e))
{
- dynamic_cast (e);
return;
}
- catch (const std::bad_cast&)
+ else
{
// TODO get bundle id (find a C++ way)
//std::string pluginId = JobOSGiUtils.getDefault().getBundleId(listener);
QString pluginId;
if (pluginId.isEmpty())
+ {
pluginId = JobManager::PI_JOBS();
+ }
QString message = "Problems occurred when invoking code from plug-in: "
- + pluginId;
+ + pluginId;
BERRY_ERROR << message;
// TODO Logging
// RuntimeLog.log(new Status(IStatus.ERROR, pluginId, JobManager.PLUGIN_ERROR,
// message, e));
}
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryWorker.cpp b/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryWorker.cpp
index ceb943a222..16d46672d5 100644
--- a/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryWorker.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.jobs/src/internal/berryWorker.cpp
@@ -1,134 +1,134 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryWorker.h"
#include "berryWorkerPool.h"
#include "berryJobManager.h"
#include "berryLog.h"
namespace berry
{
/************************* begin of nested JobRunnable class definition ****************************/
int Worker::m_nextWorkerNumber = 0;
Worker::JobRunnable::JobRunnable(Worker* currentWorker) :
ptr_currentWorker(currentWorker)
{
}
// not a good implementation yet .. without the IStatus it can not be checked if a job has been
// executed correctly
void Worker::JobRunnable::run()
{
ptr_currentWorker->setPriority(PRIO_NORMAL);
try
{
while ((ptr_currentWorker->ptr_currentJob
= ptr_currentWorker->m_wpPool.Lock()->StartJob(ptr_currentWorker)) != 0)
{
IStatus::Pointer result = Status::OK_STATUS(BERRY_STATUS_LOC);
try
{
ptr_currentWorker->ptr_currentJob->SetThread(ptr_currentWorker);
ptr_currentWorker->ptr_currentJob->Run(ptr_currentWorker->ptr_currentJob->GetProgressMonitor());
// java thread.interrupted
throw FinallyThrowException();
} catch(FinallyThrowException)
{
RunMethodFinallyExecution(result);
}
// provided an unspecific exception handling, if specific exceptions are added within core job executing methods
// the specific thrown exceptions should be handled below
catch(...)
{
RunMethodFinallyExecution(result);
}
}
throw FinallyThrowException();
} catch (FinallyThrowException&)
{
ptr_currentWorker->ptr_currentJob = 0;
Worker::Pointer sptr_currentWorker(ptr_currentWorker);
ptr_currentWorker->m_wpPool.Lock()->EndWorker(sptr_currentWorker);
} catch (...)
{
ptr_currentWorker->ptr_currentJob = 0;
Worker::Pointer sptr_currentWorker(ptr_currentWorker);
ptr_currentWorker->m_wpPool.Lock()->EndWorker(sptr_currentWorker);
}
}
void Worker::JobRunnable::RunMethodFinallyExecution(IStatus::Pointer sptr_result)
{
//clear interrupted state for this thread
//Thread.interrupted();
//result must not be null
if (sptr_result.IsNull())
{
std::runtime_error tempError("NullPointerException");
sptr_result = HandleException( ptr_currentWorker->ptr_currentJob, tempError );
}
ptr_currentWorker->m_wpPool.Lock()->EndJob( ptr_currentWorker->ptr_currentJob, sptr_result );
if ((sptr_result->GetSeverity() & (IStatus::ERROR_TYPE | IStatus::WARNING_TYPE)) != 0)
// TODO Logging RuntimeLog.log(result);
BERRY_ERROR << " Status after executing the job : " << sptr_result->ToString();
ptr_currentWorker->ptr_currentJob = 0;
//reset thread priority in case job changed it
ptr_currentWorker->setPriority(PRIO_NORMAL);
}
IStatus::Pointer Worker::JobRunnable::HandleException(InternalJob::Pointer sptr_job, const std::exception& exception)
{
QString msg = "An internal error occurred while executing the job: " + sptr_job->GetName();
IStatus::Pointer sptr_errorStatus(new Status(IStatus::ERROR_TYPE, JobManager::PI_JOBS(),
JobManager::PLUGIN_ERROR, msg, ctkException(exception.what()), BERRY_STATUS_LOC));
return sptr_errorStatus ;
}
/************************* end of nested JobRunnable class definition ****************************/
Worker::Worker(WeakPointer myPool) :
- Poco::Thread("Worker-" + m_nextWorkerNumber++), m_Runnable(this), m_wpPool(
+ Poco::Thread("Worker-" + std::to_string(m_nextWorkerNumber++)), m_Runnable(this), m_wpPool(
myPool), ptr_currentJob(0)
{
}
void Worker::Start()
{
Poco::Thread::start(m_Runnable);
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/CMakeLists.txt b/BlueBerry/Bundles/org.blueberry.core.runtime/CMakeLists.txt
index f2597a4a60..378e17bfbd 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/CMakeLists.txt
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/CMakeLists.txt
@@ -1,45 +1,50 @@
project(org_blueberry_core_runtime)
set(QT_USE_QTXML 1)
MACRO_CREATE_CTK_PLUGIN(EXPORT_DIRECTIVE org_blueberry_core_runtime_EXPORT
- EXPORTED_INCLUDE_SUFFIXES src src/application src/registry)
+ EXPORTED_INCLUDE_SUFFIXES src
+ src/application
+ src/debug
+ src/dynamichelpers
+ src/registry
+)
target_link_libraries(${PLUGIN_TARGET} PUBLIC Poco::Foundation Poco::Util Poco::XML)
if(MITK_USE_Qt5)
target_link_libraries(${PLUGIN_TARGET} PRIVATE Qt5::Gui Qt5::Xml)
endif()
# Set compiler flags
target_compile_definitions(${PLUGIN_TARGET} PUBLIC "$<$:POCO_NO_UNWINDOWS;WIN32_LEAN_AND_MEAN>")
add_executable(${OSGI_APP} MACOSX_BUNDLE "src/application/berryMain.cpp")
target_link_libraries(${OSGI_APP} PRIVATE ${PROJECT_NAME} mbilog)
if(_ctk_test_plugins)
add_dependencies(${OSGI_APP} ${_ctk_test_plugins})
add_dependencies(BlueBerry ${OSGI_APP})
set_property(TARGET ${OSGI_APP} APPEND PROPERTY LABELS BlueBerry)
endif()
configure_file(src/application/solstice.ini
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${OSGI_APP}.ini)
add_executable(${OSGI_UI_APP} MACOSX_BUNDLE "src/application/berryMainUI.cpp")
target_link_libraries(${OSGI_UI_APP} PRIVATE ${PROJECT_NAME} mbilog)
if(MITK_USE_Qt5)
target_link_libraries(${OSGI_UI_APP} PRIVATE Qt5::Widgets)
endif()
if(_ctk_test_plugins)
add_dependencies(${OSGI_UI_APP} ${_ctk_test_plugins})
add_dependencies(BlueBerry ${OSGI_UI_APP})
set_property(TARGET ${OSGI_UI_APP} APPEND PROPERTY LABELS BlueBerry)
endif()
configure_file(src/application/solstice.ini
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${OSGI_UI_APP}.ini)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/berryConfig.h.in" "${CMAKE_CURRENT_BINARY_DIR}/berryConfig.h" @ONLY)
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/files.cmake b/BlueBerry/Bundles/org.blueberry.core.runtime/files.cmake
index 4b1d810f09..8dd98f286c 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/files.cmake
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/files.cmake
@@ -1,119 +1,133 @@
set(MOC_H_FILES
src/berryPlugin.h
src/internal/berryCTKPluginListener.h
src/internal/berryCTKPluginActivator.h
+ src/internal/berryDebugOptions.h
src/internal/berryExtensionRegistry.h
src/internal/berryPreferencesService.h
)
set(CACHED_RESOURCE_FILES
plugin.xml
)
set(SRC_CPP_FILES
berryBackingStoreException.cpp
berryContributorFactory.cpp
berryCoreException.cpp
berryDebugBreakpointManager.cpp
berryDebugUtil.cpp
berryException.cpp
berryExtensionType.cpp
berryIAdaptable.cpp
berryIAdapterManager.cpp
berryIDebugObjectListener.cpp
berryILog.cpp
berryIPreferences.cpp
+ berryIProduct.cpp
berryIBerryPreferences.cpp
berryIPreferencesService.cpp
berryListenerList.h
berryLog.cpp
berryMultiStatus.cpp
berryObject.cpp
berryObjectGeneric.h
berryObjectList.h
berryObjects.cpp
berryObjectString.cpp
berryObjectStringMap.cpp
+ berryObjectTypeInfo.cpp
berryOperationCanceledException.cpp
berryPlatform.cpp
berryPlatformException.cpp
berryPlatformObject.cpp
berryPlugin.cpp
+ berryReflection.cpp
berrySafeRunner.cpp
berrySmartPointer.h
berryStatus.cpp
berryWeakPointer.h
# application
application/berryIApplication.cpp
application/berryStarter.cpp
+ debug/berryDebugOptionsListener.cpp
+ debug/berryIDebugOptions.cpp
+
+ dynamichelpers/berryExtensionTracker.cpp
+ dynamichelpers/berryIExtensionChangeHandler.cpp
+ dynamichelpers/berryIExtensionTracker.cpp
+
# registry
registry/berryIConfigurationElement.cpp
registry/berryIContributor.cpp
registry/berryIExecutableExtension.cpp
registry/berryIExecutableExtensionFactory.cpp
registry/berryIExtension.cpp
registry/berryIExtensionPoint.cpp
+ registry/berryIExtensionPointFilter.cpp
registry/berryIExtensionRegistry.cpp
registry/berryInvalidRegistryObjectException.cpp
registry/berryIRegistryEventListener.cpp
registry/berryRegistryConstants.cpp
)
set(INTERNAL_CPP_FILES
berryAbstractPreferencesStorage.cpp
berryCombinedEventDelta.cpp
berryConfigurationElement.h
berryConfigurationElement.cpp
berryConfigurationElementAttribute.cpp
berryConfigurationElementDescription.cpp
berryConfigurationElementHandle.cpp
berryCTKPluginActivator.cpp
berryCTKPluginListener.cpp
berryCTKPluginUtils.cpp
+ berryDebugOptions.cpp
berryExtension.cpp
berryExtensionHandle.cpp
berryExtensionPoint.cpp
berryExtensionPointHandle.cpp
berryExtensionRegistry.cpp
berryExtensionsParser.cpp
berryHandle.cpp
berryInternalPlatform.cpp
berryIObjectManager.cpp
berryIRuntimeConstants.cpp
berryLogImpl.cpp
berryKeyedElement.cpp
berryKeyedHashSet.cpp
berryPreferences.cpp
berryPreferencesService.cpp
berryProvisioningInfo.cpp
berryRegistryContribution.cpp
berryRegistryContributor.cpp
berryRegistryObjectFactory.cpp
berryRegistryIndexChildren.cpp
berryRegistryIndexElement.cpp
berryRegistryMessages.cpp
berryRegistryObject.cpp
berryRegistryObjectManager.cpp
berryRegistryObjectReferenceMap.cpp
berryRegistryProperties.cpp
berryRegistryStrategy.cpp
berryRegistryTimestamp.cpp
berryRegistrySupport.cpp
+ berrySimpleExtensionPointFilter.cpp
berryTemporaryObjectManager.cpp
berryThirdLevelConfigurationElementHandle.cpp
berryXMLPreferencesStorage.cpp
)
set(CPP_FILES )
foreach(file ${SRC_CPP_FILES})
set(CPP_FILES ${CPP_FILES} src/${file})
endforeach(file ${SRC_CPP_FILES})
foreach(file ${INTERNAL_CPP_FILES})
set(CPP_FILES ${CPP_FILES} src/internal/${file})
endforeach(file ${INTERNAL_CPP_FILES})
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdaptable.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdaptable.h
index 04cde820b9..c73dfb1200 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdaptable.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdaptable.h
@@ -1,91 +1,91 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef _BERRY_IADAPTABLE_H_
#define _BERRY_IADAPTABLE_H_
#include
#include
#include
#include
namespace berry {
/**
* An interface for an adaptable object.
*
* Adaptable objects can be dynamically extended to provide different
* interfaces (or "adapters"). Adapters are created by adapter
* factories, which are in turn managed by type by adapter managers.
*
* For example,
*
* IAdaptable a = [some adaptable];
* IFoo x = (IFoo)a.getAdapter(IFoo.class);
* if (x != null)
* [do IFoo things with x]
*
*
* This interface can be used without OSGi running.
*
* Clients may implement this interface, or obtain a default implementation
* of this interface by subclassing PlatformObject
.
*
* @see IAdapterFactory
* @see IAdapterManager
* @see PlatformObject
*/
struct org_blueberry_core_runtime_EXPORT IAdaptable
{
public:
/**
* Returns an object which is an instance of the given class
* associated with this object. Returns null
if
* no such object can be found.
*
* @param adapterType the adapter class to look up
* @return a object castable to the given class,
* or null
if this object does not
* have an adapter for the given class
*/
- virtual Object* GetAdapter(const QString& adapterType) = 0;
+ virtual Object* GetAdapter(const QString& adapterType) const = 0;
template
A* GetAdapter()
{
const char* typeName = qobject_interface_iid();
if (typeName == NULL)
{
- BERRY_WARN << "Error getting adapter for '" << Object::DemangleName(typeid(*this).name()) << "': "
- << "Cannot get the interface id for type '" << Object::DemangleName(typeid(A).name())
+ BERRY_WARN << "Error getting adapter for '" << Reflection::DemangleName(typeid(*this).name()) << "': "
+ << "Cannot get the interface id for type '" << Reflection::GetClassName()
<< "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
return NULL;
}
return dynamic_cast(this->GetAdapter(typeName));
}
virtual ~IAdaptable();
};
} // namespace berry
#endif /*_BERRY_IADAPTABLE_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdapterManager.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdapterManager.h
index 6c3384cb1d..981432f675 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdapterManager.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIAdapterManager.h
@@ -1,287 +1,287 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYIADAPTERMANAGER_H_
#define BERRYIADAPTERMANAGER_H_
#include
#include
#include "berryPlatformObject.h"
#include "berryIAdapterFactory.h"
#include
#include
namespace berry
{
/**
* An adapter manager maintains a registry of adapter factories. Clients
* directly invoke methods on an adapter manager to register and unregister
* adapters. All adaptable objects (that is, objects that implement the IAdaptable
* interface) tunnel IAdaptable.getAdapter
invocations to their
* adapter manager's IAdapterManger.getAdapter
method. The
* adapter manager then forwards this request unmodified to the IAdapterFactory.getAdapter
* method on one of the registered adapter factories.
*
* Adapter factories can be registered programmatically using the registerAdapters
* method. Alternatively, they can be registered declaratively using the
* org.blueberry.core.runtime.adapters
extension point. Factories registered
* with this extension point will not be able to provide adapters until their
* corresponding plugin has been activated.
*
* The following code snippet shows how one might register an adapter of type
* com.example.acme.Sticky
on resources in the workspace.
*
*
*
* IAdapterFactory pr = new IAdapterFactory() {
* public Class[] getAdapterList() {
* return new Class[] { com.example.acme.Sticky.class };
* }
* public Object getAdapter(Object adaptableObject, Class adapterType) {
* IResource res = (IResource) adaptableObject;
* QualifiedName key = new QualifiedName("com.example.acme", "sticky-note");
* try {
* com.example.acme.Sticky v = (com.example.acme.Sticky) res.getSessionProperty(key);
* if (v == null) {
* v = new com.example.acme.Sticky();
* res.setSessionProperty(key, v);
* }
* } catch (CoreException e) {
* // unable to access session property - ignore
* }
* return v;
* }
* }
* Platform.getAdapterManager().registerAdapters(pr, IResource.class);
*
*
*
* This interface can be used without OSGi running.
*
* This interface is not intended to be implemented by clients.
*
* @see IAdaptable
* @see IAdapterFactory
*/
struct org_blueberry_core_runtime_EXPORT IAdapterManager: public Object
{
berryObjectMacro(berry::IAdapterManager)
/**
* This value can be returned to indicate that no applicable adapter factory
* was found.
* @since org.blueberry.equinox.common 3.3
*/
static const int NONE;
/**
* This value can be returned to indicate that an adapter factory was found,
* but has not been loaded.
* @since org.blueberry.equinox.common 3.3
*/
static const int NOT_LOADED;
/**
* This value can be returned to indicate that an adapter factory is loaded.
* @since org.blueberry.equinox.common 3.3
*/
static const int LOADED;
/**
* Returns a Poco::Any object which contains an instance of the given name associated
* with the given adaptable. Returns an empty Poco::Any if no such object can
* be found.
*
* Note that this method will never cause plug-ins to be loaded. If the
* only suitable factory is not yet loaded, this method will return an empty Poco::Any.
* If activation of the plug-in providing the factory is required, use the
* LoadAdapter
method instead.
*
* @param adaptable the adaptable object being queried (usually an instance
* of IAdaptable
)
* @param adapterTypeName the fully qualified name of the type of adapter to look up
* @return a Poco::Any castable to the given adapter type, or empty
* if the given adaptable object does not have an available adapter of the
* given type
*/
template
A* GetAdapter(const Object* adaptable)
{
const char* typeName = qobject_interface_iid();
if (typeName == NULL)
{
- BERRY_WARN << "Error getting adapter for '" << Object::DemangleName(typeid(*adaptable).name()) << "': "
- << "Cannot get the interface id for type '" << Object::DemangleName(typeid(A).name())
+ BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
+ << "Cannot get the interface id for type '" << Reflection::GetClassName()
<< "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
return NULL;
}
return dynamic_cast(this->GetAdapter(adaptable, typeName, false));
}
/**
* Returns an object which is an instance of the given class name associated
* with the given object. Returns null
if no such object can
* be found.
*
* Note that this method will never cause plug-ins to be loaded. If the
* only suitable factory is not yet loaded, this method will return null
.
* If activation of the plug-in providing the factory is required, use the
* loadAdapter
method instead.
*
* @param adaptable the adaptable object being queried (usually an instance
* of IAdaptable
)
* @param adapterTypeName the fully qualified name of the type of adapter to look up
* @return an object castable to the given adapter type, or null
* if the given adaptable object does not have an available adapter of the
* given type
*/
virtual Object* GetAdapter(const Object* adaptable, const QString& adapterTypeName) = 0;
/**
* Returns whether there is an adapter factory registered that may be able
* to convert adaptable
to an object of type adapterTypeName
.
*
* Note that a return value of true
does not guarantee that
* a subsequent call to GetAdapter
with the same arguments
* will return a non-empty result. If the factory's plug-in has not yet been
* loaded, or if the factory itself returns nothing, then
* GetAdapter
will still return an empty Poco::Any.
*
* @param adaptable the adaptable object being queried (usually an instance
* of IAdaptable
)
* @param adapterTypeName the fully qualified class name of an adapter to
* look up
* @return true
if there is an adapter factory that claims
* it can convert adaptable
to an object of type adapterType
,
* and false
otherwise.
*/
virtual bool HasAdapter(const Object* adaptableType, const QString& adapterType) = 0;
template
int QueryAdapter(const Object* adaptable)
{
const char* typeName = qobject_interface_iid();
if (typeName == NULL)
{
- BERRY_WARN << "Error querying adapter manager for '" << Object::DemangleName(typeid(*adaptable).name()) << "': "
- << "Cannot get the interface id for type '" << Object::DemangleName(typeid(A).name())
+ BERRY_WARN << "Error querying adapter manager for '" << Reflection::GetClassName(adaptable) << "': "
+ << "Cannot get the interface id for type '" << Reflection::GetClassName()
<< "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
return NONE;
}
return this->QueryAdapter(adaptable, typeName);
}
/**
* Returns a status of an adapter factory registered that may be able
* to convert adaptable
to an object of type adapterTypeName
.
*
* One of the following values can be returned:
* - {@link berry::IAdapterManager::NONE} if no applicable adapter factory was found;
* - {@link berry::IAdapterManager::NOT_LOADED} if an adapter factory was found, but has not been loaded;
* - {@link berry::IAdapterManager::LOADED} if an adapter factory was found, and it is loaded.
*
* @param adaptable the adaptable object being queried (usually an instance
* of IAdaptable
)
* @param adapterTypeName the fully qualified class name of an adapter to
* look up
* @return a status of the adapter
*/
virtual int QueryAdapter(const Object* adaptableType, const QString& adapterType) = 0;
/**
* Returns an object that is an instance of the given class name associated
* with the given object. Returns an empty Poco::Any if no such object can
* be found.
*
* Note that unlike the GetAdapter
methods, this method
* will cause the plug-in that contributes the adapter factory to be loaded
* if necessary. As such, this method should be used judiciously, in order
* to avoid unnecessary plug-in activations. Most clients should avoid
* activation by using GetAdapter
instead.
*
* @param adaptable the adaptable object being queried (usually an instance
* of IAdaptable
)
* @param adapterTypeName the fully qualified name of the type of adapter to look up
* @return a Poco::Any castable to the given adapter type, or empty
* if the given adaptable object does not have an available adapter of the
* given type
*/
template
A* LoadAdapter(const Object* adaptable)
{
const char* typeName = qobject_interface_iid();
if (typeName == NULL)
{
- BERRY_WARN << "Error getting adapter for '" << Object::DemangleName(typeid(*adaptable).name()) << "': "
- << "Cannot get the interface id for type '" << Object::DemangleName(typeid(A).name())
+ BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
+ << "Cannot get the interface id for type '" << Reflection::GetClassName()
<< "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
return NULL;
}
return dynamic_cast(this->GetAdapter(adaptable, typeName, true));
}
/**
* Registers the given adapter factory as extending objects of the given
* type.
*
* @param factory the adapter factory
* @param adaptableTypeName the fully qualified typename being extended
* @see #UnregisterAdapters(IAdapterFactory*)
* @see #UnregisterAdapters(IAdapterFactory*, const std::adaptableTypeName&)
*/
virtual void RegisterAdapters(IAdapterFactory* factory,
const QString& adaptableTypeName) = 0;
/**
* Removes the given adapter factory completely from the list of registered
* factories. Equivalent to calling UnregisterAdapters(IAdapterFactory*, const std::string&)
* on all classes against which it had been explicitly registered. Does
* nothing if the given factory is not currently registered.
*
* @param factory the adapter factory to remove
* @see #RegisterAdapters(IAdapterFactory*, const std::string&)
*/
virtual void UnregisterAdapters(IAdapterFactory* factory) = 0;
/**
* Removes the given adapter factory from the list of factories registered
* as extending the given class. Does nothing if the given factory and type
* combination is not registered.
*
* @param factory the adapter factory to remove
* @param adaptableTypeName one of the type names against which the given factory is
* registered
* @see #RegisterAdapters(IAdapterFactory*, const std::string&)
*/
virtual void UnregisterAdapters(IAdapterFactory* factory,
const QString& adaptableTypeName) = 0;
private:
virtual Object* GetAdapter(const Object* adaptable, const QString& adapterType, bool force) = 0;
};
} // namespace berry
Q_DECLARE_INTERFACE(berry::IAdapterManager, "org.blueberry.service.IAdapterManager")
#endif /*BERRYIADAPTERMANAGER_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.cpp
index 3b9d740123..b0d98e82d3 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.cpp
@@ -1,25 +1,54 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryIBerryPreferences.h"
namespace berry {
IBerryPreferences::~IBerryPreferences ()
{
}
+IBerryPreferences::ChangeEvent::ChangeEvent(IBerryPreferences* source, const QString& property,
+ const QString& oldValue, const QString& newValue)
+ : m_Source(source)
+ , m_Property(property)
+ , m_OldValue(oldValue)
+ , m_NewValue(newValue)
+{
+}
+
+IBerryPreferences* IBerryPreferences::ChangeEvent::GetSource() const
+{
+ return m_Source;
+}
+
+QString IBerryPreferences::ChangeEvent::GetProperty() const
+{
+ return m_Property;
+}
+
+QString IBerryPreferences::ChangeEvent::GetOldValue() const
+{
+ return m_OldValue;
+}
+
+QString IBerryPreferences::ChangeEvent::GetNewValue() const
+{
+ return m_NewValue;
+}
+
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.h
index 7e6586a608..391cc75784 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferences.h
@@ -1,48 +1,71 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYIBERRYPREFERENCES_H_
#define BERRYIBERRYPREFERENCES_H_
#include
#include "berryIPreferences.h"
#include "berryMessage.h"
namespace berry
{
- ///
- /// Like IEclipsePreferences an extension to the osgi-IPreferences
- /// to send out events when nodes or values changed in a node.
- ///
+ /**
+ * Like IEclipsePreferences an extension to the osgi-IPreferences
+ * to send out events when nodes or values changed in a node.
+ */
struct org_blueberry_core_runtime_EXPORT IBerryPreferences : virtual public IPreferences
{
berryObjectMacro(berry::IBerryPreferences)
+ class org_blueberry_core_runtime_EXPORT ChangeEvent {
+ IBerryPreferences* const m_Source;
+ const QString m_Property;
+ const QString m_OldValue;
+ const QString m_NewValue;
+
+ public:
+
+ ChangeEvent(IBerryPreferences* source, const QString& property,
+ const QString& oldValue, const QString& newValue);
+
+ IBerryPreferences* GetSource() const;
+ QString GetProperty() const;
+ QString GetOldValue() const;
+ QString GetNewValue() const;
+ };
+
virtual ~IBerryPreferences();
- ///
- /// Invoked when this node was changed, that is when a property
- /// was changed or when a new child node was inserted.
- ///
+ /**
+ * Invoked when this node was changed, that is when a property
+ * was changed or when a new child node was inserted.
+ */
berry::Message1 OnChanged;
+ /**
+ * Adds a property change listener to this preferences node.
+ * The listener will be informed about property changes of
+ * this preference node, but not about changes to child nodes.
+ */
+ berry::Message1 OnPropertyChanged;
};
} // namespace berry
#endif /*BERRYIBERRYPREFERENCES_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferencesService.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferencesService.h
index f64675296e..369670c13a 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferencesService.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIBerryPreferencesService.h
@@ -1,42 +1,44 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYIBERRYPREFERENCESSERVICE_H_
#define BERRYIBERRYPREFERENCESSERVICE_H_
#include "berryIPreferencesService.h"
namespace berry
{
- struct IBerryPreferencesService : public IPreferencesService
- {
- ///
- /// Try to import the prefs from the given file.
- /// Existing properties will be overridden!
- /// Returns true if the preferences could be imported.
- ///
- virtual void ImportPreferences(const QString& f, const QString& name="") = 0;
-
- ///
- /// Exports the current system preferences to the given file.
- ///
- virtual void ExportPreferences(const QString& f, const QString& name="") = 0;
-
- };
+
+struct IBerryPreferencesService : public IPreferencesService
+{
+ /**
+ * Try to import the prefs from the given file.
+ * Existing properties will be overridden!
+ * Returns true if the preferences could be imported.
+ */
+ virtual void ImportPreferences(const QString& f, const QString& name="") = 0;
+
+ /**
+ * Exports the current system preferences to the given file.
+ */
+ virtual void ExportPreferences(const QString& f, const QString& name="") = 0;
+
+};
+
} // namespace berry
Q_DECLARE_INTERFACE(berry::IBerryPreferencesService, "org.blueberry.core.runtime.IBerryPreferencesService")
#endif /*BERRYIBERRYPREFERENCESSERVICE_H_*/
diff --git a/Plugins/org.mitk.gui.qt.ext/src/QmitkExtActionConstants.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIProduct.cpp
similarity index 76%
copy from Plugins/org.mitk.gui.qt.ext/src/QmitkExtActionConstants.cpp
copy to BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIProduct.cpp
index 4c9481b513..4a429a0961 100644
--- a/Plugins/org.mitk.gui.qt.ext/src/QmitkExtActionConstants.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIProduct.cpp
@@ -1,21 +1,26 @@
/*===================================================================
-The Medical Imaging Interaction Toolkit (MITK)
+BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
+#include "berryIProduct.h"
-#include "QmitkExtActionConstants.h"
+namespace berry {
-const QString QmitkExtActionConstants::M_WINDOW = "window";
+IProduct::~IProduct()
+{
+}
+
+}
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIProduct.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIProduct.h
new file mode 100644
index 0000000000..9a4b535d73
--- /dev/null
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryIProduct.h
@@ -0,0 +1,98 @@
+/*===================================================================
+
+BlueBerry Platform
+
+Copyright (c) German Cancer Research Center,
+Division of Medical and Biological Informatics.
+All rights reserved.
+
+This software is distributed WITHOUT ANY WARRANTY; without
+even the implied warranty of MERCHANTABILITY or FITNESS FOR
+A PARTICULAR PURPOSE.
+
+See LICENSE.txt or http://www.mitk.org for details.
+
+===================================================================*/
+
+#ifndef BERRYIPRODUCT_H
+#define BERRYIPRODUCT_H
+
+#include
+
+#include
+#include
+
+class ctkPlugin;
+
+namespace berry {
+
+/**
+ * Products are the BlueBerry unit of branding. From the runtime point of view they have
+ * a name, id and description and identify the BlueBerry application to run.
+ *
+ * Since the bulk of the branding related information is
+ * specific to the UI, products also carry an arbitrary set of properties. The valid set of
+ * key-value pairs and their interpretation defined by the UI of the target environment.
+ * For example, in the standard BlueBerry UI, IProductConstants
+ * the properties of interest to the UI. Other clients may specify additional properties.
+ *
+ * Products can be defined directly using extensions to the org.blueberry.core.runtime.products
+ * extension point or by using facilities provided by IProductProvider implementations.
+ *
+ * @see IProductProvider
+ */
+struct org_blueberry_core_runtime_EXPORT IProduct
+{
+ virtual ~IProduct();
+
+ /**
+ * Returns the application associated with this product. This information is used
+ * to guide the runtime as to what application extension to create and execute.
+ *
+ * @return this product's application or null
if none
+ */
+ virtual QString GetApplication() const = 0;
+
+ /**
+ * Returns the name of this product. The name is typically used in the title
+ * bar of UI windows.
+ *
+ * @return the name of this product or null
if none
+ */
+ virtual QString GetName() const = 0;
+
+ /**
+ * Returns the text description of this product
+ *
+ * @return the description of this product or null
if none
+ */
+ virtual QString GetDescription() const = 0;
+
+ /** Returns the unique product id of this product.
+ *
+ * @return the id of this product
+ */
+ virtual QString GetId() const = 0;
+
+ /**
+ * Returns the property of this product with the given key.
+ * null
is returned if there is no such key/value pair.
+ *
+ * @param key the name of the property to return
+ * @return the value associated with the given key or null
if none
+ */
+ virtual QString GetProperty(const QString& key) const = 0;
+
+ /**
+ * Returns the plug-in which is responsible for the definition of this product.
+ * Typically this is used as a base for searching for images and other files
+ * that are needed in presenting the product.
+ *
+ * @return the plug-in which defines this product or null
if none
+ */
+ virtual QSharedPointer GetDefiningPlugin() const = 0;
+};
+
+}
+
+#endif // BERRYIPRODUCT_H
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryISafeRunnable.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryISafeRunnable.h
index d5d434628b..18df36fb2b 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryISafeRunnable.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryISafeRunnable.h
@@ -1,102 +1,102 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYISAFERUNNABLE_H_
#define BERRYISAFERUNNABLE_H_
#include
#include
#include
namespace berry
{
/**
* Safe runnables represent blocks of code and associated exception
* handlers. They are typically used when a plug-in needs to call some
* untrusted code (e.g., code contributed by another plug-in via an
* extension).
*
* This interface can be used without OSGi running.
*
* Clients may implement this interface.
*
* @see SafeRunner#run(ISafeRunnable)
*/
struct org_blueberry_core_runtime_EXPORT ISafeRunnable: public Object
{
berryObjectMacro(berry::ISafeRunnable)
/**
* Handles an exception thrown by this runnable's run
* method. The processing done here should be specific to the
* particular usecase for this runnable. Generalized exception
* processing (e.g., logging in the platform's log) is done by the
* Platform's run mechanism.
*
* @param exception an exception which occurred during processing
* the body of this runnable (i.e., in run()
)
* @see SafeRunner#run(ISafeRunnable)
*/
- virtual void HandleException(const std::exception& exception) = 0;
+ virtual void HandleException(const ctkException& exception) = 0;
/**
* Runs this runnable. Any exceptions thrown from this method will
* be passed to this runnable's handleException
* method.
*
* @exception Exception if a problem occurred while running this method.
* The exception will be processed by handleException
* @see SafeRunner#run(ISafeRunnable)
*/
virtual void Run() = 0;
};
template
struct SafeRunnableDelegate: public ISafeRunnable
{
typedef void(R::*RunCallback)();
typedef void(R::*HandleExcCallback)(const std::exception&);
SafeRunnableDelegate(R* runnable, RunCallback func, HandleExcCallback handleFunc = 0) :
m_Runnable(runnable), m_RunFunc(func), m_HandleExcFunc(handleFunc)
{
}
void Run()
{
m_Runnable->*m_RunFunc();
}
- void HandleException(const std::exception& exception)
+ void HandleException(const ctkException& exception)
{
if (m_HandleExcFunc)
m_Runnable->*m_HandleExcFunc(exception);
}
private:
R* m_Runnable;
RunCallback m_RunFunc;
HandleExcCallback m_HandleExcFunc;
};
}
#endif /* BERRYISAFERUNNABLE_H_ */
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryMacros.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryMacros.h
index 2dc5b376ea..4b6ad43fb6 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryMacros.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryMacros.h
@@ -1,41 +1,91 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef __BERRY_MACROS_H__
#define __BERRY_MACROS_H__
#include "berryWeakPointer.h"
+#include "berryReflection.h"
#include "berryExtensionType.h"
+class QStringList;
-#define berryObjectMacro(className) \
- typedef className Self; \
- typedef berry::SmartPointer Pointer; \
- typedef berry::SmartPointer ConstPointer; \
- typedef berry::WeakPointer WeakPtr; \
- typedef berry::WeakPointer ConstWeakPtr; \
- static const char* GetStaticClassName() \
+#define berryArgGlue(x, y) x y
+#define berryArgCount(_1,_2,_3,_4,_5,_6,_7,_8,count,...) count
+#define berryExpandArgs(args) berryArgCount args
+#define berryCountArgsMax8(...) berryExpandArgs((__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0))
+
+#define berryOverloadMacro2(name, count) name##count
+#define berryOverloadMacro1(name, count) berryOverloadMacro2(name, count)
+#define berryOverloadMacro(name, count) berryOverloadMacro1(name, count)
+#define berryCallOverload(name, ...) berryArgGlue(berryOverloadMacro(name, berryCountArgsMax8(__VA_ARGS__)), (__VA_ARGS__))
+
+#define berryObjectMacro(...) berryCallOverload(berryObjectMacro, __VA_ARGS__)
+
+#define berryObjectTypeInfo(...) \
+ static ::berry::Reflection::TypeInfo GetStaticTypeInfo() \
+ { return ::berry::Reflection::TypeInfo::New(); } \
+ ::berry::Reflection::TypeInfo GetTypeInfo() const override \
+ { return Self::GetStaticTypeInfo(); } \
+ typedef ::berry::Reflection::TypeList<__VA_ARGS__> SuperclassTypes; \
+ static QList< ::berry::Reflection::TypeInfo> GetStaticSuperclasses() \
+ { return ::berry::Reflection::GetSuperclasses(); } \
+ QList< ::berry::Reflection::TypeInfo> GetSuperclasses() const override \
+ { return Self::GetStaticSuperclasses(); }
+
+#define berryObjectMacro1(className) \
+ typedef className Self; \
+ typedef berry::SmartPointer Pointer; \
+ typedef berry::SmartPointer ConstPointer; \
+ typedef berry::WeakPointer WeakPtr; \
+ typedef berry::WeakPointer ConstWeakPtr; \
+ static const char* GetStaticClassName() \
{ return #className; }
-#define BERRY_REGISTER_EXTENSION_CLASS(_ClassType, _PluginContext)\
-{\
- QString typeName = _PluginContext->getPlugin()->getSymbolicName();\
- typeName = (typeName + "_") + _ClassType::staticMetaObject.className();\
- ::berry::registerExtensionType<_ClassType>(typeName.toLatin1().data());\
+#define berryObjectMacro2(className, super1) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1)
+#define berryObjectMacro3(className, super1, super2) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1, super2)
+#define berryObjectMacro4(className, super1, super2, super3) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1, super2, super3)
+#define berryObjectMacro5(className, super1, super2, super3, super4) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1, super2, super3, super4)
+#define berryObjectMacro6(className, super1, super2, super3, super4, super5) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1, super2, super3, super4, super5)
+#define berryObjectMacro7(className, super1, super2, super3, super4, super5, super6) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1, super2, super3, super4, super5, super6)
+#define berryObjectMacro8(className, super1, super2, super3, super4, super5, super6, super7) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1, super2, super3, super4, super5, super6, super7)
+#define berryObjectMacro9(className, super1, super2, super3, super4, super5, super6, super7, super8) \
+ berryObjectMacro1(className) \
+ berryObjectTypeInfo(super1, super2, super3, super4, super5, super6, super7, super8)
+
+#define BERRY_REGISTER_EXTENSION_CLASS(_ClassType, _PluginContext) \
+{ \
+ Q_UNUSED(_PluginContext) \
+ QString typeName = _ClassType::staticMetaObject.className(); \
+ ::berry::registerExtensionType<_ClassType>(typeName.toLatin1().data()); \
}
#endif /*__BERRY_MACROS_H__*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.cpp
index b55ab7ab43..b3a714b5cf 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.cpp
@@ -1,322 +1,302 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryObject.h"
#ifdef BLUEBERRY_DEBUG_SMARTPOINTER
#include "berryDebugUtil.h"
#endif
#include "berryLog.h"
+#include "berryReflection.h"
#include
#include
#include
#include
-// Better name demangling for gcc
-#if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 )
-#define GCC_USEDEMANGLE
-#endif
-
-#ifdef GCC_USEDEMANGLE
-#include
-#include
-#endif
-
-#if defined(_WIN32) && defined(NDEBUG)
-// exported from VC CRT
-extern "C"
-char * __unDName(char * outputString, const char * name, int maxStringLength,
- void * (* pAlloc )(size_t), void (* pFree )(void *),
- unsigned short disableFlags);
-#endif
-
namespace berry
{
void Object::Delete()
{
this->UnRegister();
}
-QString Object::DemangleName(const char* mangledName)
-{
- QString name(mangledName);
-#ifdef GCC_USEDEMANGLE
- int status;
- char* unmangled = abi::__cxa_demangle(mangledName, 0, 0, &status);
-
- if(status == 0)
- {
- name = QString(unmangled);
- free(unmangled);
- }
-#elif defined(_WIN32) && defined(NDEBUG)
- char * const unmangled = __unDName(0, mangledName, 0, malloc, free, 0x2800);
- if (unmangled)
- {
- name = QString(unmangled);
- free(unmangled);
- }
-#endif
- return name;
-}
-
#ifdef _WIN32
void*
Object
::operator new(size_t n)
{
return new char[n];
}
void*
Object
::operator new[](size_t n)
{
return new char[n];
}
void
Object
::operator delete(void* m)
{
delete [] (char*)m;
}
void
Object
::operator delete[](void* m, size_t)
{
delete [] (char*)m;
}
#endif
const char* Object::GetStaticClassName()
{
return "berry::Object";
}
QString Object::GetClassName() const
{
- return DemangleName(typeid(*this).name());
+ return Reflection::DemangleName(typeid(*this).name());
+}
+
+Reflection::TypeInfo Object::GetStaticTypeInfo()
+{
+ return Reflection::TypeInfo::New();
+}
+
+Reflection::TypeInfo Object::GetTypeInfo() const
+{
+ return Self::GetStaticTypeInfo();
+}
+
+QList Object::GetStaticSuperclasses()
+{
+ return QList();
+}
+
+QList Object::GetSuperclasses() const
+{
+ return GetStaticSuperclasses();
}
QDebug Object::Print(QDebug os, Indent indent) const
{
os = this->PrintHeader(os, indent);
os = this->PrintSelf(os, indent.GetNextIndent());
return this->PrintTrailer(os, indent);
}
QString Object::ToString() const
{
QString str;
QDebug ss(&str);
this->Print(ss);
return str;
}
uint Object::HashCode() const
{
return qHash(this);
}
bool Object::operator<(const Object* o) const
{
return this < o;
}
void Object::Register() const
{
m_ReferenceCount.ref();
}
void Object::UnRegister(bool del) const
{
if (!m_ReferenceCount.deref() && del)
{
delete this;
}
}
void Object::SetReferenceCount(int ref)
{
QMutexLocker lock(&m_ReferenceCountLock);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
m_ReferenceCount.store(ref);
#else
m_ReferenceCount = ref;
#endif
if (ref == 0)
{
delete this;
}
}
bool Object::operator==(const Object* o) const
{
return this == o;
}
#ifdef BLUEBERRY_DEBUG_SMARTPOINTER
unsigned int Object::GetTraceId() const
{
return m_TraceId;
}
unsigned int& Object::GetTraceIdCounter() const
{
static unsigned int traceId = 0;
return traceId;
}
#endif
Object::Object() :
m_ReferenceCount(0)
{
#ifdef BLUEBERRY_DEBUG_SMARTPOINTER
unsigned int& id = GetTraceIdCounter();
m_TraceId = ++id;
DebugUtil::RegisterObject(this);
#endif
}
Object::~Object()
{
/**
* warn user if reference counting is on and the object is being referenced
* by another object.
*/
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
if (m_ReferenceCount.load() > 0)
#else
if (m_ReferenceCount > 0)
#endif
{
// A general exception safety rule is that destructors should
// never throw. Something is wrong with a program that reaches
// this point anyway. Also this is the least-derived class so the
// whole object has been destroyed by this point anyway. Just
// issue a warning.
BERRY_WARN << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n"
<< this->GetClassName() << " (" << this
<< "): Trying to delete object with non-zero reference count.";
}
/**
* notifies the registered functions that the object is being destroyed
*/
m_DestroyMessage.Send();
#ifdef BLUEBERRY_DEBUG_SMARTPOINTER
DebugUtil::UnregisterObject(this);
#endif
}
QDebug Object::PrintSelf(QDebug os, Indent Indent) const
{
- QString demangledName = DemangleName(typeid(*this).name());
+ QString demangledName = Reflection::DemangleName(typeid(*this).name());
os << Indent << "RTTI typeinfo: " << demangledName << '\n';
os << Indent << "Reference Count: " <<
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
m_ReferenceCount.load()
#else
m_ReferenceCount
#endif
<< '\n';
return os;
}
/**
* Define a default print header for all objects.
*/
QDebug Object::PrintHeader(QDebug os, Indent Indent) const
{
os << Indent << this->GetClassName() << " (" << this << ")\n";
return os;
}
/**
* Define a default print trailer for all objects.
*/
QDebug Object::PrintTrailer(QDebug os, Indent /*Indent*/) const
{
return os;
}
// ============== Indent related implementations ==============
static const char blanks[41] = " ";
Indent Indent::GetNextIndent()
{
int Indent = m_Indent + 2;
if (Indent > 40)
{
Indent = 40;
}
return Indent;
}
QDebug operator<<(QDebug os, const berry::Indent& ind)
{
os.nospace() << blanks + (40 - ind.m_Indent);
return os;
}
} // namespace berry
QDebug operator<<(QDebug os, const berry::Object& o)
{
return o.Print(os);
}
QDebug operator<<(QDebug os, const berry::SmartPointer& o)
{
return o->Print(os);
}
QDebug operator<<(QDebug os, const berry::SmartPointer& o)
{
return o->Print(os);
}
QTextStream& operator<<(QTextStream& os, const berry::Object& o)
{
os << o.ToString();
return os;
}
QTextStream& operator<<(QTextStream& os, const berry::SmartPointer& o)
{
os << o->ToString();
return os;
}
//QTextStream& operator<<(QTextStream& os, const berry::SmartPointer& o)
//{
// os << o->ToString();
// return os;
//}
uint qHash(const berry::Object& o)
{
return o.HashCode();
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.h
index 47ad990cf0..663afd2395 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObject.h
@@ -1,247 +1,251 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
-#ifndef BERRYOSGILIGHTOBJECT_H_
-#define BERRYOSGILIGHTOBJECT_H_
+#ifndef BERRYOBJECT_H_
+#define BERRYOBJECT_H_
#include
#include "berryMacros.h"
#include "berryMessage.h"
#include
#include
#include
#include
#include
#ifdef _MSC_VER
// disable inheritance by dominance warnings
#pragma warning( disable : 4250 4275 4251 )
// disable warning: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#pragma warning( disable : 4290 )
#endif
class QDebug;
class QTextStream;
namespace berry {
class org_blueberry_core_runtime_EXPORT Indent
{
public:
/** Standard class typedefs. */
typedef Indent Self;
/** Construct the object with an initial Indentation level. */
Indent(int ind = 0) { m_Indent=ind; }
/**
* Determine the next Indentation level. Keep Indenting by two until the
* a maximum of forty spaces is reached.
*/
Indent GetNextIndent();
/** Print out the Indentation. Basically output a bunch of spaces. */
friend org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const Indent& o);
private:
int m_Indent;
};
/** \class Object
* \brief Light weight base class for most BlueBerry classes.
*
* Object is copied from itk::LightObject and is the highest
* level base class for most BlueBerry objects. It
* implements reference counting and the API for object printing.
*
*/
class org_blueberry_core_runtime_EXPORT Object
{
private:
mutable Message<> m_DestroyMessage;
public:
typedef Object Self;
typedef berry::SmartPointer Pointer;
typedef berry::SmartPointer ConstPointer;
typedef berry::WeakPointer WeakPtr;
typedef berry::WeakPointer ConstWeakPtr;
static const char* GetStaticClassName();
virtual QString GetClassName() const;
+ static Reflection::TypeInfo GetStaticTypeInfo();
+ virtual Reflection::TypeInfo GetTypeInfo() const;
+
+ static QList GetStaticSuperclasses();
+ virtual QList GetSuperclasses() const;
+
/** Delete an BlueBerry object. This method should always be used to delete an
* object when the new operator was used to create it. Using the C
* delete method will not work with reference counting. */
virtual void Delete();
#ifdef _WIN32
/** Used to avoid dll boundary problems. */
void* operator new(size_t);
void* operator new[](size_t);
void operator delete(void*);
void operator delete[](void*, size_t);
#endif
- static QString DemangleName(const char* typeName);
-
/**
* Cause the object to print itself out. This is usually used to provide
* detailed information about the object's state. It just calls the
* header/self/trailer virtual print methods, which can be overriden by
* subclasses.
*/
QDebug Print(QDebug os, Indent Indent=0) const;
/**
* Returns a string representation of this object. The default
* implementation returns an empty string.
*/
virtual QString ToString() const;
/**
* Returns a hash code value for the object.
*/
virtual uint HashCode() const;
/**
* Override this method to implement a specific "less than" operator
* for associative STL containers.
*/
virtual bool operator<(const Object*) const;
/** Increase the reference count (mark as used by another object). */
void Register() const;
/** Decrease the reference count (release by another object).
* Set del to false if you do not want the object to be deleted if
* the reference count is zero (use with care!) */
void UnRegister(bool del = true) const;
/** Gets the reference count on this object. */
int GetReferenceCount() const
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
return m_ReferenceCount.load();
#else
return m_ReferenceCount;
#endif
}
/** Sets the reference count on this object. This is a dangerous
* method, use it with care. */
void SetReferenceCount(int);
inline void AddDestroyListener(const MessageAbstractDelegate<>& delegate) const
{ m_DestroyMessage += delegate; }
inline void RemoveDestroyListener(const MessageAbstractDelegate<>& delegate) const
{ m_DestroyMessage -= delegate; }
/**
* A generic comparison method. Override this method in subclasses and
* cast to your derived class to provide a more detailed comparison.
*/
virtual bool operator==(const Object*) const;
#ifdef BLUEBERRY_DEBUG_SMARTPOINTER
unsigned int GetTraceId() const;
private:
unsigned int m_TraceId;
unsigned int& GetTraceIdCounter() const;
public:
#endif
protected:
friend struct QScopedPointerObjectDeleter;
Object();
virtual ~Object();
/**
* Methods invoked by Print() to print information about the object
* including superclasses. Typically not called by the user (use Print()
* instead) but used in the hierarchical print process to combine the
* output of several classes.
*/
virtual QDebug PrintSelf(QDebug os, Indent indent) const;
virtual QDebug PrintHeader(QDebug os, Indent indent) const;
virtual QDebug PrintTrailer(QDebug os, Indent indent) const;
/** Number of uses of this object by other objects. */
mutable QAtomicInt m_ReferenceCount;
/** Mutex lock to protect modification to the reference count */
mutable QMutex m_ReferenceCountLock;
private:
Object(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
// A custom deleter for QScopedPointer
// berry::Object instances in a QScopedPointer should have reference count one,
// such that they are not accidentally deleted when a temporary smart pointer
// pointing to it goes out of scope. This deleter fixes the reference count and
// always deletes the instance. Use a berry::SmartPointer if the lifetime should
// exceed the one of the pointer.
struct QScopedPointerObjectDeleter
{
static inline void cleanup(Object* obj)
{
if (obj == NULL) return;
obj->UnRegister(false);
delete obj;
}
};
org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::Indent& o);
}
/**
* This operator allows all subclasses of Object to be printed via QDebug <<.
* It in turn invokes the Print method, which in turn will invoke the
* PrintSelf method that all objects should define, if they have anything
* interesting to print out.
*/
org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::Object& o);
org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::SmartPointer& o);
org_blueberry_core_runtime_EXPORT QDebug operator<<(QDebug os, const berry::SmartPointer& o);
org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::Object& o);
org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer& o);
//org_blueberry_core_runtime_EXPORT QTextStream& operator<<(QTextStream& os, const berry::SmartPointer& o);
Q_DECLARE_METATYPE(berry::Object::Pointer)
org_blueberry_core_runtime_EXPORT uint qHash(const berry::Object& o);
-#endif /*BERRYOSGILIGHTOBJECT_H_*/
+#endif /*BERRYOBJECT_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObjectTypeInfo.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObjectTypeInfo.cpp
new file mode 100644
index 0000000000..0ad5f76465
--- /dev/null
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObjectTypeInfo.cpp
@@ -0,0 +1,46 @@
+/*===================================================================
+
+BlueBerry Platform
+
+Copyright (c) German Cancer Research Center,
+Division of Medical and Biological Informatics.
+All rights reserved.
+
+This software is distributed WITHOUT ANY WARRANTY; without
+even the implied warranty of MERCHANTABILITY or FITNESS FOR
+A PARTICULAR PURPOSE.
+
+See LICENSE.txt or http://www.mitk.org for details.
+
+===================================================================*/
+
+#include "berryObjectTypeInfo.h"
+
+namespace berry {
+
+ObjectTypeInfo::ObjectTypeInfo()
+{
+
+}
+
+ObjectTypeInfo::ObjectTypeInfo(const Reflection::TypeInfo &typeInfo)
+ : Reflection::TypeInfo(typeInfo)
+{
+}
+
+bool ObjectTypeInfo::operator==(const Object *other) const
+{
+ if (const ObjectTypeInfo* otherStr = dynamic_cast(other))
+ {
+ return static_cast(*this) == static_cast(*otherStr);
+ }
+ return false;
+}
+
+bool ObjectTypeInfo::operator==(const Reflection::TypeInfo &other) const
+{
+ return static_cast(*this) == other;
+}
+
+}
+
diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtWorkbenchTweaklet.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObjectTypeInfo.h
similarity index 50%
copy from BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtWorkbenchTweaklet.h
copy to BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObjectTypeInfo.h
index 90365ba2c1..f227f4a4f1 100644
--- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtWorkbenchTweaklet.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryObjectTypeInfo.h
@@ -1,45 +1,42 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
-#ifndef BERRYQTWORKBENCHTWEAKLET_H_
-#define BERRYQTWORKBENCHTWEAKLET_H_
+#ifndef BERRYOBJECTTYPEINFO_H
+#define BERRYOBJECTTYPEINFO_H
-#include
+#include
-#include
+#include
namespace berry {
-class BERRY_UI_QT QtWorkbenchTweaklet : public QObject, public WorkbenchTweaklet
+class org_blueberry_core_runtime_EXPORT ObjectTypeInfo : public Reflection::TypeInfo, public Object
{
- Q_OBJECT
- Q_INTERFACES(berry::WorkbenchTweaklet)
-
public:
- berryObjectMacro(QtWorkbenchTweaklet)
-
- QtWorkbenchTweaklet();
+ berryObjectMacro(ObjectTypeInfo, Reflection::TypeInfo, Object)
- Display* CreateDisplay();
+ ObjectTypeInfo();
+ ObjectTypeInfo(const Reflection::TypeInfo& typeInfo);
- bool IsRunning();
+ bool operator==(const Object* other) const;
+ bool operator==(const Reflection::TypeInfo& other) const;
};
-} // namespace berry
+}
-#endif /*BERRYQTWORKBENCHTWEAKLET_H_*/
+#endif // BERRYOBJECTTYPEINFO_H
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.cpp
index 48debef554..8423167ca1 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.cpp
@@ -1,240 +1,257 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include
#include "berryPlatform.h"
#include "internal/berryInternalPlatform.h"
+#include "internal/berryIRuntimeConstants.h"
namespace berry {
+const QString Platform::PI_RUNTIME = IRuntimeConstants::PI_RUNTIME();
+
int Platform::OS_FREE_BSD = BERRY_OS_FREE_BSD;
int Platform::OS_AIX = BERRY_OS_AIX;
int Platform::OS_HPUX = BERRY_OS_HPUX;
int Platform::OS_TRU64 = BERRY_OS_TRU64;
int Platform::OS_LINUX = BERRY_OS_LINUX;
int Platform::OS_MAC_OS_X = BERRY_OS_MAC_OS_X;
int Platform::OS_NET_BSD = BERRY_OS_NET_BSD;
int Platform::OS_OPEN_BSD = BERRY_OS_OPEN_BSD;
int Platform::OS_IRIX = BERRY_OS_IRIX;
int Platform::OS_SOLARIS = BERRY_OS_SOLARIS;
int Platform::OS_QNX = BERRY_OS_QNX;
int Platform::OS_VXWORKS = BERRY_OS_VXWORKS;
int Platform::OS_CYGWIN = BERRY_OS_CYGWIN;
int Platform::OS_UNKNOWN_UNIX = BERRY_OS_UNKNOWN_UNIX;
int Platform::OS_WINDOWS_NT = BERRY_OS_WINDOWS_NT;
int Platform::OS_WINDOWS_CE = BERRY_OS_WINDOWS_CE;
int Platform::OS_VMS = BERRY_OS_VMS;
int Platform::ARCH_ALPHA = BERRY_ARCH_ALPHA;
int Platform::ARCH_IA32 = BERRY_ARCH_IA32;
int Platform::ARCH_IA64 = BERRY_ARCH_IA64;
int Platform::ARCH_MIPS = BERRY_ARCH_MIPS;
int Platform::ARCH_HPPA = BERRY_ARCH_HPPA;
int Platform::ARCH_PPC = BERRY_ARCH_PPC;
int Platform::ARCH_POWER = BERRY_ARCH_POWER;
int Platform::ARCH_SPARC = BERRY_ARCH_SPARC;
int Platform::ARCH_AMD64 = BERRY_ARCH_AMD64;
int Platform::ARCH_ARM = BERRY_ARCH_ARM;
QString Platform::PROP_QTPLUGIN_PATH = "BlueBerry.qtplugin_path";
QString Platform::ARG_NEWINSTANCE = "BlueBerry.newInstance";
QString Platform::ARG_CLEAN = "BlueBerry.clean";
QString Platform::ARG_APPLICATION = "BlueBerry.application";
QString Platform::ARG_HOME = "BlueBerry.home";
QString Platform::ARG_STORAGE_DIR = "BlueBerry.storageDir";
QString Platform::ARG_PLUGIN_CACHE = "BlueBerry.plugin_cache_dir";
QString Platform::ARG_PLUGIN_DIRS = "BlueBerry.plugin_dirs";
QString Platform::ARG_FORCE_PLUGIN_INSTALL = "BlueBerry.forcePlugins";
QString Platform::ARG_PRELOAD_LIBRARY = "BlueBerry.preloadLibrary";
QString Platform::ARG_PROVISIONING = "BlueBerry.provisioning";
+QString Platform::ARG_DEBUG = "BlueBerry.debug";
QString Platform::ARG_CONSOLELOG = "BlueBerry.consoleLog";
QString Platform::ARG_TESTPLUGIN = "BlueBerry.testplugin";
QString Platform::ARG_TESTAPPLICATION = "BlueBerry.testapplication";
QString Platform::ARG_NO_REGISTRY_CACHE = "BlueBerry.noRegistryCache";
QString Platform::ARG_NO_LAZY_REGISTRY_CACHE_LOADING = "BlueBerry.noLazyRegistryCacheLoading";
QString Platform::ARG_REGISTRY_MULTI_LANGUAGE = "BlueBerry.registryMultiLanguage";
QString Platform::ARG_XARGS = "xargs";
QDir Platform::GetConfigurationPath()
{
return InternalPlatform::GetInstance()->GetConfigurationPath();
}
IAdapterManager* Platform::GetAdapterManager()
{
return InternalPlatform::GetInstance()->GetAdapterManager();
}
IExtensionRegistry *Platform::GetExtensionRegistry()
{
return InternalPlatform::GetInstance()->GetExtensionRegistry();
}
IPreferencesService *Platform::GetPreferencesService()
{
return InternalPlatform::GetInstance()->GetPreferencesService();
}
//PlatformEvents& Platform::GetEvents()
//{
// return InternalPlatform::GetInstance()->GetEvents();
//}
QDir Platform::GetInstallPath()
{
return InternalPlatform::GetInstance()->GetInstallPath();
}
QDir Platform::GetInstancePath()
{
return InternalPlatform::GetInstance()->GetInstancePath();
}
int Platform::GetOS()
{
return BERRY_OS;
}
int Platform::GetOSArch()
{
return BERRY_ARCH;
}
bool Platform::IsUnix()
{
#ifdef BERRY_OS_FAMILY_UNIX
return true;
#else
return false;
#endif
}
bool Platform::IsWindows()
{
#ifdef BERRY_OS_FAMILY_WINDOWS
return true;
#else
return false;
#endif
}
bool Platform::IsBSD()
{
#ifdef BERRY_OS_FAMILY_BSD
return true;
#else
return false;
#endif
}
bool Platform::IsLinux()
{
#ifdef BERRY_OS_FAMILY_LINUX
return true;
#else
return false;
#endif
}
bool Platform::IsVMS()
{
#ifdef BERRY_OS_FAMILY_VMS
return true;
#else
return false;
#endif
}
bool Platform::GetStatePath(QDir& statePath, const QSharedPointer& plugin, bool create)
{
return InternalPlatform::GetInstance()->GetStatePath(statePath, plugin, create);
}
QDir Platform::GetUserPath()
{
return InternalPlatform::GetInstance()->GetUserPath();
}
QString Platform::GetProperty(const QString& key)
{
+ if (!GetConfiguration().hasProperty(key.toStdString())) return QString::null;
return QString::fromStdString(GetConfiguration().getString(key.toStdString(), ""));
}
bool Platform::IsRunning()
{
return InternalPlatform::GetInstance()->IsRunning();
}
int& Platform::GetRawApplicationArgs(char**& argv)
{
return InternalPlatform::GetInstance()->GetRawApplicationArgs(argv);
}
QStringList Platform::GetApplicationArgs()
{
return InternalPlatform::GetInstance()->GetApplicationArgs();
}
QString Platform::GetExtendedApplicationArgs()
{
return QString::fromStdString(InternalPlatform::GetInstance()->GetConfiguration().getString(ARG_XARGS.toStdString(), ""));
}
void Platform::GetOptionSet(Poco::Util::OptionSet& os)
{
InternalPlatform::GetInstance()->defineOptions(os);
}
Poco::Util::LayeredConfiguration& Platform::GetConfiguration()
{
return InternalPlatform::GetInstance()->GetConfiguration();
}
QSharedPointer Platform::GetCTKPlugin(const QString& symbolicName)
{
QList > plugins =
InternalPlatform::GetInstance()->GetCTKPluginFrameworkContext()->getPlugins();
foreach(QSharedPointer plugin, plugins)
{
if (plugin->getSymbolicName() == symbolicName)
return plugin;
}
return QSharedPointer(0);
}
QSharedPointer Platform::GetCTKPlugin(long id)
{
return InternalPlatform::GetInstance()->GetCTKPluginFrameworkContext()->getPlugin(id);
}
QSharedPointer Platform::GetPlugin(const QString& symbolicName)
{
return InternalPlatform::GetInstance()->GetPlugin(symbolicName);
}
QList > Platform::GetPlugins(const QString& symbolicName,
const QString& version)
{
return InternalPlatform::GetInstance()->GetPlugins(symbolicName, version);
}
+QVariant berry::Platform::GetDebugOption(const QString& option)
+{
+ return InternalPlatform::GetInstance()->GetOption(option);
+}
+
+IProduct* berry::Platform::GetProduct()
+{
+ //TODO
+ //return InternalPlatform::GetDefault()->GetProduct();
+ return nullptr;
+}
+
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.h
index 17729b8601..c3951dc491 100644
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatform.h
@@ -1,432 +1,458 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRY_Platform_INCLUDED
#define BERRY_Platform_INCLUDED
//
// Platform Identification
//
#define BERRY_OS_FREE_BSD 0x0001
#define BERRY_OS_AIX 0x0002
#define BERRY_OS_HPUX 0x0003
#define BERRY_OS_TRU64 0x0004
#define BERRY_OS_LINUX 0x0005
#define BERRY_OS_MAC_OS_X 0x0006
#define BERRY_OS_NET_BSD 0x0007
#define BERRY_OS_OPEN_BSD 0x0008
#define BERRY_OS_IRIX 0x0009
#define BERRY_OS_SOLARIS 0x000a
#define BERRY_OS_QNX 0x000b
#define BERRY_OS_VXWORKS 0x000c
#define BERRY_OS_CYGWIN 0x000d
#define BERRY_OS_UNKNOWN_UNIX 0x00ff
#define BERRY_OS_WINDOWS_NT 0x1001
#define BERRY_OS_WINDOWS_CE 0x1011
#define BERRY_OS_VMS 0x2001
#if defined(__FreeBSD__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS_FAMILY_BSD 1
#define BERRY_OS BERRY_OS_FREE_BSD
#elif defined(_AIX) || defined(__TOS_AIX__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_AIX
#elif defined(hpux) || defined(_hpux)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_HPUX
#elif defined(__digital__) || defined(__osf__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_TRU64
#elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__TOS_LINUX__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_LINUX
#elif defined(__APPLE__) || defined(__TOS_MACOS__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS_FAMILY_BSD 1
#define BERRY_OS BERRY_OS_MAC_OS_X
#elif defined(__NetBSD__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS_FAMILY_BSD 1
#define BERRY_OS BERRY_OS_NET_BSD
#elif defined(__OpenBSD__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS_FAMILY_BSD 1
#define BERRY_OS BERRY_OS_OPEN_BSD
#elif defined(sgi) || defined(__sgi)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_IRIX
#elif defined(sun) || defined(__sun)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_SOLARIS
#elif defined(__QNX__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_QNX
#elif defined(unix) || defined(__unix) || defined(__unix__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_UNKNOWN_UNIX
#elif defined(_WIN32_WCE)
#define BERRY_OS_FAMILY_WINDOWS 1
#define BERRY_OS BERRY_OS_WINDOWS_CE
#elif defined(_WIN32) || defined(_WIN64)
#define BERRY_OS_FAMILY_WINDOWS 1
#define BERRY_OS BERRY_OS_WINDOWS_NT
#elif defined(__CYGWIN__)
#define BERRY_OS_FAMILY_UNIX 1
#define BERRY_OS BERRY_OS_CYGWIN
#elif defined(__VMS)
#define BERRY_OS_FAMILY_VMS 1
#define BERRY_OS BERRY_OS_VMS
#endif
//
// Hardware Architecture and Byte Order
//
#define BERRY_ARCH_ALPHA 0x01
#define BERRY_ARCH_IA32 0x02
#define BERRY_ARCH_IA64 0x03
#define BERRY_ARCH_MIPS 0x04
#define BERRY_ARCH_HPPA 0x05
#define BERRY_ARCH_PPC 0x06
#define BERRY_ARCH_POWER 0x07
#define BERRY_ARCH_SPARC 0x08
#define BERRY_ARCH_AMD64 0x09
#define BERRY_ARCH_ARM 0x0a
#if defined(__ALPHA) || defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA)
#define BERRY_ARCH BERRY_ARCH_ALPHA
#define BERRY_ARCH_LITTLE_ENDIAN 1
#elif defined(i386) || defined(__i386) || defined(__i386__) || defined(_M_IX86)
#define BERRY_ARCH BERRY_ARCH_IA32
#define BERRY_ARCH_LITTLE_ENDIAN 1
#elif defined(_IA64) || defined(__IA64__) || defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
#define BERRY_ARCH BERRY_ARCH_IA64
#if defined(hpux) || defined(_hpux)
#define BERRY_ARCH_BIG_ENDIAN 1
#else
#define BERRY_ARCH_LITTLE_ENDIAN 1
#endif
#elif defined(__x86_64__)
#define BERRY_ARCH BERRY_ARCH_AMD64
#define BERRY_ARCH_LITTLE_ENDIAN 1
#elif defined(_M_X64)
#define BERRY_ARCH BERRY_ARCH_AMD64
#define BERRY_ARCH_LITTLE_ENDIAN 1
#elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(_M_MRX000)
#define BERRY_ARCH BERRY_ARCH_MIPS
#define BERRY_ARCH_BIG_ENDIAN 1
#elif defined(__hppa) || defined(__hppa__)
#define BERRY_ARCH BERRY_ARCH_HPPA
#define BERRY_ARCH_BIG_ENDIAN 1
#elif defined(__PPC) || defined(__POWERPC__) || defined(__powerpc) || defined(__PPC__) || \
defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(_M_PPC)
#define BERRY_ARCH BERRY_ARCH_PPC
#define BERRY_ARCH_BIG_ENDIAN 1
#elif defined(_POWER) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_ARCH_PWR3) || \
defined(_ARCH_PWR4) || defined(__THW_RS6000)
#define BERRY_ARCH BERRY_ARCH_POWER
#define BERRY_ARCH_BIG_ENDIAN 1
#elif defined(__sparc__) || defined(__sparc) || defined(sparc)
#define BERRY_ARCH BERRY_ARCH_SPARC
#define BERRY_ARCH_BIG_ENDIAN 1
#elif defined(__arm__) || defined(__arm) || defined(ARM) || defined(_ARM_) || defined(__ARM__) || defined(_M_ARM)
#define BERRY_ARCH BERRY_ARCH_ARM
#if defined(__ARMEB__)
#define BERRY_ARCH_BIG_ENDIAN 1
#else
#define BERRY_ARCH_LITTLE_ENDIAN 1
#endif
#endif
#include
#include
#include
#include
#include
class ctkPlugin;
namespace Poco {
class Path;
}
namespace berry {
struct IAdapterManager;
struct IBundle;
struct IExtensionPointService;
struct IExtensionRegistry;
struct IPreferencesService;
+struct IProduct;
/**
* The central class of the BlueBerry Platform Runtime. This class cannot
* be instantiated or subclassed by clients; all functionality is provided
* by static methods. Features include:
*
* - the platform registry of installed plug-ins
* - the platform adapter manager
* - the platform log
*
*
* Most users don't have to worry about Platform's lifecycle. However, if your
* code can call methods of this class when Platform is not running, it becomes
* necessary to check {@link #IsRunning()} before making the call. A runtime
* exception might be thrown or incorrect result might be returned if a method
* from this class is called while Platform is not running.
*
*/
class org_blueberry_core_runtime_EXPORT Platform
{
public:
+
+ static const QString PI_RUNTIME;
+
static int OS_FREE_BSD;
static int OS_AIX;
static int OS_HPUX;
static int OS_TRU64;
static int OS_LINUX;
static int OS_MAC_OS_X;
static int OS_NET_BSD;
static int OS_OPEN_BSD;
static int OS_IRIX;
static int OS_SOLARIS;
static int OS_QNX;
static int OS_VXWORKS;
static int OS_CYGWIN;
static int OS_UNKNOWN_UNIX;
static int OS_WINDOWS_NT;
static int OS_WINDOWS_CE;
static int OS_VMS;
static int ARCH_ALPHA;
static int ARCH_IA32;
static int ARCH_IA64;
static int ARCH_MIPS;
static int ARCH_HPPA;
static int ARCH_PPC;
static int ARCH_POWER;
static int ARCH_SPARC;
static int ARCH_AMD64;
static int ARCH_ARM;
static QString PROP_QTPLUGIN_PATH;
static QString ARG_NEWINSTANCE;
static QString ARG_CLEAN;
static QString ARG_APPLICATION;
static QString ARG_HOME;
static QString ARG_STORAGE_DIR;
static QString ARG_PLUGIN_CACHE;
static QString ARG_PLUGIN_DIRS;
static QString ARG_FORCE_PLUGIN_INSTALL;
static QString ARG_PRELOAD_LIBRARY;
static QString ARG_PROVISIONING;
+ static QString ARG_DEBUG;
static QString ARG_CONSOLELOG;
static QString ARG_TESTPLUGIN;
static QString ARG_TESTAPPLICATION;
static QString ARG_NO_REGISTRY_CACHE;
static QString ARG_NO_LAZY_REGISTRY_CACHE_LOADING;
static QString ARG_REGISTRY_MULTI_LANGUAGE;
static QString ARG_XARGS;
/**
* Returns the adapter manager used for extending
* IAdaptable
objects.
*
* @return the adapter manager for this platform
* @see IAdapterManager
*/
static IAdapterManager* GetAdapterManager();
/**
* Returns the extension registry for this platform.
* May return null
if the registry has not been created yet.
*
* @return existing extension registry or null
* @see IExtensionRegistry
*/
static IExtensionRegistry* GetExtensionRegistry();
/**
* Return the interface into the preference mechanism. The returned
* object can be used for such operations as searching for preference
* values across multiple scopes and preference import/export.
*
* Clients are also able to acquire the IPreferencesService service via
* CTK mechanisms and use it for preference functions.
*
*
* @return an object to interface into the preference mechanism
*/
static IPreferencesService* GetPreferencesService();
+ /**
+ * Returns the product which was selected when running this BlueBerry instance
+ * or null
if none
+ * @return the current product or null
if none
+ */
+ static IProduct* GetProduct();
+
+ /**
+ * Returns the identified option. A null QString
+ * is returned if no such option is found. Options are specified
+ * in the general form <plug-in id>/<option-path>.
+ * For example, org.blueberry.core.runtime/debug
+ *
+ * Clients are also able to acquire the {@link DebugOptions} service
+ * and query it for debug options.
+ *
+ * @param option the name of the option to lookup
+ * @return the value of the requested debug option or QString::null
+ */
+ static QVariant GetDebugOption(const QString& option);
+
/**
* Returns the path of the configuration information
* used to run this instance of the BlueBerry platform.
* The configuration area typically
* contains the list of plug-ins available for use, various settings
* (those shared across different instances of the same configuration)
* and any other such data needed by plug-ins.
* An empty path is returned if the platform is running without a configuration location.
*
* @return the location of the platform's configuration data area
*/
static QDir GetConfigurationPath();
/**
* Returns the path of the base installation for the running platform
*
* @return the location of the platform's installation area or null
if none
*/
static QDir GetInstallPath();
/**
* Returns the path of the platform's working directory (also known as the instance data area).
* An empty path is returned if the platform is running without an instance location.
*
* @return the location of the platform's instance data area or null
if none
*/
static QDir GetInstancePath();
/**
* Returns the path in the local file system of the
* plug-in state area for the given plug-in.
* If the plug-in state area did not exist prior to this call,
* it is created.
*
* The plug-in state area is a file directory within the
* platform's metadata area where a plug-in is free to create files.
* The content and structure of this area is defined by the plug-in,
* and the particular plug-in is solely responsible for any files
* it puts there. It is recommended for plug-in preference settings and
* other configuration parameters.
*
*
* @param plugin the plug-in whose state location is returned
* @return a local file system path
* TODO Investigate the usage of a service factory
*/
static bool GetStatePath(QDir& statePath, const QSharedPointer& plugin, bool create = true);
/**
* Returns the path of the platform's user data area. The user data area is a location on the system
* which is specific to the system's current user. By default it is located relative to the
* location given by the System property "user.home".
* An empty path is returned if the platform is running without an user location.
*
* @return the location of the platform's user data area or null
if none
*/
static QDir GetUserPath();
static int GetOS();
static int GetOSArch();
static bool IsUnix();
static bool IsWindows();
static bool IsBSD();
static bool IsLinux();
static bool IsVMS();
static QString GetProperty(const QString& key);
static bool IsRunning();
static Poco::Util::LayeredConfiguration& GetConfiguration();
/**
* Returns the unmodified, original command line arguments
*
*/
static int& GetRawApplicationArgs(char**& argv);
/**
* Returns the applications command line arguments which
* have not been consumed by the platform.
*/
static QStringList GetApplicationArgs();
/**
* Returns the "extended" command line arguments. This is
* just the string given as argument to the "--xargs" option.
*/
static QString GetExtendedApplicationArgs();
static void GetOptionSet(Poco::Util::OptionSet &os);
/**
* @param symbolicName
* @deprecated Use GetPlugin(const QString&) instead
*/
static QSharedPointer GetCTKPlugin(const QString& symbolicName);
/**
* @brief GetCTKPlugin
* @param id
* @deprecated Use GetPlugin(long) instead
*/
static QSharedPointer GetCTKPlugin(long id);
/**
* Returns the resolved plug-in with the specified symbolic name that has the
* highest version. If no resolved plug-ins are installed that have the
* specified symbolic name then null is returned.
*
* Note that clients may want to filter
* the results based on the state of the plug-ins.
*
* @param symbolicName the symbolic name of the plug-in to be returned.
* @return the plug-in that has the specified symbolic name with the
* highest version, or null if no plug-in is found.
*/
static QSharedPointer GetPlugin(const QString& symbolicName);
/**
* Returns all plug-ins with the specified symbolic name. If no resolved plug-ins
* with the specified symbolic name can be found, an empty list is returned.
* If the version argument is not null then only the plug-ins that have
* the specified symbolic name and a version greater than or equal to the
* specified version are returned. The returned plug-ins are ordered in
* descending plug-in version order.
*
* Note that clients may want to filter
* the results based on the state of the plug-ins.
*
* @param symbolicName the symbolic name of the plug-ins that are to be returned.
* @param version the version that the returned plug-in versions must match,
* or QString() if no version matching is to be done.
* @return the list of plug-ins with the specified name that match the
* specified version and match rule, or null if no plug-ins are found.
*/
static QList > GetPlugins(const QString& symbolicName,
const QString& version = QString());
private:
Platform();
};
} // namespace
#endif // BERRY_Platform_INCLUDED
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.cpp
index 459d37d793..b6983a0ab1 100755
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.cpp
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.cpp
@@ -1,41 +1,41 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryPlatformObject.h"
#include "berryPlatform.h"
#include "berryIAdapterManager.h"
namespace berry {
PlatformObject::PlatformObject()
{
}
-Object* PlatformObject::GetAdapter(const QString& adapter)
+Object* PlatformObject::GetAdapter(const QString& adapter) const
{
IAdapterManager* adapterManager = Platform::GetAdapterManager();
if (adapterManager)
{
return adapterManager->GetAdapter(this, adapter);
}
else
{
return NULL;
}
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.h b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.h
index ceaeb41b66..8ffc870a5d 100755
--- a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.h
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryPlatformObject.h
@@ -1,84 +1,85 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYPLATFORMOBJECT_H_
#define BERRYPLATFORMOBJECT_H_
#include
#include
#include "berryIAdaptable.h"
namespace berry {
/**
* An abstract superclass implementing the IAdaptable
* interface. getAdapter
invocations are directed
* to the platform's adapter manager.
*
* Note: In situations where it would be awkward to subclass this
* class, the same affect can be achieved simply by implementing
* the IAdaptable
interface and explicitly forwarding
* the getAdapter
request to the platform's
* adapater manager. The method would look like:
*
* public Object getAdapter(Class adapter) {
* return Platform.getAdapterManager().getAdapter(this, adapter);
* }
*
*
*
* Clients may subclass.
*
*
* @see Platform#getAdapterManager
*/
-class org_blueberry_core_runtime_EXPORT PlatformObject : public virtual Object, public IAdaptable {
+class org_blueberry_core_runtime_EXPORT PlatformObject : public virtual Object, public virtual IAdaptable
+{
public:
- berryObjectMacro(berry::PlatformObject);
+ berryObjectMacro(berry::PlatformObject)
/**
* Constructs a new platform object.
*/
PlatformObject();
/**
* Returns an object which is an instance of the given class
* associated with this object. Returns null
if
* no such object can be found.
*
* This implementation of the method declared by IAdaptable
* passes the request along to the platform's adapter manager; roughly
* Platform.getAdapterManager().getAdapter(this, adapter)
.
* Subclasses may override this method (however, if they do so, they
* should invoke the method on their superclass to ensure that the
* Platform's adapter manager is consulted).
*
*
* @see IAdaptable#getAdapter
* @see Platform#getAdapterManager
*/
- Object* GetAdapter(const QString& adapter);
+ Object* GetAdapter(const QString& adapter) const;
};
}
#endif /* BERRYPLATFORMOBJECT_H_ */
diff --git a/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.cpp b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.cpp
new file mode 100644
index 0000000000..ed6db9c471
--- /dev/null
+++ b/BlueBerry/Bundles/org.blueberry.core.runtime/src/berryReflection.cpp
@@ -0,0 +1,109 @@
+/*===================================================================
+
+BlueBerry Platform
+
+Copyright (c) German Cancer Research Center,
+Division of Medical and Biological Informatics.
+All rights reserved.
+
+This software is distributed WITHOUT ANY WARRANTY; without
+even the implied warranty of MERCHANTABILITY or FITNESS FOR
+A PARTICULAR PURPOSE.
+
+See LICENSE.txt or http://www.mitk.org for details.
+
+===================================================================*/
+
+#include "berryReflection.h"
+
+#include "berryObject.h"
+
+// Better name demangling for gcc
+#if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 )
+#define GCC_USEDEMANGLE
+#endif
+
+#ifdef GCC_USEDEMANGLE
+#include
+#include
+#endif
+
+#if defined(_WIN32) && defined(NDEBUG)
+// exported from VC CRT
+extern "C"
+char * __unDName(char * outputString, const char * name, int maxStringLength,
+ void * (* pAlloc )(size_t), void (* pFree )(void *),
+ unsigned short disableFlags);
+#endif
+
+namespace berry {
+
+namespace Reflection {
+
+QString DemangleName(const char* mangledName)
+{
+ QString name(mangledName);
+#ifdef GCC_USEDEMANGLE
+ int status;
+ char* unmangled = abi::__cxa_demangle(mangledName, 0, 0, &status);
+
+ if(status == 0)
+ {
+ name = QString(unmangled);
+ free(unmangled);
+ }
+#elif defined(_WIN32) && defined(NDEBUG)
+ char * const unmangled = __unDName(0, mangledName, 0, malloc, free, 0x2800);
+ if (unmangled)
+ {
+ QString unmangledName(unmangled);
+ name = unmangledName.split(' ', QString::SkipEmptyParts).back();
+ free(unmangled);
+ }
+#else
+ name = name.split(' ', QString::SkipEmptyParts).back();
+#endif
+ return name;
+}
+
+#ifdef GetClassName
+// clash with WinUser.h definition
+#undef GetClassName
+#endif
+
+QString GetClassName(const Object* obj)
+{
+ return DemangleName(typeid(*const_cast