div class="twikiTopBar">

Chair for Computer Aided Medical Procedures & Augmented Reality
Lehrstuhl für Informatikanwendungen in der Medizin & Augmented Reality

TemplateService Class Reference
[Base class for DWARF services]

The class handling service startup and shutdown. More...

Inheritance diagram for TemplateService:

Inheritance graph
[legend]

Public Member Functions

 TemplateService ()
 Sets the service's name to "Unknown", the real name is set at startService.
virtual ~TemplateService ()
 Calls stopService to destroy all ability and need objects.
virtual char * getStatus ()
 Returns the current status.
void startService (DWARF::ActiveServiceDescription_ptr serviceDesc)
 Called by Service Manager on startup.
void stopService (DWARF::ActiveServiceDescription_ptr serviceDesc)
 Called by Service Manager on shutdown.
std::vector< std::string > * getAbilities ()
 returns a list with all abilities' names
std::vector< std::string > * getNeeds ()
 returns a list with all needs' names
void addAbility (CORBA::String_var name, CORBA::Object_ptr object)
 add a CORBA object registered for ability <name>
CORBA::Object_var getAbility (std::string name)
 returns the CORBA object registered for ability <name>
void addNeed (CORBA::String_var name, CORBA::Object_ptr object)
 add a CORBA object registered for need <name>
CORBA::Object_var getNeed (std::string name)
 returns the CORBA object registered for need <name>
DWARF::ActiveServiceDescription_ptr getServiceDesc ()
 returns this service's description object
void blockUntilRunning ()
 Blocks the execution until the service is running.
void blockUntilStopped ()
 Blocks the execution until the service has stopped.

Protected Member Functions

void parseAbilities (DWARF::ActiveServiceDescription_ptr serviceDesc)
 Parse all abilities and set up corresponding objects.
virtual CORBA::Object_ptr createAbilityObject (DWARF::AbilityDescription_ptr abilityDescr)
 Create an Ability object for a given description.
virtual bool checkAbilityObject (CORBA::Object_ptr ability, DWARF::AbilityDescription_ptr abilityDescr)
 Check whether a given Ability implements all connector protocols.
void parseNeeds (DWARF::ActiveServiceDescription_ptr serviceDesc)
 Parse all needs and set up corresponding objects.
virtual CORBA::Object_ptr createNeedObject (DWARF::NeedDescription_ptr needDescr)
 Create a Need object for a given description.
virtual bool checkNeedObject (CORBA::Object_ptr need, DWARF::NeedDescription_ptr needDescr)
 Check whether a given Need implements all connector protocols.
void checkContextSwitch (DWARF::ActiveServiceDescription_ptr serviceDesc)
 Sets up ContextSwitch need.
virtual CORBA::Object_ptr createContextSwitchObject (DWARF::NeedDescription_ptr needDescr, DWARF::ActiveServiceDescription_ptr serviceDesc)
 Method to provide a ContextSwitch object.
virtual void run ()
 The ccre method of the service. Started in a separate thread Once this method returns, this thread is terminated.
bool shouldRun ()
 Returns whether the service is running.
const ObjectMap & getAbilityMap () const
 Return a reference to the ability map.
const ObjectMap & getNeedMap () const
 Return a reference to the need map.

Static Protected Member Functions

static void * controlThreadStarter (void *data)
 Calls the run() method of the given controller object.

Protected Attributes

std::string m_name
 The service's name, set on startService.
volatile bool m_shouldRun
 State variable containing whether the service should run.
DWARF::ActiveServiceDescription_ptr m_serviceDesc
 This service's description object.

Private Attributes

ObjectMap m_abilityMap
 A map containing all abilities.
ObjectMap m_needMap
 A map containing all needs.
omni_mutex m_mutexShouldRun
 Mutex for access to m_shouldRun.
omni_condition m_signalShouldRun
 Condition variable to signal the start of the run() method.

Detailed Description

The class handling service startup and shutdown.

This class is derived from the DWARF::BasicService interface and handles service startup and shutdown.

Author:
Martin Wagner <martin@augmentedreality.de>

Definition at line 85 of file TemplateService.h.


Member Function Documentation

void TemplateService::blockUntilRunning  ) 
 

Blocks the execution until the service is running.

This method blocks the execution until startService() is called and the thread executing the run() is created.

Definition at line 637 of file TemplateService.cpp.

void TemplateService::blockUntilStopped  ) 
 

Blocks the execution until the service has stopped.

This method blocks the execution until stopService() is called.

Definition at line 643 of file TemplateService.cpp.

bool TemplateService::checkAbilityObject CORBA::Object_ptr  ability,
DWARF::AbilityDescription_ptr  abilityDescr
[protected, virtual]
 

Check whether a given Ability implements all connector protocols.

Parse all connectors of the given ability description. Test if the given object implements the necessary interface using _is_a().

