all: Use g_get_real_time() when possible

Instead of a call to g_get_current_time().
This commit is contained in:
Bastien Nocera 2014-09-24 15:15:23 +02:00
parent 8271045a68
commit 5ddfe0dba1
9 changed files with 16 additions and 37 deletions

View file

@ -68,14 +68,12 @@ static gboolean
up_backend_changed_time_cb (UpBackend *backend) up_backend_changed_time_cb (UpBackend *backend)
{ {
UpDevice *device; UpDevice *device;
GTimeVal timeval;
//FIXME! //FIXME!
device = NULL; device = NULL;
/* reset time */ /* reset time */
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
return TRUE; return TRUE;
} }

View file

@ -382,7 +382,6 @@ static gboolean
up_device_supply_refresh (UpDevice *device) up_device_supply_refresh (UpDevice *device)
{ {
GObject *object; GObject *object;
GTimeVal timeval;
UpDeviceKind type; UpDeviceKind type;
gboolean ret; gboolean ret;
@ -400,10 +399,8 @@ up_device_supply_refresh (UpDevice *device)
break; break;
} }
if (ret) { if (ret)
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
}
return ret; return ret;
} }

View file

@ -219,7 +219,6 @@ static gboolean
up_device_csr_refresh (UpDevice *device) up_device_csr_refresh (UpDevice *device)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GTimeVal timeval;
UpDeviceCsr *csr = UP_DEVICE_CSR (device); UpDeviceCsr *csr = UP_DEVICE_CSR (device);
libusb_device_handle *handle = NULL; libusb_device_handle *handle = NULL;
guint8 buf[80]; guint8 buf[80];
@ -275,8 +274,7 @@ up_device_csr_refresh (UpDevice *device)
} }
/* reset time */ /* reset time */
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
/* success */ /* success */
ret = TRUE; ret = TRUE;

View file

@ -393,7 +393,6 @@ up_device_hid_refresh (UpDevice *device)
{ {
gboolean set = FALSE; gboolean set = FALSE;
gboolean ret = FALSE; gboolean ret = FALSE;
GTimeVal timeval;
guint i; guint i;
struct hiddev_event ev[64]; struct hiddev_event ev[64];
int rd; int rd;
@ -428,8 +427,7 @@ up_device_hid_refresh (UpDevice *device)
up_device_hid_fixup_state (device); up_device_hid_fixup_state (device);
/* reset time */ /* reset time */
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
out: out:
return ret; return ret;
} }

View file

@ -153,7 +153,6 @@ out:
static gboolean static gboolean
up_device_idevice_refresh (UpDevice *device) up_device_idevice_refresh (UpDevice *device)
{ {
GTimeVal timeval;
UpDeviceIdevice *idevice = UP_DEVICE_IDEVICE (device); UpDeviceIdevice *idevice = UP_DEVICE_IDEVICE (device);
lockdownd_client_t client = NULL; lockdownd_client_t client = NULL;
plist_t dict, node; plist_t dict, node;
@ -201,8 +200,7 @@ up_device_idevice_refresh (UpDevice *device)
plist_free (dict); plist_free (dict);
/* reset time */ /* reset time */
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
retval = TRUE; retval = TRUE;

View file

@ -1088,7 +1088,6 @@ static gboolean
up_device_supply_refresh (UpDevice *device) up_device_supply_refresh (UpDevice *device)
{ {
gboolean ret; gboolean ret;
GTimeVal timeval;
UpDeviceSupply *supply = UP_DEVICE_SUPPLY (device); UpDeviceSupply *supply = UP_DEVICE_SUPPLY (device);
UpDeviceKind type; UpDeviceKind type;
UpDeviceState state; UpDeviceState state;
@ -1109,10 +1108,8 @@ up_device_supply_refresh (UpDevice *device)
} }
/* reset time if we got new data */ /* reset time if we got new data */
if (ret) { if (ret)
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
}
return ret; return ret;
} }

View file

