summaryrefslogtreecommitdiff
path: root/src/linux/up-device-wup.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2010-01-18 12:49:30 +0000
committerRichard Hughes <richard@hughsie.com>2010-01-18 12:49:30 +0000
commit25e51c96136c45632091a7b240f8935ce1d239ce (patch)
tree85d17e0631078617488d2b626575003f80bd7686 /src/linux/up-device-wup.c
parentd2550b4c7854e970719b07b48ecdb61af9c01b6f (diff)
trivial: DkpDevice -> UpDevice (no ABI or API break)
Diffstat (limited to 'src/linux/up-device-wup.c')
-rw-r--r--src/linux/up-device-wup.c156
1 files changed, 78 insertions, 78 deletions
diff --git a/src/linux/up-device-wup.c b/src/linux/up-device-wup.c
index 8fc3296..96aec4f 100644
--- a/src/linux/up-device-wup.c
+++ b/src/linux/up-device-wup.c
@@ -47,58 +47,58 @@
#include "up-enum.h"
#include "up-device-wup.h"
-#define DKP_DEVICE_WUP_REFRESH_TIMEOUT 10 /* seconds */
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_WATTS 0x0
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_VOLTS 0x1
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_AMPS 0x2
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_KWH 0x3
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_COST 0x4
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MONTHLY_KWH 0x5
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MONTHLY_COST 0x6
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MAX_WATTS 0x7
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MAX_VOLTS 0x8
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MAX_AMPS 0x9
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MIN_WATTS 0xa
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MIN_VOLTS 0xb
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_MIN_AMPS 0xc
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_POWER_FACTOR 0xd
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_DUTY_CYCLE 0xe
-#define DKP_DEVICE_WUP_RESPONSE_OFFSET_POWER_CYCLE 0xf
+#define UP_DEVICE_WUP_REFRESH_TIMEOUT 10 /* seconds */
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_WATTS 0x0
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_VOLTS 0x1
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_AMPS 0x2
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_KWH 0x3
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_COST 0x4
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MONTHLY_KWH 0x5
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MONTHLY_COST 0x6
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MAX_WATTS 0x7
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MAX_VOLTS 0x8
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MAX_AMPS 0x9
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MIN_WATTS 0xa
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MIN_VOLTS 0xb
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_MIN_AMPS 0xc
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_POWER_FACTOR 0xd
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_DUTY_CYCLE 0xe
+#define UP_DEVICE_WUP_RESPONSE_OFFSET_POWER_CYCLE 0xf
/* commands can never be bigger then this */
-#define DKP_DEVICE_WUP_COMMAND_LEN 256
+#define UP_DEVICE_WUP_COMMAND_LEN 256
-struct DkpDeviceWupPrivate
+struct UpDeviceWupPrivate
{
guint poll_timer_id;
int fd;
};
-G_DEFINE_TYPE (DkpDeviceWup, dkp_device_wup, DKP_TYPE_DEVICE)
-#define DKP_DEVICE_WUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_WUP, DkpDeviceWupPrivate))
+G_DEFINE_TYPE (UpDeviceWup, up_device_wup, UP_TYPE_DEVICE)
+#define UP_DEVICE_WUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_DEVICE_WUP, UpDeviceWupPrivate))
-static gboolean dkp_device_wup_refresh (DkpDevice *device);
+static gboolean up_device_wup_refresh (UpDevice *device);
/**
- * dkp_device_wup_poll_cb:
+ * up_device_wup_poll_cb:
**/
static gboolean
-dkp_device_wup_poll_cb (DkpDeviceWup *wup)
+up_device_wup_poll_cb (UpDeviceWup *wup)
{
- DkpDevice *device = DKP_DEVICE (wup);
+ UpDevice *device = UP_DEVICE (wup);
- egg_debug ("Polling: %s", dkp_device_get_object_path (device));
- dkp_device_wup_refresh (device);
+ egg_debug ("Polling: %s", up_device_get_object_path (device));
+ up_device_wup_refresh (device);
/* always continue polling */
return TRUE;
}
/**
- * dkp_device_wup_set_speed:
+ * up_device_wup_set_speed:
**/
static gboolean
-dkp_device_wup_set_speed (DkpDeviceWup *wup)
+up_device_wup_set_speed (UpDeviceWup *wup)
{
struct termios t;
int retval;
@@ -126,12 +126,12 @@ dkp_device_wup_set_speed (DkpDeviceWup *wup)
}
/**
- * dkp_device_wup_write_command:
+ * up_device_wup_write_command:
*
* data: a command string in the form "#command,subcommand,datalen,data[n]", e.g. "#R,W,0"
**/
static gboolean
-dkp_device_wup_write_command (DkpDeviceWup *wup, const gchar *data)
+up_device_wup_write_command (UpDeviceWup *wup, const gchar *data)
{
guint ret = TRUE;
gint retval;
@@ -148,16 +148,16 @@ dkp_device_wup_write_command (DkpDeviceWup *wup, const gchar *data)
}
/**
- * dkp_device_wup_read_command:
+ * up_device_wup_read_command:
*
* Return value: Some data to parse
**/
static gchar *
-dkp_device_wup_read_command (DkpDeviceWup *wup)
+up_device_wup_read_command (UpDeviceWup *wup)
{
int retval;
- gchar buffer[DKP_DEVICE_WUP_COMMAND_LEN];
- retval = read (wup->priv->fd, &buffer, DKP_DEVICE_WUP_COMMAND_LEN);
+ gchar buffer[UP_DEVICE_WUP_COMMAND_LEN];
+ retval = read (wup->priv->fd, &buffer, UP_DEVICE_WUP_COMMAND_LEN);
if (retval < 0) {
egg_debug ("failed to read from fd: %s", strerror (errno));
return NULL;
@@ -166,12 +166,12 @@ dkp_device_wup_read_command (DkpDeviceWup *wup)
}
/**
- * dkp_device_wup_parse_command:
+ * up_device_wup_parse_command:
*
* Return value: Som data to parse
**/
static gboolean
-dkp_device_wup_parse_command (DkpDeviceWup *wup, const gchar *data)
+up_device_wup_parse_command (UpDeviceWup *wup, const gchar *data)
{
gboolean ret = FALSE;
gchar command;
@@ -182,7 +182,7 @@ dkp_device_wup_parse_command (DkpDeviceWup *wup, const gchar *data)
guint size;
guint length;
guint number_tokens;
- DkpDevice *device = DKP_DEVICE (wup);
+ UpDevice *device = UP_DEVICE (wup);
const guint offset = 3;
/* invalid */
@@ -272,8 +272,8 @@ dkp_device_wup_parse_command (DkpDeviceWup *wup, const gchar *data)
/* update the command fields */
if (command == 'd' && subcommand == '-' && number_tokens - offset == 18) {
g_object_set (device,
- "energy-rate", strtod (tokens[offset+DKP_DEVICE_WUP_RESPONSE_OFFSET_WATTS], NULL) / 10.0f,
- "voltage", strtod (tokens[offset+DKP_DEVICE_WUP_RESPONSE_OFFSET_VOLTS], NULL) / 10.0f,
+ "energy-rate", strtod (tokens[offset+UP_DEVICE_WUP_RESPONSE_OFFSET_WATTS], NULL) / 10.0f,
+ "voltage", strtod (tokens[offset+UP_DEVICE_WUP_RESPONSE_OFFSET_VOLTS], NULL) / 10.0f,
NULL);
ret = TRUE;
} else {
@@ -287,14 +287,14 @@ out:
}
/**
- * dkp_device_wup_coldplug:
+ * up_device_wup_coldplug:
*
* Return %TRUE on success, %FALSE if we failed to get data and should be removed
**/
static gboolean
-dkp_device_wup_coldplug (DkpDevice *device)
+up_device_wup_coldplug (UpDevice *device)
{
- DkpDeviceWup *wup = DKP_DEVICE_WUP (device);
+ UpDeviceWup *wup = UP_DEVICE_WUP (device);
GUdevDevice *native;
gboolean ret = FALSE;
const gchar *device_file;
@@ -305,7 +305,7 @@ dkp_device_wup_coldplug (DkpDevice *device)
const gchar *product;
/* detect what kind of device we are */
- native = G_UDEV_DEVICE (dkp_device_get_native (device));
+ native = G_UDEV_DEVICE (up_device_get_native (device));
type = g_udev_device_get_property (native, "DKP_MONITOR_TYPE");
if (type == NULL || g_strcmp0 (type, "wup") != 0)
goto out;
@@ -326,30 +326,30 @@ dkp_device_wup_coldplug (DkpDevice *device)
egg_debug ("opened %s", device_file);
/* set speed */
- ret = dkp_device_wup_set_speed (wup);
+ ret = up_device_wup_set_speed (wup);
if (!ret) {
egg_debug ("not a WUP device (cannot set speed): %s", device_file);
goto out;
}
/* attempt to clear */
- ret = dkp_device_wup_write_command (wup, "#R,W,0;");
+ ret = up_device_wup_write_command (wup, "#R,W,0;");
if (!ret)
egg_debug ("failed to clear, nonfatal");
/* setup logging interval */
- data = g_strdup_printf ("#L,W,3,E,1,%i;", DKP_DEVICE_WUP_REFRESH_TIMEOUT);
- ret = dkp_device_wup_write_command (wup, data);
+ data = g_strdup_printf ("#L,W,3,E,1,%i;", UP_DEVICE_WUP_REFRESH_TIMEOUT);
+ ret = up_device_wup_write_command (wup, data);
if (!ret)
egg_debug ("failed to setup logging interval, nonfatal");
g_free (data);
/* dummy read */
- data = dkp_device_wup_read_command (wup);
+ data = up_device_wup_read_command (wup);
egg_debug ("data after clear %s", data);
/* shouldn't do anything */
- dkp_device_wup_parse_command (wup, data);
+ up_device_wup_parse_command (wup, data);
g_free (data);
/* prefer DKP names */
@@ -376,7 +376,7 @@ dkp_device_wup_coldplug (DkpDevice *device)
/* coldplug */
egg_debug ("coldplug");
- dkp_device_wup_refresh (device);
+ up_device_wup_refresh (device);
/* hardcode true, as we'll retry later if busy */
ret = TRUE;
@@ -386,27 +386,27 @@ out:
}
/**
- * dkp_device_wup_refresh:
+ * up_device_wup_refresh:
*
* Return %TRUE on success, %FALSE if we failed to refresh or no data
**/
static gboolean
-dkp_device_wup_refresh (DkpDevice *device)
+up_device_wup_refresh (UpDevice *device)
{
gboolean ret = FALSE;
GTimeVal timeval;
gchar *data = NULL;
- DkpDeviceWup *wup = DKP_DEVICE_WUP (device);
+ UpDeviceWup *wup = UP_DEVICE_WUP (device);
/* get data */
- data = dkp_device_wup_read_command (wup);
+ data = up_device_wup_read_command (wup);
if (data == NULL) {
egg_debug ("no data");
goto out;
}
/* parse */
- ret = dkp_device_wup_parse_command (wup, data);
+ ret = up_device_wup_parse_command (wup, data);
if (!ret) {
egg_debug ("failed to parse %s", data);
goto out;
@@ -423,29 +423,29 @@ out:
}
/**
- * dkp_device_wup_init:
+ * up_device_wup_init:
**/
static void
-dkp_device_wup_init (DkpDeviceWup *wup)
+up_device_wup_init (UpDeviceWup *wup)
{
- wup->priv = DKP_DEVICE_WUP_GET_PRIVATE (wup);
+ wup->priv = UP_DEVICE_WUP_GET_PRIVATE (wup);
wup->priv->fd = -1;
- wup->priv->poll_timer_id = g_timeout_add_seconds (DKP_DEVICE_WUP_REFRESH_TIMEOUT,
- (GSourceFunc) dkp_device_wup_poll_cb, wup);
+ wup->priv->poll_timer_id = g_timeout_add_seconds (UP_DEVICE_WUP_REFRESH_TIMEOUT,
+ (GSourceFunc) up_device_wup_poll_cb, wup);
}
/**
- * dkp_device_wup_finalize:
+ * up_device_wup_finalize:
**/
static void
-dkp_device_wup_finalize (GObject *object)
+up_device_wup_finalize (GObject *object)
{
- DkpDeviceWup *wup;
+ UpDeviceWup *wup;
g_return_if_fail (object != NULL);
- g_return_if_fail (DKP_IS_WUP (object));
+ g_return_if_fail (UP_IS_DEVICE_WUP (object));
- wup = DKP_DEVICE_WUP (object);
+ wup = UP_DEVICE_WUP (object);
g_return_if_fail (wup->priv != NULL);
if (wup->priv->fd > 0)
@@ -453,31 +453,31 @@ dkp_device_wup_finalize (GObject *object)
if (wup->priv->poll_timer_id > 0)
g_source_remove (wup->priv->poll_timer_id);
- G_OBJECT_CLASS (dkp_device_wup_parent_class)->finalize (object);
+ G_OBJECT_CLASS (up_device_wup_parent_class)->finalize (object);
}
/**
- * dkp_device_wup_class_init:
+ * up_device_wup_class_init:
**/
static void
-dkp_device_wup_class_init (DkpDeviceWupClass *klass)
+up_device_wup_class_init (UpDeviceWupClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- DkpDeviceClass *device_class = DKP_DEVICE_CLASS (klass);
+ UpDeviceClass *device_class = UP_DEVICE_CLASS (klass);
- object_class->finalize = dkp_device_wup_finalize;
- device_class->coldplug = dkp_device_wup_coldplug;
- device_class->refresh = dkp_device_wup_refresh;
+ object_class->finalize = up_device_wup_finalize;
+ device_class->coldplug = up_device_wup_coldplug;
+ device_class->refresh = up_device_wup_refresh;
- g_type_class_add_private (klass, sizeof (DkpDeviceWupPrivate));
+ g_type_class_add_private (klass, sizeof (UpDeviceWupPrivate));
}
/**
- * dkp_device_wup_new:
+ * up_device_wup_new:
**/
-DkpDeviceWup *
-dkp_device_wup_new (void)
+UpDeviceWup *
+up_device_wup_new (void)
{
- return g_object_new (DKP_TYPE_WUP, NULL);
+ return g_object_new (UP_TYPE_DEVICE_WUP, NULL);
}