CppMicroServices

C++ Micro Services: Micro Services Classes
Micro Services Classes

This category includes classes related to the C++ Micro Services component. More...

Namespaces

 ServiceConstants
 

Classes

class  Framework
 The CppMicroServices Framework. More...
 
class  FrameworkFactory
 A factory for creating Framework instances. More...
 
class  LDAPFilter
 An RFC 1960-based Filter. More...
 
class  Module
 Represents a CppMicroServices module. More...
 
struct  ModuleActivator
 Customizes the starting and stopping of a CppMicroServices module. More...
 
class  ModuleContext
 A module's execution context within the framework. More...
 
class  ModuleEvent
 An event from the Micro Services framework describing a module lifecycle change. More...
 
struct  ModuleEventHook
 Module Event Hook Service. More...
 
struct  ModuleFindHook
 Module Context Hook Service. More...
 
class  ModuleResource
 Represents a resource (text file, image, etc.) embedded in a CppMicroServices module. More...
 
class  ModuleResourceStream
 An input stream class for ModuleResource objects. More...
 
class  ModuleSettings
 Query and set certain properties of the CppMicroServices library. More...
 
class  ModuleVersion
 Version identifier for CppMicroServices modules. More...
 
struct  PrototypeServiceFactory
 A factory for prototype scope services. More...
 
class  ServiceEvent
 An event from the Micro Services framework describing a service lifecycle change. More...
 
struct  ServiceEventListenerHook
 Service Event Listener Hook Service. More...
 
class  ServiceException
 A service exception used to indicate that a service problem occurred. More...
 
class  ServiceFactory
 A factory for module scope services. More...
 
struct  ServiceFindHook
 Service Find Hook Service. More...
 
struct  MakeInterfaceMap< Interfaces >
 Helper class for constructing InterfaceMap instances based on service implementations or service factories. More...
 
struct  ServiceListenerHook
 Service Listener Hook Service. More...
 
struct  ServiceListenerHook::ListenerInfo
 Information about a Service Listener. More...
 
class  ServiceObjects< S >
 Allows multiple service objects for a service to be obtained. More...
 
class  ServiceObjects< void >
 Allows multiple service objects for a service to be obtained. More...
 
class  ServiceReference< S >
 A reference to a service. More...
 
class  ServiceReferenceBase
 A reference to a service. More...
 
class  ServiceRegistration< I1, Interfaces >
 A registered service. More...
 
class  ServiceRegistrationBase
 A registered service. More...
 
struct  TrackedTypeTraitsBase< T, TTT >
 A base class template for type traits for objects tracked by a ServiceTracker instance. More...
 
struct  TrackedTypeTraits< S, T * >
 Default type traits for custom tracked objects of pointer type. More...
 
class  ServiceTracker< S, TTT >
 The ServiceTracker class simplifies using services from the framework's service registry. More...
 
struct  ServiceTrackerCustomizer< S, T >
 The ServiceTrackerCustomizer interface allows a ServiceTracker to customize the service objects that are tracked. More...
 

Macros

#define US_EXPORT_MODULE_ACTIVATOR(_activator_type)
 Export a module activator class. More...
 
#define US_INITIALIZE_STATIC_MODULE(_module_name)
 Initialize a static module. More...
 
#define US_IMPORT_MODULE(_module_name)
 Import a static module. More...
 
#define US_INITIALIZE_MODULE
 Creates initialization code for a module. More...
 
#define US_DECLARE_SERVICE_INTERFACE(_service_interface_type, _service_interface_id)
 Declare a service interface id. More...
 

Typedefs

typedef std::map< std::string, void * > InterfaceMap
 A map containing interfaces ids and their corresponding service object pointers. More...
 
typedef std::unordered_map< std::string, AnyServiceProperties
 A hash table with std::string as the key type and Any as the value type. More...
 
typedef ServiceReference< void > ServiceReferenceU
 A service reference of unknown type, which is not bound to any interface identifier. More...
 
typedef ServiceRegistration< void > ServiceRegistrationU
 A service registration object of unknown type. More...
 

Enumerations

