What's a control ?

A control is a ruby class that will be called by the command protocol “control control_name [arguments]” sent by the client to the server. Actually, a control is a specific action, for example the amarok control class is composed of one or several methods to manage amarok application on linux OS.

Each control is located in the “server/controls” directory.

There is another method to create a specific action for remote controlling : exec.

Why creating a control rather than an exec ?

When you create a control, you beneficiate of ruby's power and flexibility.

On top of that, whenever the server executes a control, it keeps persistent data in the client context because each control call is made by the same class instance. For example, if you want to set the volume to a value and keep this value all the time to do a simple incrementation to increase the volume, you can store this value in a class member.

Finally, the last features offered by PwrCtl controls are :

  • Platform specificity handling : just fill in the PLATFORMS constant to be protected of non supported platform.
  • Complete handling of network dialog : message method sends a message of different types (:info, :alert, :error) to the client which is calling the control.

How to create one

Let's see an example :

class Demo

        ## OPTIONAL: Plaforms supported
        PLATFORMS = ['windows', 'linux']

        ## OPTIONAL: Control initialization
        def initialize
                puts 'Demo control initialized'
        end

        ## REQUIRED: Control entry point
        # args is an Array containing the control arguments
        def run(args)
                message('Control Demo ok :)', :info)
        end

end

These are optional:

  • PLATFORMS is the constant for the platform specificity handling.
  • initialize is the constructor method of the control class. This method is called only one time, during the first client call of the control.

These are required:

  • run is the entry point of the control class. This method will be called each time the client will call the control. args is an array containing the control arguments passed by the client.


Please note it's very important to name your control class <your control name>.capitalize. For example if you want to create the “amarok” control, name it “Amarok” when your create the class.

control.txt · Last modified: 2009/06/21 00:27 (external edit)
Back to top
Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0