Hi Yashodhan,

> 
> I have created a set of services and a plugin based on mitkCoreServices
> (org.mitk.core.services). My understanding of the
> mitkCoreServicesPlugin is that it serves to start the
> DataStorageService.

A more suited terminology would be that it "registers" the DataStorageService. 
If you are considering to execute cpu-intensive code inside the constructor of 
a service, you may want to defer the execution of this code until a service 
consumer calls a method on your service implementation. Otherwise, application 
startup may be delayed considerably.
 
> I was wondering how this plugin is linked with or called from the main
> application? I was hoping for a mechanism where a user could start
> different plugins that would start different services. Does something
> like this exist?
> 

All MITK plugins depend (may be implicitly) on org.mitk.core.services. You can 
introduce plug-in dependencies by writing something like

Require-Bundle: org.mitk.core.services, ...

In your plugins MANIFEST.MF file. This ensures that all dependencies are loaded 
and started. 

If you have a set of plugins implementing different service interfaces, you can 
use your plugins IBundleContext (you can get it from inside your 
IBundleActivator::Start() method) to start a specific plugin (which would than 
register a service class). For example (untested):

// your IBundleContext
berry::IBundleContext::Pointer context = ...
berry::IBundle::ConstPointer cplugin = 
context->FindBundle("my.fancy.service.plugin");
// unfortunately, this is needed due to a design problem (I think)
berry::IBundle::Pointer plugin = 
berry::IBundle::Pointer(const_cast<berry::IBundle*>(plugin.GetPointer()));
plugin->Start();
MyFancyService::Pointer fancyService = 
context->GetService<MyFancyService>("my.fancy.service");


This approach allows you decouple the service interface and the implementation, 
if you want. For example:

Plugin A: contains a "service interface" IMyFancyService
Plugin B: implements IMyFancyService in MyFancyImpl (Require-Bundle: A)
Plugin C: uses IMyFancyService (Require-Bundle: A) by starting the concrete 
implementation via context->FindBundle("B")...

If loading your service implementation plugins is cheap, you can also "force" 
their loading on application startup, by writing:

Bundle-ActivationPolicy: eager

In their MANIFEST.MF file. This way, you don't need to manually start the 
plugins. Note that registering different implementations for the same service 
id is not (yet) supported. You would get a Poco::ExistsException thrown.

Hope this helps,
Sascha

------------------------------------------------------------------------------

_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to