Bugzilla – Bug 5968
Changed plugin loading to allow a plugin to provide services
Last modified: 2007-11-02 21:35:08 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
Implemented as change 14305. Erland please try and close the bug if you are happy!
I've verified that this works correctly and it solves the issues I had.