enum  ModuleEvent::Type {
  ModuleEvent::LOADED, ModuleEvent::UNLOADED, ModuleEvent::LOADING, ModuleEvent::UNLOADING,
  ModuleEvent::INSTALLED, ModuleEvent::UNINSTALLED
}
 
enum  ServiceEvent::Type { ServiceEvent::REGISTERED, ServiceEvent::MODIFIED, ServiceEvent::UNREGISTERING, ServiceEvent::MODIFIED_ENDMATCH }
 
enum  ServiceException::Type {
  ServiceException::UNSPECIFIED, ServiceException::UNREGISTERED, ServiceException::FACTORY_ERROR, ServiceException::FACTORY_EXCEPTION,
  ServiceException::REMOTE, ServiceException::FACTORY_RECURSION
}
 

Functions

static ModuleContextGetModuleContext ()
 Returns the module context of the calling module. More...
 
std::ostream & operator<< (std::ostream &os, const LDAPFilter &filter)
 
std::ostream & operator<< (std::ostream &os, const Module &module)
 
std::ostream & operator<< (std::ostream &os, Module const *module)
 
std::ostream & operator<< (std::ostream &os, const ModuleResource &resource)
 
std::ostream & operator<< (std::ostream &os, const ModuleVersion &v)
 
template<class T >
std::string us_service_interface_iid ()
 Returns a unique id for a given type. More...
 
template<class Interface >
Interface * ExtractInterface (const InterfaceMap &map)
 Extract a service interface pointer from a given InterfaceMap instance. More...
 
std::ostream & operator<< (std::ostream &os, const ServiceReferenceBase &serviceRef)
 
std::ostream & operator<< (std::ostream &os, ModuleEvent::Type eventType)
 
std::ostream & operator<< (std::ostream &os, const ModuleEvent &event)
 
std::ostream & operator<< (std::ostream &os, const ServiceEvent::Type &type)
 
std::ostream & operator<< (std::ostream &os, const ServiceEvent &event)
 
std::ostream & operator<< (std::ostream &os, const ServiceException &exc)
 
template<class T >
ServiceFactoryToFactory (T &factory, typename std::enable_if< std::is_class< T >::value, T >::type *=nullptr)
 Cast the argument to a ServiceFactory pointer. More...
 
template<class T >
ServiceFactoryToFactory (T factory, typename std::enable_if< std::is_pointer< T >::value &&std::is_class< typename std::remove_pointer< T >::type >::value >::type *=nullptr)
 Cast the argument to a ServiceFactory pointer. More...
 

Detailed Description

This category includes classes related to the C++ Micro Services component.

The C++ Micro Services component provides a dynamic service registry based on the service layer as specified in the OSGi R4.2 specifications.

Macro Definition Documentation

#define US_DECLARE_SERVICE_INTERFACE (   _service_interface_type,
  _service_interface_id 
)

Declare a service interface id.

This macro associates the given identifier _service_interface_id (a string literal) to the interface class called _service_interface_type. The Identifier must be unique. For example:

1 #include <usServiceInterface.h>
2 
3 struct ISomeInterace { ... };
4 
5 US_DECLARE_SERVICE_INTERFACE(ISomeInterface, "com.mycompany.service.ISomeInterface/1.0")

The usage of this macro is optional and the service interface id which is automatically associated with any type is usually good enough (the demangled type name). However, care must be taken if the default id is compared with a string literal hard-coding a service interface id. E.g. the default id for templated types in the STL may differ between platforms. For user-defined types and templates the ids are typically consistent, but platform specific default template arguments will lead to different ids.

This macro is normally used right after the class definition for _service_interface_type, in a header file.

If you want to use US_DECLARE_SERVICE_INTERFACE with interface classes declared in a namespace then you have to make sure the US_DECLARE_SERVICE_INTERFACE macro call is not inside a namespace though. For example:

1 #include <usServiceInterface.h>
2 
3 namespace Foo
4 {
5  struct ISomeInterface { ... };
6 }
7 
8 US_DECLARE_SERVICE_INTERFACE(Foo::ISomeInterface, "com.mycompany.service.ISomeInterface/1.0")
Parameters
_service_interface_typeThe service interface type.
_service_interface_idA string literal representing a globally unique identifier.
#define US_EXPORT_MODULE_ACTIVATOR (   _activator_type)