Returns:
<<true>> if the object matches all connectors, <<false>> otherwise

Definition at line 371 of file TemplateService.cpp.

void TemplateService::checkContextSwitch DWARF::ActiveServiceDescription_ptr  serviceDesc  )  [protected]
 

Sets up ContextSwitch need.

This method checks for a need of type ContextSwitch. If it exists, it sets up an object of type ContextSwitch and registers it with the service manager. This object provides an ObjRef interface of type ContextSwitch that allows context estimation components to change this service's attributes. If an attribute is changed, set or deleted, this service's attributes get adjusted accordingly. Thus, all abilities not overriding the contextual attribute have this attribute set, too. In addition, the predicates of all needs with attribute "ContextAffected" set to "true" are adjusted such that they require the contextual attribute. For example, if a need's predicate was (AnimalType=Sheep) before a call changeContextAttribute( "AnimalType", "Cow" ); was received, it will be (AnimalType=Cow) afterwards. If a call setContextAttribute( "User", "Joe"); is received, the new value of the predicate will be (&(User=Joe)(AnimalType=Cow)).

Parameters:
serviceDesc This service's service description

Definition at line 553 of file TemplateService.cpp.

bool TemplateService::checkNeedObject CORBA::Object_ptr  need,
DWARF::NeedDescription_ptr  needDescr
[protected, virtual]
 

Check whether a given Need implements all connector protocols.

Parse all connectors of the given ability description. Test if the given object implements the necessary interface using dynamic_cast.

Returns:
<<true>> if the object matches all connectors, <<false>> otherwise

Definition at line 495 of file TemplateService.cpp.

void * TemplateService::controlThreadStarter void *  data  )  [static, protected]
 

Calls the run() method of the given controller object.

Does nothing except calling the run() method of the Service object. Note that it is this object's responsibility to terminate the thread by returning from the run() method

Parameters:
data A pointer to a ServiceController object.

Definition at line 623 of file TemplateService.cpp.

virtual CORBA::Object_ptr TemplateService::createAbilityObject DWARF::AbilityDescription_ptr  abilityDescr  )  [inline, protected, virtual]
 

Create an Ability object for a given description.

Create a CORBA object that can corresponds to the ability name given in the abilitydescription. Override this method for your own service. Take care that your method puts the newly created object in the m_abilityMap

Parameters:
abilityDescr The description of the ability
Returns:
The created C++ Object_ptr

Reimplemented in ViewerFacade, ExampleService, DWARF::PoseService, ARTkMarkerConfiguratorService, ARTkNFTConfiguratorService, ShmemViewer, ARTkMarkerDetectionService, ARTkPoseReconstructService, Ubitrack::ContextEstimationService, DWARF::MarkerLoaderService, StaticEdgeService, Filter, Filter, and Filter.

Definition at line 213 of file TemplateService.h.

CORBA::Object_ptr TemplateService::createContextSwitchObject DWARF::NeedDescription_ptr  needDescr,
DWARF::ActiveServiceDescription_ptr  serviceDesc
[protected, virtual]
 

Method to provide a ContextSwitch object.

Override this method to change the default behavior that is described with the ContextSwitch class

Parameters:
needDescr the need description
ServiceDescr This service's service description
Returns:
A CORBA object that can be registered with the service manager.

Definition at line 607 of file TemplateService.cpp.

virtual CORBA::Object_ptr TemplateService::createNeedObject DWARF::NeedDescription_ptr  needDescr  )  [inline, protected, virtual]
 

Create a Need object for a given description.

Create a CORBA object that can corresponds to the need name given in the need description. Override this method for your own service. Take care that your method puts the newly created object in the m_needMap

Parameters:
needDescr The description of the ability
Returns:
If the Object could be created, it is returned, otherwise NULL is returned.

Reimplemented in ViewerFacade, ExampleService, DWARF::PoseService, ARTkMarkerConfiguratorService, ARTkNFTConfiguratorService, ShmemViewer, ARTkMarkerDetectionService, ARTkPoseReconstructService, Ubitrack::ContextEstimationService, DWARF::MarkerLoaderService, InferenceServicePush, InferenceServiceSyncPush, InvertServicePush, KalmanService, DWARF::ErrorVisualizerService, Filter, Filter, and Filter.

Definition at line 234 of file TemplateService.h.

const ObjectMap& TemplateService::getAbilityMap  )  const [inline, protected]
 

Return a reference to the ability map.

Returns:
Constant reference to the ability map

Definition at line 307 of file TemplateService.h.

const ObjectMap& TemplateService::getNeedMap  )  const [inline, protected]
 

Return a reference to the need map.

Returns:
Constant reference to the need map

Definition at line 315 of file TemplateService.h.

char * TemplateService::getStatus  )  [virtual]
 

Returns the current status.

This method stems from the DWARF Service interface. It is not necessary to implement it, however, you can provide more or less useful status information to the service manager and other services interested in (e.g. DIVE)

