PDA

View Full Version : Help with Slim::Control::Request::subscribe



max.spicer
2006-05-07, 10:20
I'm finally getting around to updating a few plugins to use the new Request::subscribe model and am trying to filter out commands appropriately. I'd like to be called if the command is "playlist newsong", power or stop. However, I can't quite work out how to do this.

I can say
Slim::Control::Request::subscribe(\&commandCallback, [['stop', 'power', 'playlist']]);

or

Slim::Control::Request::subscribe(\&commandCallback, [['playlist'],['newsong']);

But how do I combine the two without saying that I'm after "power newsong" and "stop newsong"?

For now I've just removed the newsong filter, but that means I'm getting a lot of playlist commands that I don't care about.

Thanks,

Max

Grotus
2006-05-07, 11:05
max.spicer blurted out:
> I'm finally getting around to updating a few plugins to use the new
> Request::subscribe model and am trying to filter out commands
> appropriately. I'd like to be called if the command is "playlist
> newsong", power or stop. However, I can't quite work out how to do
> this.
>
> I can say
> Slim::Control::Request::subscribe(\&commandCallback, [['stop', 'power',
> 'playlist']]);
>
> or
>
> Slim::Control::Request::subscribe(\&commandCallback,
> [['playlist'],['newsong']);
>
> But how do I combine the two without saying that I'm after "power
> newsong" and "stop newsong"?
>
> For now I've just removed the newsong filter, but that means I'm
> getting a lot of playlist commands that I don't care about.
>
> Thanks,
>
> Max

You could wrap your command callback in two different routines

sub commandCallback {
# do something
}
sub commandCallback1 { return commandCallback(@_);}
sub commandCallback2 { return commandCallback(@_);}

Then do something like this:
Slim::Control::Request::subscribe(\&commandCallback1,[['playlist'],['newsong']]);
Slim::Control::Request::subscribe(\&commandCallback2, [['stop', 'power']]);

Fred
2006-05-07, 13:25
Yes, this is a limitation. I did not feel it was worth proposing the ultimate command filtering mechanism: simple way to avoid calling everybody for every ir and button was the main objective.

Feel free to improve it, though :-)

The method Grotus proposed is fine. The other is to use your first proposal and in the call back, use $request->isCommand([['playlist'], ['newsong']]) and same for stop and power.

HTH

Fred