Siglaunchd

From Openmoko

Revision as of 23:35, 23 November 2008 by Tomhacohen (Talk | contribs)

Jump to: navigation, search


This project is daemon which listens to dbus signals and runs applications accordingly. The signals, application to run and some rules that will be evaluated against incoming dbus signals can be easily changed in the configuration file. This application is mainly intended to work with the openmoko framework so end users will be able to run application upon events without too much effort, though that isn't a limitation. For example, one can set the aux button to launch the dialer and the other can set a sound when screen is dimmed with as little as no effort.

(The default config file is set to run the profile-changer when the aux button is pressed for more than a second)

Contents

Package

  • author: Tom Hacohen <available_at_profile>
  • this is a python script so code resides in /usr/bin/siglaunchd (hopefuly in a public svn soon)
  • link: package

How To Use

siglaunchd connects to predefined dbus signals checks some parameters and if the signal matches the application associated with it is launched.

This daemon reads the configuration file looking for records of the type: bin=interface;busname;path;signal;rule1,rule2...
While:

  • bin is the binary to run (and parameters)
  • interface, busname, path and signal are dbus related
  • rules are seperated by a ',' and look like arg[id](=|<|>)value. arg[] is a configuration file patteren and shouldn't be changed.

For example if I a rule to check if the first parameter got from the dbus signal equals to "test" the rule will be: 0=test


Example configuration file line: "DISPLAY=:0.0 openmoko-terminal2"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>1


I used this configuration to run the openmoko-terminal2 everytime I held the aux button for 2 seconds or more.

You can actually add as many lines you want to the config and associate as many applications needed to a single signal with different/same rules(in different lines) .

Another example: the "Event" signal form the "org.freesmartphone.Device.Input" interface in the framework sends looks like this: Event ( ssi ) where the arguments are: the first s = name of input device the second s = the action took place i = duration of the event. We can then tell the dameno to "echo hi" (not very useful) everytime an Event signal of any kind arrives like this:

"echo hi"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;

DON'T FORGET THE LAST ';'!!!

