[maemo-developers] Low Battery signal N800/N810

From: kumar lomash kumar.lomash at gmail.com
Date: Mon May 5 08:21:05 EEST 2008
Thanks Kees,

Actually I was looking for some API which could poll these messages for me
inside my application so that I could attach it to my g_main loop and do
other things in the same thread. Luckily for me I found the solution in the
source code of ACMonitor.
Here is what I did for battery:
battery_info_get kind of registers the callback for battery signals,
bme_message_handler is called everytime a signal is sent from com.nokia.bme
Code: -
#define BME_SIG_PATH "/com/nokia/bme/signal"
#define BME_SIG_IFC  "com.nokia.bme.signal"
#define BME_REQ_PATH "/com/nokia/bme/request"
#define BME_REQ_IFC  "com.nokia.bme.request"
void battery_info_get()
{
      DBusMessage *db_msg;
    DBusConnection *db_conn;
    DBusError  dberror;
    GMainLoop *loop;

    dbus_error_init(&dberror);
    prog_data.db_conn = db_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dberror);
    if(db_conn == NULL)
    {
        printf("Failed to open connection to system message bus: %s\n",
dberror.message);
        dbus_error_free(&dberror);
        return;
    }
    dbus_bus_add_match(db_conn,
"type='signal',path='"BME_SIG_PATH"',interface='"BME_SIG_IFC"'",NULL);
    dbus_connection_add_filter(db_conn,
(DBusHandleMessageFunction)bme_message_handler, NULL, NULL);
    db_msg = dbus_message_new_signal(BME_REQ_PATH, BME_REQ_IFC,
"status_info_req");
    dbus_connection_send(db_conn, db_msg, NULL);
    dbus_connection_flush(db_conn);
    dbus_message_unref(db_msg);
    dbus_connection_setup_with_g_main(db_conn, NULL);
}

static DBusHandlerResult bme_message_handler(DBusConnection *_conn,
DBusMessage *_msg, gpointer *ctx)
{
    if(dbus_message_get_type(_msg) == DBUS_MESSAGE_TYPE_SIGNAL)
    {
        const char *member;
        member = dbus_message_get_member(_msg);
        if(!strcmp(member, "battery_low"))
        {
            prog_data.battery_low = TRUE;
            /* Do something */
        }
        else if(!strcmp(member, "charger_charging_on"))
        {
            prog_data.charging = TRUE;
        }
        else if(!strcmp(member, "charger_charging_off"))
        {
            prog_data.charging = FALSE;
        }

        printf("dbus-printed %s\n", member);
    }
    return DBUS_HANDLER_RESULT_HANDLED;
}
On Mon, May 5, 2008 at 12:56 AM, Kees Jongenburger <
kees.jongenburger at gmail.com> wrote:

> Hi
>
> I am fairly new to dbus but if you run dbus-monitor --system from a
> console
> and hover over the battery monitor applet you will see what calls are used
> to
> get this information.
>
> Nokia-N810-50-2:~# dbus-monitor --system
> signal sender=org.freedesktop.DBus -> dest=:1.67
> path=/org/freedesktop/DBus; interface=org.freedesktop.DBus;
> member=NameAcquired
>   string ":1.67"
> signal sender=:1.20 -> dest=(null destination)
> path=/com/nokia/bme/request; interface=com.nokia.bme.request;
> member=timeleft_info_req
> signal sender=:1.9 -> dest=(null destination)
> path=/com/nokia/bme/signal; interface=com.nokia.bme.signal;
> member=battery_timeleft
>   uint32 5280
>   uint32 120
>
>
> Hope this helps greetings
>
>
> On Mon, Apr 28, 2008 at 8:26 AM, kumar lomash <kumar.lomash at gmail.com>
> wrote:
> > Hi,
> >
> > I have been trying to get a signal when battery status (time left, etc)
> > changes. I understand that I will have to use lib osso APIs for this,
> but I
> > am unable to find a service prvider (e.g. com.nokia.battery ???) to
> connect
> > to.
> >  Is this documented somewhere? I could not find anything on this.
> >
> > Can someone please send details of which service/interface to connect
> to?
> >
> > Thanks a lot,
> > Lomash
> >
> > _______________________________________________
> >  maemo-developers mailing list
> >  maemo-developers at maemo.org
> >  https://lists.maemo.org/mailman/listinfo/maemo-developers
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maemo.org/pipermail/maemo-developers/attachments/20080505/82a72088/attachment.htm 
More information about the maemo-developers mailing list