42

Looking for fun, Feeling groovy…

Tag: fso

Battery Plugin and more..

After a little chat with mickeyl, I realised that exposing crucial functions like load() and unload() was not that of a good idea considering how odeviced is supposed to closely interact with the underlying devices. Consequently there has been some changes over the last week,

  • No DBus interface for the service.
  • Plugins have now access to a set of helper functions. Only two at the moment (Think setting up DBus object paths)
  • Plugins once loaded become resident, that is they cannot be unloaded. If plugins are to be disabled during startup, just remove them from the “enable” field in the global configuration file.
  • Per plugin configuration. Each plugins now have their own configuration. Makes more sense, since this mean plugins can have greater freedom with their settings. I really like how the newly checked in battery plugin exploits this.
  • Freshly checked in battery plugin. Makes use of sysfs for its functions viz. get_current_brightness, set_brightness, get_maximum_brightness.

SysFS (/sys in 2.6.x.x) is sort of similar to the /proc filesystem and acts as an interface for user-space applications to control/access various devices. One of the neat things about sysfs is the fact that all files consist of only a single entry. This means I don’t have to write a separate parser to extract data from them. So a simple fprintf or fscanf or even the seemingly mundane “echo” can be used to control the devices.

I am also planning to work on the python shell for odeviced for a while. This will be really convenient for testing the service. Something like this,

> Wifi is_on wlan0
True

The code can be checked out from here. I can’t wait till I get hold of a FreeRunner to test odeviced out. :)

The code is in…

Yay. Got the repository for odeviced set up at http://git.freesmartphone.org

Boy, do I love git.

First frigging milestone..

Why Milestone? Nope, I didn’t come up with fancy code or a “beautiful” one for that matter (Came up with a way to unload plugins). Milestone, because today was the first day I was squeezing up my half empty head to work around a teency weency problem. In short, I am happy I was actually thinking today about squishing a segmentation fault which was bringing the whole house down due to dbus and the kinky wifi plugin.

Now a word of warning. The wifi plugin is a circus freak of sorts. Being the lazy bum I am, I found it a drag to manually get into the trouble of coming up with xml introspection data for the “org.freesmartphone.Device.plugins.wifi” interface.

Instead I just came up with a grand plan of letting valac generate wifi.c and wifi.h, which I could modify later. Piece of cake? Sure…

After the wifi plugin is loaded it works pretty well. The keyword being “After”…By the way, check the progress report which I sent to the smartphone-standards list. That should give you an idea of how odeviced works and looks like. In fact, it works pretty satisfactorily discounting the segmentation faults  :D, which is easily reproducible in the following ways,

  • Don’t load the wifi plugin on startup, set enable=0 in odeviced.conf. Instead load it manually after odeviced starts up and begins to idle.
  • If the wifi plugin is already loaded, unload it and then try to load it again.

Part of this problem might be my arrogance of not to use GTypeModules for dynamically typing the plugins. I need to discuss with my mentor, mickeyl about this once he gets back to business after LinuxTag.

The barely bare bones powercontrol plugin loads and unloads without any problems, but it doesn’t do anything as remotely useful as the wifi plugin!! Just contains an init function that has a printf in it (bleh!, thank goodness it didn’t bail out).

Oh and the all important tarball is here. Highly effective than laughing gas!

…Another gdb session beckons

odeviced: progress report :P

So, presenting a preliminary skeleton service for odeviced that loads shared object libraries (or in other words plugins). Nothing to be proud of, but hey, something is better than nothing.

Here’s a screenshot of a very very preliminary odeviced in action..

odeviced

Basically its just a dbus service that can load modules from a predefined location. Here’s how it works currently,

  • Setup all the boring stuff like registering the object path and getting the connection to the DBus system bus. The interface used will be “org.freesmartphone.Device”.
  • The service reads the configuration file at /etc/odeviced.conf whose contents are as follows,
    # General configurations
    [odeviced]
    device_name=FreeRunner

    [powercontrol]
    enable=1
  • So from the above configuration, the device name is set to FreeRunner and odeviced tries to load the powercontrol plugin since “enable” is set to 1. Of course, the dbus service exposes the load method to load plugins manually after the service has started if the need arises.
  • The default directory for plugins is at ‘/usr/share/odeviced/plugins’. Maybe additional directories for other plugins can be set in odeviced.conf. By now odeviced tries to load the plugin libpowercontrol.so under ‘/usr/share/odeviced/plugins’.
  • After successful loading of the plugin, odeviced executes the init function in the plugin which is of the form <plugin_name>_init. In our case it is powercontrol_init. The dbus paths for the plugins are to be set here. So we would have object paths such as “/org/freesmartphone/Device/plugins/powercontrol’. This is yet to be done.
  • As evident in the above screenshot the powercontrol_init contains a single printf statement which merely spits out “In powercontrol”. And yes, the powercontrol plugin is written in good ol’ C.

Notice the gnome-terminal at the right. It is running a simple python helper script for testing odeviced. It simply reads from stdin and calls the `load’ method offered by the dbus service with the input as the argument. As you can see, powercontrol has been loaded successfully but “l” and “this_aint_a_plugin” gives a critical warning that these plugins couldn’t be found.

What needs to be done

  • Make the code “beautiful”. :D. I am constantly on the lookout for vala’ish ways of doing things. Still need to work on my OOP skills :/.
  • Come up with a decent plugin for powercontrol.
  • Put in some example apps or port the existing OM ones to use odeviced.
Design a site like this with WordPress.com
Get started