diff --git a/Modules/CppMicroServices/core/doc/snippets/uServices-activator/main.cpp b/Modules/CppMicroServices/core/doc/snippets/uServices-activator/main.cpp index 8b9feebd56..a5ee9aebfb 100644 --- a/Modules/CppMicroServices/core/doc/snippets/uServices-activator/main.cpp +++ b/Modules/CppMicroServices/core/doc/snippets/uServices-activator/main.cpp @@ -1,27 +1,27 @@ #include US_USE_NAMESPACE //! [0] class MyActivator : public ModuleActivator { public: - void Load(ModuleContext* /*context*/) + void Load(ModuleContext* /*context*/) override { /* register stuff */ } - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { /* cleanup */ } }; US_EXPORT_MODULE_ACTIVATOR(MyActivator) //![0] int main(int /*argc*/, char* /*argv*/[]) { MyActivator ma; return 0; } diff --git a/Modules/CppMicroServices/core/doc/snippets/uServices-registration/main.cpp b/Modules/CppMicroServices/core/doc/snippets/uServices-registration/main.cpp index 511791e1ac..d3ba6e4446 100644 --- a/Modules/CppMicroServices/core/doc/snippets/uServices-registration/main.cpp +++ b/Modules/CppMicroServices/core/doc/snippets/uServices-registration/main.cpp @@ -1,115 +1,115 @@ #include #include #include #include US_USE_NAMESPACE struct InterfaceA { virtual ~InterfaceA() {} }; struct InterfaceB { virtual ~InterfaceB() {} }; struct InterfaceC { virtual ~InterfaceC() {} }; //! [1-1] class MyService : public InterfaceA {}; //! [1-1] //! [2-1] class MyService2 : public InterfaceA, public InterfaceB {}; //! [2-1] class MyActivator : public ModuleActivator { public: - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { Register1(context); Register2(context); RegisterFactory1(context); RegisterFactory2(context); } void Register1(ModuleContext* context) { //! [1-2] MyService* myService = new MyService; context->RegisterService(myService); //! [1-2] } void Register2(ModuleContext* context) { //! [2-2] MyService2* myService = new MyService2; context->RegisterService(myService); //! [2-2] } void RegisterFactory1(ModuleContext* context) { //! [f1] class MyServiceFactory : public ServiceFactory { - virtual InterfaceMap GetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/) + virtual InterfaceMap GetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/) override { MyService* myService = new MyService; return MakeInterfaceMap(myService); } virtual void UngetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/, - const InterfaceMap& service) + const InterfaceMap& service) override { delete ExtractInterface(service); } }; MyServiceFactory* myServiceFactory = new MyServiceFactory; context->RegisterService(myServiceFactory); //! [f1] } void RegisterFactory2(ModuleContext* context) { //! [f2] class MyServiceFactory : public ServiceFactory { - virtual InterfaceMap GetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/) + virtual InterfaceMap GetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/) override { MyService2* myService = new MyService2; return MakeInterfaceMap(myService); } virtual void UngetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/, - const InterfaceMap& service) + const InterfaceMap& service) override { delete ExtractInterface(service); } }; MyServiceFactory* myServiceFactory = new MyServiceFactory; context->RegisterService(static_cast(myServiceFactory)); //! [f2] // In the RegisterService call above, we could remove the static_cast because local types // are not considered in template argument type deduction and hence the compiler choose // the correct RegisterService(ServiceFactory*) overload. However, local types are // usually the exception and using a non-local type for the service factory would make the // compiler choose RegisterService(Impl*) instead, unless we use the static_cast. } - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { /* cleanup */ } }; US_EXPORT_MODULE_ACTIVATOR(MyActivator) int main(int /*argc*/, char* /*argv*/[]) { MyActivator ma; return 0; } diff --git a/Modules/CppMicroServices/core/doc/snippets/uServices-servicelistenerhook/main.cpp b/Modules/CppMicroServices/core/doc/snippets/uServices-servicelistenerhook/main.cpp index b8e64fb7c7..e9486d7631 100644 --- a/Modules/CppMicroServices/core/doc/snippets/uServices-servicelistenerhook/main.cpp +++ b/Modules/CppMicroServices/core/doc/snippets/uServices-servicelistenerhook/main.cpp @@ -1,51 +1,51 @@ #include #include US_USE_NAMESPACE //! [1] class MyServiceListenerHook : public ServiceListenerHook { private: class Tracked { // Do some work during construction and destruction }; US_UNORDERED_MAP_TYPE tracked; public: - void Added(const std::vector& listeners) + void Added(const std::vector& listeners) override { for (std::vector::const_iterator iter = listeners.begin(), endIter = listeners.end(); iter != endIter; ++iter) { // Lock the tracked object for thread-safe access if (iter->IsRemoved()) return; tracked.insert(std::make_pair(*iter, Tracked())); } } - void Removed(const std::vector& listeners) + void Removed(const std::vector& listeners) override { for (std::vector::const_iterator iter = listeners.begin(), endIter = listeners.end(); iter != endIter; ++iter) { // Lock the tracked object for thread-safe access // If we got a corresponding "Added" event before, the Tracked // destructor will do some cleanup... tracked.erase(*iter); } } }; //! [1] int main(int /*argc*/, char* /*argv*/[]) { return 0; } diff --git a/Modules/CppMicroServices/core/doc/snippets/uServices-servicetracker/main.cpp b/Modules/CppMicroServices/core/doc/snippets/uServices-servicetracker/main.cpp index 4cbf68249b..db66194a84 100644 --- a/Modules/CppMicroServices/core/doc/snippets/uServices-servicetracker/main.cpp +++ b/Modules/CppMicroServices/core/doc/snippets/uServices-servicetracker/main.cpp @@ -1,113 +1,113 @@ #include #include US_USE_NAMESPACE struct IFooService {}; ///! [tt] struct MyTrackedClass { /* ... */ }; //! [tt] //! [ttt] struct MyTrackedClassTraits : public TrackedTypeTraitsBase { static bool IsValid(const TrackedType&) { // Dummy implementation return true; } static void Dispose(TrackedType&) {} static TrackedType DefaultValue() { return TrackedType(); } }; //! [ttt] //! [customizer] struct MyTrackingCustomizer : public ServiceTrackerCustomizer { - virtual MyTrackedClass AddingService(const ServiceReferenceType&) + virtual MyTrackedClass AddingService(const ServiceReferenceType&) override { return MyTrackedClass(); } - virtual void ModifiedService(const ServiceReferenceType&, MyTrackedClass) + virtual void ModifiedService(const ServiceReferenceType&, MyTrackedClass) override { } - virtual void RemovedService(const ServiceReferenceType&, MyTrackedClass) + virtual void RemovedService(const ServiceReferenceType&, MyTrackedClass) override { } }; //! [customizer] struct MyTrackingPointerCustomizer : public ServiceTrackerCustomizer { - virtual MyTrackedClass* AddingService(const ServiceReferenceType&) + virtual MyTrackedClass* AddingService(const ServiceReferenceType&) override { return new MyTrackedClass(); } - virtual void ModifiedService(const ServiceReferenceType&, MyTrackedClass*) + virtual void ModifiedService(const ServiceReferenceType&, MyTrackedClass*) override { } - virtual void RemovedService(const ServiceReferenceType&, MyTrackedClass*) + virtual void RemovedService(const ServiceReferenceType&, MyTrackedClass*) override { } }; // For compilation test purposes only struct MyTrackingCustomizerVoid : public ServiceTrackerCustomizer { - virtual MyTrackedClass AddingService(const ServiceReferenceType&) + virtual MyTrackedClass AddingService(const ServiceReferenceType&) override { return MyTrackedClass(); } - virtual void ModifiedService(const ServiceReferenceType&, MyTrackedClass) + virtual void ModifiedService(const ServiceReferenceType&, MyTrackedClass) override { } - virtual void RemovedService(const ServiceReferenceType&, MyTrackedClass) + virtual void RemovedService(const ServiceReferenceType&, MyTrackedClass) override { } }; int main(int /*argc*/, char* /*argv*/[]) { { //! [tracker] MyTrackingCustomizer myCustomizer; ServiceTracker tracker(GetModuleContext(), &myCustomizer); //! [tracker] } { //! [tracker2] MyTrackingPointerCustomizer myCustomizer; ServiceTracker > tracker(GetModuleContext(), &myCustomizer); //! [tracker2] } // For compilation test purposes only MyTrackingCustomizerVoid myCustomizer2; try { ServiceTracker tracker2(GetModuleContext(), &myCustomizer2); ServiceTracker > tracker3(GetModuleContext()); } catch (const us::ServiceException&) {} return 0; } #include US_INITIALIZE_MODULE diff --git a/Modules/CppMicroServices/core/doc/snippets/uServices-singleton/main.cpp b/Modules/CppMicroServices/core/doc/snippets/uServices-singleton/main.cpp index 63ec571af4..a822cf65b4 100644 --- a/Modules/CppMicroServices/core/doc/snippets/uServices-singleton/main.cpp +++ b/Modules/CppMicroServices/core/doc/snippets/uServices-singleton/main.cpp @@ -1,73 +1,73 @@ #include #include #include "SingletonOne.h" #include "SingletonTwo.h" US_USE_NAMESPACE class MyActivator : public ModuleActivator { public: MyActivator() : m_SingletonOne(NULL) , m_SingletonTwo(NULL) {} //![0] - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { // The Load() method of the module activator is called during static // initialization time of the shared library. // First create and register a SingletonTwoService instance. m_SingletonTwo = new SingletonTwoService; m_SingletonTwoReg = context->RegisterService(m_SingletonTwo); // Now the SingletonOneService constructor will get a valid // SingletonTwoService instance. m_SingletonOne = new SingletonOneService; m_SingletonOneReg = context->RegisterService(m_SingletonOne); } //![0] //![1] - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { // Services are automatically unregistered during unloading of // the shared library after the call to Unload(ModuleContext*) // has returned. // Since SingletonOneService needs a non-null SingletonTwoService // instance in its destructor, we explicitly unregister and delete the // SingletonOneService instance here. This way, the SingletonOneService // destructor will still get a valid SingletonTwoService instance. m_SingletonOneReg.Unregister(); delete m_SingletonOne; // For singletonTwoService, we could rely on the automatic unregistering // by the service registry and on automatic deletion if you used // smart pointer reference counting. You must not delete service instances // in this method without unregistering them first. m_SingletonTwoReg.Unregister(); delete m_SingletonTwo; } //![1] private: SingletonOneService* m_SingletonOne; SingletonTwoService* m_SingletonTwo; ServiceRegistration m_SingletonOneReg; ServiceRegistration m_SingletonTwoReg; }; US_EXPORT_MODULE_ACTIVATOR(MyActivator) int main() { } diff --git a/Modules/CppMicroServices/core/doc/snippets/uServices-staticmodules/MyStaticModule.cpp b/Modules/CppMicroServices/core/doc/snippets/uServices-staticmodules/MyStaticModule.cpp index f61e009f6e..ddbef8d773 100644 --- a/Modules/CppMicroServices/core/doc/snippets/uServices-staticmodules/MyStaticModule.cpp +++ b/Modules/CppMicroServices/core/doc/snippets/uServices-staticmodules/MyStaticModule.cpp @@ -1,39 +1,39 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include US_USE_NAMESPACE struct MyStaticModuleActivator : public ModuleActivator { - void Load(ModuleContext* /*context*/) + void Load(ModuleContext* /*context*/) override { std::cout << "Hello from a static module." << std::endl; } - void Unload(ModuleContext* /*context*/) {} + void Unload(ModuleContext* /*context*/) override {} }; US_EXPORT_MODULE_ACTIVATOR(MyStaticModuleActivator) US_INITIALIZE_MODULE diff --git a/Modules/CppMicroServices/core/include/usAny.h b/Modules/CppMicroServices/core/include/usAny.h index bfa2250d35..38d933e742 100644 --- a/Modules/CppMicroServices/core/include/usAny.h +++ b/Modules/CppMicroServices/core/include/usAny.h @@ -1,577 +1,577 @@ /*============================================================================= Library: CppMicroServices Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved. Extracted from Boost 1.46.1 and adapted for CppMicroServices. Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =========================================================================*/ #ifndef US_ANY_H #define US_ANY_H #include #include #include #include #include #include #include #include US_BEGIN_NAMESPACE class Any; US_Core_EXPORT std::string any_value_to_string(const Any& any); US_Core_EXPORT std::string any_value_to_json(const Any& val); US_Core_EXPORT std::string any_value_to_json(const std::string& val); US_Core_EXPORT std::string any_value_to_json(bool val); template std::string any_value_to_string(const T& val) { std::stringstream ss; ss << val; return ss.str(); } template std::string any_value_to_json(const T& val) { return any_value_to_string(val); } /** * \internal */ template std::string container_to_string(Iterator i1, Iterator i2) { std::stringstream ss; ss << "["; const Iterator begin = i1; for ( ; i1 != i2; ++i1) { if (i1 == begin) ss << any_value_to_string(*i1); else ss << "," << any_value_to_string(*i1); } ss << "]"; return ss.str(); } /** * \internal */ template std::string container_to_json(Iterator i1, Iterator i2) { std::stringstream ss; ss << "["; const Iterator begin = i1; for ( ; i1 != i2; ++i1) { if (i1 == begin) ss << any_value_to_json(*i1); else ss << "," << any_value_to_json(*i1); } ss << "]"; return ss.str(); } template std::string any_value_to_string(const std::vector& vec) { return container_to_string(vec.begin(), vec.end()); } template std::string any_value_to_json(const std::vector& vec) { return container_to_json(vec.begin(), vec.end()); } template std::string any_value_to_string(const std::list& l) { return container_to_string(l.begin(), l.end()); } template std::string any_value_to_json(const std::list& l) { return container_to_json(l.begin(), l.end()); } template std::string any_value_to_string(const std::set& s) { return container_to_string(s.begin(), s.end()); } template std::string any_value_to_json(const std::set& s) { return container_to_json(s.begin(), s.end()); } template std::string any_value_to_string(const std::map& m); template std::string any_value_to_string(const std::map& m); template std::string any_value_to_json(const std::map& m); template std::string any_value_to_json(const std::map& m); /** * \ingroup MicroServicesUtils * * An Any class represents a general type and is capable of storing any type, supporting type-safe extraction * of the internally stored data. * * Code taken from the Boost 1.46.1 library. Original copyright by Kevlin Henney. Modified for CppMicroServices. */ class Any { public: /** * Creates an empty any type. */ Any(): _content(0) { } /** * Creates an Any which stores the init parameter inside. * * \param value The content of the Any * * Example: * \code * Any a(13); * Any a(string("12345")); * \endcode */ template Any(const ValueType& value) : _content(new Holder(value)) { } /** * Copy constructor, works with empty Anys and initialized Any values. * * \param other The Any to copy */ Any(const Any& other) : _content(other._content ? other._content->Clone() : 0) { } ~Any() { delete _content; } /** * Swaps the content of the two Anys. * * \param rhs The Any to swap this Any with. */ Any& Swap(Any& rhs) { std::swap(_content, rhs._content); return *this; } /** * Assignment operator for all types != Any. * * \param rhs The value which should be assigned to this Any. * * Example: * \code * Any a = 13; * Any a = string("12345"); * \endcode */ template Any& operator = (const ValueType& rhs) { Any(rhs).Swap(*this); return *this; } /** * Assignment operator for Any. * * \param rhs The Any which should be assigned to this Any. */ Any& operator = (const Any& rhs) { Any(rhs).Swap(*this); return *this; } /** * returns true if the Any is empty */ bool Empty() const { return !_content; } /** * Returns a string representation for the content. * * Custom types should either provide a std::ostream& operator<<(std::ostream& os, const CustomType& ct) * function or specialize the any_value_to_string template function for meaningful output. */ std::string ToString() const { return _content->ToString(); } /** * Returns a JSON representation for the content. * * Custom types should specialize the any_value_to_json template function for meaningful output. */ std::string ToJSON() const { return Empty() ? "null" : _content->ToJSON(); } /** * Returns the type information of the stored content. * If the Any is empty typeid(void) is returned. * It is suggested to always query an Any for its type info before trying to extract * data via an any_cast/ref_any_cast. */ const std::type_info& Type() const { return _content ? _content->Type() : typeid(void); } private: class Placeholder { public: virtual ~Placeholder() { } virtual std::string ToString() const = 0; virtual std::string ToJSON() const = 0; virtual const std::type_info& Type() const = 0; virtual Placeholder* Clone() const = 0; }; template class Holder: public Placeholder { public: Holder(const ValueType& value) : _held(value) { } - virtual std::string ToString() const + virtual std::string ToString() const override { return any_value_to_string(_held); } - virtual std::string ToJSON() const + virtual std::string ToJSON() const override { return any_value_to_json(_held); } - virtual const std::type_info& Type() const + virtual const std::type_info& Type() const override { return typeid(ValueType); } - virtual Placeholder* Clone() const + virtual Placeholder* Clone() const override { return new Holder(_held); } ValueType _held; private: // intentionally left unimplemented Holder& operator=(const Holder &); }; private: template friend ValueType* any_cast(Any*); template friend ValueType* unsafe_any_cast(Any*); Placeholder* _content; }; class BadAnyCastException : public std::bad_cast { public: BadAnyCastException(const std::string& msg = "") : std::bad_cast(), _msg(msg) {} ~BadAnyCastException() throw() {} - virtual const char * what() const throw() + virtual const char * what() const throw() override { if (_msg.empty()) return "US_PREPEND_NAMESPACE(BadAnyCastException): " "failed conversion using US_PREPEND_NAMESPACE(any_cast)"; else return _msg.c_str(); } private: std::string _msg; }; /** * any_cast operator used to extract the ValueType from an Any*. Will return a pointer * to the stored value. * * Example Usage: * \code * MyType* pTmp = any_cast(pAny) * \endcode * Will return NULL if the cast fails, i.e. types don't match. */ template ValueType* any_cast(Any* operand) { return operand && operand->Type() == typeid(ValueType) ? &static_cast*>(operand->_content)->_held : 0; } /** * any_cast operator used to extract a const ValueType pointer from an const Any*. Will return a const pointer * to the stored value. * * Example Usage: * \code * const MyType* pTmp = any_cast(pAny) * \endcode * Will return NULL if the cast fails, i.e. types don't match. */ template const ValueType* any_cast(const Any* operand) { return any_cast(const_cast(operand)); } /** * any_cast operator used to extract a copy of the ValueType from an const Any&. * * Example Usage: * \code * MyType tmp = any_cast(anAny) * \endcode * Will throw a BadCastException if the cast fails. * Dont use an any_cast in combination with references, i.e. MyType& tmp = ... or const MyType& = ... * Some compilers will accept this code although a copy is returned. Use the ref_any_cast in * these cases. */ template ValueType any_cast(const Any& operand) { ValueType* result = any_cast(const_cast(&operand)); if (!result) throw BadAnyCastException("Failed to convert between const Any types"); return *result; } /** * any_cast operator used to extract a copy of the ValueType from an Any&. * * Example Usage: * \code * MyType tmp = any_cast(anAny) * \endcode * Will throw a BadCastException if the cast fails. * Dont use an any_cast in combination with references, i.e. MyType& tmp = ... or const MyType& tmp = ... * Some compilers will accept this code although a copy is returned. Use the ref_any_cast in * these cases. */ template ValueType any_cast(Any& operand) { ValueType* result = any_cast(&operand); if (!result) throw BadAnyCastException("Failed to convert between Any types"); return *result; } /** * ref_any_cast operator used to return a const reference to the internal data. * * Example Usage: * \code * const MyType& tmp = ref_any_cast(anAny); * \endcode */ template const ValueType& ref_any_cast(const Any & operand) { ValueType* result = any_cast(const_cast(&operand)); if (!result) throw BadAnyCastException("RefAnyCast: Failed to convert between const Any types"); return *result; } /** * ref_any_cast operator used to return a reference to the internal data. * * Example Usage: * \code * MyType& tmp = ref_any_cast(anAny); * \endcode */ template ValueType& ref_any_cast(Any& operand) { ValueType* result = any_cast(&operand); if (!result) throw BadAnyCastException("RefAnyCast: Failed to convert between Any types"); return *result; } /** * \internal * * The "unsafe" versions of any_cast are not part of the * public interface and may be removed at any time. They are * required where we know what type is stored in the any and can't * use typeid() comparison, e.g., when our types may travel across * different shared libraries. */ template ValueType* unsafe_any_cast(Any* operand) { return &static_cast*>(operand->_content)->_held; } /** * \internal * * The "unsafe" versions of any_cast are not part of the * public interface and may be removed at any time. They are * required where we know what type is stored in the any and can't * use typeid() comparison, e.g., when our types may travel across * different shared libraries. */ template const ValueType* unsafe_any_cast(const Any* operand) { return any_cast(const_cast(operand)); } template std::string any_value_to_string(const std::map& m) { std::stringstream ss; ss << "{"; typedef typename std::map::const_iterator Iterator; Iterator i1 = m.begin(); const Iterator begin = i1; const Iterator end = m.end(); for ( ; i1 != end; ++i1) { if (i1 == begin) ss << i1->first << " : " << i1->second.ToString(); else ss << ", " << i1->first << " : " << i1->second.ToString(); } ss << "}"; return ss.str(); } template std::string any_value_to_string(const std::map& m) { std::stringstream ss; ss << "{"; typedef typename std::map::const_iterator Iterator; Iterator i1 = m.begin(); const Iterator begin = i1; const Iterator end = m.end(); for ( ; i1 != end; ++i1) { if (i1 == begin) ss << i1->first << " : " << i1->second; else ss << ", " << i1->first << " : " << i1->second; } ss << "}"; return ss.str(); } template std::string any_value_to_json(const std::map& m) { std::stringstream ss; ss << "{"; typedef typename std::map::const_iterator Iterator; Iterator i1 = m.begin(); const Iterator begin = i1; const Iterator end = m.end(); for ( ; i1 != end; ++i1) { if (i1 == begin) ss << "\"" << i1->first << "\" : " << i1->second.ToJSON(); else ss << ", " << "\"" << i1->first << "\" : " << i1->second.ToJSON(); } ss << "}"; return ss.str(); } template std::string any_value_to_json(const std::map& m) { std::stringstream ss; ss << "{"; typedef typename std::map::const_iterator Iterator; Iterator i1 = m.begin(); const Iterator begin = i1; const Iterator end = m.end(); for ( ; i1 != end; ++i1) { if (i1 == begin) ss << "\"" << i1->first << "\" : " << i1->second; else ss << ", " << "\"" << i1->first << "\" : " << i1->second; } ss << "}"; return ss.str(); } US_END_NAMESPACE #endif // US_ANY_H diff --git a/Modules/CppMicroServices/core/src/module/usCoreModuleActivator.cpp b/Modules/CppMicroServices/core/src/module/usCoreModuleActivator.cpp index cf49fd7966..87d028c852 100644 --- a/Modules/CppMicroServices/core/src/module/usCoreModuleActivator.cpp +++ b/Modules/CppMicroServices/core/src/module/usCoreModuleActivator.cpp @@ -1,47 +1,47 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include "usModuleActivator.h" #include "usModule.h" #include "usModulePrivate.h" #include "usCoreModuleContext_p.h" US_BEGIN_NAMESPACE class CoreModuleActivator : public ModuleActivator { - void Load(ModuleContext* mc) + void Load(ModuleContext* mc) override { mc->GetModule()->d->coreCtx->Init(); } - void Unload(ModuleContext* /*mc*/) + void Unload(ModuleContext* /*mc*/) override { //mc->GetModule()->d->coreCtx->Uninit(); } }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(CoreModuleActivator)) diff --git a/Modules/CppMicroServices/core/src/module/usModuleResourceBuffer_p.h b/Modules/CppMicroServices/core/src/module/usModuleResourceBuffer_p.h index f98614f8ae..b7138b1774 100644 --- a/Modules/CppMicroServices/core/src/module/usModuleResourceBuffer_p.h +++ b/Modules/CppMicroServices/core/src/module/usModuleResourceBuffer_p.h @@ -1,68 +1,68 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef USMODULERESOURCEBUFFER_P_H #define USMODULERESOURCEBUFFER_P_H #include #include US_BEGIN_NAMESPACE class ModuleResourceBufferPrivate; class US_Core_EXPORT ModuleResourceBuffer: public std::streambuf { public: explicit ModuleResourceBuffer(void* data, std::size_t size, std::ios_base::openmode mode); ~ModuleResourceBuffer(); private: - int_type underflow(); + int_type underflow() override; - int_type uflow(); + int_type uflow() override; - int_type pbackfail(int_type ch); + int_type pbackfail(int_type ch) override; - std::streamsize showmanyc(); + std::streamsize showmanyc() override; - pos_type seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out); - pos_type seekpos (pos_type sp, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out); + pos_type seekoff (off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override; + pos_type seekpos (pos_type sp, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override; // purposely not implemented ModuleResourceBuffer(const ModuleResourceBuffer&); ModuleResourceBuffer& operator=(const ModuleResourceBuffer&); private: ModuleResourceBufferPrivate* d; }; US_END_NAMESPACE #endif // USMODULERESOURCEBUFFER_P_H diff --git a/Modules/CppMicroServices/core/src/service/usServiceHooks_p.h b/Modules/CppMicroServices/core/src/service/usServiceHooks_p.h index ea7e003c78..ec047fb29c 100644 --- a/Modules/CppMicroServices/core/src/service/usServiceHooks_p.h +++ b/Modules/CppMicroServices/core/src/service/usServiceHooks_p.h @@ -1,73 +1,73 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef USSERVICEHOOKS_P_H #define USSERVICEHOOKS_P_H #include "usServiceTracker.h" #include "usServiceListeners_p.h" US_BEGIN_NAMESPACE struct ServiceListenerHook; class ServiceHooks : private MultiThreaded<>, private ServiceTrackerCustomizer { private: CoreModuleContext* coreCtx; ServiceTracker* listenerHookTracker; bool bOpen; - virtual TrackedType AddingService(const ServiceReferenceType& reference); - virtual void ModifiedService(const ServiceReferenceType& reference, TrackedType service); - virtual void RemovedService(const ServiceReferenceType& reference, TrackedType service); + virtual TrackedType AddingService(const ServiceReferenceType& reference) override; + virtual void ModifiedService(const ServiceReferenceType& reference, TrackedType service) override; + virtual void RemovedService(const ServiceReferenceType& reference, TrackedType service) override; public: ServiceHooks(CoreModuleContext* coreCtx); ~ServiceHooks(); void Open(); void Close(); bool IsOpen() const; void FilterServiceReferences(ModuleContext* mc, const std::string& service, const std::string& filter, std::vector& refs); void FilterServiceEventReceivers(const ServiceEvent& evt, ServiceListeners::ServiceListenerEntries& receivers); void HandleServiceListenerReg(const ServiceListenerEntry& sle); void HandleServiceListenerUnreg(const ServiceListenerEntry& sle); void HandleServiceListenerUnreg(const std::vector& set); }; US_END_NAMESPACE #endif // USSERVICEHOOKS_P_H diff --git a/Modules/CppMicroServices/core/test/modules/libA/usTestModuleA.cpp b/Modules/CppMicroServices/core/test/modules/libA/usTestModuleA.cpp index ce8c625065..8ef066de4c 100644 --- a/Modules/CppMicroServices/core/test/modules/libA/usTestModuleA.cpp +++ b/Modules/CppMicroServices/core/test/modules/libA/usTestModuleA.cpp @@ -1,77 +1,77 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include "usTestModuleAService.h" #include #include #include US_BEGIN_NAMESPACE struct TestModuleA : public TestModuleAService { TestModuleA(ModuleContext* mc) { US_INFO << "Registering TestModuleAService"; sr = mc->RegisterService(this); } void Unregister() { if (sr) { sr.Unregister(); sr = 0; } } private: ServiceRegistration sr; }; class TestModuleAActivator : public ModuleActivator { public: TestModuleAActivator() : s(0) {} ~TestModuleAActivator() { delete s; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { s = new TestModuleA(context); } - void Unload(ModuleContext*) + void Unload(ModuleContext*) override { } private: TestModuleA* s; }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(TestModuleAActivator)) diff --git a/Modules/CppMicroServices/core/test/modules/libA2/usTestModuleA2.cpp b/Modules/CppMicroServices/core/test/modules/libA2/usTestModuleA2.cpp index dbc67185bb..a8b1088361 100644 --- a/Modules/CppMicroServices/core/test/modules/libA2/usTestModuleA2.cpp +++ b/Modules/CppMicroServices/core/test/modules/libA2/usTestModuleA2.cpp @@ -1,76 +1,76 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include "usTestModuleA2Service.h" #include #include US_BEGIN_NAMESPACE struct TestModuleA2 : public TestModuleA2Service { TestModuleA2(ModuleContext* mc) { US_INFO << "Registering TestModuleA2Service"; sr = mc->RegisterService(this); } void Unregister() { if (sr) { sr.Unregister(); } } private: ServiceRegistration sr; }; class TestModuleA2Activator : public ModuleActivator { public: TestModuleA2Activator() : s(0) {} ~TestModuleA2Activator() { delete s; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { s = new TestModuleA2(context); } - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { s->Unregister(); } private: TestModuleA2* s; }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(TestModuleA2Activator)) diff --git a/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleB.cpp b/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleB.cpp index 70b5befedf..c1f571ec40 100644 --- a/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleB.cpp +++ b/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleB.cpp @@ -1,66 +1,66 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include "usTestModuleBService.h" #include #include #include US_BEGIN_NAMESPACE struct TestModuleB : public TestModuleBService { TestModuleB(ModuleContext* mc) { US_INFO << "Registering TestModuleBService"; mc->RegisterService(this); } }; class TestModuleBActivator : public ModuleActivator { public: TestModuleBActivator() : s(0) {} ~TestModuleBActivator() { delete s; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { s = new TestModuleB(context); } - void Unload(ModuleContext*) + void Unload(ModuleContext*) override { } private: TestModuleB* s; }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(TestModuleBActivator)) US_IMPORT_MODULE(TestModuleImportedByB) diff --git a/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleImportedByB.cpp b/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleImportedByB.cpp index b4a446fe03..0e67a4a3fb 100644 --- a/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleImportedByB.cpp +++ b/Modules/CppMicroServices/core/test/modules/libBWithStatic/usTestModuleImportedByB.cpp @@ -1,64 +1,64 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include "usTestModuleBService.h" #include #include US_BEGIN_NAMESPACE struct TestModuleImportedByB : public TestModuleBService { TestModuleImportedByB(ModuleContext* mc) { US_INFO << "Registering TestModuleImportedByB"; mc->RegisterService(this); } }; class TestModuleImportedByBActivator : public ModuleActivator { public: TestModuleImportedByBActivator() : s(0) {} ~TestModuleImportedByBActivator() { delete s; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { s = new TestModuleImportedByB(context); } - void Unload(ModuleContext*) + void Unload(ModuleContext*) override { } private: TestModuleImportedByB* s; }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(TestModuleImportedByBActivator)) diff --git a/Modules/CppMicroServices/core/test/modules/libH/usTestModuleH.cpp b/Modules/CppMicroServices/core/test/modules/libH/usTestModuleH.cpp index 497b9b0025..31fbe99097 100644 --- a/Modules/CppMicroServices/core/test/modules/libH/usTestModuleH.cpp +++ b/Modules/CppMicroServices/core/test/modules/libH/usTestModuleH.cpp @@ -1,140 +1,140 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include #include #include US_BEGIN_NAMESPACE struct TestModuleH { virtual ~TestModuleH() {} }; struct TestModuleH2 { virtual ~TestModuleH2() {} }; class TestProduct : public TestModuleH { // Module* caller; public: TestProduct(Module* /*caller*/) //: caller(caller) {} }; class TestProduct2 : public TestProduct, public TestModuleH2 { public: TestProduct2(Module* caller) : TestProduct(caller) {} }; class TestModuleHPrototypeServiceFactory : public PrototypeServiceFactory { std::map > fcbind; // Map calling module with implementation public: - InterfaceMap GetService(Module* caller, const ServiceRegistrationBase& /*sReg*/) + InterfaceMap GetService(Module* caller, const ServiceRegistrationBase& /*sReg*/) override { std::cout << "GetService (prototype) in H" << std::endl; TestProduct2* product = new TestProduct2(caller); fcbind[caller->GetModuleId()].push_back(product); return MakeInterfaceMap(product); } - void UngetService(Module* caller, const ServiceRegistrationBase& /*sReg*/, const InterfaceMap& service) + void UngetService(Module* caller, const ServiceRegistrationBase& /*sReg*/, const InterfaceMap& service) override { TestProduct2* product = dynamic_cast(ExtractInterface(service)); delete product; fcbind[caller->GetModuleId()].remove(product); } }; class TestModuleHActivator : public ModuleActivator, public ServiceFactory { std::string thisServiceName; ServiceRegistration factoryService; ServiceRegistration prototypeFactoryService; ModuleContext* mc; std::map fcbind; // Map calling module with implementation TestModuleHPrototypeServiceFactory prototypeFactory; public: TestModuleHActivator() : thisServiceName(us_service_interface_iid()) , mc(NULL) {} - void Load(ModuleContext* mc) + void Load(ModuleContext* mc) override { std::cout << "start in H" << std::endl; this->mc = mc; factoryService = mc->RegisterService(this); prototypeFactoryService = mc->RegisterService(static_cast(&prototypeFactory)); } - void Unload(ModuleContext* /*mc*/) + void Unload(ModuleContext* /*mc*/) override { factoryService.Unregister(); } - InterfaceMap GetService(Module* caller, const ServiceRegistrationBase& /*sReg*/) + InterfaceMap GetService(Module* caller, const ServiceRegistrationBase& /*sReg*/) override { std::cout << "GetService in H" << std::endl; TestProduct* product = new TestProduct(caller); fcbind.insert(std::make_pair(caller->GetModuleId(), product)); return MakeInterfaceMap(product); } - void UngetService(Module* caller, const ServiceRegistrationBase& /*sReg*/, const InterfaceMap& service) + void UngetService(Module* caller, const ServiceRegistrationBase& /*sReg*/, const InterfaceMap& service) override { TestModuleH* product = ExtractInterface(service); delete product; fcbind.erase(caller->GetModuleId()); } }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(us::TestModuleHActivator) diff --git a/Modules/CppMicroServices/core/test/modules/libM/usTestModuleM.cpp b/Modules/CppMicroServices/core/test/modules/libM/usTestModuleM.cpp index 1a89029c2a..ceec0d89f2 100644 --- a/Modules/CppMicroServices/core/test/modules/libM/usTestModuleM.cpp +++ b/Modules/CppMicroServices/core/test/modules/libM/usTestModuleM.cpp @@ -1,43 +1,43 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include US_BEGIN_NAMESPACE class TestModuleMActivator : public ModuleActivator { public: - void Load(ModuleContext*) + void Load(ModuleContext*) override { } - void Unload(ModuleContext*) + void Unload(ModuleContext*) override { } }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(TestModuleMActivator)) diff --git a/Modules/CppMicroServices/core/test/modules/libS/usTestModuleS.cpp b/Modules/CppMicroServices/core/test/modules/libS/usTestModuleS.cpp index 75cf59331c..e8fae0a999 100644 --- a/Modules/CppMicroServices/core/test/modules/libS/usTestModuleS.cpp +++ b/Modules/CppMicroServices/core/test/modules/libS/usTestModuleS.cpp @@ -1,142 +1,142 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include "../../usServiceControlInterface.h" #include "usTestModuleSService0.h" #include "usTestModuleSService1.h" #include "usTestModuleSService2.h" #include "usTestModuleSService3.h" #include #include #include US_BEGIN_NAMESPACE class TestModuleS : public ServiceControlInterface, public TestModuleSService0, public TestModuleSService1, public TestModuleSService2, public TestModuleSService3 { public: TestModuleS(ModuleContext* mc) : mc(mc) { for(int i = 0; i <= 3; ++i) { servregs.push_back(ServiceRegistrationU()); } sreg = mc->RegisterService(this); sciReg = mc->RegisterService(this); } virtual const char* GetNameOfClass() const { return "TestModuleS"; } - void ServiceControl(int offset, const std::string& operation, int ranking) + void ServiceControl(int offset, const std::string& operation, int ranking) override { if (0 <= offset && offset <= 3) { if (operation == "register") { if (!servregs[offset]) { std::stringstream servicename; servicename << SERVICE << offset; InterfaceMap ifm; ifm.insert(std::make_pair(servicename.str(), static_cast(this))); ServiceProperties props; props.insert(std::make_pair(ServiceConstants::SERVICE_RANKING(), Any(ranking))); servregs[offset] = mc->RegisterService(ifm, props); } } if (operation == "unregister") { if (servregs[offset]) { ServiceRegistrationU sr1 = servregs[offset]; sr1.Unregister(); servregs[offset] = 0; } } } } void Unregister() { if (sreg) { sreg.Unregister(); } if (sciReg) { sciReg.Unregister(); } } private: static const std::string SERVICE; // = "us::TestModuleSService" ModuleContext* mc; std::vector servregs; ServiceRegistration sreg; ServiceRegistration sciReg; }; const std::string TestModuleS::SERVICE = "us::TestModuleSService"; class TestModuleSActivator : public ModuleActivator { public: TestModuleSActivator() : s(0) {} ~TestModuleSActivator() { delete s; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { s = new TestModuleS(context); } - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { #ifndef US_BUILD_SHARED_LIBS s->Unregister(); #endif } private: TestModuleS* s; }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(TestModuleSActivator)) diff --git a/Modules/CppMicroServices/core/test/modules/libSL1/usActivatorSL1.cpp b/Modules/CppMicroServices/core/test/modules/libSL1/usActivatorSL1.cpp index 7c1419babe..96f23afd6e 100644 --- a/Modules/CppMicroServices/core/test/modules/libSL1/usActivatorSL1.cpp +++ b/Modules/CppMicroServices/core/test/modules/libSL1/usActivatorSL1.cpp @@ -1,106 +1,106 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include "usFooService.h" US_BEGIN_NAMESPACE class ActivatorSL1 : public ModuleActivator, public ModulePropsInterface, public ServiceTrackerCustomizer { public: ActivatorSL1() : tracker(0), context(0) { } ~ActivatorSL1() { delete tracker; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { this->context = context; InterfaceMap im = MakeInterfaceMap(this); im.insert(std::make_pair(std::string("ActivatorSL1"), this)); sr = context->RegisterService(im); delete tracker; tracker = new FooTracker(context, this); tracker->Open(); } - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { tracker->Close(); } - const Properties& GetProperties() const + const Properties& GetProperties() const override { return props; } - FooService* AddingService(const ServiceReferenceType& reference) + FooService* AddingService(const ServiceReferenceType& reference) override { props["serviceAdded"] = true; FooService* fooService = context->GetService(reference); fooService->foo(); return fooService; } - void ModifiedService(const ServiceReferenceType& /*reference*/, FooService* /*service*/) + void ModifiedService(const ServiceReferenceType& /*reference*/, FooService* /*service*/) override {} - void RemovedService(const ServiceReferenceType& /*reference*/, FooService* /*service*/) + void RemovedService(const ServiceReferenceType& /*reference*/, FooService* /*service*/) override { props["serviceRemoved"] = true; } private: ModulePropsInterface::Properties props; ServiceRegistrationU sr; typedef ServiceTracker FooTracker; FooTracker* tracker; ModuleContext* context; }; // ActivatorSL1 US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(ActivatorSL1)) diff --git a/Modules/CppMicroServices/core/test/modules/libSL3/usActivatorSL3.cpp b/Modules/CppMicroServices/core/test/modules/libSL3/usActivatorSL3.cpp index 17cb010005..a6b609d322 100644 --- a/Modules/CppMicroServices/core/test/modules/libSL3/usActivatorSL3.cpp +++ b/Modules/CppMicroServices/core/test/modules/libSL3/usActivatorSL3.cpp @@ -1,99 +1,99 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include US_BEGIN_NAMESPACE class ActivatorSL3 : public ModuleActivator, public ModulePropsInterface, public ServiceTrackerCustomizer { public: ActivatorSL3() : tracker(0), context(0) {} ~ActivatorSL3() { delete tracker; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { this->context = context; InterfaceMap im = MakeInterfaceMap(this); im.insert(std::make_pair(std::string("ActivatorSL3"), this)); sr = context->RegisterService(im); delete tracker; tracker = new FooTracker(context, this); tracker->Open(); } - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { tracker->Close(); } - const ModulePropsInterface::Properties& GetProperties() const + const ModulePropsInterface::Properties& GetProperties() const override { return props; } - FooService* AddingService(const ServiceReferenceType& reference) + FooService* AddingService(const ServiceReferenceType& reference) override { props["serviceAdded"] = true; US_INFO << "SL3: Adding reference =" << reference; FooService* fooService = context->GetService(reference); fooService->foo(); return fooService; } - void ModifiedService(const ServiceReferenceType& /*reference*/, FooService* /*service*/) + void ModifiedService(const ServiceReferenceType& /*reference*/, FooService* /*service*/) override { } - void RemovedService(const ServiceReferenceType& reference, FooService* /*service*/) + void RemovedService(const ServiceReferenceType& reference, FooService* /*service*/) override { props["serviceRemoved"] = true; US_INFO << "SL3: Removing reference =" << reference; } private: typedef ServiceTracker FooTracker; FooTracker* tracker; ModuleContext* context; ServiceRegistrationU sr; ModulePropsInterface::Properties props; }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(ActivatorSL3)) diff --git a/Modules/CppMicroServices/core/test/modules/libSL4/usActivatorSL4.cpp b/Modules/CppMicroServices/core/test/modules/libSL4/usActivatorSL4.cpp index 70d3952b7b..fdfd4a3061 100644 --- a/Modules/CppMicroServices/core/test/modules/libSL4/usActivatorSL4.cpp +++ b/Modules/CppMicroServices/core/test/modules/libSL4/usActivatorSL4.cpp @@ -1,64 +1,64 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include US_BEGIN_NAMESPACE class ActivatorSL4 : public ModuleActivator, public FooService { public: ~ActivatorSL4() { } - void foo() + void foo() override { US_INFO << "TestModuleSL4: Doing foo"; } - void Load(ModuleContext* context) + void Load(ModuleContext* context) override { sr = context->RegisterService(this); US_INFO << "TestModuleSL4: Registered " << sr; } - void Unload(ModuleContext* /*context*/) + void Unload(ModuleContext* /*context*/) override { } private: ServiceRegistration sr; }; US_END_NAMESPACE US_EXPORT_MODULE_ACTIVATOR(US_PREPEND_NAMESPACE(ActivatorSL4)) diff --git a/Modules/CppMicroServices/core/test/usModuleHooksTest.cpp b/Modules/CppMicroServices/core/test/usModuleHooksTest.cpp index b9c68bdf56..094fa44df3 100644 --- a/Modules/CppMicroServices/core/test/usModuleHooksTest.cpp +++ b/Modules/CppMicroServices/core/test/usModuleHooksTest.cpp @@ -1,194 +1,194 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include #include #include #include "usTestingMacros.h" #include "usTestingConfig.h" US_USE_NAMESPACE namespace { #ifdef US_PLATFORM_WINDOWS static const std::string LIB_PATH = US_RUNTIME_OUTPUT_DIRECTORY; #else static const std::string LIB_PATH = US_LIBRARY_OUTPUT_DIRECTORY; #endif class TestModuleListener { public: void ModuleChanged(const ModuleEvent moduleEvent) { this->events.push_back(moduleEvent); } std::vector events; }; class TestModuleFindHook : public ModuleFindHook { public: - void Find(const ModuleContext* /*context*/, ShrinkableVector& modules) + void Find(const ModuleContext* /*context*/, ShrinkableVector& modules) override { for (ShrinkableVector::iterator i = modules.begin(); i != modules.end();) { if ((*i)->GetName() == "TestModuleA") { i = modules.erase(i); } else { ++i; } } } }; class TestModuleEventHook : public ModuleEventHook { public: - void Event(const ModuleEvent& event, ShrinkableVector& contexts) + void Event(const ModuleEvent& event, ShrinkableVector& contexts) override { if (event.GetType() == ModuleEvent::LOADING || event.GetType() == ModuleEvent::UNLOADING) { contexts.erase(std::remove(contexts.begin(), contexts.end(), GetModuleContext()), contexts.end()); } } }; void TestFindHook() { SharedLibrary libA(LIB_PATH, "TestModuleA"); #ifdef US_BUILD_SHARED_LIBS try { libA.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) } #endif Module* moduleA = GetModuleContext()->GetModule("TestModuleA"); US_TEST_CONDITION_REQUIRED(moduleA != 0, "Test for existing module TestModuleA") US_TEST_CONDITION(moduleA->GetName() == "TestModuleA", "Test module name") US_TEST_CONDITION(moduleA->IsLoaded() == true, "Test if loaded correctly"); long moduleAId = moduleA->GetModuleId(); US_TEST_CONDITION_REQUIRED(moduleAId > 0, "Test for valid module id") US_TEST_CONDITION_REQUIRED(GetModuleContext()->GetModule(moduleAId) != NULL, "Test for non-filtered GetModule(long) result") TestModuleFindHook findHook; ServiceRegistration findHookReg = GetModuleContext()->RegisterService(&findHook); US_TEST_CONDITION_REQUIRED(GetModuleContext()->GetModule(moduleAId) == NULL, "Test for filtered GetModule(long) result") std::vector modules = GetModuleContext()->GetModules(); for (std::vector::iterator i = modules.begin(); i != modules.end(); ++i) { if((*i)->GetName() == "TestModuleA") { US_TEST_FAILED_MSG(<< "TestModuleA not filtered from GetModules()") } } findHookReg.Unregister(); libA.Unload(); } #ifdef US_BUILD_SHARED_LIBS void TestEventHook() { TestModuleListener moduleListener; GetModuleContext()->AddModuleListener(&moduleListener, &TestModuleListener::ModuleChanged); SharedLibrary libA(LIB_PATH, "TestModuleA"); try { libA.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) } US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 2, "Test for received load module events") libA.Unload(); US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 4, "Test for received unload module events") TestModuleEventHook eventHook; ServiceRegistration eventHookReg = GetModuleContext()->RegisterService(&eventHook); moduleListener.events.clear(); try { libA.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) } US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 1, "Test for filtered load module events") US_TEST_CONDITION_REQUIRED(moduleListener.events[0].GetType() == ModuleEvent::LOADED, "Test for LOADED event") libA.Unload(); US_TEST_CONDITION_REQUIRED(moduleListener.events.size() == 2, "Test for filtered unload module events") US_TEST_CONDITION_REQUIRED(moduleListener.events[1].GetType() == ModuleEvent::UNLOADED, "Test for UNLOADED event") eventHookReg.Unregister(); GetModuleContext()->RemoveModuleListener(&moduleListener, &TestModuleListener::ModuleChanged); } #endif } // end unnamed namespace int usModuleHooksTest(int /*argc*/, char* /*argv*/[]) { US_TEST_BEGIN("ModuleHooksTest"); TestFindHook(); #ifdef US_BUILD_SHARED_LIBS TestEventHook(); #endif US_TEST_END() } diff --git a/Modules/CppMicroServices/core/test/usServiceHooksTest.cpp b/Modules/CppMicroServices/core/test/usServiceHooksTest.cpp index be44b68a4c..cdbc44c496 100644 --- a/Modules/CppMicroServices/core/test/usServiceHooksTest.cpp +++ b/Modules/CppMicroServices/core/test/usServiceHooksTest.cpp @@ -1,414 +1,414 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include #include #include #include #include #include "usTestingMacros.h" #include "usTestingConfig.h" US_USE_NAMESPACE namespace { #ifdef US_PLATFORM_WINDOWS static const std::string LIB_PATH = US_RUNTIME_OUTPUT_DIRECTORY; #else static const std::string LIB_PATH = US_LIBRARY_OUTPUT_DIRECTORY; #endif class TestServiceListener { public: void ServiceChanged(const ServiceEvent serviceEvent) { this->events.push_back(serviceEvent); } std::vector events; }; class TestServiceEventListenerHook : public ServiceEventListenerHook { private: int id; public: TestServiceEventListenerHook(int id) : id(id) { } typedef ShrinkableMap > MapType; - void Event(const ServiceEvent& /*event*/, MapType& listeners) + void Event(const ServiceEvent& /*event*/, MapType& listeners) override { US_TEST_CONDITION_REQUIRED(listeners.size() > 0 && listeners.find(GetModuleContext()) != listeners.end(), "Check listener content"); ShrinkableVector& listenerInfos = listeners[GetModuleContext()]; // listener count should be 2 because the event listener hooks are called with // the list of listeners before filtering them according to ther LDAP filter if (id == 1) { #ifdef US_BUILD_SHARED_LIBS US_TEST_CONDITION(listenerInfos.size() == 2, "2 service listeners expected"); #else US_TEST_CONDITION(listenerInfos.size() >= 2, "2 service listeners expected"); #endif US_TEST_CONDITION(listenerInfos[0].IsRemoved() == false, "Listener is not removed"); US_TEST_CONDITION(listenerInfos[1].IsRemoved() == false, "Listener is not removed"); US_TEST_CONDITION(!(listenerInfos[0] == listenerInfos[1]), "listener info inequality"); } else { // there is already one listener filtered out #ifdef US_BUILD_SHARED_LIBS US_TEST_CONDITION(listenerInfos.size() == 1, "1 service listener expected"); #else US_TEST_CONDITION(listenerInfos.size() >= 1, "1 service listener expected"); #endif US_TEST_CONDITION(listenerInfos[0].IsRemoved() == false, "Listener is not removed"); } if (listenerInfo.IsNull()) { listenerInfo = listenerInfos[0]; } else { US_TEST_CONDITION(listenerInfo == listenerInfos[0], "Equal listener info objects"); } // Remove the listener without a filter from the list for(ShrinkableVector::iterator infoIter = listenerInfos.begin(); infoIter != listenerInfos.end();) { if (infoIter->GetFilter().empty()) { infoIter = listenerInfos.erase(infoIter); } else { ++infoIter; } } #ifdef US_BUILD_SHARED_LIBS US_TEST_CONDITION(listenerInfos.size() == 1, "One listener with LDAP filter should remain"); #else US_TEST_CONDITION(listenerInfos.size() >= 1, "One listener with LDAP filter should remain"); #endif ordering.push_back(id); } ServiceListenerHook::ListenerInfo listenerInfo; static std::vector ordering; }; std::vector TestServiceEventListenerHook::ordering; class TestServiceFindHook : public ServiceFindHook { private: int id; public: TestServiceFindHook(int id) : id(id) { } void Find(const ModuleContext* context, const std::string& /*name*/, - const std::string& /*filter*/, ShrinkableVector& references) + const std::string& /*filter*/, ShrinkableVector& references) override { US_TEST_CONDITION(context == GetModuleContext(), "Module context"); references.clear(); ordering.push_back(id); } static std::vector ordering; }; std::vector TestServiceFindHook::ordering; class TestServiceListenerHook : public ServiceListenerHook { private: int id; public: TestServiceListenerHook(int id) : id(id) { } - void Added(const std::vector& listeners) + void Added(const std::vector& listeners) override { for (std::vector::const_iterator iter = listeners.begin(); iter != listeners.end(); ++iter) { if (iter->IsRemoved() || iter->GetModuleContext() != GetModuleContext()) continue; listenerInfos.insert(*iter); lastAdded = listeners.back(); ordering.push_back(id); } } - void Removed(const std::vector& listeners) + void Removed(const std::vector& listeners) override { for (std::vector::const_iterator iter = listeners.begin(); iter != listeners.end(); ++iter) { listenerInfos.erase(*iter); ordering.push_back(id*10); } lastRemoved = listeners.back(); } static std::vector ordering; US_UNORDERED_SET_TYPE listenerInfos; ListenerInfo lastAdded; ListenerInfo lastRemoved; }; std::vector TestServiceListenerHook::ordering; void TestEventListenerHook() { ModuleContext* context = GetModuleContext(); TestServiceListener serviceListener1; TestServiceListener serviceListener2; context->AddServiceListener(&serviceListener1, &TestServiceListener::ServiceChanged); context->AddServiceListener(&serviceListener2, &TestServiceListener::ServiceChanged, LDAPProp(ServiceConstants::OBJECTCLASS()) == "bla"); TestServiceEventListenerHook serviceEventListenerHook1(1); ServiceProperties hookProps1; hookProps1[ServiceConstants::SERVICE_RANKING()] = 10; ServiceRegistration eventListenerHookReg1 = context->RegisterService(&serviceEventListenerHook1, hookProps1); TestServiceEventListenerHook serviceEventListenerHook2(2); ServiceProperties hookProps2; hookProps2[ServiceConstants::SERVICE_RANKING()] = 0; ServiceRegistration eventListenerHookReg2 = context->RegisterService(&serviceEventListenerHook2, hookProps2); std::vector expectedOrdering; expectedOrdering.push_back(1); expectedOrdering.push_back(1); expectedOrdering.push_back(2); US_TEST_CONDITION(serviceEventListenerHook1.ordering == expectedOrdering, "Event listener hook call order"); US_TEST_CONDITION(serviceListener1.events.empty(), "service event of service event listener hook"); US_TEST_CONDITION(serviceListener2.events.empty(), "no service event for filtered listener"); #ifdef US_BUILD_SHARED_LIBS SharedLibrary libA(LIB_PATH, "TestModuleA"); try { libA.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) } expectedOrdering.push_back(1); expectedOrdering.push_back(2); US_TEST_CONDITION(serviceEventListenerHook1.ordering == expectedOrdering, "Event listener hook call order"); libA.Unload(); #endif US_TEST_CONDITION(serviceListener1.events.empty(), "no service event due to service event listener hook"); US_TEST_CONDITION(serviceListener2.events.empty(), "no service event for filtered listener due to service event listener hook"); eventListenerHookReg2.Unregister(); eventListenerHookReg1.Unregister(); context->RemoveServiceListener(&serviceListener1, &TestServiceListener::ServiceChanged); context->RemoveServiceListener(&serviceListener2, &TestServiceListener::ServiceChanged); } void TestListenerHook() { ModuleContext* context = GetModuleContext(); TestServiceListener serviceListener1; TestServiceListener serviceListener2; context->AddServiceListener(&serviceListener1, &TestServiceListener::ServiceChanged); context->AddServiceListener(&serviceListener2, &TestServiceListener::ServiceChanged, LDAPProp(ServiceConstants::OBJECTCLASS()) == "bla"); TestServiceListenerHook serviceListenerHook1(1); ServiceProperties hookProps1; hookProps1[ServiceConstants::SERVICE_RANKING()] = 0; ServiceRegistration listenerHookReg1 = context->RegisterService(&serviceListenerHook1, hookProps1); TestServiceListenerHook serviceListenerHook2(2); ServiceProperties hookProps2; hookProps2[ServiceConstants::SERVICE_RANKING()] = 10; ServiceRegistration listenerHookReg2 = context->RegisterService(&serviceListenerHook2, hookProps2); #ifdef US_BUILD_SHARED_LIBS // check if hooks got notified about the existing listeners US_TEST_CONDITION_REQUIRED(serviceListenerHook1.listenerInfos.size() == 2, "Notification about existing listeners") #endif const std::size_t listenerInfoSizeOld = serviceListenerHook1.listenerInfos.size() - 2; context->AddServiceListener(&serviceListener1, &TestServiceListener::ServiceChanged); ServiceListenerHook::ListenerInfo lastAdded = serviceListenerHook1.lastAdded; #ifdef US_BUILD_SHARED_LIBS std::vector expectedOrdering; expectedOrdering.push_back(1); expectedOrdering.push_back(1); expectedOrdering.push_back(2); expectedOrdering.push_back(2); expectedOrdering.push_back(20); expectedOrdering.push_back(10); expectedOrdering.push_back(2); expectedOrdering.push_back(1); US_TEST_CONDITION(serviceListenerHook1.ordering == expectedOrdering, "Listener hook call order"); #endif context->AddServiceListener(&serviceListener1, &TestServiceListener::ServiceChanged, LDAPProp(ServiceConstants::OBJECTCLASS()) == "blub"); US_TEST_CONDITION(lastAdded == serviceListenerHook1.lastRemoved, "Same ListenerInfo object)"); US_TEST_CONDITION(!(lastAdded == serviceListenerHook1.lastAdded), "New ListenerInfo object)"); #ifdef US_BUILD_SHARED_LIBS expectedOrdering.push_back(20); expectedOrdering.push_back(10); expectedOrdering.push_back(2); expectedOrdering.push_back(1); US_TEST_CONDITION(serviceListenerHook1.ordering == expectedOrdering, "Listener hook call order"); #endif context->RemoveServiceListener(&serviceListener1, &TestServiceListener::ServiceChanged); context->RemoveServiceListener(&serviceListener2, &TestServiceListener::ServiceChanged); #ifdef US_BUILD_SHARED_LIBS expectedOrdering.push_back(20); expectedOrdering.push_back(10); expectedOrdering.push_back(20); expectedOrdering.push_back(10); US_TEST_CONDITION(serviceListenerHook1.ordering == expectedOrdering, "Listener hook call order"); #endif US_TEST_CONDITION_REQUIRED(serviceListenerHook1.listenerInfos.size() == listenerInfoSizeOld, "Removed listener infos") listenerHookReg2.Unregister(); listenerHookReg1.Unregister(); } void TestFindHook() { ModuleContext* context = GetModuleContext(); TestServiceFindHook serviceFindHook1(1); ServiceProperties hookProps1; hookProps1[ServiceConstants::SERVICE_RANKING()] = 0; ServiceRegistration findHookReg1 = context->RegisterService(&serviceFindHook1, hookProps1); TestServiceFindHook serviceFindHook2(2); ServiceProperties hookProps2; hookProps2[ServiceConstants::SERVICE_RANKING()] = 10; ServiceRegistration findHookReg2 = context->RegisterService(&serviceFindHook2, hookProps2); std::vector expectedOrdering; US_TEST_CONDITION(serviceFindHook1.ordering == expectedOrdering, "Find hook call order"); TestServiceListener serviceListener; context->AddServiceListener(&serviceListener, &TestServiceListener::ServiceChanged); #ifdef US_BUILD_SHARED_LIBS SharedLibrary libA(LIB_PATH, "TestModuleA"); try { libA.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG(<< "Load module exception: " << e.what()) } US_TEST_CONDITION(serviceListener.events.size() == 1, "Service registered"); #endif std::vector refs = context->GetServiceReferences("us::TestModuleAService"); US_TEST_CONDITION(refs.empty(), "Empty references"); ServiceReferenceU ref = context->GetServiceReference("us::TestModuleAService"); US_TEST_CONDITION(!ref, "Invalid reference (filtered out)"); expectedOrdering.push_back(2); expectedOrdering.push_back(1); expectedOrdering.push_back(2); expectedOrdering.push_back(1); US_TEST_CONDITION(serviceFindHook1.ordering == expectedOrdering, "Find hook call order"); findHookReg2.Unregister(); findHookReg1.Unregister(); refs = context->GetServiceReferences("us::TestModuleAService"); US_TEST_CONDITION(!refs.empty(), "Non-empty references"); ref = context->GetServiceReference("us::TestModuleAService"); US_TEST_CONDITION(ref, "Valid reference"); #ifdef US_BUILD_SHARED_LIBS libA.Unload(); #endif context->RemoveServiceListener(&serviceListener, &TestServiceListener::ServiceChanged); } } // end unnamed namespace int usServiceHooksTest(int /*argc*/, char* /*argv*/[]) { US_TEST_BEGIN("ServiceHooksTest"); TestListenerHook(); TestFindHook(); TestEventListenerHook(); US_TEST_END() } diff --git a/Modules/CppMicroServices/core/test/usServiceTemplateTest.cpp b/Modules/CppMicroServices/core/test/usServiceTemplateTest.cpp index b91dae1bd5..153defe7b8 100644 --- a/Modules/CppMicroServices/core/test/usServiceTemplateTest.cpp +++ b/Modules/CppMicroServices/core/test/usServiceTemplateTest.cpp @@ -1,208 +1,208 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include "usTestingMacros.h" struct Interface1 {}; struct Interface2 {}; struct Interface3 {}; struct MyService1 : public Interface1 {}; struct MyService2 : public Interface1, public Interface2 {}; struct MyService3 : public Interface1, public Interface2, public Interface3 {}; struct MyFactory1 : public us::ServiceFactory { std::map m_idToServiceMap; - virtual us::InterfaceMap GetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/) + virtual us::InterfaceMap GetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/) override { MyService1* s = new MyService1; m_idToServiceMap.insert(std::make_pair(module->GetModuleId(), s)); return us::MakeInterfaceMap(s); } virtual void UngetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/, - const us::InterfaceMap& service) + const us::InterfaceMap& service) override { std::map::iterator iter = m_idToServiceMap.find(module->GetModuleId()); if (iter != m_idToServiceMap.end()) { US_TEST_CONDITION(static_cast(iter->second) == us::ExtractInterface(service), "Compare service pointer") delete iter->second; m_idToServiceMap.erase(iter); } } }; struct MyFactory2 : public us::ServiceFactory { std::map m_idToServiceMap; - virtual us::InterfaceMap GetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/) + virtual us::InterfaceMap GetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/) override { MyService2* s = new MyService2; m_idToServiceMap.insert(std::make_pair(module->GetModuleId(), s)); return us::MakeInterfaceMap(s); } virtual void UngetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/, - const us::InterfaceMap& service) + const us::InterfaceMap& service) override { std::map::iterator iter = m_idToServiceMap.find(module->GetModuleId()); if (iter != m_idToServiceMap.end()) { US_TEST_CONDITION(static_cast(iter->second) == us::ExtractInterface(service), "Compare service pointer") delete iter->second; m_idToServiceMap.erase(iter); } } }; struct MyFactory3 : public us::ServiceFactory { std::map m_idToServiceMap; - virtual us::InterfaceMap GetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/) + virtual us::InterfaceMap GetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/) override { MyService3* s = new MyService3; m_idToServiceMap.insert(std::make_pair(module->GetModuleId(), s)); return us::MakeInterfaceMap(s); } virtual void UngetService(us::Module* module, const us::ServiceRegistrationBase& /*registration*/, - const us::InterfaceMap& service) + const us::InterfaceMap& service) override { std::map::iterator iter = m_idToServiceMap.find(module->GetModuleId()); if (iter != m_idToServiceMap.end()) { US_TEST_CONDITION(static_cast(iter->second) == us::ExtractInterface(service), "Compare service pointer") delete iter->second; m_idToServiceMap.erase(iter); } } }; US_USE_NAMESPACE int usServiceTemplateTest(int /*argc*/, char* /*argv*/[]) { US_TEST_BEGIN("ServiceTemplateTest"); ModuleContext* mc = GetModuleContext(); // Register compile tests MyService1 s1; MyService2 s2; MyService3 s3; us::ServiceRegistration sr1 = mc->RegisterService(&s1); us::ServiceRegistration sr2 = mc->RegisterService(&s2); us::ServiceRegistration sr3 = mc->RegisterService(&s3); MyFactory1 f1; us::ServiceRegistration sfr1 = mc->RegisterService(&f1); MyFactory2 f2; us::ServiceRegistration sfr2 = mc->RegisterService(static_cast(&f2)); MyFactory3 f3; us::ServiceRegistration sfr3 = mc->RegisterService(static_cast(&f3)); #ifdef US_BUILD_SHARED_LIBS US_TEST_CONDITION(mc->GetModule()->GetRegisteredServices().size() == 6, "# of reg services") #endif std::vector > s1refs = mc->GetServiceReferences(); US_TEST_CONDITION(s1refs.size() == 6, "# of interface1 regs") std::vector > s2refs = mc->GetServiceReferences(); US_TEST_CONDITION(s2refs.size() == 4, "# of interface2 regs") std::vector > s3refs = mc->GetServiceReferences(); US_TEST_CONDITION(s3refs.size() == 2, "# of interface3 regs") Interface1* i1 = mc->GetService(sr1.GetReference()); US_TEST_CONDITION(i1 == static_cast(&s1), "interface1 ptr") i1 = NULL; US_TEST_CONDITION(mc->UngetService(sr1.GetReference()), "unget interface1 ptr") i1 = mc->GetService(sfr1.GetReference()); US_TEST_CONDITION(i1 == static_cast(f1.m_idToServiceMap[mc->GetModule()->GetModuleId()]), "interface1 factory ptr") i1 = NULL; US_TEST_CONDITION(mc->UngetService(sfr1.GetReference()), "unget interface1 factory ptr") i1 = mc->GetService(sr2.GetReference(InterfaceType())); US_TEST_CONDITION(i1 == static_cast(&s2), "interface1 ptr") i1 = NULL; US_TEST_CONDITION(mc->UngetService(sr2.GetReference(InterfaceType())), "unget interface1 ptr") i1 = mc->GetService(sfr2.GetReference(InterfaceType())); US_TEST_CONDITION(i1 == static_cast(f2.m_idToServiceMap[mc->GetModule()->GetModuleId()]), "interface1 factory ptr") i1 = NULL; US_TEST_CONDITION(mc->UngetService(sfr2.GetReference(InterfaceType())), "unget interface1 factory ptr") Interface2* i2 = mc->GetService(sr2.GetReference(InterfaceType())); US_TEST_CONDITION(i2 == static_cast(&s2), "interface2 ptr") i2 = NULL; US_TEST_CONDITION(mc->UngetService(sr2.GetReference(InterfaceType())), "unget interface2 ptr") i2 = mc->GetService(sfr2.GetReference(InterfaceType())); US_TEST_CONDITION(i2 == static_cast(f2.m_idToServiceMap[mc->GetModule()->GetModuleId()]), "interface2 factory ptr") i2 = NULL; US_TEST_CONDITION(mc->UngetService(sfr2.GetReference(InterfaceType())), "unget interface2 factory ptr") i1 = mc->GetService(sr3.GetReference(InterfaceType())); US_TEST_CONDITION(i1 == static_cast(&s3), "interface1 ptr") i1 = NULL; US_TEST_CONDITION(mc->UngetService(sr3.GetReference(InterfaceType())), "unget interface1 ptr") i1 = mc->GetService(sfr3.GetReference(InterfaceType())); US_TEST_CONDITION(i1 == static_cast(f3.m_idToServiceMap[mc->GetModule()->GetModuleId()]), "interface1 factory ptr") i1 = NULL; US_TEST_CONDITION(mc->UngetService(sfr3.GetReference(InterfaceType())), "unget interface1 factory ptr") i2 = mc->GetService(sr3.GetReference(InterfaceType())); US_TEST_CONDITION(i2 == static_cast(&s3), "interface2 ptr") i2 = NULL; US_TEST_CONDITION(mc->UngetService(sr3.GetReference(InterfaceType())), "unget interface2 ptr") i2 = mc->GetService(sfr3.GetReference(InterfaceType())); US_TEST_CONDITION(i2 == static_cast(f3.m_idToServiceMap[mc->GetModule()->GetModuleId()]), "interface2 factory ptr") i2 = NULL; US_TEST_CONDITION(mc->UngetService(sfr3.GetReference(InterfaceType())), "unget interface2 factory ptr") Interface3* i3 = mc->GetService(sr3.GetReference(InterfaceType())); US_TEST_CONDITION(i3 == static_cast(&s3), "interface3 ptr") i3 = NULL; US_TEST_CONDITION(mc->UngetService(sr3.GetReference(InterfaceType())), "unget interface3 ptr") i3 = mc->GetService(sfr3.GetReference(InterfaceType())); US_TEST_CONDITION(i3 == static_cast(f3.m_idToServiceMap[mc->GetModule()->GetModuleId()]), "interface3 factory ptr") i3 = NULL; US_TEST_CONDITION(mc->UngetService(sfr3.GetReference(InterfaceType())), "unget interface3 factory ptr") sr1.Unregister(); sr2.Unregister(); sr3.Unregister(); US_TEST_END() } diff --git a/Modules/CppMicroServices/core/test/usServiceTrackerTest.cpp b/Modules/CppMicroServices/core/test/usServiceTrackerTest.cpp index 7883d1cd42..9e9cd71af2 100644 --- a/Modules/CppMicroServices/core/test/usServiceTrackerTest.cpp +++ b/Modules/CppMicroServices/core/test/usServiceTrackerTest.cpp @@ -1,287 +1,287 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #include #include #include #include #include #include #include #include #include "usServiceControlInterface.h" #include US_USE_NAMESPACE bool CheckConvertibility(const std::vector& refs, std::vector::const_iterator idBegin, std::vector::const_iterator idEnd) { std::vector ids; ids.assign(idBegin, idEnd); for (std::vector::const_iterator sri = refs.begin(); sri != refs.end(); ++sri) { for (std::vector::iterator idIter = ids.begin(); idIter != ids.end(); ++idIter) { if (sri->IsConvertibleTo(*idIter)) { ids.erase(idIter); break; } } } return ids.empty(); } struct MyInterfaceOne { virtual ~MyInterfaceOne() {} }; struct MyInterfaceTwo { virtual ~MyInterfaceTwo() {} }; class MyCustomizer : public us::ServiceTrackerCustomizer { public: MyCustomizer(us::ModuleContext* context) : m_context(context) {} - virtual MyInterfaceOne* AddingService(const ServiceReferenceType& reference) + virtual MyInterfaceOne* AddingService(const ServiceReferenceType& reference) override { US_TEST_CONDITION_REQUIRED(reference, "AddingService() valid reference") return m_context->GetService(reference); } - virtual void ModifiedService(const ServiceReferenceType& reference, MyInterfaceOne* service) + virtual void ModifiedService(const ServiceReferenceType& reference, MyInterfaceOne* service) override { US_TEST_CONDITION(reference, "ModifiedService() valid reference") US_TEST_CONDITION(service, "ModifiedService() valid service") } - virtual void RemovedService(const ServiceReferenceType& reference, MyInterfaceOne* service) + virtual void RemovedService(const ServiceReferenceType& reference, MyInterfaceOne* service) override { US_TEST_CONDITION(reference, "RemovedService() valid reference") US_TEST_CONDITION(service, "RemovedService() valid service") } private: us::ModuleContext* m_context; }; void TestFilterString() { us::ModuleContext* context = us::GetModuleContext(); MyCustomizer customizer(context); us::LDAPFilter filter("(" + us::ServiceConstants::SERVICE_ID() + ">=0)"); us::ServiceTracker tracker(context, filter, &customizer); tracker.Open(); struct MyServiceOne : public MyInterfaceOne {}; struct MyServiceTwo : public MyInterfaceTwo {}; MyServiceOne serviceOne; MyServiceTwo serviceTwo; ServiceRegistration reg1 = context->RegisterService(&serviceOne); ServiceRegistration reg2 = context->RegisterService(&serviceTwo); US_TEST_CONDITION(tracker.GetServiceReferences().size() == 1, "tracking count") reg1.Unregister(); reg2.Unregister(); } void TestServiceTracker() { #ifdef US_PLATFORM_WINDOWS const std::string LIB_PATH = US_RUNTIME_OUTPUT_DIRECTORY; #else const std::string LIB_PATH = US_LIBRARY_OUTPUT_DIRECTORY; #endif ModuleContext* mc = GetModuleContext(); SharedLibrary libS(LIB_PATH, "TestModuleS"); #ifdef US_BUILD_SHARED_LIBS // Start the test target to get a service published. try { libS.Load(); } catch (const std::exception& e) { US_TEST_FAILED_MSG( << "Failed to load module, got exception: " << e.what() ); } #endif // 1. Create a ServiceTracker with ServiceTrackerCustomizer == null std::string s1("us::TestModuleSService"); ServiceReferenceU servref = mc->GetServiceReference(s1 + "0"); US_TEST_CONDITION_REQUIRED(servref != 0, "Test if registered service of id us::TestModuleSService0"); ServiceReference servCtrlRef = mc->GetServiceReference(); US_TEST_CONDITION_REQUIRED(servCtrlRef != 0, "Test if constrol service was registered"); ServiceControlInterface* serviceController = mc->GetService(servCtrlRef); US_TEST_CONDITION_REQUIRED(serviceController != 0, "Test valid service controller"); std::auto_ptr > st1(new ServiceTracker(mc, servref)); // 2. Check the size method with an unopened service tracker US_TEST_CONDITION_REQUIRED(st1->Size() == 0, "Test if size == 0"); // 3. Open the service tracker and see what it finds, // expect to find one instance of the implementation, // "org.cppmicroservices.TestModuleSService0" st1->Open(); std::vector sa2 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa2.size() == 1, "Checking ServiceTracker size"); US_TEST_CONDITION_REQUIRED(s1 + "0" == sa2[0].GetInterfaceId(), "Checking service implementation name"); // 5. Close this service tracker st1->Close(); // 6. Check the size method, now when the servicetracker is closed US_TEST_CONDITION_REQUIRED(st1->Size() == 0, "Checking ServiceTracker size"); // 7. Check if we still track anything , we should get null sa2 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa2.empty(), "Checking ServiceTracker size"); // 8. A new Servicetracker, this time with a filter for the object std::string fs = std::string("(") + ServiceConstants::OBJECTCLASS() + "=" + s1 + "*" + ")"; LDAPFilter f1(fs); st1.reset(new ServiceTracker(mc, f1)); // add a service serviceController->ServiceControl(1, "register", 7); // 9. Open the service tracker and see what it finds, // expect to find two instances of references to // "org.cppmicroservices.TestModuleSService*" // i.e. they refer to the same piece of code std::vector ids; ids.push_back((s1 + "0")); ids.push_back((s1 + "1")); ids.push_back((s1 + "2")); ids.push_back((s1 + "3")); st1->Open(); sa2 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa2.size() == 2, "Checking service reference count"); US_TEST_CONDITION_REQUIRED(CheckConvertibility(sa2, ids.begin(), ids.begin()+2), "Check for expected interface id [0]"); US_TEST_CONDITION_REQUIRED(sa2[1].IsConvertibleTo(s1 + "1"), "Check for expected interface id [1]"); // 10. Get libTestModuleS to register one more service and see if it appears serviceController->ServiceControl(2, "register", 1); sa2 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa2.size() == 3, "Checking service reference count"); US_TEST_CONDITION_REQUIRED(CheckConvertibility(sa2, ids.begin(), ids.begin()+3), "Check for expected interface id [2]"); // 11. Get libTestModuleS to register one more service and see if it appears serviceController->ServiceControl(3, "register", 2); sa2 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa2.size() == 4, "Checking service reference count"); US_TEST_CONDITION_REQUIRED(CheckConvertibility(sa2, ids.begin(), ids.end()), "Check for expected interface id [3]"); // 12. Get libTestModuleS to unregister one service and see if it disappears serviceController->ServiceControl(3, "unregister", 0); sa2 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa2.size() == 3, "Checking service reference count"); // 13. Get the highest ranking service reference, it should have ranking 7 ServiceReferenceU h1 = st1->GetServiceReference(); int rank = any_cast(h1.GetProperty(ServiceConstants::SERVICE_RANKING())); US_TEST_CONDITION_REQUIRED(rank == 7, "Check service rank"); // 14. Get the service of the highest ranked service reference InterfaceMap o1 = st1->GetService(h1); US_TEST_CONDITION_REQUIRED(!o1.empty(), "Check for non-null service"); // 14a Get the highest ranked service, directly this time InterfaceMap o3 = st1->GetService(); US_TEST_CONDITION_REQUIRED(!o3.empty(), "Check for non-null service"); US_TEST_CONDITION_REQUIRED(o1 == o3, "Check for equal service instances"); // 15. Now release the tracking of that service and then try to get it // from the servicetracker, which should yield a null object serviceController->ServiceControl(1, "unregister", 7); InterfaceMap o2 = st1->GetService(h1); US_TEST_CONDITION_REQUIRED(o2.empty(), "Checkt that service is null"); // 16. Get all service objects this tracker tracks, it should be 2 std::vector ts1 = st1->GetServices(); US_TEST_CONDITION_REQUIRED(ts1.size() == 2, "Check service count"); // 17. Test the remove method. // First register another service, then remove it being tracked serviceController->ServiceControl(1, "register", 7); h1 = st1->GetServiceReference(); std::vector sa3 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa3.size() == 3, "Check service reference count"); US_TEST_CONDITION_REQUIRED(CheckConvertibility(sa3, ids.begin(), ids.begin()+3), "Check for expected interface id [0]"); st1->Remove(h1); // remove tracking on one servref sa2 = st1->GetServiceReferences(); US_TEST_CONDITION_REQUIRED(sa2.size() == 2, "Check service reference count"); // 18. Test the addingService method,add a service reference // 19. Test the removedService method, remove a service reference // 20. Test the waitForService method InterfaceMap o9 = st1->WaitForService(50); US_TEST_CONDITION_REQUIRED(!o9.empty(), "Checking WaitForService method"); } int usServiceTrackerTest(int /*argc*/, char* /*argv*/[]) { US_TEST_BEGIN("ServiceTrackerTest") TestFilterString(); TestServiceTracker(); US_TEST_END() } diff --git a/Modules/CppMicroServices/core/test/usTestDriverActivator.h b/Modules/CppMicroServices/core/test/usTestDriverActivator.h index 30a6cc2f4e..5ef86f56c8 100644 --- a/Modules/CppMicroServices/core/test/usTestDriverActivator.h +++ b/Modules/CppMicroServices/core/test/usTestDriverActivator.h @@ -1,49 +1,49 @@ /*============================================================================= Library: CppMicroServices Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================*/ #ifndef USTESTDRIVERACTIVATOR_H #define USTESTDRIVERACTIVATOR_H #include US_BEGIN_NAMESPACE class TestDriverActivator : public ModuleActivator { public: TestDriverActivator(); static bool LoadCalled(); - void Load(ModuleContext*); + void Load(ModuleContext*) override; - void Unload(ModuleContext* ); + void Unload(ModuleContext* ) override; private: static TestDriverActivator* m_Instance; bool m_LoadCalled; }; US_END_NAMESPACE #endif // USTESTDRIVERACTIVATOR_H