@ -48,7 +48,6 @@ up_device_unifying_refresh (UpDevice *device)
{ {
gboolean ret; gboolean ret;
GError *error = NULL; GError *error = NULL;
GTimeVal timeval;
HidppRefreshFlags refresh_flags; HidppRefreshFlags refresh_flags;
UpDeviceState state = UP_DEVICE_STATE_UNKNOWN; UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
UpDeviceUnifying *unifying = UP_DEVICE_UNIFYING (device); UpDeviceUnifying *unifying = UP_DEVICE_UNIFYING (device);
@ -95,7 +94,6 @@ up_device_unifying_refresh (UpDevice *device)
state = UP_DEVICE_STATE_UNKNOWN; state = UP_DEVICE_STATE_UNKNOWN;
} }
g_get_current_time (&timeval);
lux = hidpp_device_get_luminosity (priv->hidpp_device); lux = hidpp_device_get_luminosity (priv->hidpp_device);
if (lux >= 0) { if (lux >= 0) {
g_object_set (device, "luminosity", lux, NULL); g_object_set (device, "luminosity", lux, NULL);
@ -105,7 +103,7 @@ up_device_unifying_refresh (UpDevice *device)
"is-present", hidpp_device_is_reachable (priv->hidpp_device), "is-present", hidpp_device_is_reachable (priv->hidpp_device),
"percentage", (gdouble) hidpp_device_get_batt_percentage (priv->hidpp_device), "percentage", (gdouble) hidpp_device_get_batt_percentage (priv->hidpp_device),
"state", state, "state", state,
"update-time", (guint64) timeval.tv_sec, "update-time", (guint64) g_get_real_time (),
NULL); NULL);
out: out:
return TRUE; return TRUE;

View file

@ -388,7 +388,6 @@ static gboolean
up_device_wup_refresh (UpDevice *device) up_device_wup_refresh (UpDevice *device)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GTimeVal timeval;
gchar *data = NULL; gchar *data = NULL;
UpDeviceWup *wup = UP_DEVICE_WUP (device); UpDeviceWup *wup = UP_DEVICE_WUP (device);
@ -407,8 +406,7 @@ up_device_wup_refresh (UpDevice *device)
} }
/* reset time */ /* reset time */
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
out: out:
g_free (data); g_free (data);

View file

@ -399,7 +399,6 @@ static gboolean
up_apm_device_refresh(UpDevice* device) up_apm_device_refresh(UpDevice* device)
{ {
UpDeviceKind type; UpDeviceKind type;
GTimeVal timeval;
gboolean ret; gboolean ret;
g_object_get (device, "type", &type, NULL); g_object_get (device, "type", &type, NULL);
@ -415,10 +414,8 @@ up_apm_device_refresh(UpDevice* device)
break; break;
} }
if (ret) { if (ret)
g_get_current_time (&timeval); g_object_set (device, "update-time", (guint64) g_get_real_time (), NULL);
g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL);
}
return ret; return ret;
} }
@ -578,8 +575,8 @@ static void
up_backend_init (UpBackend *backend) up_backend_init (UpBackend *backend)
{ {
GError *err = NULL; GError *err = NULL;
GTimeVal timeval;
UpDeviceClass *device_class; UpDeviceClass *device_class;
gint64 current_time;
backend->priv = UP_BACKEND_GET_PRIVATE (backend); backend->priv = UP_BACKEND_GET_PRIVATE (backend);
backend->priv->is_laptop = up_native_is_laptop(); backend->priv->is_laptop = up_native_is_laptop();
@ -604,7 +601,7 @@ up_backend_init (UpBackend *backend)
} }
/* setup dummy */ /* setup dummy */
g_get_current_time (&timeval); current_time = g_get_real_time ();
g_object_set (backend->priv->battery, g_object_set (backend->priv->battery,
"type", UP_DEVICE_KIND_BATTERY, "type", UP_DEVICE_KIND_BATTERY,
"power-supply", TRUE, "power-supply", TRUE,
@ -614,13 +611,13 @@ up_backend_init (UpBackend *backend)
"state", UP_DEVICE_STATE_UNKNOWN, "state", UP_DEVICE_STATE_UNKNOWN,
"percentage", 0.0f, "percentage", 0.0f,
"time-to-empty", (gint64) 0, "time-to-empty", (gint64) 0,
"update-time", (guint64) timeval.tv_sec, "update-time", (guint64) current_time,
(void*) NULL); (void*) NULL);
g_object_set (backend->priv->ac, g_object_set (backend->priv->ac,
"type", UP_DEVICE_KIND_LINE_POWER, "type", UP_DEVICE_KIND_LINE_POWER,
"online", TRUE, "online", TRUE,
"power-supply", TRUE, "power-supply", TRUE,
"update-time", (guint64) timeval.tv_sec, "update-time", (guint64) current_time,
(void*) NULL); (void*) NULL);
} }
} }