Warning:
called only from service manager. Do not call these methods yourself!
Returns:
CORBA string that must be generated using string_dup

Reimplemented in ARTkMarkerDetectionService, Parsephone, and Parsephone.

Definition at line 122 of file TemplateService.cpp.

void TemplateService::parseAbilities DWARF::ActiveServiceDescription_ptr  serviceDesc  )  [protected]
 

Parse all abilities and set up corresponding objects.

Parse all Abilities, for each found do

  1. Check for its type and connector protocol.
  2. Based on type, instantiate an object from a specific class (this is dependent on the actual service).
  3. Check whether this object can handle the specified protocol.
  4. Store the Ability description in a private hashmap.
Parameters:
serviceDesc The description of this service.

Definition at line 301 of file TemplateService.cpp.

void TemplateService::parseNeeds DWARF::ActiveServiceDescription_ptr  serviceDesc  )  [protected]
 

Parse all needs and set up corresponding objects.

Parse all Needs, for each found do

  1. Check for its type and connector protocol.
  2. Based on type, instantiate an object from a specific class (this is dependent on the actual service).
  3. Check whether this object can handle the specified protocol.
  4. Store the Need description in a private hashmap.
Parameters:
serviceDesc The description of this service.

Definition at line 423 of file TemplateService.cpp.

void TemplateService::run  )  [protected, virtual]
 

The ccre method of the service. Started in a separate thread Once this method returns, this thread is terminated.

The default implementation returns immediately. Use this method as the central workhorse of your service. First, initailize everything that's needed, then do some more or less useful work and finally return when m_shouldRun is set to false or some other conditions occurr.

Reimplemented in ViewerFacade, ExampleService, DWARF::ContinuousPoseService, DWARF::PoseService, ARTkMarkerConfiguratorService, ARTkNFTConfiguratorService, DWARF::PoseDataPlayer, ShmemViewer, ARTkMarkerDetectionService, ARTkPoseReconstructService, DWARF::ARTInterpreter, DWARF::IntersenseTracker, XsensTrackerService, ARTkFusion, Ubitrack::ContextEstimationService, DWARF::MarkerLoaderService, SamplerService, DWARF::ErrorVisualizerService, DWARF::InferenceService, DWARF::Inference1Service, DWARF::StaticAutoCalibrationService, DWARF::StaticCalibrationService, Filter, Filter, Parsephone, Filter, and JeepService.

Definition at line 632 of file TemplateService.cpp.

bool TemplateService::shouldRun  )  [protected]
 

Returns whether the service is running.

This method returns the value of m_shouldRun which indicates if startService() was called and the service is running

Returns:
True if the service is running, else false

Definition at line 648 of file TemplateService.cpp.

void TemplateService::startService DWARF::ActiveServiceDescription_ptr  serviceDesc  ) 
 

Called by Service Manager on startup.

This method is called by the service manager on startup. Use this method as the core initialization routine, parsing the service's description for needs and abilities and instantiating corresponding objects.

The sequence of action is as follows:

  1. Back up the service description to a private variable.
  2. Parse all Needs and Abilities (call createAbility/NeedObject for every need), here you can implement your own behavior by subclassing
  3. Check if a need of type ContextSwitch exists and set up a handler object
  4. Execute the run() method in a new thread. Implement your own behavior by subclassing, the default method returns immediately.

Document how the ContextSwitch mechanism works

Parameters:
serviceDesc The description of this service. This is a service's only opportunity to get hold of its own service description. If it is needed later on, store a copy of it in a member variable
Warning:
This method should only be called by the service manager.

Reimplemented in KalmanService.

Definition at line 151 of file TemplateService.cpp.

void TemplateService::stopService DWARF::ActiveServiceDescription_ptr  serviceDesc  ) 
 

Called by Service Manager on shutdown.

This method is called by the service manager on shutdown of the service. We use this method to delete the Service Control object, assuming that it takes all necessary means in its destructor to stop the controller thread(s). In addition, we delete all objects handling the service's needs and abilities

Parameters:
serviceDesc The service's description given by the service manager
Warning:
This method should only be called by the service manager.

Definition at line 197 of file TemplateService.cpp.


Field Documentation

volatile bool TemplateService::m_shouldRun [protected]
 

State variable containing whether the service should run.

This member enables to implement an execution loop in run(). This variable is set to false on construction of the service. When startService() is called, it will be set to true and the new service thread which executes run() is started. If set to false, run() should return.

Warning:
The direct access to this variable is not threadsafe. Please use the m_mutexShouldRun mutex variable to ensure thread safety. This variable should be private, however the interface was defined to allow protected access.

Definition at line 194 of file TemplateService.h.

TemplateService Class Reference | generated on Sun Apr 29 02:01:11 2007 by Doxygen 1.4.1 for DWARF