MBServiceManager Class Reference

Inherits from NSObject
Conforms to MBSingleton
Declared in MBServiceManager.h

Overview

This class manages the lifecycle of various runtime services that adopt the MBService protocol.

Services are shared resources that need to be available any time at least one client is using the service.

Attaching & detaching services

Rather than starting and stopping services directly, clients coordinate through the MBServiceManager singleton, which provides an interface allowing users to attach to and detach from various services.

Attaching a service signals that a client of that service wishes to keep it running. The first time a client attaches a service, the MBServiceManager will start the service. As long as there is at least one client attached to a service, the service will remain running.

Once a client no longer requires the use of a service, it should detach. When the last remaining client detaches, the MBServiceManager will stop the service.

Note that some services do not support being stopped, in which case detaching has no effect.

Services within MBML

Within MBML, the <AttachService> and <DetachService> listener actions can be used. See MBAttachServiceAction and MBDetachServiceAction for additional information.

Warning: You must not create instances of this class yourself; this class is a singleton. Call the instance class method (declared by the MBSingleton protocol) to acquire the singleton instance.

Acquiring service instances

– serviceForClassName:

Returns the singleton instance of the service implemented by the class with the specified name.

- (id)serviceForClassName:(NSString *)serviceClassName

Parameters

serviceClassName

The name of the class implementing the MBService protocol.

Return Value

A pointer to the singleton MBService with the specified class name, or nil if there isn’t one.

Declared In

MBServiceManager.h

– serviceForClass:

Returns the singleton instance of the service implemented the specified class.

- (id)serviceForClass:(Class)serviceClass

Parameters

serviceClass

The Class implementing the MBService protocol.

Return Value

A pointer to the singleton MBService of the specified class, or nil if there isn’t one.

Declared In

MBServiceManager.h

Attaching to services

– attachToService:

Attaches to the specified service, incrementing its attach count by one.

- (void)attachToService:(MBService *)service

Parameters

service

The service being attached.

Discussion

Services with an attach count greater than zero will be kept running by the MBServiceManager.

Note: When the service is no longer needed, the caller should be sure to detach the service.

Declared In

MBServiceManager.h

– attachToServiceClass:

Attaches to the service with the given class name, incrementing its attach count by one.

- (id)attachToServiceClass:(Class)serviceClass

Parameters

serviceClass

The implementing class of the service class to attach.

Return Value

If successful, the MBService instance that was attached. Will return nil on failure.

Discussion

Services with an attach count greater than zero will be kept running by the MBServiceManager.

Note: When the service is no longer needed, the caller should be sure to detach the service.

Declared In

MBServiceManager.h

– attachToServiceClassNamed:

Attaches to the service with the given class name, incrementing its attach count by one.

- (id)attachToServiceClassNamed:(NSString *)serviceClassName

Parameters

serviceClassName

The name of the service class to attach.

Return Value

If successful, the MBService instance that was attached. Will return nil on failure.

Discussion

Services with an attach count greater than zero will be kept running by the MBServiceManager.

Note: When the service is no longer needed, the caller should be sure to detach the service.

Declared In

MBServiceManager.h

Detaching from services

– detachFromService:

Detaches from the specified service, decrementing its attach count by one.

- (void)detachFromService:(MBService *)service

Parameters

service

The service being attached.

Discussion

Services are stopped by the MBServiceManager when their attach count decreases to zero.

Note: Code should only detach from a service if it previously attached to the same service.

Declared In

MBServiceManager.h

– detachFromServiceClass:

Detaches from the service with the given class name, decrementing its attach count by one.

- (void)detachFromServiceClass:(Class)serviceClass

Parameters

serviceClass

The implementing class of the service class to detach.

Discussion

Services are stopped by the MBServiceManager when their attach count decreases to zero.

Note: Code should only detach from a service if it previously attached to the same service. Detach requests are ignored if the service isn’t already running.

Declared In

MBServiceManager.h

– detachFromServiceClassNamed:

Detaches from the service with the given class name, decrementing its attach count by one.

- (void)detachFromServiceClassNamed:(NSString *)serviceClassName

Parameters

serviceClassName

The name of the service class to attach.

Discussion

Services are stopped by the MBServiceManager when their attach count decreases to zero.

Note: Code should only detach from a service if it previously attached to the same service. Detach requests are ignored if the service isn’t already running.

Declared In

MBServiceManager.h

Querying the status of services

– isServiceRunning:

Determines whether the specified service is running.

- (BOOL)isServiceRunning:(MBService *)service

Parameters

service

The service whose status is sought.

Return Value

YES if the service is running; NO if it is not.

Discussion

A service will remain running as long as its attach count is greater than zero.

Declared In

MBServiceManager.h

– attachCountForService:

Determines the current attach count of a service.

- (NSUInteger)attachCountForService:(MBService *)service

Parameters

service

The service whose attach count is sought.

Return Value

The service’s current attach count.

Declared In

MBServiceManager.h