Export a module activator class.

Parameters
_activator_typeThe fully-qualified type-name of the module activator class.

Call this macro after the definition of your module activator to make it accessible by the CppMicroServices library.

Example:

class MyActivator : public ModuleActivator
{
public:
void Load(ModuleContext* /*context*/)
{ /* register stuff */ }
void Unload(ModuleContext* /*context*/)
{ /* cleanup */ }
};
#define US_IMPORT_MODULE (   _module_name)

Import a static module.

Parameters
_module_nameThe name of the module to import.

This macro imports the static module named _module_name.

Inserting this macro into your application's source code will allow you to make use of a static module. It will initialize the static module and calls its ModuleActivator. If the module does not provide an activator, use the US_INITIALIZE_STATIC_MODULE macro instead. Do not forget to actually link the static module to the importing executable or shared library.

Example:

#include <usModuleImport.h>
US_IMPORT_MODULE(MyStaticModule1)
See also
US_INITIALIZE_STATIC_MODULE
US_IMPORT_MODULE_RESOURCES
Static Modules
#define US_INITIALIZE_MODULE

Creates initialization code for a module.

Each module which wants to register itself with the CppMicroServices library has to put a call to this macro in one of its source files. Further, the module's source files must be compiled with the US_MODULE_NAME pre-processor definition set to a module-unique identifier.

Calling the US_INITIALIZE_MODULE macro will initialize the module for use with the CppMicroServices library, using a default auto-load directory named after the US_MODULE_NAME definition.

See also
MicroServices_AutoLoading
Remarks
If you are using CMake, consider using the provided CMake macro usFunctionGenerateModuleInit().
#define US_INITIALIZE_STATIC_MODULE (   _module_name)

Initialize a static module.

Parameters
_module_nameThe name of the module to initialize.

This macro initializes the static module named _module_name.

If the module provides an activator, use the US_IMPORT_MODULE macro instead, to ensure that the activator is called. Do not forget to actually link the static module to the importing executable or shared library.

See also
US_IMPORT_MODULE
US_IMPORT_MODULE_RESOURCES
Static Modules

Typedef Documentation

typedef std::map<std::string, void*> InterfaceMap

A map containing interfaces ids and their corresponding service object pointers.

InterfaceMap instances represent a complete service object which implementes one or more service interfaces. For each implemented service interface, there is an entry in the map with the key being the service interface id and the value a pointer to the service interface implementation.

To create InterfaceMap instances, use the MakeInterfaceMap helper class.

Note
This is a low-level type and should only rarely be used.
See also
MakeInterfaceMap
typedef std::unordered_map<std::string, Any> ServiceProperties

A hash table with std::string as the key type and Any as the value type.

It is typically used for passing service properties to ModuleContext::RegisterService.

A service reference of unknown type, which is not bound to any interface identifier.

A service registration object of unknown type.

Enumeration Type Documentation

Enumerator
UNSPECIFIED 

No exception type is unspecified.

UNREGISTERED 

The service has been unregistered.

FACTORY_ERROR 

The service factory produced an invalid service object.

FACTORY_EXCEPTION 

The service factory threw an exception.

REMOTE 

An error occurred invoking a remote service.

FACTORY_RECURSION 

The service factory resulted in a recursive call to itself for the requesting module.

Enumerator
LOADED 

The module has been loaded.

The module's ModuleActivator Load method has been executed.

UNLOADED 

The module has been unloaded.

The module's ModuleActivator Unload method has been executed.

LOADING 

The module is about to be loaded.

The module's ModuleActivator Load method is about to be called.

UNLOADING 

The module is about to be unloaded.

The module's ModuleActivator Unload method is about to be called.

INSTALLED 

The bundle has been installed.

The bundle has been installed by the Framework.

UNINSTALLED 

The bundle has been uninstalled.

The bundle has been removed from the Framework.

Enumerator
REGISTERED 

This service has been registered.

This event is delivered after the service has been registered with the framework.

