Skip to content

Commit

Permalink
Merge pull request #59 from plundstr/next
Browse files Browse the repository at this point in the history
dbus support to thermal manager
  • Loading branch information
Pekka Lundstrom committed Feb 27, 2014
2 parents 508702b + 2b18e40 commit be4f62b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/Makefile.am
Expand Up @@ -154,7 +154,7 @@ if WANT_HW_THERMAL_MGMT
thermalobject_hw_la_SOURCES = thermalobject_hw.c \
thermalsensor_hw.c \
thermalsensor_hw.h
thermalobject_hw_la_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
thermalobject_hw_la_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS)
thermalobject_hw_la_LIBADD = $(GLIB_LIBS)
endif

Expand Down
62 changes: 62 additions & 0 deletions modules/thermalobject_hw.c
Expand Up @@ -30,6 +30,10 @@
#include "dsme/modules.h"
#include "dsme/logging.h"

#include "dsme_dbus.h"
#include "dbusproxy.h"
#include <dsme/thermalmanager_dbus_if.h>

static bool core_registered = false;
static bool battery_registered = false;

Expand Down Expand Up @@ -78,6 +82,64 @@ static thermal_object_t battery_thermal_object = {
0
};

static int measured_core_temp = INVALID_TEMPERATURE;
static int measured_battery_temp = INVALID_TEMPERATURE;

static void core_temp_cb(thermal_object_t* thermal_object, int temp)
{
(void) thermal_object;
measured_core_temp = temp;
}

static void battery_temp_cb(thermal_object_t* thermal_object, int temp)
{
(void) thermal_object;
measured_battery_temp = temp;
}

static void core_temperature(const DsmeDbusMessage* request,
DsmeDbusMessage** reply)
{
dsme_hw_get_core_temperature(NULL, core_temp_cb);
*reply = dsme_dbus_reply_new(request);
dsme_dbus_message_append_int(*reply, measured_core_temp);
}

static void battery_temperature(const DsmeDbusMessage* request,
DsmeDbusMessage** reply)
{
dsme_hw_get_battery_temperature(NULL, battery_temp_cb);
*reply = dsme_dbus_reply_new(request);
dsme_dbus_message_append_int(*reply, measured_battery_temp);
}

static const dsme_dbus_binding_t methods[] = {
{ core_temperature, "core_temperature" },
{ battery_temperature, "battery_temperature" },
{ 0, 0 }
};

static bool bound = false;
static const char* const service = thermalmanager_service;
static const char* const interface = thermalmanager_interface;

DSME_HANDLER(DSM_MSGTYPE_DBUS_CONNECT, client, msg)
{
dsme_log(LOG_DEBUG, "thermalobject_hw: DBUS_CONNECT");
dsme_dbus_bind_methods(&bound, methods, service, interface);
}

DSME_HANDLER(DSM_MSGTYPE_DBUS_DISCONNECT, client, msg)
{
dsme_log(LOG_DEBUG, "thermalobject_hw: DBUS_DISCONNECT");
dsme_dbus_unbind_methods(&bound, methods, service, interface);
}

module_fn_info_t message_handlers[] = {
DSME_HANDLER_BINDING(DSM_MSGTYPE_DBUS_CONNECT),
DSME_HANDLER_BINDING(DSM_MSGTYPE_DBUS_DISCONNECT),
{ 0 }
};

void module_init(module_t* handle)
{
Expand Down
11 changes: 6 additions & 5 deletions util/dsmetemperature
@@ -1,11 +1,12 @@
#!/bin/sh

export PERIOD=5
PERIOD=5

echo Displaying elapsed time and estimated surface temperature every $PERIOD seconds
echo Displaying date, core and battery temperature every $PERIOD seconds

export STARTTIME=$(date +"%s")
while true; do
dbus-send --system --print-reply --dest=com.nokia.thermalmanager /com/nokia/thermalmanager com.nokia.thermalmanager.estimate_surface_temperature | grep int32 | while read HABA TEMPERATURE; do echo $(expr $(date +"%s") - $STARTTIME) $TEMPERATURE; done
sleep 5
CORE_TEMP=$(dbus-send --system --print-reply --dest=com.nokia.thermalmanager /com/nokia/thermalmanager com.nokia.thermalmanager.core_temperature | grep int32 | tr -s ' ' | cut -d ' ' -f3)
BATTERY_TEMP=$(dbus-send --system --print-reply --dest=com.nokia.thermalmanager /com/nokia/thermalmanager com.nokia.thermalmanager.battery_temperature | grep int32 | tr -s ' ' | cut -d ' ' -f3)
echo "`date +\"%x %T\"` core=$CORE_TEMP battery=$BATTERY_TEMP"
sleep $PERIOD
done

0 comments on commit be4f62b

Please sign in to comment.