Bug 5968 - Changed plugin loading to allow a plugin to provide services
: Changed plugin loading to allow a plugin to provide services
Status: RESOLVED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Plugins
: 7.0
: PC Other
: P2 enhancement (vote)
: ---
Assigned To: Unassigned bug - please assign me!
http://forums.slimdevices.com/showthr...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-10-29 21:50 UTC by Erland Isaksson
Modified: 2007-11-02 21:35 UTC (History)
0 users

See Also:
Category: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erland Isaksson 2007-10-29 21:50:36 UTC
Today it isn't possible for plugins to provide services for other plugins that requires registration during initPlugin.
The reason is that dependent on the order the plugins are loaded the plugin providing the services might be loaded last which results in that the plugin using the services can't register with it during its initPlugin method.

I've several plugins myself that have this problem today, so far I've solved it by in initPlugin adding a call to:

Slim::Utils::Scheduler::add_task(\&lateInitPlugin);

And then perform the registration in the lateInitPlugin method instead. However, this feels a bit ugly and it also causes timeout issues with SC7 as mentioned in: https://bugs-archive.lyrion.org/show_bug.cgi?id=5830

The solution would be to provide a multi step plugin initialization, where all plugin passes each step before the next step starts. For example:
1. load all plugins
2. run initPlugin1 on all plugins || nothing (if initPlugin1 doesn't exist)
3. run initPlugin2 on all plugins || initPlugin
4. run initPlugin3 on all plugins || nothing (if initPlugin3 doesn't exist)

This means plugins initialise any server functions in initPlugin1, normal
init happens in initPlugin2 where other plugins can register with it and
then initPlugin3 can be used to start the service once you know who all the
users are.

The existing plugins that doesn't provide or use services can be kept as they are with a single initPlugin, but plugins providing services or plugins using services needs to be changed so they use one or all of initPlugin1, initPlugin2 and initPlugin3.

There has already been a short discussion regarding this in the following Developer thread:
http://forums.slimdevices.com/showthread.php?t=39702
Comment 1 Adrian Smith 2007-11-01 15:23:20 UTC
Implemented as change 14305.  Erland please try and close the bug if you are happy!
Comment 2 Erland Isaksson 2007-11-02 21:35:08 UTC
I've verified that this works correctly and it solves the issues I had.