See also
ModuleContext::RegisterService()
MODIFIED 

The properties of a registered service have been modified.

This event is delivered after the service properties have been modified.

See also
ServiceRegistration::SetProperties
UNREGISTERING 

This service is in the process of being unregistered.

This event is delivered before the service has completed unregistering.

If a module is using a service that is UNREGISTERING, the module should release its use of the service when it receives this event. If the module does not release its use of the service when it receives this event, the framework will automatically release the module's use of the service while completing the service unregistration operation.

See also
ServiceRegistration::Unregister
ModuleContext::UngetService
MODIFIED_ENDMATCH 

The properties of a registered service have been modified and the new properties no longer match the listener's filter.

This event is delivered after the service properties have been modified. This event is only delivered to listeners which were added with a non-empty filter where the filter matched the service properties prior to the modification but the filter does not match the modified service properties.

See also
ServiceRegistration::SetProperties

Function Documentation

template<class Interface >
Interface* ExtractInterface ( const InterfaceMap map)

Extract a service interface pointer from a given InterfaceMap instance.

Parameters
mapa InterfaceMap instance.
Returns
The service interface pointer for the service interface id of the I1 interface type or NULL if map does not contain an entry for the given type.
See also
MakeInterfaceMap
static ModuleContext* GetModuleContext ( )
inlinestatic

Returns the module context of the calling module.

This function allows easy access to the ModuleContext instance from inside a C++ Micro Services module.

Returns
The ModuleContext of the calling module.
std::ostream& operator<< ( std::ostream &  os,
const ServiceException exc 
)
std::ostream& operator<< ( std::ostream &  os,
ModuleEvent::Type  eventType 
)
std::ostream& operator<< ( std::ostream &  os,
const ModuleEvent event 
)
std::ostream& operator<< ( std::ostream &  os,
const LDAPFilter filter 
)
std::ostream& operator<< ( std::ostream &  os,
const ServiceEvent::Type type 
)
std::ostream& operator<< ( std::ostream &  os,
const ServiceEvent event 
)
std::ostream& operator<< ( std::ostream &  os,
const ServiceReferenceBase serviceRef 
)
std::ostream& operator<< ( std::ostream &  os,
const ModuleVersion v 
)
std::ostream& operator<< ( std::ostream &  os,
const ModuleResource resource 
)
std::ostream& operator<< ( std::ostream &  os,
const Module module 
)
std::ostream& operator<< ( std::ostream &  os,
Module const *  module 
)
template<class T >
ServiceFactory* ToFactory ( T &  factory,
typename std::enable_if< std::is_class< T >::value, T >::type *  = nullptr 
)

Cast the argument to a ServiceFactory pointer.

Useful when calling ModuleContext::RegisterService with a service factory, for example:

1 MyServiceFactory* factory;
2 context->RegisterService<ISomeInterface>(ToFactory(factory));
Parameters
factoryThe service factory. May be a pointer or reference type.
Returns
A ServiceFactory pointer to the passed factory instance.
See also
ModuleContext::RegisterService(ServiceFactory* factory, const ServiceProperties& properties)
template<class T >
ServiceFactory* ToFactory ( factory,
typename std::enable_if< std::is_pointer< T >::value &&std::is_class< typename std::remove_pointer< T >::type >::value >::type *  = nullptr 
)

Cast the argument to a ServiceFactory pointer.

Useful when calling ModuleContext::RegisterService with a service factory, for example:

1 MyServiceFactory* factory;
2 context->RegisterService<ISomeInterface>(ToFactory(factory));
Parameters
factoryThe service factory. May be a pointer or reference type.
Returns
A ServiceFactory pointer to the passed factory instance.
See also
ModuleContext::RegisterService(ServiceFactory* factory, const ServiceProperties& properties)
template<class T >
std::string us_service_interface_iid ( )

Returns a unique id for a given type.

By default, the demangled name of T is returned.

This template method may be specialized directly or be using the macro US_DECLARE_SERVICE_INTERFACE to return a custom id for each service interface.

Template Parameters
TThe service interface type.
Returns
A unique id for the service interface type T.