diff --git a/.gitignore b/.gitignore index 1cd7712..75e73b0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ documentation.list installroot build RPMS +examples/example +examples/example.o diff --git a/Makefile b/Makefile index 2eb55ea..0fcbb01 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ SRC = \ mce_battery.c \ mce_charger.c \ mce_display.c \ + mce_inactivity.c \ mce_proxy.c \ mce_tklock.c GEN_SRC = \ diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..70e9e55 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,15 @@ +.PHONY: build clean mostlyclean +build:: +clean:: mostlyclean +mostlyclean:: ; $(RM) *.o *~ *.bak +PKG_NAMES += glib-2.0 +PKG_NAMES += libmce-glib +CPPFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -Wall -Wextra -Os -g -std=c99 +LDFLAGS += -g +LDLIBS += -Wl,--as-needed +CFLAGS += $(shell pkg-config --cflags $(PKG_NAMES)) +LDLIBS += $(shell pkg-config --libs $(PKG_NAMES)) +example : example.o +build:: example +clean:: ; $(RM) example diff --git a/examples/example.c b/examples/example.c new file mode 100644 index 0000000..ea872dd --- /dev/null +++ b/examples/example.c @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2023 Jolla Ltd. + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +/* ========================================================================= * + * MAINLOOP + * ========================================================================= */ + +static int mainloop_result = EXIT_SUCCESS; +static GMainLoop *mainloop_handle = NULL; + +static void mainloop_exit(int exitcode) +{ + if( mainloop_result < exitcode ) + mainloop_result = exitcode; + if( !mainloop_handle ) + exit(mainloop_result); + g_main_loop_quit(mainloop_handle); +} + +static void mainloop_quit(void) +{ + mainloop_exit(EXIT_SUCCESS); +} + +static int mainloop_run(void) +{ + mainloop_handle = g_main_loop_new(NULL, false); + g_main_loop_run(mainloop_handle); + g_main_loop_unref(mainloop_handle), + mainloop_handle = NULL; + return mainloop_result; +} + +/* ========================================================================= * + * STATUS + * ========================================================================= */ + +static const char *bool_repr(bool value) +{ + return value ? "true" : "false"; +} + +static const char *battery_status_repr(MCE_BATTERY_STATUS status) +{ + static const char * const lut[] = { + [MCE_BATTERY_UNKNOWN] = "unknown", + [MCE_BATTERY_EMPTY] = "empty", + [MCE_BATTERY_LOW] = "low", + [MCE_BATTERY_OK] = "ok", + [MCE_BATTERY_FULL] = "full", + }; + return lut[status]; +} + +static const char *charger_state_repr(MCE_CHARGER_STATE state) +{ + static const char * const lut[] = { + [MCE_CHARGER_UNKNOWN] = "unknown", + [MCE_CHARGER_ON] = "on", + [MCE_CHARGER_OFF] = "off", + }; + return lut[state]; +} + +static const char *display_state_repr(MCE_DISPLAY_STATE state) +{ + static const char * const lut[] = { + [MCE_DISPLAY_STATE_OFF] = "off", + [MCE_DISPLAY_STATE_DIM] = "dim", + [MCE_DISPLAY_STATE_ON] = "on", + }; + return lut[state]; +} + +static const char *tklock_mode_repr(MCE_TKLOCK_MODE mode) +{ + static const char * const lut[] = { + [MCE_TKLOCK_MODE_LOCKED] = "locked", + [MCE_TKLOCK_MODE_SILENT_LOCKED] = "silent_locked", + [MCE_TKLOCK_MODE_LOCKED_DIM] = "locked_dim", + [MCE_TKLOCK_MODE_LOCKED_DELAY] = "locked_delay", + [MCE_TKLOCK_MODE_SILENT_LOCKED_DIM] = "silent_locked_dim", + [MCE_TKLOCK_MODE_UNLOCKED] = "unlocked", + [MCE_TKLOCK_MODE_SILENT_UNLOCKED] = "silent_unlocked", + }; + return lut[mode]; +} + +static void battery_cb(MceBattery *battery, void *arg) +{ + const char *what_changed = arg; + printf("battery: valid=%s level=%d status=%s (%s changed)\n", + bool_repr(battery->valid), + battery->level, + battery_status_repr(battery->status), + what_changed); +} + +static void charger_cb(MceCharger *charger, void *arg) +{ + const char *what_changed = arg; + printf("charger: valid=%s state=%s (%s changed)\n", + bool_repr(charger->valid), + charger_state_repr(charger->state), + what_changed); +} + +static void display_cb(MceDisplay *display, void *arg) +{ + const char *what_changed = arg; + printf("display: valid=%s state=%s (%s changed)\n", + bool_repr(display->valid), + display_state_repr(display->state), + what_changed); +} + +static void tklock_cb(MceTklock *tklock, void *arg) +{ + const char *what_changed = arg; + printf("tklock: valid=%s mode=%s locked=%s (%s changed)\n", + bool_repr(tklock->valid), + tklock_mode_repr(tklock->mode), + bool_repr(tklock->locked), + what_changed); +} + +static void inactivity_cb(MceInactivity *inactivity, void *arg) +{ + const char *what_changed = arg; + printf("inactivity: valid=%s status=%s (%s changed)\n", + bool_repr(inactivity->valid), + bool_repr(inactivity->status), + what_changed); +} + +/* ========================================================================= * + * MAIN_ENTRY + * ========================================================================= */ + +static gboolean quit_cb(gpointer aptr) +{ + printf("quit\n"); + mainloop_quit(); + guint *id_ptr = aptr; + *id_ptr = 0; + return G_SOURCE_REMOVE; +} + +int +main(int argc, char **argv) +{ + printf("startup\n"); + + int exitcode = EXIT_FAILURE; + + MceBattery *battery = mce_battery_new(); + gulong battery_valid_id = + mce_battery_add_valid_changed_handler(battery, battery_cb, "valid"); + gulong battery_level_id = + mce_battery_add_level_changed_handler(battery, battery_cb, "level"); + gulong battery_status_id = + mce_battery_add_status_changed_handler(battery, battery_cb, "status"); + + MceCharger *charger = mce_charger_new(); + gulong charger_valid_id = + mce_charger_add_valid_changed_handler(charger, charger_cb, "valid"); + gulong charger_state_id = + mce_charger_add_state_changed_handler(charger, charger_cb, "state"); + + MceDisplay *display = mce_display_new(); + gulong display_valid_id = + mce_display_add_valid_changed_handler(display, display_cb, "valid"); + gulong display_state_id = + mce_display_add_state_changed_handler(display, display_cb, "state"); + + MceTklock *tklock = mce_tklock_new(); + gulong tklock_valid_id = + mce_tklock_add_valid_changed_handler(tklock, tklock_cb, "valid"); + gulong tklock_mode_id = + mce_tklock_add_mode_changed_handler(tklock, tklock_cb, "mode"); + gulong tklock_locked_id = + mce_tklock_add_locked_changed_handler(tklock, tklock_cb, "locked"); + + MceInactivity *inactivity = mce_inactivity_new(); + gulong inactivity_valid_id = + mce_inactivity_add_valid_changed_handler(inactivity, inactivity_cb, "valid"); + gulong inactivity_status_id = + mce_inactivity_add_status_changed_handler(inactivity, inactivity_cb, "status"); + + guint timeout_id = 0; + gint timeout_s = (argc > 1) ? strtol(argv[1], NULL, 0) : 0; + if( timeout_s > 0) + timeout_id = g_timeout_add(timeout_s * 1000, quit_cb, &timeout_id); + + guint sigterm_id = g_unix_signal_add(SIGTERM, quit_cb, &sigterm_id); + guint sigint_id = g_unix_signal_add(SIGINT, quit_cb, &sigint_id); + + printf("mainloop\n"); + exitcode = mainloop_run(); + printf("cleanup\n"); + + if( sigterm_id ) + g_source_remove(sigterm_id); + if( sigint_id ) + g_source_remove(sigint_id); + if( timeout_id ) + g_source_remove(timeout_id); + + mce_battery_remove_handler(battery, battery_valid_id); + mce_battery_remove_handler(battery, battery_level_id); + mce_battery_remove_handler(battery, battery_status_id); + mce_battery_unref(battery); + + mce_charger_remove_handler(charger, charger_valid_id); + mce_charger_remove_handler(charger, charger_state_id); + mce_charger_unref(charger); + + mce_display_remove_handler(display, display_valid_id); + mce_display_remove_handler(display, display_state_id); + mce_display_unref(display); + + mce_tklock_remove_handler(tklock, tklock_valid_id); + mce_tklock_remove_handler(tklock, tklock_mode_id); + mce_tklock_remove_handler(tklock, tklock_locked_id); + mce_tklock_unref(tklock); + + mce_inactivity_remove_handler(inactivity, inactivity_valid_id); + mce_inactivity_remove_handler(inactivity, inactivity_status_id); + mce_inactivity_unref(inactivity); + + printf("exit\n"); + return exitcode; +} diff --git a/include/mce_inactivity.h b/include/mce_inactivity.h new file mode 100644 index 0000000..7fbb9ad --- /dev/null +++ b/include/mce_inactivity.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2016 - 2023 Jolla Ltd. + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#ifndef MCE_INACTIVITY_H +#define MCE_INACTIVITY_H + +#include "mce_types.h" + +#include + +G_BEGIN_DECLS + +typedef struct mce_inactivity_priv MceInactivityPriv; + +struct mce_inactivity { + GObject object; + MceInactivityPriv* priv; + gboolean valid; + gboolean status; +}; /* MceInactivity */ + +typedef void +(*MceInactivityFunc)( + MceInactivity* inactivity, + void* arg); + +MceInactivity* +mce_inactivity_new( + void); + +MceInactivity* +mce_inactivity_ref( + MceInactivity* inactivity); + +void +mce_inactivity_unref( + MceInactivity* inactivity); + +gulong +mce_inactivity_add_valid_changed_handler( + MceInactivity* inactivity, + MceInactivityFunc fn, + void* arg); + +gulong +mce_inactivity_add_status_changed_handler( + MceInactivity* inactivity, + MceInactivityFunc fn, + void* arg); + +void +mce_inactivity_remove_handler( + MceInactivity* inactivity, + gulong id); + +void +mce_inactivity_remove_handlers( + MceInactivity* inactivity, + gulong* ids, + guint count); + +#define mce_inactivity_remove_all_handlers(t, ids) \ + mce_inactivity_remove_handlers(t, ids, G_N_ELEMENTS(ids)) + +G_END_DECLS + +#endif /* MCE_INACTIVITY_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/mce_types.h b/include/mce_types.h index bf75da7..663d367 100644 --- a/include/mce_types.h +++ b/include/mce_types.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016-2022 Jolla Ltd. - * Copyright (C) 2016-2022 Slava Monich + * Copyright (c) 2016 - 2023 Jolla Ltd. + * Copyright (c) 2016 - 2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -44,6 +44,7 @@ G_BEGIN_DECLS typedef struct mce_battery MceBattery; typedef struct mce_charger MceCharger; typedef struct mce_display MceDisplay; +typedef struct mce_inactivity MceInactivity; typedef struct mce_tklock MceTklock; G_END_DECLS diff --git a/spec/com.nokia.mce.request.xml b/spec/com.nokia.mce.request.xml index cf1801d..2e22775 100644 --- a/spec/com.nokia.mce.request.xml +++ b/spec/com.nokia.mce.request.xml @@ -19,5 +19,8 @@ + + + diff --git a/spec/com.nokia.mce.signal.xml b/spec/com.nokia.mce.signal.xml index 33db680..1ba5cb0 100644 --- a/spec/com.nokia.mce.signal.xml +++ b/spec/com.nokia.mce.signal.xml @@ -19,5 +19,8 @@ + + + diff --git a/src/mce_inactivity.c b/src/mce_inactivity.c new file mode 100644 index 0000000..7e0c3b3 --- /dev/null +++ b/src/mce_inactivity.c @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2016 - 2023 Jolla Ltd. + * + * You may use this file under the terms of BSD license as follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * any official policies, either expressed or implied. + */ + +#include "mce_inactivity.h" +#include "mce_proxy.h" +#include "mce_log_p.h" + +#include +#include + +#include + +/* Generated headers */ +#include "com.nokia.mce.request.h" +#include "com.nokia.mce.signal.h" + +struct mce_inactivity_priv { + MceProxy* proxy; + gulong proxy_valid_id; + gulong inactivity_status_ind_id; +}; + +enum mce_inactivity_signal { + SIGNAL_VALID_CHANGED, + SIGNAL_STATUS_CHANGED, + SIGNAL_COUNT +}; + +#define SIGNAL_VALID_CHANGED_NAME "mce-inactivity-valid-changed" +#define SIGNAL_STATUS_CHANGED_NAME "mce-inactivity-mode-changed" + +static guint mce_inactivity_signals[SIGNAL_COUNT] = { 0 }; + +typedef GObjectClass MceInactivityClass; +G_DEFINE_TYPE(MceInactivity, mce_inactivity, G_TYPE_OBJECT) +#define PARENT_CLASS mce_inactivity_parent_class +#define MCE_INACTIVITY_TYPE (mce_inactivity_get_type()) +#define MCE_INACTIVITY(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj,\ + MCE_INACTIVITY_TYPE,MceInactivity)) + +/*==========================================================================* + * Implementation + *==========================================================================*/ + +static +void +mce_inactivity_status_update( + MceInactivity* self, + gboolean status) +{ + MceInactivityPriv* priv = self->priv; + const gboolean prev_status = self->status; + self->status = status; + if (self->status != prev_status) { + g_signal_emit(self, mce_inactivity_signals[SIGNAL_STATUS_CHANGED], 0); + } + if (priv->proxy->valid && !self->valid) { + self->valid = TRUE; + g_signal_emit(self, mce_inactivity_signals[SIGNAL_VALID_CHANGED], 0); + } +} + +static +void +mce_inactivity_status_query_done( + GObject* proxy, + GAsyncResult* result, + gpointer arg) +{ + GError* error = NULL; + gboolean status = FALSE; + MceInactivity* self = MCE_INACTIVITY(arg); + + if (com_nokia_mce_request_call_get_inactivity_status_finish( + COM_NOKIA_MCE_REQUEST(proxy), &status, result, &error)) { + GDEBUG("inactivlty is currently %s", status ? "true" : "false"); + mce_inactivity_status_update(self, status); + } else { + /* + * We could retry but it's probably not worth the trouble. + * There is signal broadcast on mce startup / when inactivity + * state changes. + * Until then, this object stays invalid. + */ + GWARN("Failed to query inactivity status %s", GERRMSG(error)); + g_error_free(error); + } + mce_inactivity_unref(self); +} + +static +void +mce_inactivity_status_ind( + ComNokiaMceSignal* proxy, + gboolean status, + gpointer arg) +{ + GDEBUG("status is %s", status ? "true" : "false"); + mce_inactivity_status_update(MCE_INACTIVITY(arg), status); +} + +static +void +mce_inactivity_status_query( + MceInactivity* self) +{ + MceInactivityPriv* priv = self->priv; + MceProxy* proxy = priv->proxy; + + /* + * proxy->signal and proxy->request may not be available at the + * time when MceInactivity is created. In that case we have to wait + * for the valid signal before we can connect the inactivity status + * signal and submit the initial query. + */ + if (proxy->signal && !priv->inactivity_status_ind_id) { + priv->inactivity_status_ind_id = g_signal_connect(proxy->signal, + MCE_INACTIVITY_SIG, G_CALLBACK(mce_inactivity_status_ind), self); + } + if (proxy->request && proxy->valid) { + com_nokia_mce_request_call_get_inactivity_status(proxy->request, NULL, + mce_inactivity_status_query_done, mce_inactivity_ref(self)); + } +} + +static +void +mce_inactivity_valid_changed( + MceProxy* proxy, + void* arg) +{ + MceInactivity* self = MCE_INACTIVITY(arg); + + if (proxy->valid) { + mce_inactivity_status_query(self); + } else { + if (self->valid) { + self->valid = FALSE; + g_signal_emit(self, mce_inactivity_signals[SIGNAL_VALID_CHANGED], 0); + } + } +} + +/*==========================================================================* + * API + *==========================================================================*/ + +MceInactivity* +mce_inactivity_new() +{ + static MceInactivity* mce_inactivity_instance = NULL; + + if (mce_inactivity_instance) { + mce_inactivity_ref(mce_inactivity_instance); + } else { + mce_inactivity_instance = g_object_new(MCE_INACTIVITY_TYPE, NULL); + mce_inactivity_status_query(mce_inactivity_instance); + g_object_add_weak_pointer(G_OBJECT(mce_inactivity_instance), + (gpointer*)(&mce_inactivity_instance)); + } + return mce_inactivity_instance; +} + +MceInactivity* +mce_inactivity_ref( + MceInactivity* self) +{ + if (G_LIKELY(self)) { + g_object_ref(MCE_INACTIVITY(self)); + } + return self; +} + +void +mce_inactivity_unref( + MceInactivity* self) +{ + if (G_LIKELY(self)) { + g_object_unref(MCE_INACTIVITY(self)); + } +} + +gulong +mce_inactivity_add_valid_changed_handler( + MceInactivity* self, + MceInactivityFunc fn, + void* arg) +{ + return (G_LIKELY(self) && G_LIKELY(fn)) ? g_signal_connect(self, + SIGNAL_VALID_CHANGED_NAME, G_CALLBACK(fn), arg) : 0; +} + +gulong +mce_inactivity_add_status_changed_handler( + MceInactivity* self, + MceInactivityFunc fn, + void* arg) +{ + return (G_LIKELY(self) && G_LIKELY(fn)) ? g_signal_connect(self, + SIGNAL_STATUS_CHANGED_NAME, G_CALLBACK(fn), arg) : 0; +} + +void +mce_inactivity_remove_handler( + MceInactivity* self, + gulong id) +{ + if (G_LIKELY(self) && G_LIKELY(id)) { + g_signal_handler_disconnect(self, id); + } +} + +void +mce_inactivity_remove_handlers( + MceInactivity* self, + gulong* ids, + guint count) +{ + gutil_disconnect_handlers(self, ids, count); +} + +/*==========================================================================* + * Internals + *==========================================================================*/ + +static +void +mce_inactivity_init( + MceInactivity* self) +{ + MceInactivityPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self, MCE_INACTIVITY_TYPE, + MceInactivityPriv); + + self->priv = priv; + self->status = FALSE; + priv->proxy = mce_proxy_new(); + priv->proxy_valid_id = mce_proxy_add_valid_changed_handler(priv->proxy, + mce_inactivity_valid_changed, self); +} + +static +void +mce_inactivity_finalize( + GObject* object) +{ + MceInactivity* self = MCE_INACTIVITY(object); + MceInactivityPriv* priv = self->priv; + + if (priv->inactivity_status_ind_id) { + g_signal_handler_disconnect(priv->proxy->signal, + priv->inactivity_status_ind_id); + } + mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id); + mce_proxy_unref(priv->proxy); + G_OBJECT_CLASS(PARENT_CLASS)->finalize(object); +} + +static +void +mce_inactivity_class_init( + MceInactivityClass* klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS(klass); + + object_class->finalize = mce_inactivity_finalize; + g_type_class_add_private(klass, sizeof(MceInactivityPriv)); + mce_inactivity_signals[SIGNAL_VALID_CHANGED] = + g_signal_new(SIGNAL_VALID_CHANGED_NAME, + G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, G_TYPE_NONE, 0); + mce_inactivity_signals[SIGNAL_STATUS_CHANGED] = + g_signal_new(SIGNAL_STATUS_CHANGED_NAME, + G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, G_TYPE_NONE, 0); +} + +/* + * Local Variables: + * status: C + * c-basic-offset: 4 + * indent-tabs-status: nil + * End: + */