If we want it only to occur when the aux button is released (doesn't matter how much time it was held) we will do the following:

"echo hi"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX, arg[1]=released

Mind the fact that now there is no ; at the end!!! (only needed before the rules)


Now, if we want, we can tell it to echo hi only if the button was released after i seconds where 4<i<7, i.e, i =5,6 we will do the following:

"echo hi"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX, arg[1]=released, arg[2]>4, arg[2]<7

The same argument can be evaluated as many times you like, use it. Btw, all the rules are logicaly connected with an AND operation, so they all must match! If you want an OR logical connection you must add a brand new line differing in what you want it to differ.

This daemon is designed for use with the openmoko framework, read about the framework dbus signals at: http://git.freesmartphone.org/?p=specs.git;a=blob_plain;f=html/index.html

Please send me feedback about bugs/suggestions. Enjoy.

Change Log

0.2.1:

  • fixed a minor regex spaces bug

0.2.0:

  • added spaces support for the configuartion file. spaces do not break the configuration anymore.
  • arg[id]>value is the new rules pattern and replaced the old id>value.
  • the daemon now starts when installed, no need to start it explicitly.
  • stopped using the deprecated os.system and started using the subprocess module

0.1.3:

  • added a scripts dir in /usr/share/siglaunchd/scripts/ that's the proper place to put custom user scripts (and stock example ones)
  • wrote the profile-changer app, a script packed with the siglaunchd that controls the framework's phone profile using a gui.

TODO

  • upgrade the rules system (add more complex variable types for comparison in the rules)
  • add errors (and a log file?) when the configuration file is broken
  • < and > only supports floats, add string support (= works with strings).
  • add support for SIGHUP so configuration will be loaded without app restart
  • change the config files to be in xml/other format instead of the current custom one
  • fix the example script to first load the gui and only the probe dbus.

List of users configs

This is a list of config lines users added. If you use any custom config yourself (you should, the stock config is a demo) please add it here so others may use them as well.

AUX button - Launch The profile-changer (STOCK)

"DISPLAY=:0.0 /usr/share/siglaunchd/scripts/profile-changer"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>0

AUX button - Launch Terminal

"DISPLAY=:0.0 openmoko-terminal2"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>1

AUX button - Launch Framework-settings

"DISPLAY=:0.0 python fso-settings"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>1

Power button - Launch Flashlight

Although the power button is set to be the suspend on fso/shr and when held for more than 10 seconds it will shut down the device, in the area between, I set it to launch the flashlight app, because I don't like messing with stuff when I need my flashlight on! (you can easily change it to run anything else, so this is also a good example for using the power button)

"DISPLAY=:0.0 /usr/bin/flashlight"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=POWER, arg[1]=released, arg[2]>1, arg[2]<8

Incoming message alert

just replace the echo message with the script (popup?) you want to run.

"DISPLAY=:0.0 echo message"=org.freesmartphone.GSM.SMS;org.freesmartphone.ogsmd;/org/freesmartphone/GSM/Device;IncomingMessage;

Personal tools


This project is daemon which listens to dbus signals and runs applications accordingly. The signals, application to run and some rules that will be evaluated against incoming dbus signals can be easily changed in the configuration file. This application is mainly intended to work with the openmoko framework so end users will be able to run application upon events without too much effort, though that isn't a limitation. For example, one can set the aux button to launch the dialer and the other can set a sound when screen is dimmed with as little as no effort.

(The default config file is set to run the profile-changer when the aux button is pressed for more than a second)

Package

  • author: Tom Hacohen <available_at_profile>
  • this is a python script so code resides in /usr/bin/siglaunchd (hopefuly in a public svn soon)
  • link: package

How To Use

siglaunchd connects to predefined dbus signals checks some parameters and if the signal matches the application associated with it is launched.

This daemon reads the configuration file looking for records of the type: bin=interface;busname;path;signal;rule1,rule2...
While:

  • bin is the binary to run (and parameters)
  • interface, busname, path and signal are dbus related
  • rules are seperated by a ',' and look like arg[id](=|<|>)value. arg[] is a configuration file patteren and shouldn't be changed.

For example if I a rule to check if the first parameter got from the dbus signal equals to "test" the rule will be: 0=test


Example configuration file line: "DISPLAY=:0.0 openmoko-terminal2"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>1


I used this configuration to run the openmoko-terminal2 everytime I held the aux button for 2 seconds or more.

You can actually add as many lines you want to the config and associate as many applications needed to a single signal with different/same rules(in different lines) .

Another example: the "Event" signal form the "org.freesmartphone.Device.Input" interface in the framework sends looks like this: Event ( ssi ) where the arguments are: the first s = name of input device the second s = the action took place i = duration of the event. We can then tell the dameno to "echo hi" (not very useful) everytime an Event signal of any kind arrives like this:

"echo hi"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;

DON'T FORGET THE LAST ';'!!!

If we want it only to occur when the aux button is released (doesn't matter how much time it was held) we will do the following:

"echo hi"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX, arg[1]=released

Mind the fact that now there is no ; at the end!!! (only needed before the rules)


Now, if we want, we can tell it to echo hi only if the button was released after i seconds where 4<i<7, i.e, i =5,6 we will do the following:

"echo hi"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX, arg[1]=released, arg[2]>4, arg[2]<7

The same argument can be evaluated as many times you like, use it. Btw, all the rules are logicaly connected with an AND operation, so they all must match! If you want an OR logical connection you must add a brand new line differing in what you want it to differ.

This daemon is designed for use with the openmoko framework, read about the framework dbus signals at: http://git.freesmartphone.org/?p=specs.git;a=blob_plain;f=html/index.html

Please send me feedback about bugs/suggestions. Enjoy.

Change Log

0.2.1:

  • fixed a minor regex spaces bug

0.2.0:

  • added spaces support for the configuartion file. spaces do not break the configuration anymore.
  • arg[id]>value is the new rules pattern and replaced the old id>value.
  • the daemon now starts when installed, no need to start it explicitly.
  • stopped using the deprecated os.system and started using the subprocess module

0.1.3:

  • added a scripts dir in /usr/share/siglaunchd/scripts/ that's the proper place to put custom user scripts (and stock example ones)
  • wrote the profile-changer app, a script packed with the siglaunchd that controls the framework's phone profile using a gui.

TODO

  • upgrade the rules system (add more complex variable types for comparison in the rules)
  • add errors (and a log file?) when the configuration file is broken
  • < and > only supports floats, add string support (= works with strings).
  • add support for SIGHUP so configuration will be loaded without app restart
  • change the config files to be in xml/other format instead of the current custom one
  • fix the example script to first load the gui and only the probe dbus.

List of users configs

This is a list of config lines users added. If you use any custom config yourself (you should, the stock config is a demo) please add it here so others may use them as well.

AUX button - Launch The profile-changer (STOCK)

"DISPLAY=:0.0 /usr/share/siglaunchd/scripts/profile-changer"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>0

AUX button - Launch Terminal

"DISPLAY=:0.0 openmoko-terminal2"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>1

AUX button - Launch Framework-settings

"DISPLAY=:0.0 python fso-settings"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=AUX,arg[1]=released,arg[2]>1

Power button - Launch Flashlight

Although the power button is set to be the suspend on fso/shr and when held for more than 10 seconds it will shut down the device, in the area between, I set it to launch the flashlight app, because I don't like messing with stuff when I need my flashlight on! (you can easily change it to run anything else, so this is also a good example for using the power button)

"DISPLAY=:0.0 /usr/bin/flashlight"=org.freesmartphone.Device.Input;org.freesmartphone.oeventsd;/org/freesmartphone/Device/Input;Event;arg[0]=POWER, arg[1]=released, arg[2]>1, arg[2]<8

Incoming message alert

just replace the echo message with the script (popup?) you want to run.

"DISPLAY=:0.0 echo message"=org.freesmartphone.GSM.SMS;org.freesmartphone.ogsmd;/org/freesmartphone/GSM/Device;IncomingMessage;