diff --git a/documentation/doxygen/standalone/BuildInstructions.md b/documentation/doxygen/standalone/BuildInstructions.md
new file mode 100644
index 0000000000..8319e6bd7a
--- /dev/null
+++ b/documentation/doxygen/standalone/BuildInstructions.md
@@ -0,0 +1,59 @@
+Build Instructions {#BuildInstructions}
+==================
+
+The C++ Micro Services library provides [CMake][cmake] build scripts which allow the generation of
+platform and IDE specific project files.
+
+The library should compile on many different platforms. Below is a list of tested compiler/OS combinations:
+
+ - GCC 4.5 (Ubuntu 11.04 and MacOS X 10.6)
+ - GCC 4.7 (Ubuntu 12.10)
+ - Visual Studio 2008, 2010, and 2012
+ - Clang 3.0 (Ubuntu 12.10 and MacOS X 10.6)
+
+
+Prerequisites
+-------------
+
+- [CMake][cmake] 2.8 (Visual Studio 2010 and 2012 users should use the latest CMake version available)
+
+
+Configuring the Build
+---------------------
+
+When building the C++ Micro Services library, you have a few configuration options at hand.
+
+### General build options
+
+- **CMAKE_INSTALL_PREFIX**
+ The installation path.
+- **US_BUILD_SHARED_LIBS**
+ Specify if the library should be build shared or static. See \ref MicroServices_StaticModules
+ for detailed information about static CppMicroServices modules.
+- **US_BUILD_TESTING**
+ Build unit tests and code snippets.
+- **US_ENABLE_AUTOLOADING_SUPPORT**
+ Enable auto-loading of modules located in special sup-directories. See \ref MicroServices_AutoLoading
+ for detailed information about this feature.
+- **US_ENABLE_THREADING_SUPPORT**
+ Enable the use of synchronization primitives (atomics and pthread mutexes or Windows primitives)
+ to make the API thread-safe. If you are application is not multi-threaded, turn this option OFF
+ to get maximum performance.
+- **US_USE_C++11 (advanced)**
+ Enable the usage of C++11 constructs.
+- **US_ENABLE_RESOURCE_COMPRESSION (advanced)**
+ Enable compression of embedded resources. See \ref MicroServices_Resources for detailed information
+ about the resource system.
+
+### Customizing naming conventions
+
+- **US_NAMESPACE**
+ The default namespace is `us` but you may override this at will.
+- **US_HEADER_PREFIX**
+ By default, all public headers have a "us" prefix. You may specify an arbitrary prefix to match your
+ naming conventions.
+
+The above options are mainly useful when embedding the C++ Micro Services source code in your own library and
+you want to make it look like native source code.
+
+[cmake]: http://www.cmake.org
diff --git a/documentation/doxygen/standalone/MicroServices_GettingStarted.md b/documentation/doxygen/standalone/MicroServices_GettingStarted.md
new file mode 100644
index 0000000000..fec5a1105c
--- /dev/null
+++ b/documentation/doxygen/standalone/MicroServices_GettingStarted.md
@@ -0,0 +1,49 @@
+Getting Started {#MicroServices_GettingStarted}
+===============
+
+Projects which want to make use of the capabilities provided by the C++ Micro Services
+library need to set-up the correct include paths and link dependencies. Further, each
+executable or shared library which needs a ModuleContext instance must contain specific
+initialization code.
+
+The C++ Micro Services library provides \ref MicroServicesCMake "CMake utility functions"
+for CMake based projects but there are no restrictions on the type of build system used
+for a project.
+
+CMake based projects
+--------------------
+
+To easily set-up include paths and linker dependencies, use the common `find_package`
+mechanism provided by CMake:
+
+\dontinclude examples/CMakeLists.txt
+\skip project
+\until include_directories
+
+The CMake code above sets up a basic project (called CppMicroServicesExamples) and tries
+to find the CppMicroServices package and subsequently to set the necessary include
+directories. Building a shared library might then look like this:
+
+\dontinclude examples/dictionaryservice/CMakeLists.txt
+\until target_link
+
+The call to `#usFunctionGenerateModuleInit` generates the proper module initialization
+code and provides access to the module specific ModuleContext instance.
+
+Makefile based projects
+-----------------------
+
+The following Makefile is located at examples/makefile/Makefile and demonstrates a minimal
+build script:
+
+\include makefile/Makefile
+
+The variable `CppMicroServices_ROOT` is an environment variable and must be set to the
+CppMicroServices installation directory prior to invoking `make`. The module initialization
+code for the `libmodule.so` shared library is generated by using the `#US_INITIALIZE_MODULE`
+pre-processor macro at the end of the `module.cpp` source file (any source file compiled
+into the module would do):
+
+\dontinclude makefile/module.cpp
+\skip usModuleInitialization
+\until US_INITIALIZE_MODULE
diff --git a/documentation/snippets/CMakeLists.txt b/documentation/snippets/CMakeLists.txt
new file mode 100644
index 0000000000..5540734bb9
--- /dev/null
+++ b/documentation/snippets/CMakeLists.txt
@@ -0,0 +1,4 @@
+
+include_directories(${US_INCLUDE_DIRS})
+
+usFunctionCompileSnippets("${CMAKE_CURRENT_SOURCE_DIR}")
diff --git a/documentation/snippets/uServices-activator/main.cpp b/documentation/snippets/uServices-activator/main.cpp
new file mode 100644
index 0000000000..c4ba6c25e7
--- /dev/null
+++ b/documentation/snippets/uServices-activator/main.cpp
@@ -0,0 +1,27 @@
+#include
+
+US_USE_NAMESPACE
+
+//! [0]
+class MyActivator : public ModuleActivator
+{
+
+public:
+
+ void Load(ModuleContext* /*context*/)
+ { /* register stuff */ }
+
+
+ void Unload(ModuleContext* /*context*/)
+ { /* cleanup */ }
+
+};
+
+US_EXPORT_MODULE_ACTIVATOR(mylibname, MyActivator)
+//![0]
+
+int main(int /*argc*/, char* /*argv*/[])
+{
+ MyActivator ma;
+ return 0;
+}
diff --git a/documentation/snippets/uServices-modulecontext/main.cpp b/documentation/snippets/uServices-modulecontext/main.cpp
new file mode 100644
index 0000000000..a793f3b343
--- /dev/null
+++ b/documentation/snippets/uServices-modulecontext/main.cpp
@@ -0,0 +1,28 @@
+#include
+
+//! [GetModuleContext]
+#include
+#include
+#include
+
+US_USE_NAMESPACE
+
+void RetrieveModuleContext()
+{
+ ModuleContext* context = GetModuleContext();
+ Module* module = context->GetModule();
+ std::cout << "Module name: " << module->GetName() << " [id: " << module->GetModuleId() << "]\n";
+}
+//! [GetModuleContext]
+
+//! [InitializeModule]
+#include
+
+US_INITIALIZE_MODULE("My Module", "mylibname")
+//! [InitializeModule]
+
+int main(int /*argc*/, char* /*argv*/[])
+{
+ RetrieveModuleContext();
+ return 0;
+}
diff --git a/documentation/snippets/uServices-registration/main.cpp b/documentation/snippets/uServices-registration/main.cpp
new file mode 100644
index 0000000000..be9666e635
--- /dev/null
+++ b/documentation/snippets/uServices-registration/main.cpp
@@ -0,0 +1,119 @@
+#include
+#include
+#include
+#include
+
+US_USE_NAMESPACE
+
+
+struct InterfaceA { virtual ~InterfaceA() {} };
+struct InterfaceB { virtual ~InterfaceB() {} };
+struct InterfaceC { virtual ~InterfaceC() {} };
+
+US_DECLARE_SERVICE_INTERFACE(InterfaceA, "org.cppmicroservices.snippet.InterfaceA")
+US_DECLARE_SERVICE_INTERFACE(InterfaceB, "org.cppmicroservices.snippet.InterfaceB")
+US_DECLARE_SERVICE_INTERFACE(InterfaceC, "org.cppmicroservices.snippet.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)
+ {
+ 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*/)
+ {
+ MyService* myService = new MyService;
+ return MakeInterfaceMap(myService);
+ }
+
+ virtual void UngetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/,
+ const InterfaceMap& service)
+ {
+ 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*/)
+ {
+ MyService2* myService = new MyService2;
+ return MakeInterfaceMap(myService);
+ }
+
+ virtual void UngetService(Module* /*module*/, const ServiceRegistrationBase& /*registration*/,
+ const InterfaceMap& service)
+ {
+ 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*/)
+ { /* cleanup */ }
+
+};
+
+US_EXPORT_MODULE_ACTIVATOR(mylibname, MyActivator)
+
+int main(int /*argc*/, char* /*argv*/[])
+{
+ MyActivator ma;
+ return 0;
+}
diff --git a/documentation/snippets/uServices-resources/main.cpp b/documentation/snippets/uServices-resources/main.cpp
new file mode 100644
index 0000000000..474c344374
--- /dev/null
+++ b/documentation/snippets/uServices-resources/main.cpp
@@ -0,0 +1,86 @@
+#include
+#include
+#include
+#include
+#include
+#include
+
+US_USE_NAMESPACE
+
+void resourceExample()
+{
+ //! [1]
+ // Get this module's Module object
+ Module* module = GetModuleContext()->GetModule();
+
+ ModuleResource resource = module->GetResource("config.properties");
+ if (resource.IsValid())
+ {
+ // Create a ModuleResourceStream object
+ ModuleResourceStream resourceStream(resource);
+
+ // Read the contents line by line
+ std::string line;
+ while (std::getline(resourceStream, line))
+ {
+ // Process the content
+ std::cout << line << std::endl;
+ }
+ }
+ else
+ {
+ // Error handling
+ }
+ //! [1]
+}
+
+void parseComponentDefinition(std::istream&)
+{
+}
+
+void extenderPattern()
+{
+ //! [2]
+ // Get all loaded modules
+ std::vector modules;
+ ModuleRegistry::GetLoadedModules(modules);
+
+ // Check if a module defines a "service-component" property
+ // and use its value to retrieve an embedded resource containing
+ // a component description.
+ for(std::size_t i = 0; i < modules.size(); ++i)
+ {
+ Module* const module = modules[i];
+ std::string componentPath = module->GetProperty("service-component").ToString();
+ if (!componentPath.empty())
+ {
+ ModuleResource componentResource = module->GetResource(componentPath);
+ if (!componentResource.IsValid() || componentResource.IsDir()) continue;
+
+ // Create a std::istream compatible object and parse the
+ // component description.
+ ModuleResourceStream resStream(componentResource);
+ parseComponentDefinition(resStream);
+ }
+ }
+ //! [2]
+}
+
+int main(int /*argc*/, char* /*argv*/[])
+{
+ //! [0]
+ ModuleContext* moduleContext = GetModuleContext();
+ Module* module = moduleContext->GetModule();
+
+ // List all XML files in the config directory
+ std::vector xmlFiles = module->FindResources("config", "*.xml", false);
+
+ // Find the resource named vertex_shader.txt starting at the root directory
+ std::vector shaders = module->FindResources("", "vertex_shader.txt", true);
+ //! [0]
+
+ return 0;
+}
+
+#include
+US_INITIALIZE_EXECUTABLE("uServices-snippet-resources")
diff --git a/documentation/snippets/uServices-servicetracker/main.cpp b/documentation/snippets/uServices-servicetracker/main.cpp
new file mode 100644
index 0000000000..0c1bc68bef
--- /dev/null
+++ b/documentation/snippets/uServices-servicetracker/main.cpp
@@ -0,0 +1,110 @@
+#include
+#include
+
+US_USE_NAMESPACE
+
+struct IFooService {};
+
+US_DECLARE_SERVICE_INTERFACE(IFooService, "org.cppmicroservices.snippets.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 ServiceReferenceT&)
+ {
+ return MyTrackedClass();
+ }
+
+ virtual void ModifiedService(const ServiceReferenceT&, MyTrackedClass)
+ {
+ }
+
+ virtual void RemovedService(const ServiceReferenceT&, MyTrackedClass)
+ {
+ }
+};
+//! [customizer]
+
+struct MyTrackingPointerCustomizer : public ServiceTrackerCustomizer
+{
+ virtual MyTrackedClass* AddingService(const ServiceReferenceT&)
+ {
+ return new MyTrackedClass();
+ }
+
+ virtual void ModifiedService(const ServiceReferenceT&, MyTrackedClass*)
+ {
+ }
+
+ virtual void RemovedService(const ServiceReferenceT&, MyTrackedClass*)
+ {
+ }
+};
+
+// For compilation test purposes only
+struct MyTrackingCustomizerVoid : public ServiceTrackerCustomizer
+{
+ virtual MyTrackedClass AddingService(const ServiceReferenceT&)
+ {
+ return MyTrackedClass();
+ }
+
+ virtual void ModifiedService(const ServiceReferenceT&, MyTrackedClass)
+ {
+ }
+
+ virtual void RemovedService(const ServiceReferenceT&, MyTrackedClass)
+ {
+ }
+};
+
+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;
+ ServiceTracker tracker2(GetModuleContext(), &myCustomizer2);
+ ServiceTracker > tracker3(GetModuleContext());
+
+ return 0;
+}
+
+#include
+
+US_INITIALIZE_EXECUTABLE("uServices-modulecontext")
diff --git a/documentation/snippets/uServices-singleton/SingletonOne.cpp b/documentation/snippets/uServices-singleton/SingletonOne.cpp
new file mode 100644
index 0000000000..9380cb316d
--- /dev/null
+++ b/documentation/snippets/uServices-singleton/SingletonOne.cpp
@@ -0,0 +1,80 @@
+#include "SingletonOne.h"
+
+#include "SingletonTwo.h"
+
+#include
+#include
+
+#include
+#include
+
+US_USE_NAMESPACE
+
+//![s1]
+SingletonOne& SingletonOne::GetInstance()
+{
+ static SingletonOne instance;
+ return instance;
+}
+//![s1]
+
+SingletonOne::SingletonOne() : a(1)
+{
+}
+
+//![s1d]
+SingletonOne::~SingletonOne()
+{
+ std::cout << "SingletonTwo::b = " << SingletonTwo::GetInstance().b << std::endl;
+}
+//![s1d]
+
+//![ss1gi]
+SingletonOneService* SingletonOneService::GetInstance()
+{
+ static ServiceReference serviceRef;
+ static ModuleContext* context = GetModuleContext();
+
+ if (!serviceRef)
+ {
+ // This is either the first time GetInstance() was called,
+ // or a SingletonOneService instance has not yet been registered.
+ serviceRef = context->GetServiceReference();
+ }
+
+ if (serviceRef)
+ {
+ // We have a valid service reference. It always points to the service
+ // with the lowest id (usually the one which was registered first).
+ // This still might return a null pointer, if all SingletonOneService
+ // instances have been unregistered (during unloading of the library,
+ // for example).
+ return context->GetService(serviceRef);
+ }
+ else
+ {
+ // No SingletonOneService instance was registered yet.
+ return 0;
+ }
+}
+//![ss1gi]
+
+SingletonOneService::SingletonOneService()
+ : a(1)
+{
+ SingletonTwoService* singletonTwoService = SingletonTwoService::GetInstance();
+ assert(singletonTwoService != 0);
+ std::cout << "SingletonTwoService::b = " << singletonTwoService->b << std::endl;
+}
+
+//![ss1d]
+SingletonOneService::~SingletonOneService()
+{
+ SingletonTwoService* singletonTwoService = SingletonTwoService::GetInstance();
+
+ // The module activator must ensure that a SingletonTwoService instance is
+ // available during destruction of a SingletonOneService instance.
+ assert(singletonTwoService != 0);
+ std::cout << "SingletonTwoService::b = " << singletonTwoService->b << std::endl;
+}
+//![ss1d]
diff --git a/documentation/snippets/uServices-singleton/SingletonOne.h b/documentation/snippets/uServices-singleton/SingletonOne.h
new file mode 100644
index 0000000000..62dbf89270
--- /dev/null
+++ b/documentation/snippets/uServices-singleton/SingletonOne.h
@@ -0,0 +1,64 @@
+#ifndef SINGLETONONE_H
+#define SINGLETONONE_H
+
+#include
+#include
+#include
+#include
+
+
+//![s1]
+class SingletonOne
+{
+public:
+
+ static SingletonOne& GetInstance();
+
+ // Just some member
+ int a;
+
+private:
+
+ SingletonOne();
+ ~SingletonOne();
+
+ // Disable copy constructor and assignment operator.
+ SingletonOne(const SingletonOne&);
+ SingletonOne& operator=(const SingletonOne&);
+};
+//![s1]
+
+class SingletonTwoService;
+
+//![ss1]
+class SingletonOneService
+{
+public:
+
+ // This will return a SingletonOneService instance with the
+ // lowest service id at the time this method was called the first
+ // time and returned a non-null value (which is usually the instance
+ // which was registered first). A null-pointer is returned if no
+ // instance was registered yet.
+ static SingletonOneService* GetInstance();
+
+ int a;
+
+private:
+
+ // Only our module activator class should be able to instantiate
+ // a SingletonOneService object.
+ friend class MyActivator;
+
+ SingletonOneService();
+ ~SingletonOneService();
+
+ // Disable copy constructor and assignment operator.
+ SingletonOneService(const SingletonOneService&);
+ SingletonOneService& operator=(const SingletonOneService&);
+};
+
+US_DECLARE_SERVICE_INTERFACE(SingletonOneService, "org.cppmicroservices.snippet.SingletonOneService")
+//![ss1]
+
+#endif // SINGLETONONE_H
diff --git a/documentation/snippets/uServices-singleton/SingletonTwo.cpp b/documentation/snippets/uServices-singleton/SingletonTwo.cpp
new file mode 100644
index 0000000000..db18f6ae01
--- /dev/null
+++ b/documentation/snippets/uServices-singleton/SingletonTwo.cpp
@@ -0,0 +1,64 @@
+#include "SingletonTwo.h"
+
+#include "SingletonOne.h"
+#include
+
+#include
+#include
+
+US_USE_NAMESPACE
+
+SingletonTwo& SingletonTwo::GetInstance()
+{
+ static SingletonTwo instance;
+ return instance;
+}
+
+SingletonTwo::SingletonTwo() : b(2)
+{
+ std::cout << "Constructing SingletonTwo" << std::endl;
+}
+
+SingletonTwo::~SingletonTwo()
+{
+ std::cout << "Deleting SingletonTwo" << std::endl;
+ std::cout << "SingletonOne::a = " << SingletonOne::GetInstance().a << std::endl;
+}
+
+SingletonTwoService* SingletonTwoService::GetInstance()
+{
+ static ServiceReference serviceRef;
+ static ModuleContext* context = GetModuleContext();
+
+ if (!serviceRef)
+ {
+ // This is either the first time GetInstance() was called,
+ // or a SingletonTwoService instance has not yet been registered.
+ serviceRef = context->GetServiceReference();
+ }
+
+ if (serviceRef)
+ {
+ // We have a valid service reference. It always points to the service
+ // with the lowest id (usually the one which was registered first).
+ // This still might return a null pointer, if all SingletonTwoService
+ // instances have been unregistered (during unloading of the library,
+ // for example).
+ return context->GetService(serviceRef);
+ }
+ else
+ {
+ // No SingletonTwoService instance was registered yet.
+ return 0;
+ }
+}
+
+SingletonTwoService::SingletonTwoService() : b(2)
+{
+ std::cout << "Constructing SingletonTwoService" << std::endl;
+}
+
+SingletonTwoService::~SingletonTwoService()
+{
+ std::cout << "Deleting SingletonTwoService" << std::endl;
+}
diff --git a/documentation/snippets/uServices-singleton/SingletonTwo.h b/documentation/snippets/uServices-singleton/SingletonTwo.h
new file mode 100644
index 0000000000..9eb8e2b36b
--- /dev/null
+++ b/documentation/snippets/uServices-singleton/SingletonTwo.h
@@ -0,0 +1,48 @@
+#ifndef SINGLETONTWO_H
+#define SINGLETONTWO_H
+
+#include
+#include
+
+
+class SingletonTwo
+{
+public:
+
+ static SingletonTwo& GetInstance();
+
+ int b;
+
+private:
+
+ SingletonTwo();
+ ~SingletonTwo();
+
+ // Disable copy constructor and assignment operator.
+ SingletonTwo(const SingletonTwo&);
+ SingletonTwo& operator=(const SingletonTwo&);
+};
+
+class SingletonTwoService
+{
+public:
+
+ static SingletonTwoService* GetInstance();
+
+ int b;
+
+private:
+
+ friend class MyActivator;
+
+ SingletonTwoService();
+ ~SingletonTwoService();
+
+ // Disable copy constructor and assignment operator.
+ SingletonTwoService(const SingletonTwoService&);
+ SingletonTwoService& operator=(const SingletonTwoService&);
+};
+
+US_DECLARE_SERVICE_INTERFACE(SingletonTwoService, "org.cppmicroservices.snippet.SingletonTwoService")
+
+#endif // SINGLETONTWO_H
diff --git a/documentation/snippets/uServices-singleton/files.cmake b/documentation/snippets/uServices-singleton/files.cmake
new file mode 100644
index 0000000000..7de7f5c5ad
--- /dev/null
+++ b/documentation/snippets/uServices-singleton/files.cmake
@@ -0,0 +1,10 @@
+
+set(snippet_src_files
+ main.cpp
+ SingletonOne.cpp
+ SingletonTwo.cpp
+)
+
+usFunctionGenerateExecutableInit(snippet_src_files
+ IDENTIFIER "uServices_singleton"
+ )
diff --git a/documentation/snippets/uServices-singleton/main.cpp b/documentation/snippets/uServices-singleton/main.cpp
new file mode 100644
index 0000000000..9980ee1f53
--- /dev/null
+++ b/documentation/snippets/uServices-singleton/main.cpp
@@ -0,0 +1,69 @@
+#include
+#include
+#include
+
+#include "SingletonOne.h"
+#include "SingletonTwo.h"
+
+US_USE_NAMESPACE
+
+class MyActivator : public ModuleActivator
+{
+
+public:
+
+ //![0]
+ void Load(ModuleContext* context)
+ {
+ // 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*/)
+ {
+ // 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(uServices_singleton, MyActivator)
+
+int main()
+{
+}
diff --git a/documentation/snippets/uServices-staticmodules/MyStaticModule.cpp b/documentation/snippets/uServices-staticmodules/MyStaticModule.cpp
new file mode 100644
index 0000000000..2984c93702
--- /dev/null
+++ b/documentation/snippets/uServices-staticmodules/MyStaticModule.cpp
@@ -0,0 +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*/)
+ {
+ std::cout << "Hello from a static module." << std::endl;
+ }
+
+ void Unload(ModuleContext* /*context*/) {}
+};
+
+US_EXPORT_MODULE_ACTIVATOR(MyStaticModule, MyStaticModuleActivator)
+
+US_INITIALIZE_MODULE("My Static Module", "MyStaticModule")
diff --git a/documentation/snippets/uServices-staticmodules/files.cmake b/documentation/snippets/uServices-staticmodules/files.cmake
new file mode 100644
index 0000000000..2bf4c05a4b
--- /dev/null
+++ b/documentation/snippets/uServices-staticmodules/files.cmake
@@ -0,0 +1,11 @@
+set(snippet_src_files
+ main.cpp
+)
+
+set(base_dir uServices-staticmodules)
+add_library(MyStaticModule STATIC ${base_dir}/MyStaticModule.cpp)
+set_property(TARGET MyStaticModule APPEND PROPERTY COMPILE_DEFINITIONS US_STATIC_MODULE)
+
+set(snippet_link_libraries
+ MyStaticModule
+)
diff --git a/documentation/snippets/uServices-staticmodules/main.cpp b/documentation/snippets/uServices-staticmodules/main.cpp
new file mode 100644
index 0000000000..e78d3a64c4
--- /dev/null
+++ b/documentation/snippets/uServices-staticmodules/main.cpp
@@ -0,0 +1,34 @@
+#include
+
+US_USE_NAMESPACE
+
+//! [ImportStaticModuleIntoLib]
+#include
+
+US_IMPORT_MODULE(MyStaticModule)
+US_LOAD_IMPORTED_MODULES(HostingModule, MyStaticModule)
+//! [ImportStaticModuleIntoLib]
+
+// This is just for illustration purposes in code snippets
+extern "C" ModuleActivator* _us_module_activator_instance_MyStaticModule1() { return NULL; }
+extern "C" ModuleActivator* _us_module_activator_instance_MyStaticModule2() { return NULL; }
+extern "C" ModuleActivator* _us_init_resources_MyStaticModule2() { return NULL; }
+
+//! [ImportStaticModuleIntoMain]
+#include
+
+US_IMPORT_MODULE(MyStaticModule1)
+US_IMPORT_MODULE(MyStaticModule2)
+US_IMPORT_MODULE_RESOURCES(MyStaticModule2)
+US_LOAD_IMPORTED_MODULES_INTO_MAIN(MyStaticModule1 MyStaticModule2)
+//! [ImportStaticModuleIntoMain]
+
+int main(int /*argc*/, char* /*argv*/[])
+{
+ return 0;
+}
+
+//! [InitializeExecutable]
+#include
+US_INITIALIZE_EXECUTABLE("MyExecutable")
+//! [InitializeExecutable]
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000000..745bd869c3
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,137 @@
+project(CppMicroServicesExamples)
+
+cmake_minimum_required(VERSION 2.8)
+
+find_package(CppMicroServices NO_MODULE REQUIRED)
+
+include_directories(${CppMicroServices_INCLUDE_DIRS})
+
+#-----------------------------------------------------------------------------
+# Set C/CXX flags
+#-----------------------------------------------------------------------------
+
+if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CppMicroServices_CXX_FLAGS}")
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CppMicroServices_CXX_FLAGS_RELEASE}")
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CppMicroServices_CXX_FLAGS_DEBUG}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CppMicroServices_C_FLAGS}")
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CppMicroServices_C_FLAGS_RELEASE}")
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CppMicroServices_C_FLAGS_DEBUG}")
+endif()
+
+#-----------------------------------------------------------------------------
+# Init output directories
+#-----------------------------------------------------------------------------
+
+set(CppMicroServicesExamples_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
+set(CppMicroServicesExamples_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
+set(CppMicroServicesExamples_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
+
+foreach(_type ARCHIVE LIBRARY RUNTIME)
+ if(NOT CMAKE_${_type}_OUTPUT_DIRECTORY)
+ set(CMAKE_${_type}_OUTPUT_DIRECTORY ${CppMicroServicesExamples_${_type}_OUTPUT_DIRECTORY})
+ endif()
+endforeach()
+
+
+function(CreateExample _name)
+ add_library(Example-${_name} SHARED ${ARGN})
+ if(${_name}_DEPENDS)
+ foreach(_dep ${${_name}_DEPENDS})
+ include_directories(${CppMicroServicesExamples_SOURCE_DIR}/${_dep})
+ target_link_libraries(Example-${_name} Example-${_dep})
+ endforeach()
+ endif()
+ target_link_libraries(Example-${_name} ${CppMicroServices_LIBRARIES})
+ set_target_properties(Example-${_name} PROPERTIES
+ LABELS Examples
+ OUTPUT_NAME ${_name}
+ )
+endfunction()
+
+add_subdirectory(eventlistener)
+add_subdirectory(dictionaryservice)
+add_subdirectory(frenchdictionary)
+add_subdirectory(dictionaryclient)
+add_subdirectory(dictionaryclient2)
+add_subdirectory(dictionaryclient3)
+add_subdirectory(spellcheckservice)
+add_subdirectory(spellcheckclient)
+add_subdirectory(driver)
+
+#-----------------------------------------------------------------------------
+# Test if examples compile against an install tree and if the
+# Makefile example compiles
+#-----------------------------------------------------------------------------
+
+if(US_BUILD_TESTING)
+ enable_testing()
+
+ set(_example_tests )
+
+ set(_install_dir "${CppMicroServices_BINARY_DIR}/install_test/${CMAKE_INSTALL_PREFIX}")
+
+ add_test(NAME usInstallCleanTest
+ COMMAND ${CMAKE_COMMAND} -E remove_directory "${_install_dir}")
+
+ add_test(NAME usInstallTest
+ WORKING_DIRECTORY ${CppMicroServices_BINARY_DIR}
+ COMMAND ${CMAKE_COMMAND} --build ${CppMicroServices_BINARY_DIR} --target install)
+ set_tests_properties(usInstallTest PROPERTIES
+ ENVIRONMENT "DESTDIR=${CppMicroServices_BINARY_DIR}/install_test"
+ DEPENDS usInstallCleanTest)
+
+ set(_examples_binary_dir "${CppMicroServices_BINARY_DIR}/examples_build")
+
+ add_test(NAME usExamplesCleanTest
+ COMMAND ${CMAKE_COMMAND} -E remove_directory "${_examples_binary_dir}")
+
+ add_test(NAME usExamplesCreateDirTest
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${_examples_binary_dir}")
+ set_tests_properties(usExamplesCreateDirTest PROPERTIES
+ DEPENDS usExamplesCleanTest)
+
+ add_test(NAME usExamplesConfigureTest
+ WORKING_DIRECTORY ${_examples_binary_dir}
+ COMMAND ${CMAKE_COMMAND}
+ -G ${CMAKE_GENERATOR}
+ -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+ "-DCppMicroServices_DIR:PATH=${_install_dir}/${CONFIG_CMAKE_DIR}"
+ "${CMAKE_CURRENT_LIST_DIR}")
+ set_tests_properties(usExamplesConfigureTest PROPERTIES
+ DEPENDS "usInstallTest;usExamplesCreateDirTest")
+
+ add_test(NAME usExamplesBuildTest
+ WORKING_DIRECTORY ${_examples_binary_dir}
+ COMMAND ${CMAKE_COMMAND} --build .)
+ set_tests_properties(usExamplesBuildTest PROPERTIES
+ DEPENDS usExamplesConfigureTest)
+
+ list(APPEND _example_tests usInstallCleanTest usInstallTest usExamplesCleanTest
+ usExamplesCreateDirTest usExamplesConfigureTest usExamplesBuildTest)
+
+ # The makefile is Linux specific, so only try to build the Makefile example
+ # if we are on a proper system
+ if(UNIX AND NOT APPLE)
+ find_program(MAKE_COMMAND NAMES make gmake)
+ find_program(CXX_COMMAND NAMES g++)
+ mark_as_advanced(MAKE_COMMAND CXX_COMMAND)
+ if(MAKE_COMMAND AND CXX_COMMAND)
+ add_test(NAME usMakefileExampleCleanTest
+ WORKING_DIRECTORY ${CppMicroServices_SOURCE_DIR}/examples/makefile
+ COMMAND ${MAKE_COMMAND} clean)
+ add_test(NAME usMakefileExampleTest
+ WORKING_DIRECTORY ${CppMicroServices_SOURCE_DIR}/examples/makefile
+ COMMAND ${MAKE_COMMAND})
+ set_tests_properties(usMakefileExampleTest PROPERTIES
+ DEPENDS "usMakefileExampleCleanTest;usInstallTest"
+ ENVIRONMENT "CppMicroServices_ROOT=${CppMicroServices_BINARY_DIR}/install_test${CMAKE_INSTALL_PREFIX};CppMicroServices_CXX_FLAGS=${CppMicroServices_CXX_FLAGS}")
+ list(APPEND _example_tests usMakefileExampleCleanTest usMakefileExampleTest)
+ endif()
+ endif()
+
+ if(US_TEST_LABELS)
+ set_tests_properties(${_example_tests} PROPERTIES LABELS "${US_TEST_LABELS}")
+ endif()
+
+endif()
diff --git a/examples/dictionaryclient/Activator.cpp b/examples/dictionaryclient/Activator.cpp
new file mode 100644
index 0000000000..fc3d47f37d
--- /dev/null
+++ b/examples/dictionaryclient/Activator.cpp
@@ -0,0 +1,117 @@
+/*=============================================================================
+
+ 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.
+
+=============================================================================*/
+
+//! [Activator]
+#include "IDictionaryService.h"
+
+#include
+#include
+
+US_USE_NAMESPACE
+
+/**
+ * This class implements a module activator that uses a dictionary service to check for
+ * the proper spelling of a word by check for its existence in the dictionary.
+ * This modules uses the first service that it finds and does not monitor the
+ * dynamic availability of the service (i.e., it does not listen for the arrival
+ * or departure of dictionary services). When loading this module, the thread
+ * calling the Load() method is used to read words from standard input. You can
+ * stop checking words by entering an empty line, but to start checking words
+ * again you must unload and then load the module again.
+ */
+class US_ABI_LOCAL Activator : public ModuleActivator
+{
+
+public:
+
+ /**
+ * Implements ModuleActivator::Load(). Queries for all available dictionary
+ * services. If none are found it simply prints a message and returns,
+ * otherwise it reads words from standard input and checks for their
+ * existence from the first dictionary that it finds.
+ *
+ * \note It is very bad practice to use the calling thread to perform a lengthy
+ * process like this; this is only done for the purpose of the tutorial.
+ *
+ * @param context the module context for this module.
+ */
+ void Load(ModuleContext *context)
+ {
+ // Query for all service references matching any language.
+ std::vector > refs =
+ context->GetServiceReferences("(Language=*)");
+
+ if (!refs.empty())
+ {
+ std::cout << "Enter a blank line to exit." << std::endl;
+
+ // Loop endlessly until the user enters a blank line
+ while (std::cin)
+ {
+ // Ask the user to enter a word.
+ std::cout << "Enter word: ";
+
+ std::string word;
+ std::getline(std::cin, word);
+
+ // If the user entered a blank line, then
+ // exit the loop.
+ if (word.empty())
+ {
+ break;
+ }
+
+ // First, get a dictionary service and then check
+ // if the word is correct.
+ IDictionaryService* dictionary = context->GetService(refs.front());
+ if ( dictionary->CheckWord( word ) )
+ {
+ std::cout << "Correct." << std::endl;
+ }
+ else
+ {
+ std::cout << "Incorrect." << std::endl;
+ }
+
+ // Unget the dictionary service.
+ context->UngetService(refs.front());
+ }
+ }
+ else
+ {
+ std::cout << "Couldn't find any dictionary service..." << std::endl;
+ }
+ }
+
+ /**
+ * Implements ModuleActivator::Unload(). Does nothing since
+ * the C++ Micro Services library will automatically unget any used services.
+ * @param context the context for the module.
+ */
+ void Unload(ModuleContext* /*context*/)
+ {
+ // NOTE: The service is automatically released.
+ }
+
+};
+
+US_EXPORT_MODULE_ACTIVATOR(dictionaryclient, Activator)
+//![Activator]
diff --git a/examples/dictionaryclient/CMakeLists.txt b/examples/dictionaryclient/CMakeLists.txt
new file mode 100644
index 0000000000..bd610a3686
--- /dev/null
+++ b/examples/dictionaryclient/CMakeLists.txt
@@ -0,0 +1,8 @@
+set(_srcs Activator.cpp)
+
+usFunctionGenerateModuleInit(_srcs
+ NAME "Dictionary Client"
+ LIBRARY_NAME "dictionaryclient")
+
+set(dictionaryclient_DEPENDS dictionaryservice)
+CreateExample(dictionaryclient ${_srcs})
diff --git a/examples/dictionaryclient2/Activator.cpp b/examples/dictionaryclient2/Activator.cpp
new file mode 100644
index 0000000000..28d2e14276
--- /dev/null
+++ b/examples/dictionaryclient2/Activator.cpp
@@ -0,0 +1,214 @@
+/*=============================================================================
+
+ 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.
+
+=============================================================================*/
+
+//! [Activator]
+#include "IDictionaryService.h"
+
+#include
+#include
+
+US_USE_NAMESPACE
+
+/**
+ * This class implements a module activator that uses a dictionary service to check for
+ * the proper spelling of a word by checking for its existence in the
+ * dictionary. This module is more complex than the module in Example 3 because
+ * it monitors the dynamic availability of the dictionary services. In other
+ * words, if the service it is using departs, then it stops using it gracefully,
+ * or if it needs a service and one arrives, then it starts using it
+ * automatically. As before, the module uses the first service that it finds and
+ * uses the calling thread of the Load() method to read words from standard
+ * input. You can stop checking words by entering an empty line, but to start
+ * checking words again you must unload and then load the module again.
+ */
+class US_ABI_LOCAL Activator : public ModuleActivator
+{
+
+public:
+
+ Activator()
+ : m_context(NULL)
+ , m_dictionary(NULL)
+ {}
+
+ /**
+ * Implements ModuleActivator::Load(). Adds itself as a listener for service
+ * events, then queries for available dictionary services. If any
+ * dictionaries are found it gets a reference to the first one available and
+ * then starts its "word checking loop". If no dictionaries are found, then
+ * it just goes directly into its "word checking loop", but it will not be
+ * able to check any words until a dictionary service arrives; any arriving
+ * dictionary service will be automatically used by the client if a
+ * dictionary is not already in use. Once it has dictionary, it reads words
+ * from standard input and checks for their existence in the dictionary that
+ * it is using.
+ *
+ * \note It is very bad practice to use the calling thread to perform a
+ * lengthy process like this; this is only done for the purpose of
+ * the tutorial.
+ *
+ * @param context the module context for this module.
+ */
+ void Load(ModuleContext *context)
+ {
+ m_context = context;
+
+ {
+ // Use your favorite thread library to synchronize member
+ // variable access within this scope while registering
+ // the service listener and performing our initial
+ // dictionary service lookup since we
+ // don't want to receive service events when looking up the
+ // dictionary service, if one exists.
+ // MutexLocker lock(&m_mutex);
+
+ // Listen for events pertaining to dictionary services.
+ m_context->AddServiceListener(this, &Activator::ServiceChanged,
+ std::string("(&(") + ServiceConstants::OBJECTCLASS() + "=" +
+ us_service_interface_iid() + ")" + "(Language=*))");
+
+ // Query for any service references matching any language.
+ std::vector > refs =
+ context->GetServiceReferences("(Language=*)");
+
+ // If we found any dictionary services, then just get
+ // a reference to the first one so we can use it.
+ if (!refs.empty())
+ {
+ m_ref = refs.front();
+ m_dictionary = m_context->GetService(m_ref);
+ }
+ }
+
+ std::cout << "Enter a blank line to exit." << std::endl;
+
+ // Loop endlessly until the user enters a blank line
+ while (std::cin)
+ {
+ // Ask the user to enter a word.
+ std::cout << "Enter word: ";
+
+ std::string word;
+ std::getline(std::cin, word);
+
+ // If the user entered a blank line, then
+ // exit the loop.
+ if (word.empty())
+ {
+ break;
+ }
+ // If there is no dictionary, then say so.
+ else if (m_dictionary == NULL)
+ {
+ std::cout << "No dictionary available." << std::endl;
+ }
+ // Otherwise print whether the word is correct or not.
+ else if (m_dictionary->CheckWord( word ))
+ {
+ std::cout << "Correct." << std::endl;
+ }
+ else
+ {
+ std::cout << "Incorrect." << std::endl;
+ }
+ }
+ }
+
+ /**
+ * Implements ModuleActivator::Unload(). Does nothing since
+ * the C++ Micro Services library will automatically unget any used services.
+ * @param context the context for the module.
+ */
+ void Unload(ModuleContext* /*context*/)
+ {
+ // NOTE: The service is automatically released.
+ }
+
+ /**
+ * Implements ServiceListener.serviceChanged(). Checks to see if the service
+ * we are using is leaving or tries to get a service if we need one.
+ *
+ * @param event the fired service event.
+ */
+ void ServiceChanged(const ServiceEvent event)
+ {
+ // Use your favorite thread library to synchronize this
+ // method with the Load() method.
+ // MutexLocker lock(&m_mutex);
+
+ // If a dictionary service was registered, see if we
+ // need one. If so, get a reference to it.
+ if (event.GetType() == ServiceEvent::REGISTERED)
+ {
+ if (!m_ref)
+ {
+ // Get a reference to the service object.
+ m_ref = event.GetServiceReference();
+ m_dictionary = m_context->GetService(m_ref);
+ }
+ }
+ // If a dictionary service was unregistered, see if it
+ // was the one we were using. If so, unget the service
+ // and try to query to get another one.
+ else if (event.GetType() == ServiceEvent::UNREGISTERING)
+ {
+ if (event.GetServiceReference() == m_ref)
+ {
+ // Unget service object and null references.
+ m_context->UngetService(m_ref);
+ m_ref = 0;
+ m_dictionary = NULL;
+
+ // Query to see if we can get another service.
+ std::vector > refs;
+ try
+ {
+ refs = m_context->GetServiceReferences("(Language=*)");
+ }
+ catch (const std::invalid_argument& e)
+ {
+ std::cout << e.what() << std::endl;
+ }
+
+ if (!refs.empty())
+ {
+ // Get a reference to the first service object.
+ m_ref = refs.front();
+ m_dictionary = m_context->GetService(m_ref);
+ }
+ }
+ }
+ }
+
+private:
+
+ // Module context
+ ModuleContext* m_context;
+
+ // The service reference being used
+ ServiceReference m_ref;
+
+ // The service object being used
+ IDictionaryService* m_dictionary;
+};
+
+US_EXPORT_MODULE_ACTIVATOR(dictionaryclient2, Activator)
+//![Activator]
diff --git a/examples/dictionaryclient2/CMakeLists.txt b/examples/dictionaryclient2/CMakeLists.txt
new file mode 100644
index 0000000000..7e7524a088
--- /dev/null
+++ b/examples/dictionaryclient2/CMakeLists.txt
@@ -0,0 +1,8 @@
+set(_srcs Activator.cpp)
+
+usFunctionGenerateModuleInit(_srcs
+ NAME "Dictionary Client 2"
+ LIBRARY_NAME "dictionaryclient2")
+
+set(dictionaryclient2_DEPENDS dictionaryservice)
+CreateExample(dictionaryclient2 ${_srcs})
diff --git a/examples/dictionaryclient3/Activator.cpp b/examples/dictionaryclient3/Activator.cpp
new file mode 100644
index 0000000000..a97524435b
--- /dev/null
+++ b/examples/dictionaryclient3/Activator.cpp
@@ -0,0 +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.
+
+=============================================================================*/
+
+//! [Activator]
+#include "IDictionaryService.h"
+
+#include
+#include
+#include
+
+US_USE_NAMESPACE
+
+/**
+ * This class implements a module activator that uses a dictionary
+ * service to check for the proper spelling of a word by
+ * checking for its existence in the dictionary. This module
+ * uses a service tracker to dynamically monitor the availability
+ * of a dictionary service, instead of providing a custom service
+ * listener as in Example 4. The module uses the service returned
+ * by the service tracker, which is selected based on a ranking
+ * algorithm defined by the C++ Micro Services library.
+ * Again, the calling thread of the Load() method is used to read
+ * words from standard input, checking its existence in the dictionary.
+ * You can stop checking words by entering an empty line, but
+ * to start checking words again you must unload and then load
+ * the module again.
+ */
+class US_ABI_LOCAL Activator : public ModuleActivator
+{
+
+public:
+
+ Activator()
+ : m_context(NULL)
+ , m_tracker(NULL)
+ {}
+
+ /**
+ * Implements ModuleActivator::Load(). Creates a service
+ * tracker to monitor dictionary services and starts its "word
+ * checking loop". It will not be able to check any words until
+ * the service tracker finds a dictionary service; any discovered
+ * dictionary service will be automatically used by the client.
+ * It reads words from standard input and checks for their
+ * existence in the discovered dictionary.
+ *
+ * \note It is very bad practice to use the calling thread to perform a
+ * lengthy process like this; this is only done for the purpose of
+ * the tutorial.
+ *
+ * @param context the module context for this module.
+ */
+ void Load(ModuleContext *context)
+ {
+ m_context = context;
+
+ // Create a service tracker to monitor dictionary services.
+ m_tracker = new ServiceTracker(
+ m_context, LDAPFilter(std::string("(&(") + ServiceConstants::OBJECTCLASS() + "=" +
+ us_service_interface_iid() + ")" +
+ "(Language=*))")
+ );
+ m_tracker->Open();
+
+ std::cout << "Enter a blank line to exit." << std::endl;
+
+ // Loop endlessly until the user enters a blank line
+ while (std::cin)
+ {
+ // Ask the user to enter a word.
+ std::cout << "Enter word: ";
+
+ std::string word;
+ std::getline(std::cin, word);
+
+ // Get the selected dictionary, if available.
+ IDictionaryService* dictionary = m_tracker->GetService();
+
+ // If the user entered a blank line, then
+ // exit the loop.
+ if (word.empty())
+ {
+ break;
+ }
+ // If there is no dictionary, then say so.
+ else if (dictionary == NULL)
+ {
+ std::cout << "No dictionary available." << std::endl;
+ }
+ // Otherwise print whether the word is correct or not.
+ else if (dictionary->CheckWord(word))
+ {
+ std::cout << "Correct." << std::endl;
+ }
+ else
+ {
+ std::cout << "Incorrect." << std::endl;
+ }
+ }
+
+ // This automatically closes the tracker
+ delete m_tracker;
+ }
+
+ /**
+ * Implements ModuleActivator::Unload(). Does nothing since
+ * the C++ Micro Services library will automatically unget any used services.
+ * @param context the context for the module.
+ */
+ void Unload(ModuleContext* /*context*/)
+ {
+ }
+
+private:
+
+ // Module context
+ ModuleContext* m_context;
+
+ // The service tracker
+ ServiceTracker* m_tracker;
+};
+
+US_EXPORT_MODULE_ACTIVATOR(dictionaryclient3, Activator)
+//![Activator]
diff --git a/examples/dictionaryclient3/CMakeLists.txt b/examples/dictionaryclient3/CMakeLists.txt
new file mode 100644
index 0000000000..44984fbd6e
--- /dev/null
+++ b/examples/dictionaryclient3/CMakeLists.txt
@@ -0,0 +1,8 @@
+set(_srcs Activator.cpp)
+
+usFunctionGenerateModuleInit(_srcs
+ NAME "Dictionary Client 3"
+ LIBRARY_NAME "dictionaryclient3")
+
+set(dictionaryclient3_DEPENDS dictionaryservice)
+CreateExample(dictionaryclient3 ${_srcs})
diff --git a/examples/dictionaryservice/Activator.cpp b/examples/dictionaryservice/Activator.cpp
new file mode 100644
index 0000000000..a7289f7a42
--- /dev/null
+++ b/examples/dictionaryservice/Activator.cpp
@@ -0,0 +1,116 @@
+/*=============================================================================
+
+ 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.
+
+=============================================================================*/
+
+//! [Activator]
+#include "IDictionaryService.h"
+
+#include
+#include
+#include
+
+#include
+#include
+
+US_USE_NAMESPACE
+
+/**
+ * This class implements a module activator that uses the module
+ * context to register an English language dictionary service
+ * with the C++ Micro Services registry during static initialization
+ * of the module. The dictionary service interface is
+ * defined in a separate file and is implemented by a nested class.
+ */
+class US_ABI_LOCAL Activator : public ModuleActivator
+{
+
+private:
+
+ /**
+ * A private inner class that implements a dictionary service;
+ * see IDictionaryService for details of the service.
+ */
+ class DictionaryImpl : public IDictionaryService
+ {
+ // The set of words contained in the dictionary.
+ std::set m_dictionary;
+
+ public:
+
+ DictionaryImpl()
+ {
+ m_dictionary.insert("welcome");
+ m_dictionary.insert("to");
+ m_dictionary.insert("the");
+ m_dictionary.insert("micro");
+ m_dictionary.insert("services");
+ m_dictionary.insert("tutorial");
+ }
+
+ /**
+ * Implements IDictionaryService::CheckWord(). Determines
+ * if the passed in word is contained in the dictionary.
+ * @param word the word to be checked.
+ * @return true if the word is in the dictionary,
+ * false otherwise.
+ **/
+ bool CheckWord(const std::string& word)
+ {
+ std::string lword(word);
+ std::transform(lword.begin(), lword.end(), lword.begin(), ::tolower);
+
+ return m_dictionary.find(lword) != m_dictionary.end();
+ }
+ };
+
+ std::auto_ptr m_dictionaryService;
+
+
+public:
+
+ /**
+ * Implements ModuleActivator::Load(). Registers an
+ * instance of a dictionary service using the module context;
+ * attaches properties to the service that can be queried
+ * when performing a service look-up.
+ * @param context the context for the module.
+ */
+ void Load(ModuleContext* context)
+ {
+ m_dictionaryService.reset(new DictionaryImpl);
+ ServiceProperties props;
+ props["Language"] = std::string("English");
+ context->RegisterService(m_dictionaryService.get(), props);
+ }
+
+ /**
+ * Implements ModuleActivator::Unload(). Does nothing since
+ * the C++ Micro Services library will automatically unregister any registered services.
+ * @param context the context for the module.
+ */
+ void Unload(ModuleContext* /*context*/)
+ {
+ // NOTE: The service is automatically unregistered
+ }
+
+};
+
+US_EXPORT_MODULE_ACTIVATOR(dictionaryservice, Activator)
+//![Activator]
diff --git a/examples/dictionaryservice/CMakeLists.txt b/examples/dictionaryservice/CMakeLists.txt
new file mode 100644
index 0000000000..ae21e3b14c
--- /dev/null
+++ b/examples/dictionaryservice/CMakeLists.txt
@@ -0,0 +1,26 @@
+# The library name for the module
+set(_lib_name dictionaryservice)
+
+# A list of source code files
+set(_srcs
+ Activator.cpp
+ IDictionaryService.cpp
+)
+
+# Generate module initialization code
+usFunctionGenerateModuleInit(_srcs
+ NAME "Dictionary Service"
+ LIBRARY_NAME ${_lib_name})
+
+# Create the library
+add_library(Example-${_lib_name} SHARED ${_srcs})
+
+# Link the CppMicroServices library
+target_link_libraries(Example-${_lib_name} ${CppMicroServices_LIBRARIES})
+
+set_target_properties(Example-${_lib_name} PROPERTIES
+ LABELS Examples
+ OUTPUT_NAME ${_lib_name}
+)
+
+#CreateExample(dictionaryservice ${_srcs})
diff --git a/examples/dictionaryservice/IDictionaryService.cpp b/examples/dictionaryservice/IDictionaryService.cpp
new file mode 100644
index 0000000000..ef0ba43dcb
--- /dev/null
+++ b/examples/dictionaryservice/IDictionaryService.cpp
@@ -0,0 +1,25 @@
+/*=============================================================================
+
+ 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 "IDictionaryService.h"
+
+IDictionaryService::~IDictionaryService()
+{}
diff --git a/examples/dictionaryservice/IDictionaryService.h b/examples/dictionaryservice/IDictionaryService.h
new file mode 100644
index 0000000000..df806d843f
--- /dev/null
+++ b/examples/dictionaryservice/IDictionaryService.h
@@ -0,0 +1,58 @@
+/*=============================================================================
+
+ 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 IDICTIONARYSERVICE_H
+#define IDICTIONARYSERVICE_H
+
+//! [service]
+#include
+
+#include
+
+#ifdef Example_dictionaryservice_EXPORTS
+ #define DICTIONAYSERVICE_EXPORT US_ABI_EXPORT
+#else
+ #define DICTIONAYSERVICE_EXPORT US_ABI_IMPORT
+#endif
+
+/**
+ * A simple service interface that defines a dictionary service.
+ * A dictionary service simply verifies the existence of a word.
+ **/
+struct DICTIONAYSERVICE_EXPORT IDictionaryService
+{
+ // Out-of-line virtual desctructor for proper dynamic cast
+ // support with older versions of gcc.
+ virtual ~IDictionaryService();
+
+ /**
+ * Check for the existence of a word.
+ * @param word the word to be checked.
+ * @return true if the word is in the dictionary,
+ * false otherwise.
+ **/
+ virtual bool CheckWord(const std::string& word) = 0;
+};
+
+US_DECLARE_SERVICE_INTERFACE(IDictionaryService, "IDictionaryService/1.0")
+//! [service]
+
+#endif // DICTIONARYSERVICE_H
diff --git a/examples/driver/CMakeLists.txt b/examples/driver/CMakeLists.txt
new file mode 100644
index 0000000000..f37d796a46
--- /dev/null
+++ b/examples/driver/CMakeLists.txt
@@ -0,0 +1,16 @@
+
+if(WIN32)
+ string(REPLACE "/" "\\\\" CMAKE_LIBRARY_OUTPUT_DIRECTORY_NATIVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
+ string(REPLACE "/" "\\\\" CMAKE_RUNTIME_OUTPUT_DIRECTORY_NATIVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+else()
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_NATIVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_NATIVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
+endif()
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/usCppMicroServicesExampleDriverConfig.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/usCppMicroServicesExampleDriverConfig.h)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+add_executable(CppMicroServicesExampleDriver main.cpp)
+target_link_libraries(CppMicroServicesExampleDriver ${CppMicroServices_LIBRARIES})
diff --git a/examples/driver/main.cpp b/examples/driver/main.cpp
new file mode 100644
index 0000000000..f4dcfa7649
--- /dev/null
+++ b/examples/driver/main.cpp
@@ -0,0 +1,300 @@
+/*=============================================================================
+
+ 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 "usCppMicroServicesExampleDriverConfig.h"
+
+#if defined(US_PLATFORM_POSIX)
+ #include
+#elif defined(US_PLATFORM_WINDOWS)
+ #ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+ #endif
+ #include
+ #include
+#else
+ #error Unsupported platform
+#endif
+
+#include
+#include
+#include