From 10dc2bd0efb15561aeb80a4dc04342450ceed6f0 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Wed, 10 Oct 2018 18:44:00 +0300 Subject: [PATCH 01/34] [libmce-glib] Added MceBattery object. JB#43321 Allows to watch battery level and status. --- Makefile | 1 + include/mce_battery.h | 117 +++++++++ spec/com.nokia.mce.request.xml | 6 + spec/com.nokia.mce.signal.xml | 6 + src/mce_battery.c | 424 +++++++++++++++++++++++++++++++++ 5 files changed, 554 insertions(+) create mode 100644 include/mce_battery.h create mode 100644 src/mce_battery.c diff --git a/Makefile b/Makefile index 31bd6da..0d04426 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ LIB = $(LIB_SONAME).$(VERSION_MINOR).$(VERSION_RELEASE) # SRC = \ + mce_battery.c \ mce_display.c \ mce_proxy.c \ mce_tklock.c diff --git a/include/mce_battery.h b/include/mce_battery.h new file mode 100644 index 0000000..c4f5345 --- /dev/null +++ b/include/mce_battery.h @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2019 Jolla Ltd. + * Copyright (C) 2019 Slava Monich + * + * 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. + */ + +#ifndef MCE_BATTERY_H +#define MCE_BATTERY_H + +#include "mce_types.h" + +G_BEGIN_DECLS + +typedef enum mce_battery_status { + MCE_BATTERY_UNKNOWN, + MCE_BATTERY_EMPTY, + MCE_BATTERY_LOW, + MCE_BATTERY_OK, + MCE_BATTERY_FULL +} MCE_BATTERY_STATUS; + +typedef struct mce_battery_priv MceBatteryPriv; + +typedef struct mce_battery { + GObject object; + MceBatteryPriv* priv; + gboolean valid; + guint level; + MCE_BATTERY_STATUS status; +} MceBattery; + +typedef void +(*MceBatteryFunc)( + MceBattery* battery, + void* arg); + +MceBattery* +mce_battery_new( + void); + +MceBattery* +mce_battery_ref( + MceBattery* battery); + +void +mce_battery_unref( + MceBattery* battery); + +gulong +mce_battery_add_valid_changed_handler( + MceBattery* battery, + MceBatteryFunc fn, + void* arg); + +gulong +mce_battery_add_level_changed_handler( + MceBattery* battery, + MceBatteryFunc fn, + void* arg); + +gulong +mce_battery_add_status_changed_handler( + MceBattery* battery, + MceBatteryFunc fn, + void* arg); + +void +mce_battery_remove_handler( + MceBattery* battery, + gulong id); + +void +mce_battery_remove_handlers( + MceBattery* battery, + gulong *ids, + guint count); + +#define mce_battery_remove_all_handlers(d, ids) \ + mce_battery_remove_handlers(d, ids, G_N_ELEMENTS(ids)) + +G_END_DECLS + +#endif /* MCE_BATTERY_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/spec/com.nokia.mce.request.xml b/spec/com.nokia.mce.request.xml index a1af125..8867cdc 100644 --- a/spec/com.nokia.mce.request.xml +++ b/spec/com.nokia.mce.request.xml @@ -10,5 +10,11 @@ + + + + + + diff --git a/spec/com.nokia.mce.signal.xml b/spec/com.nokia.mce.signal.xml index e85f63b..73d8a4a 100644 --- a/spec/com.nokia.mce.signal.xml +++ b/spec/com.nokia.mce.signal.xml @@ -10,5 +10,11 @@ + + + + + + diff --git a/src/mce_battery.c b/src/mce_battery.c new file mode 100644 index 0000000..011773b --- /dev/null +++ b/src/mce_battery.c @@ -0,0 +1,424 @@ +/* + * Copyright (C) 2019 Jolla Ltd. + * Copyright (C) 2019 Slava Monich + * + * 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. + */ + +#include "mce_battery.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" + +enum mce_battery_ind { + BATTERY_IND_LEVEL, + BATTERY_IND_STATUS, + BATTERY_IND_COUNT +}; + +typedef enum mce_battery_flags { + BATTERY_HAVE_NONE = 0x00, + BATTERY_HAVE_LEVEL = 0x01, + BATTERY_HAVE_STATUS = 0x02 +} BATTERY_FLAGS; + +#define BATTERY_HAVE_ALL (BATTERY_HAVE_LEVEL | BATTERY_HAVE_STATUS) + +struct mce_battery_priv { + MceProxy* proxy; + BATTERY_FLAGS flags; + gulong proxy_valid_id; + gulong battery_ind_id[BATTERY_IND_COUNT]; +}; + +enum mce_battery_signal { + SIGNAL_VALID_CHANGED, + SIGNAL_LEVEL_CHANGED, + SIGNAL_STATUS_CHANGED, + SIGNAL_COUNT +}; + +#define SIGNAL_VALID_CHANGED_NAME "mce-battery-valid-changed" +#define SIGNAL_LEVEL_CHANGED_NAME "mce-battery-level-changed" +#define SIGNAL_STATUS_CHANGED_NAME "mce-battery-status-changed" + +static guint mce_battery_signals[SIGNAL_COUNT] = { 0 }; + +typedef GObjectClass MceBatteryClass; +G_DEFINE_TYPE(MceBattery, mce_battery, G_TYPE_OBJECT) +#define PARENT_CLASS mce_battery_parent_class +#define MCE_BATTERY_TYPE (mce_battery_get_type()) +#define MCE_BATTERY(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj,\ + MCE_BATTERY_TYPE,MceBattery)) + +/*==========================================================================* + * Implementation + *==========================================================================*/ + +static +void +mce_battery_check_valid( + MceBattery* self) +{ + MceBatteryPriv* priv = self->priv; + const gboolean valid = priv->proxy->valid && + (priv->flags & BATTERY_HAVE_ALL) == BATTERY_HAVE_ALL; + + if (valid != self->valid) { + self->valid = valid; + g_signal_emit(self, mce_battery_signals[SIGNAL_VALID_CHANGED], 0); + } +} + +static +void +mce_battery_level_update( + MceBattery* self, + gint level) +{ + MceBatteryPriv* priv = self->priv; + const guint new_level = (level < 0) ? 0 : (level > 100) ? 100 : level; + + if (self->level != new_level) { + self->level = new_level; + g_signal_emit(self, mce_battery_signals[SIGNAL_LEVEL_CHANGED], 0); + } + priv->flags |= BATTERY_HAVE_LEVEL; + mce_battery_check_valid(self); +} + +static +void +mce_battery_status_update( + MceBattery* self, + const char* status) +{ + MceBatteryPriv* priv = self->priv; + MCE_BATTERY_STATUS new_status; + + if (!g_strcmp0(status, MCE_BATTERY_STATUS_FULL)) { + new_status = MCE_BATTERY_FULL; + } else if (!g_strcmp0(status, MCE_BATTERY_STATUS_OK)) { + new_status = MCE_BATTERY_OK; + } else if (!g_strcmp0(status, MCE_BATTERY_STATUS_LOW)) { + new_status = MCE_BATTERY_LOW; + } else if (!g_strcmp0(status, MCE_BATTERY_STATUS_EMPTY)) { + new_status = MCE_BATTERY_EMPTY; + } else { + GASSERT(!g_strcmp0(status, MCE_BATTERY_STATUS_UNKNOWN)); + new_status = MCE_BATTERY_UNKNOWN; + } + if (self->status != new_status) { + self->status = new_status; + g_signal_emit(self, mce_battery_signals[SIGNAL_STATUS_CHANGED], 0); + } + priv->flags |= BATTERY_HAVE_STATUS; + mce_battery_check_valid(self); +} + +static +void +mce_battery_level_query_done( + GObject* proxy, + GAsyncResult* result, + gpointer arg) +{ + MceBattery* self = MCE_BATTERY(arg); + GError* error = NULL; + gint level; + + if (com_nokia_mce_request_call_get_battery_level_finish( + COM_NOKIA_MCE_REQUEST(proxy), &level, result, &error)) { + GDEBUG("Battery level is currently %d", level); + mce_battery_level_update(self, level); + } else { + /* Should retry? */ + GWARN("Failed to query battery level %s", GERRMSG(error)); + g_error_free(error); + } + mce_battery_unref(self); +} + +static +void +mce_battery_status_query_done( + GObject* proxy, + GAsyncResult* result, + gpointer arg) +{ + MceBattery* self = MCE_BATTERY(arg); + GError* error = NULL; + char* status = NULL; + + if (com_nokia_mce_request_call_get_battery_status_finish( + COM_NOKIA_MCE_REQUEST(proxy), &status, result, &error)) { + GDEBUG("Battery is currently %s", status); + mce_battery_status_update(self, status); + g_free(status); + } else { + /* Should retry? */ + GWARN("Failed to query battery status %s", GERRMSG(error)); + g_error_free(error); + } + mce_battery_unref(self); +} + +static +void +mce_battery_level_ind( + ComNokiaMceSignal* proxy, + gint level, + gpointer arg) +{ + GDEBUG("Battery level is %d", level); + mce_battery_level_update(MCE_BATTERY(arg), level); +} + +static +void +mce_battery_status_ind( + ComNokiaMceSignal* proxy, + const char* status, + gpointer arg) +{ + GDEBUG("Battery is %s", status); + mce_battery_status_update(MCE_BATTERY(arg), status); +} + +static +void +mce_battery_query( + MceBattery* self) +{ + MceBatteryPriv* priv = self->priv; + MceProxy* proxy = priv->proxy; + + /* + * proxy->signal and proxy->request may not be available at the + * time when MceBattery is created. In that case we have to wait + * for the valid signal before we can connect the battery state + * signal and submit the initial query. + */ + if (proxy->signal) { + if (!priv->battery_ind_id[BATTERY_IND_LEVEL]) { + priv->battery_ind_id[BATTERY_IND_LEVEL] = + g_signal_connect(proxy->signal, "battery-level-ind", + G_CALLBACK(mce_battery_level_ind), self); + } + + if (!priv->battery_ind_id[BATTERY_IND_STATUS]) { + priv->battery_ind_id[BATTERY_IND_STATUS] = + g_signal_connect(proxy->signal, "battery-status-ind", + G_CALLBACK(mce_battery_status_ind), self); + } + } + if (proxy->request && proxy->valid) { + com_nokia_mce_request_call_get_battery_level(proxy->request, NULL, + mce_battery_level_query_done, mce_battery_ref(self)); + com_nokia_mce_request_call_get_battery_status(proxy->request, NULL, + mce_battery_status_query_done, mce_battery_ref(self)); + } +} + +static +void +mce_battery_valid_changed( + MceProxy* proxy, + void* arg) +{ + MceBattery* self = MCE_BATTERY(arg); + MceBatteryPriv* priv = self->priv; + + if (proxy->valid) { + mce_battery_query(self); + } else { + priv->flags = BATTERY_HAVE_NONE; + } + mce_battery_check_valid(self); +} + +/*==========================================================================* + * API + *==========================================================================*/ + +MceBattery* +mce_battery_new() +{ + /* MCE assumes one battery */ + static MceBattery* mce_battery_instance = NULL; + + if (mce_battery_instance) { + mce_battery_ref(mce_battery_instance); + } else { + mce_battery_instance = g_object_new(MCE_BATTERY_TYPE, NULL); + mce_battery_query(mce_battery_instance); + g_object_add_weak_pointer(G_OBJECT(mce_battery_instance), + (gpointer*)(&mce_battery_instance)); + } + return mce_battery_instance; +} + +MceBattery* +mce_battery_ref( + MceBattery* self) +{ + if (G_LIKELY(self)) { + g_object_ref(MCE_BATTERY(self)); + } + return self; +} + +void +mce_battery_unref( + MceBattery* self) +{ + if (G_LIKELY(self)) { + g_object_unref(MCE_BATTERY(self)); + } +} + +gulong +mce_battery_add_valid_changed_handler( + MceBattery* self, + MceBatteryFunc 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_battery_add_level_changed_handler( + MceBattery* self, + MceBatteryFunc fn, + void* arg) +{ + return (G_LIKELY(self) && G_LIKELY(fn)) ? g_signal_connect(self, + SIGNAL_LEVEL_CHANGED_NAME, G_CALLBACK(fn), arg) : 0; +} + +gulong +mce_battery_add_status_changed_handler( + MceBattery* self, + MceBatteryFunc 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_battery_remove_handler( + MceBattery* self, + gulong id) +{ + if (G_LIKELY(self) && G_LIKELY(id)) { + g_signal_handler_disconnect(self, id); + } +} + +void +mce_battery_remove_handlers( + MceBattery* self, + gulong *ids, + guint count) +{ + gutil_disconnect_handlers(self, ids, count); +} + +/*==========================================================================* + * Internals + *==========================================================================*/ + +static +void +mce_battery_init( + MceBattery* self) +{ + MceBatteryPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self, MCE_BATTERY_TYPE, + MceBatteryPriv); + + self->priv = priv; + priv->proxy = mce_proxy_new(); + priv->proxy_valid_id = mce_proxy_add_valid_changed_handler(priv->proxy, + mce_battery_valid_changed, self); +} + +static +void +mce_battery_finalize( + GObject* object) +{ + MceBattery* self = MCE_BATTERY(object); + MceBatteryPriv* priv = self->priv; + + gutil_disconnect_handlers(priv->proxy->signal, priv->battery_ind_id, + G_N_ELEMENTS(priv->battery_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_battery_class_init( + MceBatteryClass* klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS(klass); + + object_class->finalize = mce_battery_finalize; + g_type_class_add_private(klass, sizeof(MceBatteryPriv)); + mce_battery_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_battery_signals[SIGNAL_LEVEL_CHANGED] = + g_signal_new(SIGNAL_LEVEL_CHANGED_NAME, + G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, G_TYPE_NONE, 0); + mce_battery_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: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From ce5fef5eb4a777dedb48d54114b8b602da6b9194 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Wed, 21 Aug 2019 21:24:38 +0300 Subject: [PATCH 02/34] [libmce-glib] Added MceCharger object. JB#46836 --- Makefile | 1 + include/mce_battery.h | 2 + include/mce_charger.h | 110 +++++++++++ spec/com.nokia.mce.request.xml | 3 + spec/com.nokia.mce.signal.xml | 3 + src/mce_charger.c | 322 +++++++++++++++++++++++++++++++++ 6 files changed, 441 insertions(+) create mode 100644 include/mce_charger.h create mode 100644 src/mce_charger.c diff --git a/Makefile b/Makefile index 0d04426..e5c2b12 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ LIB = $(LIB_SONAME).$(VERSION_MINOR).$(VERSION_RELEASE) SRC = \ mce_battery.c \ + mce_charger.c \ mce_display.c \ mce_proxy.c \ mce_tklock.c diff --git a/include/mce_battery.h b/include/mce_battery.h index c4f5345..f3cd3f8 100644 --- a/include/mce_battery.h +++ b/include/mce_battery.h @@ -35,6 +35,8 @@ #include "mce_types.h" +/* Since 1.0.6 */ + G_BEGIN_DECLS typedef enum mce_battery_status { diff --git a/include/mce_charger.h b/include/mce_charger.h new file mode 100644 index 0000000..fba952d --- /dev/null +++ b/include/mce_charger.h @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2019 Jolla Ltd. + * Copyright (C) 2019 Slava Monich + * + * 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. + */ + +#ifndef MCE_CHARGER_H +#define MCE_CHARGER_H + +#include "mce_types.h" + +/* Since 1.0.6 */ + +G_BEGIN_DECLS + +typedef enum mce_charger_state { + MCE_CHARGER_UNKNOWN, + MCE_CHARGER_ON, + MCE_CHARGER_OFF +} MCE_CHARGER_STATE; + +typedef struct mce_charger_priv MceChargerPriv; + +typedef struct mce_charger { + GObject object; + MceChargerPriv* priv; + gboolean valid; + MCE_CHARGER_STATE state; +} MceCharger; + +typedef void +(*MceChargerFunc)( + MceCharger* charger, + void* arg); + +MceCharger* +mce_charger_new( + void); + +MceCharger* +mce_charger_ref( + MceCharger* charger); + +void +mce_charger_unref( + MceCharger* charger); + +gulong +mce_charger_add_valid_changed_handler( + MceCharger* charger, + MceChargerFunc fn, + void* arg); + +gulong +mce_charger_add_state_changed_handler( + MceCharger* charger, + MceChargerFunc fn, + void* arg); + +void +mce_charger_remove_handler( + MceCharger* charger, + gulong id); + +void +mce_charger_remove_handlers( + MceCharger* charger, + gulong *ids, + guint count); + +#define mce_charger_remove_all_handlers(d, ids) \ + mce_charger_remove_handlers(d, ids, G_N_ELEMENTS(ids)) + +G_END_DECLS + +#endif /* MCE_CHARGER_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/spec/com.nokia.mce.request.xml b/spec/com.nokia.mce.request.xml index 8867cdc..cf1801d 100644 --- a/spec/com.nokia.mce.request.xml +++ b/spec/com.nokia.mce.request.xml @@ -16,5 +16,8 @@ + + + diff --git a/spec/com.nokia.mce.signal.xml b/spec/com.nokia.mce.signal.xml index 73d8a4a..33db680 100644 --- a/spec/com.nokia.mce.signal.xml +++ b/spec/com.nokia.mce.signal.xml @@ -16,5 +16,8 @@ + + + diff --git a/src/mce_charger.c b/src/mce_charger.c new file mode 100644 index 0000000..963c591 --- /dev/null +++ b/src/mce_charger.c @@ -0,0 +1,322 @@ +/* + * Copyright (C) 2019 Jolla Ltd. + * Copyright (C) 2019 Slava Monich + * + * 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. + */ + +#include "mce_charger.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_charger_priv { + MceProxy* proxy; + gulong proxy_valid_id; + gulong charger_state_ind_id; +}; + +enum mce_charger_signal { + SIGNAL_VALID_CHANGED, + SIGNAL_STATE_CHANGED, + SIGNAL_COUNT +}; + +#define SIGNAL_VALID_CHANGED_NAME "mce-charger-valid-changed" +#define SIGNAL_STATE_CHANGED_NAME "mce-charger-state-changed" + +static guint mce_charger_signals[SIGNAL_COUNT] = { 0 }; + +typedef GObjectClass MceChargerClass; +G_DEFINE_TYPE(MceCharger, mce_charger, G_TYPE_OBJECT) +#define PARENT_CLASS mce_charger_parent_class +#define MCE_CHARGER_TYPE (mce_charger_get_type()) +#define MCE_CHARGER(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj,\ + MCE_CHARGER_TYPE,MceCharger)) + +/*==========================================================================* + * Implementation + *==========================================================================*/ + +static +void +mce_charger_state_update( + MceCharger* self, + const char* value) +{ + MCE_CHARGER_STATE state; + MceChargerPriv* priv = self->priv; + + if (!g_strcmp0(value, MCE_CHARGER_STATE_ON)) { + state = MCE_CHARGER_ON; + } else if (!g_strcmp0(value, MCE_CHARGER_STATE_OFF)) { + state = MCE_CHARGER_OFF; + } else { + GASSERT(!g_strcmp0(value, MCE_CHARGER_STATE_UNKNOWN)); + state = MCE_CHARGER_UNKNOWN; + } + if (self->state != state) { + self->state = state; + g_signal_emit(self, mce_charger_signals[SIGNAL_STATE_CHANGED], 0); + } + if (priv->proxy->valid && !self->valid) { + self->valid = TRUE; + g_signal_emit(self, mce_charger_signals[SIGNAL_VALID_CHANGED], 0); + } +} + +static +void +mce_charger_state_query_done( + GObject* proxy, + GAsyncResult* result, + gpointer arg) +{ + GError* error = NULL; + char* state = NULL; + MceCharger* self = MCE_CHARGER(arg); + + if (com_nokia_mce_request_call_get_charger_state_finish( + COM_NOKIA_MCE_REQUEST(proxy), &state, result, &error)) { + GDEBUG("Charger is currently %s", state); + mce_charger_state_update(self, state); + g_free(state); + } else { + /* + * We could retry but it's probably not worth the trouble + * because the next time charger state changes we receive + * charger_state_ind signal and sync our state with mce. + * Until then, this object stays invalid. + */ + GWARN("Failed to query charger state %s", GERRMSG(error)); + g_error_free(error); + } + mce_charger_unref(self); +} + +static +void +mce_charger_state_ind( + ComNokiaMceSignal* proxy, + const char* state, + gpointer arg) +{ + GDEBUG("Charger is %s", state); + mce_charger_state_update(MCE_CHARGER(arg), state); +} + +static +void +mce_charger_state_query( + MceCharger* self) +{ + MceChargerPriv* priv = self->priv; + MceProxy* proxy = priv->proxy; + + /* + * proxy->signal and proxy->request may not be available at the + * time when MceCharger is created. In that case we have to wait + * for the valid signal before we can connect the charger state + * signal and submit the initial query. + */ + if (proxy->signal && !priv->charger_state_ind_id) { + priv->charger_state_ind_id = g_signal_connect(proxy->signal, + MCE_CHARGER_STATE_SIG, G_CALLBACK(mce_charger_state_ind), self); + } + if (proxy->request && proxy->valid) { + com_nokia_mce_request_call_get_charger_state(proxy->request, NULL, + mce_charger_state_query_done, mce_charger_ref(self)); + } +} + +static +void +mce_charger_valid_changed( + MceProxy* proxy, + void* arg) +{ + MceCharger* self = MCE_CHARGER(arg); + + if (proxy->valid) { + mce_charger_state_query(self); + } else { + if (self->valid) { + self->valid = FALSE; + g_signal_emit(self, mce_charger_signals[SIGNAL_VALID_CHANGED], 0); + } + } +} + +/*==========================================================================* + * API + *==========================================================================*/ + +MceCharger* +mce_charger_new() +{ + /* MCE assumes one charger */ + static MceCharger* mce_charger_instance = NULL; + + if (mce_charger_instance) { + mce_charger_ref(mce_charger_instance); + } else { + mce_charger_instance = g_object_new(MCE_CHARGER_TYPE, NULL); + mce_charger_state_query(mce_charger_instance); + g_object_add_weak_pointer(G_OBJECT(mce_charger_instance), + (gpointer*)(&mce_charger_instance)); + } + return mce_charger_instance; +} + +MceCharger* +mce_charger_ref( + MceCharger* self) +{ + if (G_LIKELY(self)) { + g_object_ref(MCE_CHARGER(self)); + } + return self; +} + +void +mce_charger_unref( + MceCharger* self) +{ + if (G_LIKELY(self)) { + g_object_unref(MCE_CHARGER(self)); + } +} + +gulong +mce_charger_add_valid_changed_handler( + MceCharger* self, + MceChargerFunc 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_charger_add_state_changed_handler( + MceCharger* self, + MceChargerFunc fn, + void* arg) +{ + return (G_LIKELY(self) && G_LIKELY(fn)) ? g_signal_connect(self, + SIGNAL_STATE_CHANGED_NAME, G_CALLBACK(fn), arg) : 0; +} + +void +mce_charger_remove_handler( + MceCharger* self, + gulong id) +{ + if (G_LIKELY(self) && G_LIKELY(id)) { + g_signal_handler_disconnect(self, id); + } +} + +void +mce_charger_remove_handlers( + MceCharger* self, + gulong *ids, + guint count) +{ + gutil_disconnect_handlers(self, ids, count); +} + +/*==========================================================================* + * Internals + *==========================================================================*/ + +static +void +mce_charger_init( + MceCharger* self) +{ + MceChargerPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self, MCE_CHARGER_TYPE, + MceChargerPriv); + + self->priv = priv; + priv->proxy = mce_proxy_new(); + priv->proxy_valid_id = mce_proxy_add_valid_changed_handler(priv->proxy, + mce_charger_valid_changed, self); +} + +static +void +mce_charger_finalize( + GObject* object) +{ + MceCharger* self = MCE_CHARGER(object); + MceChargerPriv* priv = self->priv; + + if (priv->charger_state_ind_id) { + g_signal_handler_disconnect(priv->proxy->signal, + priv->charger_state_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_charger_class_init( + MceChargerClass* klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS(klass); + + object_class->finalize = mce_charger_finalize; + g_type_class_add_private(klass, sizeof(MceChargerPriv)); + mce_charger_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_charger_signals[SIGNAL_STATE_CHANGED] = + g_signal_new(SIGNAL_STATE_CHANGED_NAME, + G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, G_TYPE_NONE, 0); +} + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From f5a3cb196f1be8739cc606fc46c5886ae7d3c7fc Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 22 Aug 2019 12:36:37 +0300 Subject: [PATCH 03/34] [libmce-glib] Tweaked makefile dependencies And removed unused variables --- Makefile | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index e5c2b12..3044356 100644 --- a/Makefile +++ b/Makefile @@ -114,19 +114,22 @@ ifneq ($(strip $(DEPS)),) endif endif -$(GEN_FILES): | $(GEN_DIR) -$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) -$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) - -# -# Rules -# - DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB) RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB) DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SONAME) RELEASE_LINK = $(RELEASE_BUILD_DIR)/$(LIB_SONAME) +$(GEN_FILES): | $(GEN_DIR) +$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) +$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) +$(PKGCONFIG): | $(BUILD_DIR) +$(DEBUG_LINK): | $(DEBUG_LIB) +$(RELEASE_LINK): | $(RELEASE_LIB) + +# +# Rules +# + debug: $(DEBUG_LIB) $(DEBUG_LINK) release: $(RELEASE_LIB) $(RELEASE_LINK) @@ -164,11 +167,11 @@ $(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c $(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ -$(DEBUG_LIB): $(DEBUG_BUILD_DIR) $(DEBUG_OBJS) - $(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) -o $@ +$(DEBUG_LIB): $(DEBUG_OBJS) + $(LD) $(DEBUG_LDFLAGS) $^ -o $@ -$(RELEASE_LIB): $(RELEASE_BUILD_DIR) $(RELEASE_OBJS) - $(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) -o $@ +$(RELEASE_LIB): $(RELEASE_OBJS) + $(LD) $(RELEASE_LDFLAGS) $^ -o $@ ifeq ($(KEEP_SYMBOLS),0) strip $@ endif @@ -187,8 +190,6 @@ $(PKGCONFIG): $(LIB_NAME).pc.in # INSTALL_PERM = 644 -INSTALL_OWNER = $(shell id -u) -INSTALL_GROUP = $(shell id -g) INSTALL = install INSTALL_DIRS = $(INSTALL) -d From cf94eddcb968f7d1970957cd11304bfce355052f Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 22 Aug 2019 12:38:01 +0300 Subject: [PATCH 04/34] [libmce-glib] Version 1.0.6 --- Makefile | 2 +- debian/changelog | 7 +++++++ rpm/libmce-glib.spec | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3044356..e9d6e75 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ all: debug release pkgconfig VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 5 +VERSION_RELEASE = 6 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) diff --git a/debian/changelog b/debian/changelog index c979e9e..a4d34dd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +libmce-glib (1.0.6) unstable; urgency=low + + * Added MceBattery object + * Added MceCharger object + + -- Slava Monich Thu, 22 Aug 2019 12:14:38 +0300 + libmce-glib (1.0.5) unstable; urgency=low * Added remove_all_handlers macros diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index 1d4db40..0beeab1 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,10 +1,10 @@ Name: libmce-glib -Version: 1.0.4 +Version: 1.0.6 Release: 0 Summary: MCE client library Group: Development/Libraries License: BSD -URL: https://git.merproject.org/mer-core/libmce-glib +URL: https://git.sailfishos.org/mer-core/libmce-glib Source: %{name}-%{version}.tar.bz2 BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libglibutil) From eba54c2ad4333b5e7ff0b7c5e1cee90c982c60fa Mon Sep 17 00:00:00 2001 From: Herrie Date: Mon, 26 Aug 2019 13:19:38 +0000 Subject: [PATCH 05/34] Makefile: Allow use of CC & LDFLAGS defined by build system. When building within Yocto projects such as LuneOS, we want to use CC & LDFLAGS provided by the build toolchain. Signed-off-by: Herman van Hazendonk github.com@herrie.org Signed-off-by: Christophe Chapuis chris.chapuis@gmail.com --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index e9d6e75..8ce4f67 100644 --- a/Makefile +++ b/Makefile @@ -63,14 +63,17 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release # Tools and flags # +ifndef CC CC = $(CROSS_COMPILE)gcc +endif + LD = $(CC) WARNINGS = -Wall -Wno-unused-parameter -Wno-multichar INCLUDES = -I$(INCLUDE_DIR) -I$(GEN_DIR) BASE_FLAGS = -fPIC $(CFLAGS) FULL_CFLAGS = $(BASE_FLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ $(shell pkg-config --cflags $(PKGS)) -LDFLAGS = $(BASE_FLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) \ +FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) $(shell pkg-config --libs $(PKGS)) DEBUG_FLAGS = -g RELEASE_FLAGS = @@ -85,8 +88,8 @@ endif DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2 -DEBUG_LDFLAGS = $(LDFLAGS) $(DEBUG_FLAGS) -RELEASE_LDFLAGS = $(LDFLAGS) $(RELEASE_FLAGS) +DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS) +RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS) # # Files From 8ede3b6494cbd2de14027db751daca2a78f64d81 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 30 Aug 2019 18:13:16 +0300 Subject: [PATCH 06/34] Makefile: added missing separator --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8ce4f67..e41c5be 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,7 @@ INCLUDES = -I$(INCLUDE_DIR) -I$(GEN_DIR) BASE_FLAGS = -fPIC $(CFLAGS) FULL_CFLAGS = $(BASE_FLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ $(shell pkg-config --cflags $(PKGS)) -FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) +FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) \ $(shell pkg-config --libs $(PKGS)) DEBUG_FLAGS = -g RELEASE_FLAGS = From a0632c6d2f9650a97d5e05ff975b46ddc84aa6d8 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 30 Aug 2019 18:31:34 +0300 Subject: [PATCH 07/34] Makefile: Tweaked linker command line This way shared library gets correctly linked with its dependencies --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index e41c5be..979bd54 100644 --- a/Makefile +++ b/Makefile @@ -73,8 +73,7 @@ INCLUDES = -I$(INCLUDE_DIR) -I$(GEN_DIR) BASE_FLAGS = -fPIC $(CFLAGS) FULL_CFLAGS = $(BASE_FLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ $(shell pkg-config --cflags $(PKGS)) -FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) \ - $(shell pkg-config --libs $(PKGS)) +FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) DEBUG_FLAGS = -g RELEASE_FLAGS = @@ -104,6 +103,7 @@ RELEASE_OBJS = \ $(GEN_SRC:%.c=$(RELEASE_BUILD_DIR)/%.o) \ $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o) GEN_FILES = $(GEN_SRC:%=$(GEN_DIR)/%) +LIBS = $(shell pkg-config --libs $(PKGS)) .PRECIOUS: $(GEN_FILES) # @@ -171,10 +171,10 @@ $(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ $(DEBUG_LIB): $(DEBUG_OBJS) - $(LD) $(DEBUG_LDFLAGS) $^ -o $@ + $(LD) $(DEBUG_LDFLAGS) -o $@ $^ $(LIBS) $(RELEASE_LIB): $(RELEASE_OBJS) - $(LD) $(RELEASE_LDFLAGS) $^ -o $@ + $(LD) $(RELEASE_LDFLAGS) -o $@ $^ $(LIBS) ifeq ($(KEEP_SYMBOLS),0) strip $@ endif From 517cdafd222e3a508786174a119e6f1e5a6e4b45 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 30 Aug 2019 18:20:40 +0300 Subject: [PATCH 08/34] Version 1.0.7 --- Makefile | 2 +- debian/changelog | 6 ++++++ rpm/libmce-glib.spec | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 979bd54..694e305 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ all: debug release pkgconfig VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 6 +VERSION_RELEASE = 7 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) diff --git a/debian/changelog b/debian/changelog index a4d34dd..15a6dcd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libmce-glib (1.0.7) unstable; urgency=low + + * Allow use of CC & LDFLAGS defined by build system. + + -- Slava Monich Fri, 30 Aug 2019 18:14:21 +0300 + libmce-glib (1.0.6) unstable; urgency=low * Added MceBattery object diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index 0beeab1..d59bdd8 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,5 +1,5 @@ Name: libmce-glib -Version: 1.0.6 +Version: 1.0.7 Release: 0 Summary: MCE client library Group: Development/Libraries From a17b8f296a54848d0ec29324a35b3665dfcb31f8 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 1 Nov 2019 23:40:17 +0200 Subject: [PATCH 09/34] [libmce-glib] Avoid overlinking. JB#43321 --- libmce-glib.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmce-glib.pc.in b/libmce-glib.pc.in index 4889656..f44a058 100644 --- a/libmce-glib.pc.in +++ b/libmce-glib.pc.in @@ -4,6 +4,6 @@ includedir=/usr/include Name: libmce-glib Description: MCE client library Version: [version] -Requires: libglibutil glib-2.0 gio-2.0 +Requires.private: libglibutil glib-2.0 gio-2.0 Libs: -lmce-glib Cflags: -I${includedir}/libmce-glib From 488a3f59a403f9128912a48c55c1ba0747a50c08 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Tue, 5 Nov 2019 14:29:23 +0300 Subject: [PATCH 10/34] Version 1.0.8 --- Makefile | 8 ++++---- debian/changelog | 6 ++++++ debian/copyright | 8 ++++---- rpm/libmce-glib.spec | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 694e305..6eb573b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # -*- Mode: makefile-gmake -*- -.PHONY: clean all debug release pkgconfig +.PHONY: clean all debug release pkgconfig install install-dev # # Required packages @@ -20,7 +20,7 @@ all: debug release pkgconfig VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 7 +VERSION_RELEASE = 8 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) @@ -123,8 +123,8 @@ DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SONAME) RELEASE_LINK = $(RELEASE_BUILD_DIR)/$(LIB_SONAME) $(GEN_FILES): | $(GEN_DIR) -$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) -$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) +$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) $(GEN_FILES) +$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) $(GEN_FILES) $(PKGCONFIG): | $(BUILD_DIR) $(DEBUG_LINK): | $(DEBUG_LIB) $(RELEASE_LINK): | $(RELEASE_LIB) diff --git a/debian/changelog b/debian/changelog index 15a6dcd..509891e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libmce-glib (1.0.8) unstable; urgency=low + + * Avoid overlinking. + + -- Slava Monich Tue, 05 Nov 2019 14:21:43 +0300 + libmce-glib (1.0.7) unstable; urgency=low * Allow use of CC & LDFLAGS defined by build system. diff --git a/debian/copyright b/debian/copyright index 19b3195..1275f60 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,4 +1,4 @@ -Copyright (C) 2016 Jolla Ltd. +Copyright (C) 2016-2019 Jolla Ltd. You may use this file under the terms of BSD license as follows: @@ -11,9 +11,9 @@ are met: 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 name of Jolla Ltd nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. + 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 diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index d59bdd8..287c1d7 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,5 +1,5 @@ Name: libmce-glib -Version: 1.0.7 +Version: 1.0.8 Release: 0 Summary: MCE client library Group: Development/Libraries From fa7187990949bc45567ed15cdf4c4e6f9f2b6808 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 8 Mar 2020 16:34:11 +0200 Subject: [PATCH 11/34] [libmce-glib] Ignore GLib deprecation warnings. JB#43321 Apparently, the only way to get rid of "warning: G_ADD_PRIVATE" with latest GLib is to completely disable all Glib deprecation warnings. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6eb573b..219f4aa 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,7 @@ CC = $(CROSS_COMPILE)gcc endif LD = $(CC) +DEFINES += -DGLIB_DISABLE_DEPRECATION_WARNINGS WARNINGS = -Wall -Wno-unused-parameter -Wno-multichar INCLUDES = -I$(INCLUDE_DIR) -I$(GEN_DIR) BASE_FLAGS = -fPIC $(CFLAGS) @@ -185,7 +186,7 @@ $(DEBUG_LINK): $(RELEASE_LINK): ln -sf $(LIB) $@ -$(PKGCONFIG): $(LIB_NAME).pc.in +$(PKGCONFIG): $(LIB_NAME).pc.in Makefile sed -e 's/\[version\]/'$(PCVERSION)/g $< > $@ # From f98df32c33871368630ef24fcb9b9ff230ea9774 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 8 Mar 2020 16:37:38 +0200 Subject: [PATCH 12/34] [libmce-glib] Update license. JB#43321 --- LICENSE | 32 ++++++++++++++++++++++++++++++++ debian/copyright | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5f03d76 --- /dev/null +++ b/LICENSE @@ -0,0 +1,32 @@ +Copyright (C) 2016-2020 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. diff --git a/debian/copyright b/debian/copyright index 1275f60..5f03d76 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,4 +1,4 @@ -Copyright (C) 2016-2019 Jolla Ltd. +Copyright (C) 2016-2020 Jolla Ltd. You may use this file under the terms of BSD license as follows: From fb4d97ceeba96a7423b795c55c80d9062ed8a065 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 8 Mar 2020 16:38:05 +0200 Subject: [PATCH 13/34] Version 1.0.9 --- Makefile | 2 +- debian/changelog | 10 ++++++++-- rpm/libmce-glib.spec | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 219f4aa..41c39aa 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ all: debug release pkgconfig VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 8 +VERSION_RELEASE = 9 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) diff --git a/debian/changelog b/debian/changelog index 509891e..d4e25ae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,12 +1,18 @@ +libmce-glib (1.0.9) unstable; urgency=low + + * Ignore GLib deprecation warnings + + -- Slava Monich Sun, 08 Mar 2020 16:30:35 +0200 + libmce-glib (1.0.8) unstable; urgency=low - * Avoid overlinking. + * Avoid overlinking -- Slava Monich Tue, 05 Nov 2019 14:21:43 +0300 libmce-glib (1.0.7) unstable; urgency=low - * Allow use of CC & LDFLAGS defined by build system. + * Allow use of CC & LDFLAGS defined by build system -- Slava Monich Fri, 30 Aug 2019 18:14:21 +0300 diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index 287c1d7..df3dec7 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,5 +1,5 @@ Name: libmce-glib -Version: 1.0.8 +Version: 1.0.9 Release: 0 Summary: MCE client library Group: Development/Libraries From c60c1349803a87a03ec25a76935a379a5da4c7e1 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 22 May 2020 21:49:31 +0300 Subject: [PATCH 14/34] [libmce-glib] Hide internal symbols. JB#43321 If nothing else, this makes the library file smaller by reducing the size of the dynamic symbol table. --- Makefile | 17 +++++---------- libmce-glib.map | 6 ++++++ src/mce_proxy.c | 11 +++++----- src/mce_proxy.h | 27 ++++++++++++++---------- src/mce_types_p.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 libmce-glib.map create mode 100644 src/mce_types_p.h diff --git a/Makefile b/Makefile index 41c39aa..6603890 100644 --- a/Makefile +++ b/Makefile @@ -63,10 +63,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release # Tools and flags # -ifndef CC -CC = $(CROSS_COMPILE)gcc -endif - +CC ?= $(CROSS_COMPILE)gcc LD = $(CC) DEFINES += -DGLIB_DISABLE_DEPRECATION_WARNINGS WARNINGS = -Wall -Wno-unused-parameter -Wno-multichar @@ -74,14 +71,12 @@ INCLUDES = -I$(INCLUDE_DIR) -I$(GEN_DIR) BASE_FLAGS = -fPIC $(CFLAGS) FULL_CFLAGS = $(BASE_FLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ $(shell pkg-config --cflags $(PKGS)) -FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) +FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIB_SONAME) \ + -Wl,--version-script=$(LIB_NAME).map DEBUG_FLAGS = -g RELEASE_FLAGS = -ifndef KEEP_SYMBOLS -KEEP_SYMBOLS = 0 -endif - +KEEP_SYMBOLS ?= 0 ifneq ($(KEEP_SYMBOLS),0) RELEASE_FLAGS += -g endif @@ -193,11 +188,9 @@ $(PKGCONFIG): $(LIB_NAME).pc.in Makefile # Install # -INSTALL_PERM = 644 - INSTALL = install INSTALL_DIRS = $(INSTALL) -d -INSTALL_FILES = $(INSTALL) -m $(INSTALL_PERM) +INSTALL_FILES = $(INSTALL) -m 644 INSTALL_LIB_DIR = $(DESTDIR)/usr/lib INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/$(LIB_NAME) diff --git a/libmce-glib.map b/libmce-glib.map new file mode 100644 index 0000000..e0d8ab8 --- /dev/null +++ b/libmce-glib.map @@ -0,0 +1,6 @@ +{ + global: + mce_*; + local: + *; +}; diff --git a/src/mce_proxy.c b/src/mce_proxy.c index dcb9ab6..21dc043 100644 --- a/src/mce_proxy.c +++ b/src/mce_proxy.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2020 Jolla Ltd. + * Copyright (C) 2016-2020 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 @@ -60,6 +60,7 @@ enum mce_proxy_signal { static guint mce_proxy_signals[SIGNAL_COUNT] = { 0 }; typedef GObjectClass MceProxyClass; +GType mce_proxy_get_type() MCE_INTERNAL; G_DEFINE_TYPE(MceProxy, mce_proxy, G_TYPE_OBJECT) #define PARENT_CLASS mce_proxy_parent_class #define MCE_PROXY_TYPE (mce_proxy_get_type()) diff --git a/src/mce_proxy.h b/src/mce_proxy.h index 6f9adbd..f8f0ee9 100644 --- a/src/mce_proxy.h +++ b/src/mce_proxy.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2020 Jolla Ltd. + * Copyright (C) 2016-2020 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 @@ -37,7 +37,7 @@ #ifndef MCE_PROXY_H #define MCE_PROXY_H -#include "mce_types.h" +#include "mce_types_p.h" typedef struct mce_proxy_priv MceProxyPriv; struct _ComNokiaMceSignal; @@ -58,26 +58,31 @@ typedef void MceProxy* mce_proxy_new( - void); + void) + MCE_INTERNAL; MceProxy* mce_proxy_ref( - MceProxy* proxy); + MceProxy* proxy) + MCE_INTERNAL; void mce_proxy_unref( - MceProxy* proxy); + MceProxy* proxy) + MCE_INTERNAL; gulong mce_proxy_add_valid_changed_handler( MceProxy* proxy, MceProxyFunc fn, - void* arg); + void* arg) + MCE_INTERNAL; void mce_proxy_remove_handler( MceProxy* proxy, - gulong id); + gulong id) + MCE_INTERNAL; #endif /* MCE_PROXY_H */ diff --git a/src/mce_types_p.h b/src/mce_types_p.h new file mode 100644 index 0000000..5945069 --- /dev/null +++ b/src/mce_types_p.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020 Jolla Ltd. + * Copyright (C) 2020 Slava Monich + * + * 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_TYPES_PRIVATE_H +#define MCE_TYPES_PRIVATE_H + +#include + +/* Macros */ +#define MCE_INTERNAL G_GNUC_INTERNAL + +#endif /* MCE_TYPES_PRIVATE_H */ + +/* + * Local Variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From dcfa3ffeeff99b01c697f5c17cefe8fbfd21a7da Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 22 May 2020 22:07:21 +0300 Subject: [PATCH 15/34] [libmce-glib] Respect arch specific lib dir. JB#49681 --- .gitignore | 1 + Makefile | 20 +++++++++++++------- debian/control | 4 ++-- debian/libmce-glib-dev.install | 3 --- debian/libmce-glib-dev.install.in | 3 +++ debian/libmce-glib.install | 1 - debian/libmce-glib.install.in | 1 + debian/rules | 7 ++++++- libmce-glib.pc.in | 4 ++-- rpm/libmce-glib.spec | 4 ++-- 10 files changed, 30 insertions(+), 18 deletions(-) delete mode 100644 debian/libmce-glib-dev.install create mode 100644 debian/libmce-glib-dev.install.in delete mode 100644 debian/libmce-glib.install create mode 100644 debian/libmce-glib.install.in diff --git a/.gitignore b/.gitignore index 6496a2e..1cd7712 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ debian/libmce-glib debian/libmce-glib-dev debian/*.debhelper.log debian/*.debhelper +debian/*.install debian/*.substvars debian/tmp documentation.list diff --git a/Makefile b/Makefile index 6603890..5b4d8b3 100644 --- a/Makefile +++ b/Makefile @@ -133,14 +133,13 @@ debug: $(DEBUG_LIB) $(DEBUG_LINK) release: $(RELEASE_LIB) $(RELEASE_LINK) -pkgconfig: $(PKGCONFIG) - clean: rm -f *~ $(SRC_DIR)/*~ $(INCLUDE_DIR)/*~ rpm/*~ rm -fr $(BUILD_DIR) RPMS installroot rm -fr debian/tmp debian/lib$(NAME) debian/lib$(NAME)-dev rm -f documentation.list debian/files debian/*.substvars rm -f debian/*.debhelper.log debian/*.debhelper debian/*~ + rm -f debian/*.install $(GEN_DIR): mkdir -p $@ @@ -181,8 +180,17 @@ $(DEBUG_LINK): $(RELEASE_LINK): ln -sf $(LIB) $@ +# This one could be substituted with arch specific dir +LIBDIR ?= /usr/lib +ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g') + +pkgconfig: $(PKGCONFIG) + $(PKGCONFIG): $(LIB_NAME).pc.in Makefile - sed -e 's/\[version\]/'$(PCVERSION)/g $< > $@ + sed -e 's|@version@|$(PCVERSION)|g' -e 's|@libdir@|$(ABS_LIBDIR)|g' $< > $@ + +debian/%.install: debian/%.install.in + sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@ # # Install @@ -192,11 +200,9 @@ INSTALL = install INSTALL_DIRS = $(INSTALL) -d INSTALL_FILES = $(INSTALL) -m 644 -INSTALL_LIB_DIR = $(DESTDIR)/usr/lib +INSTALL_LIB_DIR = $(DESTDIR)$(ABS_LIBDIR) INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/$(LIB_NAME) -INSTALL_PKGCONFIG_DIR = $(DESTDIR)/usr/lib/pkgconfig - -INSTALL_ALIAS = $(INSTALL_LIB_DIR)/$(LIB_SHORTCUT) +INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig install: $(INSTALL_LIB_DIR) $(INSTALL_FILES) $(RELEASE_LIB) $(INSTALL_LIB_DIR) diff --git a/debian/control b/debian/control index 980b66b..2c66284 100644 --- a/debian/control +++ b/debian/control @@ -2,13 +2,13 @@ Source: libmce-glib Section: libs Priority: optional Maintainer: Slava Monich -Build-Depends: debhelper (>= 7), libglib2.0-dev (>= 2.0), libglibutil-dev, mce-dev +Build-Depends: debhelper (>= 8.1.3), libglib2.0-dev (>= 2.0), libglibutil-dev, mce-dev Standards-Version: 3.8.4 Package: libmce-glib Section: libs Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: libglibutil (>= 1.0.5), ${shlibs:Depends}, ${misc:Depends} Description: Client library for mce Package: libmce-glib-dev diff --git a/debian/libmce-glib-dev.install b/debian/libmce-glib-dev.install deleted file mode 100644 index cce5a7d..0000000 --- a/debian/libmce-glib-dev.install +++ /dev/null @@ -1,3 +0,0 @@ -debian/tmp/usr/lib/libmce-glib.so usr/lib -include/*.h usr/include/libmce-glib -build/libmce-glib.pc usr/lib/pkgconfig diff --git a/debian/libmce-glib-dev.install.in b/debian/libmce-glib-dev.install.in new file mode 100644 index 0000000..c07d428 --- /dev/null +++ b/debian/libmce-glib-dev.install.in @@ -0,0 +1,3 @@ +debian/tmp/@LIBDIR@/libmce-glib.so @LIBDIR@ +debian/tmp/@LIBDIR@/pkgconfig/libmce-glib.pc @LIBDIR@/pkgconfig +debian/tmp/usr/include/* usr/include diff --git a/debian/libmce-glib.install b/debian/libmce-glib.install deleted file mode 100644 index 6a4fd9f..0000000 --- a/debian/libmce-glib.install +++ /dev/null @@ -1 +0,0 @@ -debian/tmp/usr/lib/libmce-glib.so.* usr/lib diff --git a/debian/libmce-glib.install.in b/debian/libmce-glib.install.in new file mode 100644 index 0000000..661666a --- /dev/null +++ b/debian/libmce-glib.install.in @@ -0,0 +1 @@ +debian/tmp/@LIBDIR@/libmce-glib.so.* @LIBDIR@ diff --git a/debian/rules b/debian/rules index 3a92007..fd7b2a3 100755 --- a/debian/rules +++ b/debian/rules @@ -4,8 +4,13 @@ # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 +LIBDIR=usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH) + +override_dh_auto_build: + dh_auto_build -- LIBDIR=$(LIBDIR) release pkgconfig debian/libmce-glib.install debian/libmce-glib-dev.install + override_dh_auto_install: - dh_auto_install -- install-dev + dh_auto_install -- LIBDIR=$(LIBDIR) install-dev %: dh $@ diff --git a/libmce-glib.pc.in b/libmce-glib.pc.in index f44a058..c89a268 100644 --- a/libmce-glib.pc.in +++ b/libmce-glib.pc.in @@ -1,9 +1,9 @@ -libdir=/usr/lib +libdir=@libdir@ includedir=/usr/include Name: libmce-glib Description: MCE client library -Version: [version] +Version: @version@ Requires.private: libglibutil glib-2.0 gio-2.0 Libs: -lmce-glib Cflags: -I${includedir}/libmce-glib diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index df3dec7..6f4c6e9 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -28,11 +28,11 @@ This package contains the development library for %{name}. %setup -q %build -make KEEP_SYMBOLS=1 release pkgconfig +make LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig %install rm -rf %{buildroot} -make install-dev DESTDIR=%{buildroot} +make LIBDIR=%{_libdir} DESTDIR=%{buildroot} install-dev %post -p /sbin/ldconfig From f9139dd620add9cb37da6bd8d08aa7107c6e5f5d Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Mon, 25 May 2020 15:13:02 +0300 Subject: [PATCH 16/34] Version 1.0.10 --- Makefile | 2 +- debian/changelog | 7 +++++++ rpm/libmce-glib.spec | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5b4d8b3..0f5925d 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ all: debug release pkgconfig VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 9 +VERSION_RELEASE = 10 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) diff --git a/debian/changelog b/debian/changelog index d4e25ae..7765d27 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +libmce-glib (1.0.10) unstable; urgency=low + + * Hide internal symbols + * Respect arch specific lib dir + + -- Slava Monich Mon, 25 May 2020 15:11:04 +0300 + libmce-glib (1.0.9) unstable; urgency=low * Ignore GLib deprecation warnings diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index 6f4c6e9..3bfc0b9 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,5 +1,5 @@ Name: libmce-glib -Version: 1.0.9 +Version: 1.0.10 Release: 0 Summary: MCE client library Group: Development/Libraries From 67c6d3342a45c913309db5af59f3d28892856103 Mon Sep 17 00:00:00 2001 From: Rinigus Date: Mon, 31 Aug 2020 09:29:50 +0300 Subject: [PATCH 17/34] [libmce-glib] Install library as executable. JB#51013 Signed-off-by: Rinigus --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0f5925d..d72fc59 100644 --- a/Makefile +++ b/Makefile @@ -205,7 +205,7 @@ INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/$(LIB_NAME) INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig install: $(INSTALL_LIB_DIR) - $(INSTALL_FILES) $(RELEASE_LIB) $(INSTALL_LIB_DIR) + $(INSTALL) -m 755 $(RELEASE_LIB) $(INSTALL_LIB_DIR) ln -sf $(LIB) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK2) ln -sf $(LIB_SYMLINK2) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK1) From dddb06111694a8ab511fc5e5d3da669219e1200d Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Mon, 8 Nov 2021 02:45:41 +0200 Subject: [PATCH 18/34] [libmce-glib] Update license. JB#43321 --- LICENSE | 2 +- debian/copyright | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 5f03d76..15359ad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (C) 2016-2020 Jolla Ltd. +Copyright (C) 2016-2021 Jolla Ltd. You may use this file under the terms of BSD license as follows: diff --git a/debian/copyright b/debian/copyright index 5f03d76..15359ad 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,4 +1,4 @@ -Copyright (C) 2016-2020 Jolla Ltd. +Copyright (C) 2016-2021 Jolla Ltd. You may use this file under the terms of BSD license as follows: From 78f487098870e7415fcf75d0e4f8b6d91fd131af Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Mon, 8 Nov 2021 02:48:22 +0200 Subject: [PATCH 19/34] [libmce-glib] Housekeeping. JB#43321 --- rpm/libmce-glib.spec | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index 3bfc0b9..d7452cb 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,15 +1,20 @@ Name: libmce-glib + Version: 1.0.10 Release: 0 Summary: MCE client library -Group: Development/Libraries License: BSD -URL: https://git.sailfishos.org/mer-core/libmce-glib +URL: https://github.com/sailfishos/libmce-glib Source: %{name}-%{version}.tar.bz2 + +%define libglibutil_version 1.0.5 + +BuildRequires: pkgconfig BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(libglibutil) -BuildRequires: pkgconfig(mce) -Requires: libglibutil >= 1.0.5 +BuildRequires: pkgconfig(libglibutil) >= %{libglibutil_version} +BuildRequires: pkgconfig(mce) >= 1.24.0 + +Requires: libglibutil >= %{libglibutil_version} Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -19,7 +24,6 @@ Provides glib-based MCE client API %package devel Summary: Development library for %{name} Requires: %{name} = %{version} -Requires: pkgconfig %description devel This package contains the development library for %{name}. @@ -28,7 +32,7 @@ This package contains the development library for %{name}. %setup -q %build -make LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig +make %{_smp_mflags} LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig %install rm -rf %{buildroot} From 0a4a06109f6966b8c6182adc6eca42f47aba0c36 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Mon, 8 Nov 2021 02:49:13 +0200 Subject: [PATCH 20/34] Version 1.0.12 --- Makefile | 2 +- debian/changelog | 6 ++++++ rpm/libmce-glib.spec | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d72fc59..fcb0adb 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ all: debug release pkgconfig VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 10 +VERSION_RELEASE = 12 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) diff --git a/debian/changelog b/debian/changelog index 7765d27..bbb439d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libmce-glib (1.0.12) unstable; urgency=low + + * Housekeeping release + + -- Slava Monich Mon, 08 Nov 2021 02:44:15 +0200 + libmce-glib (1.0.10) unstable; urgency=low * Hide internal symbols diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index d7452cb..6efc642 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,6 +1,6 @@ Name: libmce-glib -Version: 1.0.10 +Version: 1.0.12 Release: 0 Summary: MCE client library License: BSD From 7d8b7077ef55da4d1a629ef479966974aac12e38 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Wed, 19 Jan 2022 13:59:50 +0200 Subject: [PATCH 21/34] [license] Unified and freshened up licenses. JB#55991 --- LICENSE | 3 ++- debian/copyright | 3 ++- include/mce_battery.h | 8 ++++++-- include/mce_charger.h | 8 ++++++-- include/mce_display.h | 10 +++++----- include/mce_log.h | 10 +++++----- include/mce_tklock.h | 10 +++++----- include/mce_types.h | 10 +++++----- src/mce_battery.c | 8 ++++++-- src/mce_charger.c | 8 ++++++-- src/mce_display.c | 10 +++++----- src/mce_log_p.h | 10 +++++----- src/mce_proxy.c | 4 ++-- src/mce_proxy.h | 8 ++++---- src/mce_tklock.c | 10 +++++----- src/mce_types_p.h | 8 ++++---- 16 files changed, 73 insertions(+), 55 deletions(-) diff --git a/LICENSE b/LICENSE index 15359ad..b5b9b8c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ -Copyright (C) 2016-2021 Jolla Ltd. +Copyright (C) 2016-2022 Jolla Ltd. +Copyright (C) 2016-2022 Slava Monich You may use this file under the terms of BSD license as follows: diff --git a/debian/copyright b/debian/copyright index 15359ad..b5b9b8c 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,4 +1,5 @@ -Copyright (C) 2016-2021 Jolla Ltd. +Copyright (C) 2016-2022 Jolla Ltd. +Copyright (C) 2016-2022 Slava Monich You may use this file under the terms of BSD license as follows: diff --git a/include/mce_battery.h b/include/mce_battery.h index f3cd3f8..e2ec595 100644 --- a/include/mce_battery.h +++ b/include/mce_battery.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2019 Jolla Ltd. - * Copyright (C) 2019 Slava Monich + * Copyright (C) 2019-2022 Jolla Ltd. + * Copyright (C) 2019-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -28,6 +28,10 @@ * 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_BATTERY_H diff --git a/include/mce_charger.h b/include/mce_charger.h index fba952d..1ca0a6f 100644 --- a/include/mce_charger.h +++ b/include/mce_charger.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2019 Jolla Ltd. - * Copyright (C) 2019 Slava Monich + * Copyright (C) 2019-2022 Jolla Ltd. + * Copyright (C) 2019-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -28,6 +28,10 @@ * 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_CHARGER_H diff --git a/include/mce_display.h b/include/mce_display.h index 7a8c496..f5dc24e 100644 --- a/include/mce_display.h +++ b/include/mce_display.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016-2017 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 diff --git a/include/mce_log.h b/include/mce_log.h index d4351c9..bcad793 100644 --- a/include/mce_log.h +++ b/include/mce_log.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 diff --git a/include/mce_tklock.h b/include/mce_tklock.h index c5aad6e..7018626 100644 --- a/include/mce_tklock.h +++ b/include/mce_tklock.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016-2017 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 diff --git a/include/mce_types.h b/include/mce_types.h index 5515a4f..5725947 100644 --- a/include/mce_types.h +++ b/include/mce_types.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 diff --git a/src/mce_battery.c b/src/mce_battery.c index 011773b..eada639 100644 --- a/src/mce_battery.c +++ b/src/mce_battery.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2019 Jolla Ltd. - * Copyright (C) 2019 Slava Monich + * Copyright (C) 2019-2022 Jolla Ltd. + * Copyright (C) 2019-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -28,6 +28,10 @@ * 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_battery.h" diff --git a/src/mce_charger.c b/src/mce_charger.c index 963c591..8cb39b2 100644 --- a/src/mce_charger.c +++ b/src/mce_charger.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2019 Jolla Ltd. - * Copyright (C) 2019 Slava Monich + * Copyright (C) 2019-2022 Jolla Ltd. + * Copyright (C) 2019-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -28,6 +28,10 @@ * 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_charger.h" diff --git a/src/mce_display.c b/src/mce_display.c index f54cc05..7a7924a 100644 --- a/src/mce_display.c +++ b/src/mce_display.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 diff --git a/src/mce_log_p.h b/src/mce_log_p.h index 4f688fc..ea4efd3 100644 --- a/src/mce_log_p.h +++ b/src/mce_log_p.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 diff --git a/src/mce_proxy.c b/src/mce_proxy.c index 21dc043..e3c39b4 100644 --- a/src/mce_proxy.c +++ b/src/mce_proxy.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016-2020 Jolla Ltd. - * Copyright (C) 2016-2020 Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * diff --git a/src/mce_proxy.h b/src/mce_proxy.h index f8f0ee9..55bb3c8 100644 --- a/src/mce_proxy.h +++ b/src/mce_proxy.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016-2020 Jolla Ltd. - * Copyright (C) 2016-2020 Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -14,8 +14,8 @@ * 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. + * 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 diff --git a/src/mce_tklock.c b/src/mce_tklock.c index 7bce653..dac4bca 100644 --- a/src/mce_tklock.c +++ b/src/mce_tklock.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2016-2017 Jolla Ltd. - * Contact: Slava Monich + * Copyright (C) 2016-2022 Jolla Ltd. + * Copyright (C) 2016-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -13,9 +13,9 @@ * 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 name of Jolla Ltd nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. + * 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 diff --git a/src/mce_types_p.h b/src/mce_types_p.h index 5945069..1df72af 100644 --- a/src/mce_types_p.h +++ b/src/mce_types_p.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2020 Jolla Ltd. - * Copyright (C) 2020 Slava Monich + * Copyright (C) 2020-2022 Jolla Ltd. + * Copyright (C) 2020-2022 Slava Monich * * You may use this file under the terms of BSD license as follows: * @@ -14,8 +14,8 @@ * 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. + * 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 From 2e0818c64226deaf70fd4168843d3ca252b32b73 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Wed, 19 Jan 2022 14:01:54 +0200 Subject: [PATCH 22/34] [license] Install LICENSE file. JB#55991 --- rpm/libmce-glib.spec | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index 6efc642..c1c8aff 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -14,6 +14,10 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libglibutil) >= %{libglibutil_version} BuildRequires: pkgconfig(mce) >= 1.24.0 +# license macro requires rpm >= 4.11 +BuildRequires: pkgconfig(rpm) +%define license_support %(pkg-config --exists 'rpm >= 4.11'; echo $?) + Requires: libglibutil >= %{libglibutil_version} Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -45,6 +49,9 @@ make LIBDIR=%{_libdir} DESTDIR=%{buildroot} install-dev %files %defattr(-,root,root,-) %{_libdir}/%{name}.so.* +%if %{license_support} == 0 +%license LICENSE +%endif %files devel %defattr(-,root,root,-) From d83584dbd25f35d5d38c28d55db89f96696d2a23 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Wed, 19 Jan 2022 14:15:16 +0200 Subject: [PATCH 23/34] [libmce-glib] Shuffled includes a bit. JB#43321 The goal was to avoid pulling in unnecessarily. Not that it was a big deal... --- include/mce_battery.h | 10 ++++++---- include/mce_charger.h | 10 ++++++---- include/mce_display.h | 8 +++++--- include/mce_log.h | 1 + include/mce_tklock.h | 8 +++++--- include/mce_types.h | 10 +++++++++- src/mce_battery.c | 2 +- src/mce_charger.c | 2 +- src/mce_display.c | 2 +- src/mce_proxy.h | 2 ++ src/mce_tklock.c | 2 +- 11 files changed, 38 insertions(+), 19 deletions(-) diff --git a/include/mce_battery.h b/include/mce_battery.h index e2ec595..f3deeed 100644 --- a/include/mce_battery.h +++ b/include/mce_battery.h @@ -37,9 +37,11 @@ #ifndef MCE_BATTERY_H #define MCE_BATTERY_H +/* Since 1.0.6 */ + #include "mce_types.h" -/* Since 1.0.6 */ +#include G_BEGIN_DECLS @@ -53,13 +55,13 @@ typedef enum mce_battery_status { typedef struct mce_battery_priv MceBatteryPriv; -typedef struct mce_battery { +struct mce_battery { GObject object; MceBatteryPriv* priv; gboolean valid; guint level; MCE_BATTERY_STATUS status; -} MceBattery; +}; /* MceBattery */ typedef void (*MceBatteryFunc)( @@ -104,7 +106,7 @@ mce_battery_remove_handler( void mce_battery_remove_handlers( MceBattery* battery, - gulong *ids, + gulong* ids, guint count); #define mce_battery_remove_all_handlers(d, ids) \ diff --git a/include/mce_charger.h b/include/mce_charger.h index 1ca0a6f..776c884 100644 --- a/include/mce_charger.h +++ b/include/mce_charger.h @@ -37,9 +37,11 @@ #ifndef MCE_CHARGER_H #define MCE_CHARGER_H +/* Since 1.0.6 */ + #include "mce_types.h" -/* Since 1.0.6 */ +#include G_BEGIN_DECLS @@ -51,12 +53,12 @@ typedef enum mce_charger_state { typedef struct mce_charger_priv MceChargerPriv; -typedef struct mce_charger { +struct mce_charger { GObject object; MceChargerPriv* priv; gboolean valid; MCE_CHARGER_STATE state; -} MceCharger; +}; /* MceCharger */ typedef void (*MceChargerFunc)( @@ -95,7 +97,7 @@ mce_charger_remove_handler( void mce_charger_remove_handlers( MceCharger* charger, - gulong *ids, + gulong* ids, guint count); #define mce_charger_remove_all_handlers(d, ids) \ diff --git a/include/mce_display.h b/include/mce_display.h index f5dc24e..783b46c 100644 --- a/include/mce_display.h +++ b/include/mce_display.h @@ -39,6 +39,8 @@ #include "mce_types.h" +#include + G_BEGIN_DECLS typedef enum mce_display_state { @@ -49,12 +51,12 @@ typedef enum mce_display_state { typedef struct mce_display_priv MceDisplayPriv; -typedef struct mce_display { +struct mce_display { GObject object; MceDisplayPriv* priv; gboolean valid; MCE_DISPLAY_STATE state; -} MceDisplay; +}; /* MceDisplay */ typedef void (*MceDisplayFunc)( @@ -93,7 +95,7 @@ mce_display_remove_handler( void mce_display_remove_handlers( MceDisplay* display, - gulong *ids, + gulong* ids, guint count); #define mce_display_remove_all_handlers(d, ids) \ diff --git a/include/mce_log.h b/include/mce_log.h index bcad793..2cab08b 100644 --- a/include/mce_log.h +++ b/include/mce_log.h @@ -38,6 +38,7 @@ #define MCE_LOG_H #include "mce_types.h" + #include G_BEGIN_DECLS diff --git a/include/mce_tklock.h b/include/mce_tklock.h index 7018626..8aee093 100644 --- a/include/mce_tklock.h +++ b/include/mce_tklock.h @@ -39,6 +39,8 @@ #include "mce_types.h" +#include + G_BEGIN_DECLS typedef enum mce_tklock_mode { @@ -53,13 +55,13 @@ typedef enum mce_tklock_mode { typedef struct mce_tklock_priv MceTklockPriv; -typedef struct mce_tklock { +struct mce_tklock { GObject object; MceTklockPriv* priv; gboolean valid; MCE_TKLOCK_MODE mode; gboolean locked; -} MceTklock; +}; /* MceTklock */ typedef void (*MceTklockFunc)( @@ -104,7 +106,7 @@ mce_tklock_remove_handler( void mce_tklock_remove_handlers( MceTklock* tklock, - gulong *ids, + gulong* ids, guint count); #define mce_tklock_remove_all_handlers(t, ids) \ diff --git a/include/mce_types.h b/include/mce_types.h index 5725947..bf75da7 100644 --- a/include/mce_types.h +++ b/include/mce_types.h @@ -38,7 +38,15 @@ #define MCE_TYPES_H #include -#include + +G_BEGIN_DECLS + +typedef struct mce_battery MceBattery; +typedef struct mce_charger MceCharger; +typedef struct mce_display MceDisplay; +typedef struct mce_tklock MceTklock; + +G_END_DECLS #endif /* MCE_TYPES_H */ diff --git a/src/mce_battery.c b/src/mce_battery.c index eada639..1ce4acc 100644 --- a/src/mce_battery.c +++ b/src/mce_battery.c @@ -357,7 +357,7 @@ mce_battery_remove_handler( void mce_battery_remove_handlers( MceBattery* self, - gulong *ids, + gulong* ids, guint count) { gutil_disconnect_handlers(self, ids, count); diff --git a/src/mce_charger.c b/src/mce_charger.c index 8cb39b2..e40aa31 100644 --- a/src/mce_charger.c +++ b/src/mce_charger.c @@ -257,7 +257,7 @@ mce_charger_remove_handler( void mce_charger_remove_handlers( MceCharger* self, - gulong *ids, + gulong* ids, guint count) { gutil_disconnect_handlers(self, ids, count); diff --git a/src/mce_display.c b/src/mce_display.c index 7a7924a..54c36ca 100644 --- a/src/mce_display.c +++ b/src/mce_display.c @@ -257,7 +257,7 @@ mce_display_remove_handler( void mce_display_remove_handlers( MceDisplay* self, - gulong *ids, + gulong* ids, guint count) { gutil_disconnect_handlers(self, ids, count); diff --git a/src/mce_proxy.h b/src/mce_proxy.h index 55bb3c8..e578c89 100644 --- a/src/mce_proxy.h +++ b/src/mce_proxy.h @@ -39,6 +39,8 @@ #include "mce_types_p.h" +#include + typedef struct mce_proxy_priv MceProxyPriv; struct _ComNokiaMceSignal; struct _ComNokiaMceRequest; diff --git a/src/mce_tklock.c b/src/mce_tklock.c index dac4bca..8f041ac 100644 --- a/src/mce_tklock.c +++ b/src/mce_tklock.c @@ -289,7 +289,7 @@ mce_tklock_remove_handler( void mce_tklock_remove_handlers( MceTklock* self, - gulong *ids, + gulong* ids, guint count) { gutil_disconnect_handlers(self, ids, count); From 9a14618c13b2b8267af40d04633543689d1caab8 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Wed, 19 Jan 2022 14:25:44 +0200 Subject: [PATCH 24/34] Version 1.0.13 --- Makefile | 2 +- debian/changelog | 7 +++++++ rpm/libmce-glib.spec | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fcb0adb..61a06d1 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ all: debug release pkgconfig VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_RELEASE = 12 +VERSION_RELEASE = 13 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) diff --git a/debian/changelog b/debian/changelog index bbb439d..6c606e5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +libmce-glib (1.0.13) unstable; urgency=low + + * Shuffled includes a bit + * Unified and freshened up licenses + + -- Slava Monich Wed, 19 Jan 2022 14:21:38 +0200 + libmce-glib (1.0.12) unstable; urgency=low * Housekeeping release diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index c1c8aff..30df76a 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,6 +1,6 @@ Name: libmce-glib -Version: 1.0.12 +Version: 1.0.13 Release: 0 Summary: MCE client library License: BSD From 771ac3ece9b22bf83ad319cb3a58e368312add60 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Fri, 14 Apr 2023 08:20:20 +0300 Subject: [PATCH 25/34] [libmce-glib] Add MceInactivity object. Fixes JB#60550 Tracks user inactivity as reported by MCE. Created by using already existing MceTklock object as a template. Signed-off-by: Simo Piiroinen --- Makefile | 1 + include/mce_inactivity.h | 107 +++++++++++ include/mce_types.h | 5 +- spec/com.nokia.mce.request.xml | 3 + spec/com.nokia.mce.signal.xml | 3 + src/mce_inactivity.c | 315 +++++++++++++++++++++++++++++++++ 6 files changed, 432 insertions(+), 2 deletions(-) create mode 100644 include/mce_inactivity.h create mode 100644 src/mce_inactivity.c diff --git a/Makefile b/Makefile index 61a06d1..4e1908e 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/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: + */ From aeaea4ff4e09035761029f277bd3329a7e94e4a9 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 23 Apr 2023 21:59:23 +0300 Subject: [PATCH 26/34] [libmce-glib] A better way to silence deprecation warnings --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 61a06d1..2eb55ea 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,8 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release CC ?= $(CROSS_COMPILE)gcc LD = $(CC) -DEFINES += -DGLIB_DISABLE_DEPRECATION_WARNINGS +DEFINES += -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 \ + -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_MAX_ALLOWED WARNINGS = -Wall -Wno-unused-parameter -Wno-multichar INCLUDES = -I$(INCLUDE_DIR) -I$(GEN_DIR) BASE_FLAGS = -fPIC $(CFLAGS) From 5a848146b49679dad62caa9a1d638d06c724cbad Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 23 Apr 2023 22:00:44 +0300 Subject: [PATCH 27/34] [debian] Bumped debhelper compat level to 7 --- debian/compat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/compat b/debian/compat index 7ed6ff8..7f8f011 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -5 +7 From 7e0b708217c8337a1e51bb6d0b23b2e1ddcabefd Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Fri, 14 Apr 2023 12:18:17 +0300 Subject: [PATCH 28/34] [libmce-glib] Add an example application Serves as an example on how to use functionality provided by libmce-glib and is useful also for testing and debugging the library itself. Note that the application is built using libmce-glib headers and libraries that are installed in the development environment - the same way regular applications not included in libmce-glib source tree need to operate. Signed-off-by: Simo Piiroinen --- .gitignore | 2 + examples/Makefile | 15 +++ examples/example.c | 278 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+) create mode 100644 examples/Makefile create mode 100644 examples/example.c 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/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; +} From 49cff7f515979777d137cbb6a78076a50fdb99f2 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Mon, 8 May 2023 10:48:56 +0300 Subject: [PATCH 29/34] Version 1.1.0 --- Makefile | 4 ++-- debian/changelog | 7 +++++++ rpm/libmce-glib.spec | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0fcbb01..5cd6564 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ all: debug release pkgconfig # VERSION_MAJOR = 1 -VERSION_MINOR = 0 -VERSION_RELEASE = 13 +VERSION_MINOR = 1 +VERSION_RELEASE = 0 # Version for pkg-config PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE) diff --git a/debian/changelog b/debian/changelog index 6c606e5..2382fe1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +libmce-glib (1.1.0) unstable; urgency=low + + * Add an example application + * Add MceInactivity object + + -- Simo Piiroinen Mon, 08 May 2023 10:46:08 +0300 + libmce-glib (1.0.13) unstable; urgency=low * Shuffled includes a bit diff --git a/rpm/libmce-glib.spec b/rpm/libmce-glib.spec index 30df76a..0673af8 100644 --- a/rpm/libmce-glib.spec +++ b/rpm/libmce-glib.spec @@ -1,6 +1,6 @@ Name: libmce-glib -Version: 1.0.13 +Version: 1.1.0 Release: 0 Summary: MCE client library License: BSD From a6e3ba2c61aaa06a1415dfc92f089368c38ea162 Mon Sep 17 00:00:00 2001 From: Marius Gripsgard Date: Thu, 21 Sep 2023 03:59:35 +0200 Subject: [PATCH 30/34] src/display: Fix display power state changed signal --- src/mce_display.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mce_display.c b/src/mce_display.c index 3dd9477..fd6634f 100644 --- a/src/mce_display.c +++ b/src/mce_display.c @@ -61,7 +61,7 @@ enum mce_display_signal { #define MCE_DISPLAY_OFF_STRING "off" #define MCE_DISPLAY_ON_STRING "on" -#define MCE_DISPLAY_SIG "DisplayPowerStateChange" +#define MCE_DISPLAY_SIG "display-power-state-change" static guint mce_display_signals[SIGNAL_COUNT] = { 0 }; @@ -128,6 +128,7 @@ void mce_display_power_state_change( ComCanonicalUnityScreen* proxy, int32_t status, + int32_t reason, gpointer arg) { GDEBUG("Display is %d", status); From b5d5f5289416c1189cf73f4a3421a2207ad17663 Mon Sep 17 00:00:00 2001 From: Marius Gripsgard Date: Thu, 21 Sep 2023 04:02:57 +0200 Subject: [PATCH 31/34] treewide: Add support for ayatana battery and charger --- Makefile | 5 +- spec/org.ayatana.indicator.power.Battery.xml | 39 ++++++ src/mce_battery.c | 136 ++++++------------- src/mce_charger.c | 78 +++++------ src/mce_display.c | 10 +- src/mce_proxy.c | 81 ++++++++--- src/mce_proxy.h | 5 +- 7 files changed, 186 insertions(+), 168 deletions(-) create mode 100644 spec/org.ayatana.indicator.power.Battery.xml diff --git a/Makefile b/Makefile index 34dd6c3..f551a61 100644 --- a/Makefile +++ b/Makefile @@ -41,11 +41,12 @@ SRC = \ mce_battery.c \ mce_charger.c \ mce_display.c \ - mce_inactivity.c \ mce_proxy.c GEN_SRC = \ - com.canonical.Unity.Screen.c + com.canonical.Unity.Screen.c \ + org.ayatana.indicator.power.Battery.c +# mce_inactivity.c \ # # Directories # diff --git a/spec/org.ayatana.indicator.power.Battery.xml b/spec/org.ayatana.indicator.power.Battery.xml new file mode 100644 index 0000000..76bbfca --- /dev/null +++ b/spec/org.ayatana.indicator.power.Battery.xml @@ -0,0 +1,39 @@ + + + + + + + + + The battery's power level. Possible values: 'ok', 'low', 'very_low', 'critical' + + + + + + + + The battery's power level in percentage. + + + + + + + + Whether or not ayatana-indicator-power-service is warning the user about low battery power. + + + + + + + + Whether or not the battery is discharging + + + + + + \ No newline at end of file diff --git a/src/mce_battery.c b/src/mce_battery.c index 1ce4acc..0ee896c 100644 --- a/src/mce_battery.c +++ b/src/mce_battery.c @@ -38,14 +38,16 @@ #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" +#include "org.ayatana.indicator.power.Battery.h" + +#define MCE_BATTERY_STATUS_OK "ok" +#define MCE_BATTERY_STATUS_LOW "low" +#define MCE_BATTERY_STATUS_EMPTY "very_low" +#define MCE_BATTERY_STATUS_CRITICAL "critical" +#define MCE_BATTERY_STATUS_UNKNOWN "unknown" enum mce_battery_ind { BATTERY_IND_LEVEL, @@ -65,7 +67,7 @@ struct mce_battery_priv { MceProxy* proxy; BATTERY_FLAGS flags; gulong proxy_valid_id; - gulong battery_ind_id[BATTERY_IND_COUNT]; + gulong battery_ind_id; }; enum mce_battery_signal { @@ -133,13 +135,13 @@ mce_battery_status_update( MceBatteryPriv* priv = self->priv; MCE_BATTERY_STATUS new_status; - if (!g_strcmp0(status, MCE_BATTERY_STATUS_FULL)) { - new_status = MCE_BATTERY_FULL; - } else if (!g_strcmp0(status, MCE_BATTERY_STATUS_OK)) { + if (!g_strcmp0(status, MCE_BATTERY_STATUS_OK)) { new_status = MCE_BATTERY_OK; } else if (!g_strcmp0(status, MCE_BATTERY_STATUS_LOW)) { new_status = MCE_BATTERY_LOW; } else if (!g_strcmp0(status, MCE_BATTERY_STATUS_EMPTY)) { + new_status = MCE_BATTERY_LOW; + } else if (!g_strcmp0(status, MCE_BATTERY_STATUS_CRITICAL)) { new_status = MCE_BATTERY_EMPTY; } else { GASSERT(!g_strcmp0(status, MCE_BATTERY_STATUS_UNKNOWN)); @@ -153,73 +155,31 @@ mce_battery_status_update( mce_battery_check_valid(self); } -static -void -mce_battery_level_query_done( - GObject* proxy, - GAsyncResult* result, - gpointer arg) +static void +on_properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + const gchar* const *invalidated_properties, + gpointer user_data) { - MceBattery* self = MCE_BATTERY(arg); - GError* error = NULL; - gint level; + GVariantIter iter; + const gchar *key; + GVariant *value; - if (com_nokia_mce_request_call_get_battery_level_finish( - COM_NOKIA_MCE_REQUEST(proxy), &level, result, &error)) { - GDEBUG("Battery level is currently %d", level); - mce_battery_level_update(self, level); - } else { - /* Should retry? */ - GWARN("Failed to query battery level %s", GERRMSG(error)); - g_error_free(error); + g_variant_iter_init (&iter, changed_properties); + while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) + { + if (!g_strcmp0(key, "PowerPercentage")) { + gint level; + g_variant_get (value, "i", &level); + mce_battery_level_update(MCE_BATTERY(user_data), level); + } else if (!g_strcmp0(key, "PowerLevel")) { + const char* status; + g_variant_get (value, "s", &status); + mce_battery_status_update(MCE_BATTERY(user_data), status); + } + + g_variant_unref (value); } - mce_battery_unref(self); -} - -static -void -mce_battery_status_query_done( - GObject* proxy, - GAsyncResult* result, - gpointer arg) -{ - MceBattery* self = MCE_BATTERY(arg); - GError* error = NULL; - char* status = NULL; - - if (com_nokia_mce_request_call_get_battery_status_finish( - COM_NOKIA_MCE_REQUEST(proxy), &status, result, &error)) { - GDEBUG("Battery is currently %s", status); - mce_battery_status_update(self, status); - g_free(status); - } else { - /* Should retry? */ - GWARN("Failed to query battery status %s", GERRMSG(error)); - g_error_free(error); - } - mce_battery_unref(self); -} - -static -void -mce_battery_level_ind( - ComNokiaMceSignal* proxy, - gint level, - gpointer arg) -{ - GDEBUG("Battery level is %d", level); - mce_battery_level_update(MCE_BATTERY(arg), level); -} - -static -void -mce_battery_status_ind( - ComNokiaMceSignal* proxy, - const char* status, - gpointer arg) -{ - GDEBUG("Battery is %s", status); - mce_battery_status_update(MCE_BATTERY(arg), status); } static @@ -236,24 +196,17 @@ mce_battery_query( * for the valid signal before we can connect the battery state * signal and submit the initial query. */ - if (proxy->signal) { - if (!priv->battery_ind_id[BATTERY_IND_LEVEL]) { - priv->battery_ind_id[BATTERY_IND_LEVEL] = - g_signal_connect(proxy->signal, "battery-level-ind", - G_CALLBACK(mce_battery_level_ind), self); - } - - if (!priv->battery_ind_id[BATTERY_IND_STATUS]) { - priv->battery_ind_id[BATTERY_IND_STATUS] = - g_signal_connect(proxy->signal, "battery-status-ind", - G_CALLBACK(mce_battery_status_ind), self); - } + if (proxy->ayatana_request && !priv->battery_ind_id) { + priv->battery_ind_id = g_signal_connect(proxy->ayatana_request, "g-properties-changed", + G_CALLBACK(on_properties_changed), self); } - if (proxy->request && proxy->valid) { - com_nokia_mce_request_call_get_battery_level(proxy->request, NULL, - mce_battery_level_query_done, mce_battery_ref(self)); - com_nokia_mce_request_call_get_battery_status(proxy->request, NULL, - mce_battery_status_query_done, mce_battery_ref(self)); + + if (proxy->ayatana_request && proxy->valid) { + const char* status = org_ayatana_indicator_power_battery_get_power_level(proxy->ayatana_request); + mce_battery_status_update(self, status); + + u_int32_t level = org_ayatana_indicator_power_battery_get_power_percentage(proxy->ayatana_request); + mce_battery_level_update(self, level); } } @@ -389,8 +342,7 @@ mce_battery_finalize( MceBattery* self = MCE_BATTERY(object); MceBatteryPriv* priv = self->priv; - gutil_disconnect_handlers(priv->proxy->signal, priv->battery_ind_id, - G_N_ELEMENTS(priv->battery_ind_id)); + mce_proxy_remove_handler(priv->proxy, priv->battery_ind_id); mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id); mce_proxy_unref(priv->proxy); G_OBJECT_CLASS(PARENT_CLASS)->finalize(object); diff --git a/src/mce_charger.c b/src/mce_charger.c index e40aa31..5c44c09 100644 --- a/src/mce_charger.c +++ b/src/mce_charger.c @@ -38,14 +38,14 @@ #include "mce_proxy.h" #include "mce_log_p.h" -#include -#include - #include +#define MCE_CHARGER_STATE_ON "on" +#define MCE_CHARGER_STATE_OFF "off" +#define MCE_CHARGER_STATE_UNKNOWN "unknown" + /* Generated headers */ -#include "com.nokia.mce.request.h" -#include "com.nokia.mce.signal.h" +#include "org.ayatana.indicator.power.Battery.h" struct mce_charger_priv { MceProxy* proxy; @@ -102,44 +102,27 @@ mce_charger_state_update( } } -static -void -mce_charger_state_query_done( - GObject* proxy, - GAsyncResult* result, - gpointer arg) +static void +on_properties_changed (GDBusProxy *proxy, + GVariant *changed_properties, + const gchar* const *invalidated_properties, + gpointer user_data) { - GError* error = NULL; - char* state = NULL; - MceCharger* self = MCE_CHARGER(arg); + GVariantIter iter; + const gchar *key; + GVariant *value; - if (com_nokia_mce_request_call_get_charger_state_finish( - COM_NOKIA_MCE_REQUEST(proxy), &state, result, &error)) { - GDEBUG("Charger is currently %s", state); - mce_charger_state_update(self, state); - g_free(state); - } else { - /* - * We could retry but it's probably not worth the trouble - * because the next time charger state changes we receive - * charger_state_ind signal and sync our state with mce. - * Until then, this object stays invalid. - */ - GWARN("Failed to query charger state %s", GERRMSG(error)); - g_error_free(error); + g_variant_iter_init (&iter, changed_properties); + while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) + { + if (!g_strcmp0(key, "IsDischarging")) { + gboolean state; + g_variant_get (value, "b", &state); + mce_charger_state_update(MCE_CHARGER(user_data), state ? MCE_CHARGER_STATE_OFF : MCE_CHARGER_STATE_ON); + } + + g_variant_unref (value); } - mce_charger_unref(self); -} - -static -void -mce_charger_state_ind( - ComNokiaMceSignal* proxy, - const char* state, - gpointer arg) -{ - GDEBUG("Charger is %s", state); - mce_charger_state_update(MCE_CHARGER(arg), state); } static @@ -156,13 +139,14 @@ mce_charger_state_query( * for the valid signal before we can connect the charger state * signal and submit the initial query. */ - if (proxy->signal && !priv->charger_state_ind_id) { - priv->charger_state_ind_id = g_signal_connect(proxy->signal, - MCE_CHARGER_STATE_SIG, G_CALLBACK(mce_charger_state_ind), self); + if (proxy->ayatana_request && !priv->charger_state_ind_id) { + priv->charger_state_ind_id = g_signal_connect(proxy->ayatana_request, "g-properties-changed", + G_CALLBACK(on_properties_changed), self); } - if (proxy->request && proxy->valid) { - com_nokia_mce_request_call_get_charger_state(proxy->request, NULL, - mce_charger_state_query_done, mce_charger_ref(self)); + + if (proxy->ayatana_request && proxy->valid) { + gboolean state = org_ayatana_indicator_power_battery_get_is_discharging(proxy->ayatana_request); + mce_charger_state_update(self, state ? MCE_CHARGER_STATE_OFF : MCE_CHARGER_STATE_ON); } } @@ -290,7 +274,7 @@ mce_charger_finalize( MceChargerPriv* priv = self->priv; if (priv->charger_state_ind_id) { - g_signal_handler_disconnect(priv->proxy->signal, + g_signal_handler_disconnect(priv->proxy->ayatana_request, priv->charger_state_ind_id); } mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id); diff --git a/src/mce_display.c b/src/mce_display.c index fd6634f..ba9e80a 100644 --- a/src/mce_display.c +++ b/src/mce_display.c @@ -149,12 +149,12 @@ mce_display_status_query( * for the valid signal before we can connect the display state * signal and submit the initial query. */ - if (proxy->signal && !priv->display_status_ind_id) { - priv->display_status_ind_id = g_signal_connect(proxy->signal, + if (proxy->unity_request && !priv->display_status_ind_id) { + priv->display_status_ind_id = g_signal_connect(proxy->unity_request, MCE_DISPLAY_SIG, G_CALLBACK(mce_display_power_state_change), self); } - if (proxy->request && proxy->valid) { - com_canonical_unity_screen_call_get_display_power_state(proxy->request, NULL, + if (proxy->unity_request && proxy->valid) { + com_canonical_unity_screen_call_get_display_power_state(proxy->unity_request, NULL, mce_display_status_query_done, mce_display_ref(self)); } } @@ -283,7 +283,7 @@ mce_display_finalize( MceDisplayPriv* priv = self->priv; if (priv->display_status_ind_id) { - g_signal_handler_disconnect(priv->proxy->signal, + g_signal_handler_disconnect(priv->proxy->unity_request, priv->display_status_ind_id); } mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id); diff --git a/src/mce_proxy.c b/src/mce_proxy.c index a5f0d3d..e2b279a 100644 --- a/src/mce_proxy.c +++ b/src/mce_proxy.c @@ -39,12 +39,18 @@ /* Generated headers */ #include "com.canonical.Unity.Screen.h" +#include "org.ayatana.indicator.power.Battery.h" GLOG_MODULE_DEFINE("mce"); struct mce_proxy_priv { GDBusConnection* bus; + GDBusConnection* session_bus; guint mce_watch_id; + guint ayatana_watch_id; + + gboolean unity_valid; + gboolean ayatana_valid; }; enum mce_proxy_signal { @@ -56,7 +62,9 @@ enum mce_proxy_signal { #define MCE_SERVICE "com.canonical.Unity.Screen" #define MCE_REQUEST_PATH "/com/canonical/Unity/Screen" -#define MCE_SIGNAL_PATH "/com/canonical/Unity/Screen" + +#define AYATANA_SERVICE "org.ayatana.indicator.power" +#define AYATANA_REQUEST_PATH "/org/ayatana/indicator/power/Battery" static guint mce_proxy_signals[SIGNAL_COUNT] = { 0 }; @@ -107,11 +115,16 @@ mce_proxy_init_check( { MceProxyPriv* priv = self->priv; - if (self->signal && self->request && !priv->mce_watch_id) { + if ( self->unity_request && !priv->mce_watch_id) { priv->mce_watch_id = g_bus_watch_name_on_connection(priv->bus, MCE_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, mce_name_appeared, mce_name_vanished, self, NULL); } + if (self->ayatana_request && !priv->ayatana_watch_id) { + priv->ayatana_watch_id = g_bus_watch_name_on_connection(priv->session_bus, + AYATANA_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, + mce_name_appeared, mce_name_vanished, self, NULL); + } } static @@ -124,9 +137,9 @@ mce_proxy_request_proxy_new_finished( MceProxy* self = MCE_PROXY(arg); GError* error = NULL; - GASSERT(!self->request); - self->request = com_canonical_unity_screen_proxy_new_finish(result, &error); - if (self->request) { + GASSERT(!self->unity_request); + self->unity_request = com_canonical_unity_screen_proxy_new_finish(result, &error); + if (self->unity_request) { mce_proxy_init_check(self); } else { GERR("Failed to initialize MCE request proxy: %s", GERRMSG(error)); @@ -137,7 +150,7 @@ mce_proxy_request_proxy_new_finished( static void -mce_proxy_signal_proxy_new_finished( +mce_proxy_request_proxy_session_new_finished( GObject* object, GAsyncResult* result, gpointer arg) @@ -145,12 +158,12 @@ mce_proxy_signal_proxy_new_finished( MceProxy* self = MCE_PROXY(arg); GError* error = NULL; - GASSERT(!self->signal); - self->signal = com_canonical_unity_screen_proxy_new_finish(result, &error); - if (self->signal) { + GASSERT(!self->ayatana_request); + self->ayatana_request = org_ayatana_indicator_power_battery_proxy_new_finish(result, &error); + if (self->ayatana_request) { mce_proxy_init_check(self); } else { - GERR("Failed to initialize MCE signal proxy: %s", GERRMSG(error)); + GERR("Failed to initialize MCE ayatana request proxy: %s", GERRMSG(error)); g_error_free(error); } mce_proxy_unref(self); @@ -170,15 +183,10 @@ mce_proxy_bus_get_finished( priv->bus = g_bus_get_finish(result, &error); if (priv->bus) { com_canonical_unity_screen_proxy_new(priv->bus, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + G_DBUS_PROXY_FLAGS_NONE, MCE_SERVICE, MCE_REQUEST_PATH, NULL, mce_proxy_request_proxy_new_finished, mce_proxy_ref(self)); - com_canonical_unity_screen_proxy_new(priv->bus, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - MCE_SERVICE, MCE_SIGNAL_PATH, NULL, - mce_proxy_signal_proxy_new_finished, - mce_proxy_ref(self)); } else { GERR("Failed to attach to system bus: %s", GERRMSG(error)); g_error_free(error); @@ -186,6 +194,31 @@ mce_proxy_bus_get_finished( mce_proxy_unref(self); } +static +void +mce_proxy_session_bus_get_finished( + GObject* object, + GAsyncResult* result, + gpointer arg) +{ + MceProxy* self = MCE_PROXY(arg); + MceProxyPriv* priv = self->priv; + GError* error = NULL; + + priv->session_bus = g_bus_get_finish(result, &error); + if (priv->session_bus) { + org_ayatana_indicator_power_battery_proxy_new(priv->session_bus, + G_DBUS_PROXY_FLAGS_NONE, + AYATANA_SERVICE, AYATANA_REQUEST_PATH, NULL, + mce_proxy_request_proxy_session_new_finished, + mce_proxy_ref(self)); + } else{ + GERR("Failed to attach to session bus: %s", GERRMSG(error)); + g_error_free(error); + } + mce_proxy_unref(self); +} + MceProxy* mce_proxy_new() { @@ -200,6 +233,8 @@ mce_proxy_new() mce_proxy_instance = g_object_new(MCE_PROXY_TYPE, NULL); g_bus_get(G_BUS_TYPE_SYSTEM, NULL, mce_proxy_bus_get_finished, mce_proxy_ref(mce_proxy_instance)); + g_bus_get(G_BUS_TYPE_SESSION, NULL, mce_proxy_session_bus_get_finished, + mce_proxy_ref(mce_proxy_instance)); g_object_add_weak_pointer(G_OBJECT(mce_proxy_instance), (gpointer*)(&mce_proxy_instance)); } @@ -265,15 +300,21 @@ mce_proxy_finalize( if (priv->mce_watch_id) { g_bus_unwatch_name(priv->mce_watch_id); } - if (self->signal) { - g_object_unref(self->signal); + if (priv->ayatana_watch_id) { + g_bus_unwatch_name(priv->ayatana_watch_id); } - if (self->request) { - g_object_unref(self->request); + if (self->unity_request) { + g_object_unref(self->unity_request); + } + if (self->ayatana_request) { + g_object_unref(self->ayatana_request); } if (priv->bus) { g_object_unref(priv->bus); } + if (priv->session_bus) { + g_object_unref(priv->session_bus); + } G_OBJECT_CLASS(PARENT_CLASS)->finalize(object); } diff --git a/src/mce_proxy.h b/src/mce_proxy.h index 8aa2641..f02a137 100644 --- a/src/mce_proxy.h +++ b/src/mce_proxy.h @@ -43,13 +43,14 @@ typedef struct mce_proxy_priv MceProxyPriv; struct _ComCanonicalUnityScreen; +struct _OrgAyatanaIndicatorPowerBattery; typedef struct mce_proxy { GObject object; MceProxyPriv* priv; gboolean valid; - struct _ComCanonicalUnityScreen* signal; - struct _ComCanonicalUnityScreen* request; + struct _ComCanonicalUnityScreen* unity_request; + struct _OrgAyatanaIndicatorPowerBattery* ayatana_request; } MceProxy; typedef void From b2c8f8026a1e13fbeb9fe876b9c12865323b3e58 Mon Sep 17 00:00:00 2001 From: Marius Gripsgard Date: Thu, 21 Sep 2023 04:03:20 +0200 Subject: [PATCH 32/34] examples: Make example work with our stub --- examples/example.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/example.c b/examples/example.c index ea872dd..6c9911f 100644 --- a/examples/example.c +++ b/examples/example.c @@ -43,8 +43,8 @@ #include #include #include -#include -#include +//#include +//#include /* ========================================================================= * * MAINLOOP @@ -111,12 +111,12 @@ 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[] = { @@ -130,6 +130,7 @@ static const char *tklock_mode_repr(MCE_TKLOCK_MODE mode) }; return lut[mode]; } +*/ static void battery_cb(MceBattery *battery, void *arg) { @@ -159,6 +160,7 @@ static void display_cb(MceDisplay *display, void *arg) what_changed); } +/* static void tklock_cb(MceTklock *tklock, void *arg) { const char *what_changed = arg; @@ -169,6 +171,7 @@ static void tklock_cb(MceTklock *tklock, void *arg) what_changed); } + static void inactivity_cb(MceInactivity *inactivity, void *arg) { const char *what_changed = arg; @@ -177,6 +180,7 @@ static void inactivity_cb(MceInactivity *inactivity, void *arg) bool_repr(inactivity->status), what_changed); } +*/ /* ========================================================================= * * MAIN_ENTRY @@ -218,6 +222,7 @@ main(int argc, char **argv) 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"); @@ -231,7 +236,7 @@ main(int argc, char **argv) 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) @@ -264,6 +269,7 @@ main(int argc, char **argv) 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); @@ -272,7 +278,7 @@ main(int argc, char **argv) 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; } From 1c86495779dac5bfacf131092e74136fa03000a2 Mon Sep 17 00:00:00 2001 From: Jami Kettunen Date: Sat, 13 Jul 2024 12:54:50 +0300 Subject: [PATCH 33/34] treewide: Migrate to UPower D-Bus API from ayatana power indicator --- Makefile | 2 +- spec/org.ayatana.indicator.power.Battery.xml | 39 - spec/org.freedesktop.UPower.Device.xml | 833 +++++++++++++++++++ src/mce_battery.c | 69 +- src/mce_charger.c | 51 +- src/mce_proxy.c | 70 +- src/mce_proxy.h | 4 +- 7 files changed, 935 insertions(+), 133 deletions(-) delete mode 100644 spec/org.ayatana.indicator.power.Battery.xml create mode 100644 spec/org.freedesktop.UPower.Device.xml diff --git a/Makefile b/Makefile index f551a61..f3b82e5 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ SRC = \ mce_proxy.c GEN_SRC = \ com.canonical.Unity.Screen.c \ - org.ayatana.indicator.power.Battery.c + org.freedesktop.UPower.Device.c # mce_inactivity.c \ # diff --git a/spec/org.ayatana.indicator.power.Battery.xml b/spec/org.ayatana.indicator.power.Battery.xml deleted file mode 100644 index 76bbfca..0000000 --- a/spec/org.ayatana.indicator.power.Battery.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - The battery's power level. Possible values: 'ok', 'low', 'very_low', 'critical' - - - - - - - - The battery's power level in percentage. - - - - - - - - Whether or not ayatana-indicator-power-service is warning the user about low battery power. - - - - - - - - Whether or not the battery is discharging - - - - - - \ No newline at end of file diff --git a/spec/org.freedesktop.UPower.Device.xml b/spec/org.freedesktop.UPower.Device.xml new file mode 100644 index 0000000..cd11841 --- /dev/null +++ b/spec/org.freedesktop.UPower.Device.xml @@ -0,0 +1,833 @@ + +]> + + + + + + Objects implementing this interface are usually discovered through + the org.freedesktop.UPower interface on + the /org/freedesktop/UPower object on + the D-Bus system bus service with the well-known + name org.freedesktop.UPower using + the + EnumerateDevices + method. + + + + +$ dbus-send --print-reply \ + --system \ + --dest=org.freedesktop.UPower \ + /org/freedesktop/UPower/devices/battery_BAT0 \ + org.freedesktop.DBus.Properties.GetAll \ + string:org.freedesktop.UPower.Device + +method return sender=:1.386 -> dest=:1.477 reply_serial=2 + array [ + dict entry( + string "native-path" + variant string "/sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:01/PNP0C09:00/PNP0C0A:00/power_supply/BAT0" + ) + dict entry( + string "vendor" + variant string "SONY" + ) + dict entry( + string "model" + variant string "42T4568" + ) + dict entry( + string "serial" + variant string "4179" + ) + dict entry( + string "update-time" + variant uint64 1226417875 + ) + dict entry( + string "type" + variant uint 2 + ) + dict entry( + string "power-supply" + variant boolean true + ) + dict entry( + string "has-history" + variant boolean true + ) + dict entry( + string "has-statistics" + variant boolean true + ) + dict entry( + string "online" + variant boolean false + ) + dict entry( + string "energy" + variant double 72.85 + ) + dict entry( + string "energy-empty" + variant double 0 + ) + dict entry( + string "energy-full" + variant double 74.55 + ) + dict entry( + string "energy-full-design" + variant double 74.88 + ) + dict entry( + string "energy-rate" + variant double 0 + ) + dict entry( + string "voltage" + variant double 16.415 + ) + dict entry( + string "time-to-empty" + variant int64 0 + ) + dict entry( + string "time-to-full" + variant int64 0 + ) + dict entry( + string "percentage" + variant double 97.7197 + ) + dict entry( + string "is-present" + variant boolean true + ) + dict entry( + string "state" + variant uint 3 + ) + dict entry( + string "is-rechargeable" + variant boolean true + ) + dict entry( + string "capacity" + variant double 100 + ) + dict entry( + string "technology" + variant uint 1 + ) + ] + + + + + Unless otherwise noted, an empty string or the value 0 in a + property on this interface means not set. + + + + + + + + + + + + Refreshes the data collected from the power source. + + + Callers will need to make sure that the daemon was started in debug mode + + if an error occured while refreshing + + + + + + + + + The type of history. + Valid types are rate or charge. + + + The amount of data to return in seconds, or 0 for all. + + + + + The approximate number of points to return. + A higher resolution is more accurate, at the expense of plotting speed. + + + + + + The history data for the power device, if the device supports history. + Data is ordered from the earliest in time, to the newest data point. + Each element contains the following members: + + + time + + The time value in seconds from the gettimeofday() method. + + + + value + + The data value, for instance the rate in W or the charge in %. + + + + state + + The state of the device, for instance charging or + discharging. + + + + + + + + + Gets history for the power device that is persistent across reboots. + + + + + + + + + + The mode for the statistics. + Valid types are charging or discharging. + + + + The statistics data for the power device. + Each element contains the following members: + + + value + + The value of the percentage point, usually in seconds + + + + accuracy + + The accuracy of the prediction in percent. + + + + + + + + + Gets statistics for the power device that may be interesting + to show on a graph in the session. + + + + + + + + + + + OS specific native path of the power source. On Linux this + is the sysfs path, for + example /sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0. Is + blank if the device is being driven by a user space + driver. + + + + + + + + + + Name of the vendor of the battery. + + + + + + + + + + Name of the model of this battery. + + + + + + + + + + Unique serial number of the battery. + + + + + + + + + + The point in time (seconds since the Epoch Jan 1, 1970 + 0:00 UTC) that data was read from the power source. + + + + + + + + + + Type of power source. + + + + 0Unknown + + + 1Line Power + + + 2Battery + + + 3Ups + + + 4Monitor + + + 5Mouse + + + 6Keyboard + + + 7Pda + + + 8Phone + + + 9Media Player + + + 10Tablet + + + 11Computer + + + 12Gaming Input + + + 13Pen + + + 14Touchpad + + + 15Modem + + + 16Network + + + 17Headset + + + 18Speakers + + + 19Headphones + + + 20Video + + + 21Other Audio + + + 22Remote Control + + + 23Printer + + + 24Scanner + + + 25Camera + + + 26Wearable + + + 27Toy + + + 28Bluetooth Genreic + + + + If the value is set to "Battery", you will need to verify that the + property power-supply + has the value "true" before considering it as a laptop battery. Otherwise it + will likely be the battery for a device of an unknown type. + + + + + + + + + + If the power device is used to supply the system. + This would be set TRUE for laptop batteries and UPS devices, + but set FALSE for wireless mice or PDAs. + + + + + + + + + + If the power device has history. + + + + + + + + + + If the power device has statistics. + + + + + + + + + + Whether power is currently being provided through line power. + This property is only valid if the property + type + has the value "line-power". + + + + + + + + + + Amount of energy (measured in Wh) currently available in + the power source. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy (measured in Wh) in the power source when + it's considered to be empty. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy (measured in Wh) in the power source when + it's considered full. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy (measured in Wh) the power source is + designed to hold when it's considered full. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Amount of energy being drained from the source, measured + in W. If positive, the source is being discharged, if + negative it's being charged. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Voltage in the Cell or being recorded by the meter. + + + + + + + + + + The number of charge cycles as defined by the TCO certification, or -1 if + that value is unknown or not applicable. + + + + + + + + + + Luminosity being recorded by the meter. + + + + + + + + + + Number of seconds until the power source is considered empty. + Is set to 0 if unknown. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Number of seconds until the power source is considered full. + Is set to 0 if unknown. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + The amount of energy left in the power source expressed as + a percentage between 0 and 100. Typically this is the same as + (energy - + energy-empty) / + (energy-full - + energy-empty). + However, some primitive power sources are capable of only + reporting percentages and in this case the energy-* + properties will be unset while this property is set. + + This property is only valid if the property + type + has the value "battery". + + + The percentage will be an approximation if the battery level + is set to something other than None. The percentage is kept for compatibility reasons. + + + + + + + + + + The temperature of the device in degrees Celsius. This property is + only valid if the property + type + has the value "battery". + + + + + + + + + + If the power source is present in the bay. + This field is required as some batteries are hot-removable, for example + expensive UPS and most laptop batteries. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + The battery power state. + + + + 0Unknown + + + 1Charging + + + 2Discharging + + + 3Empty + + + 4Fully charged + + + 5Pending charge + + + 6Pending discharge + + + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + If the power source is rechargeable. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + The capacity of the power source expressed as a percentage between 0 and 100. + The capacity of the battery will reduce with age. + A capacity value less than 75% is usually a sign that you should renew your battery. + Typically this value is the same as + (full-design / + full) * 100. + However, some primitive power sources are not capable reporting capacity + and in this case the capacity property will be unset. + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Technology used in the battery: + + + + 0Unknown + + + 1Lithium ion + + + 2Lithium polymer + + + 3Lithium iron phosphate + + + 4Lead acid + + + 5Nickel cadmium + + + 6Nickel metal hydride + + + + This property is only valid if the property + type + has the value "battery". + + + + + + + + + + Warning level of the battery: + + + + 0Unknown + + + 1None + + + 2Discharging (only for UPSes) + + + 3Low + + + 4Critical + + + 5Action + + + + + + + + + + + The level of the battery for devices which do not report a percentage but rather a coarse battery level. If the value + is None, then the device does not support coarse battery reporting, and the percentage should be used instead. + + + + 0Unknown + + + 1None (the battery does not use a coarse level of battery reporting) + + + 3Low + + + 4Critical + + + 6Normal + + + 7High + + + 8Full + + + + + + + + + + +

An icon name, following the Icon Naming Specification

+

Note that the icons might not match end-user expectations in terms of presentation relative to the amount of battery left or perceived to be left. It is recommended that front-ends use the BatteryLevel property first, if available, followed by the Percentage, to present a more realistic battery level to the user.

+
+
+
+
+
+ +
diff --git a/src/mce_battery.c b/src/mce_battery.c index 0ee896c..008b359 100644 --- a/src/mce_battery.c +++ b/src/mce_battery.c @@ -41,7 +41,7 @@ #include /* Generated headers */ -#include "org.ayatana.indicator.power.Battery.h" +#include "org.freedesktop.UPower.Device.h" #define MCE_BATTERY_STATUS_OK "ok" #define MCE_BATTERY_STATUS_LOW "low" @@ -109,23 +109,6 @@ mce_battery_check_valid( } } -static -void -mce_battery_level_update( - MceBattery* self, - gint level) -{ - MceBatteryPriv* priv = self->priv; - const guint new_level = (level < 0) ? 0 : (level > 100) ? 100 : level; - - if (self->level != new_level) { - self->level = new_level; - g_signal_emit(self, mce_battery_signals[SIGNAL_LEVEL_CHANGED], 0); - } - priv->flags |= BATTERY_HAVE_LEVEL; - mce_battery_check_valid(self); -} - static void mce_battery_status_update( @@ -155,6 +138,35 @@ mce_battery_status_update( mce_battery_check_valid(self); } +static +void +mce_battery_level_update( + MceBattery* self, + gdouble level) +{ + // values from ayatana-indicator-power/src/notifier.c + char* status; + if (level <= 2) + status = MCE_BATTERY_STATUS_CRITICAL; + else if (level <= 5) + status = MCE_BATTERY_STATUS_EMPTY; + else if (level <= 10) + status = MCE_BATTERY_STATUS_LOW; + else + status = MCE_BATTERY_STATUS_OK; + mce_battery_status_update(self, status); + + MceBatteryPriv* priv = self->priv; + const guint new_level = (level < 0) ? 0 : (level > 100) ? 100 : level; + + if (self->level != new_level) { + self->level = new_level; + g_signal_emit(self, mce_battery_signals[SIGNAL_LEVEL_CHANGED], 0); + } + priv->flags |= BATTERY_HAVE_LEVEL; + mce_battery_check_valid(self); +} + static void on_properties_changed (GDBusProxy *proxy, GVariant *changed_properties, @@ -168,14 +180,10 @@ on_properties_changed (GDBusProxy *proxy, g_variant_iter_init (&iter, changed_properties); while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) { - if (!g_strcmp0(key, "PowerPercentage")) { - gint level; - g_variant_get (value, "i", &level); + if (!g_strcmp0(key, "Percentage")) { + gdouble level; + g_variant_get (value, "d", &level); mce_battery_level_update(MCE_BATTERY(user_data), level); - } else if (!g_strcmp0(key, "PowerLevel")) { - const char* status; - g_variant_get (value, "s", &status); - mce_battery_status_update(MCE_BATTERY(user_data), status); } g_variant_unref (value); @@ -196,16 +204,13 @@ mce_battery_query( * for the valid signal before we can connect the battery state * signal and submit the initial query. */ - if (proxy->ayatana_request && !priv->battery_ind_id) { - priv->battery_ind_id = g_signal_connect(proxy->ayatana_request, "g-properties-changed", + if (proxy->upower_request && !priv->battery_ind_id) { + priv->battery_ind_id = g_signal_connect(proxy->upower_request, "g-properties-changed", G_CALLBACK(on_properties_changed), self); } - if (proxy->ayatana_request && proxy->valid) { - const char* status = org_ayatana_indicator_power_battery_get_power_level(proxy->ayatana_request); - mce_battery_status_update(self, status); - - u_int32_t level = org_ayatana_indicator_power_battery_get_power_percentage(proxy->ayatana_request); + if (proxy->upower_request && proxy->valid) { + gdouble level = org_freedesktop_upower_device_get_percentage(proxy->upower_request); mce_battery_level_update(self, level); } } diff --git a/src/mce_charger.c b/src/mce_charger.c index 5c44c09..7e1f012 100644 --- a/src/mce_charger.c +++ b/src/mce_charger.c @@ -45,7 +45,18 @@ #define MCE_CHARGER_STATE_UNKNOWN "unknown" /* Generated headers */ -#include "org.ayatana.indicator.power.Battery.h" +#include "org.freedesktop.UPower.Device.h" + +enum upower_state { + UPOWER_STATE_UNKNOWN, + UPOWER_STATE_CHARGING, + UPOWER_STATE_DISCHARGING, + UPOWER_STATE_EMPTY, + UPOWER_STATE_FULLY_CHARGED, + UPOWER_STATE_PENDING_CHARGE, + UPOWER_STATE_PENDING_DISCHARGE, + UPOWER_STATE_COUNT +}; struct mce_charger_priv { MceProxy* proxy; @@ -102,6 +113,24 @@ mce_charger_state_update( } } +static void +mce_charger_update_charging_state ( + MceCharger* self, + enum upower_state state) +{ + gboolean discharging; + switch (state) { + case UPOWER_STATE_CHARGING: + case UPOWER_STATE_FULLY_CHARGED: + discharging = 0; + break; + default: + discharging = 1; + break; + } + mce_charger_state_update(self, discharging ? MCE_CHARGER_STATE_OFF : MCE_CHARGER_STATE_ON); +} + static void on_properties_changed (GDBusProxy *proxy, GVariant *changed_properties, @@ -115,10 +144,10 @@ on_properties_changed (GDBusProxy *proxy, g_variant_iter_init (&iter, changed_properties); while (g_variant_iter_next (&iter, "{&sv}", &key, &value)) { - if (!g_strcmp0(key, "IsDischarging")) { - gboolean state; - g_variant_get (value, "b", &state); - mce_charger_state_update(MCE_CHARGER(user_data), state ? MCE_CHARGER_STATE_OFF : MCE_CHARGER_STATE_ON); + if (!g_strcmp0(key, "State")) { + enum upower_state state; + g_variant_get (value, "u", &state); + mce_charger_update_charging_state(MCE_CHARGER(user_data), state); } g_variant_unref (value); @@ -139,14 +168,14 @@ mce_charger_state_query( * for the valid signal before we can connect the charger state * signal and submit the initial query. */ - if (proxy->ayatana_request && !priv->charger_state_ind_id) { - priv->charger_state_ind_id = g_signal_connect(proxy->ayatana_request, "g-properties-changed", + if (proxy->upower_request && !priv->charger_state_ind_id) { + priv->charger_state_ind_id = g_signal_connect(proxy->upower_request, "g-properties-changed", G_CALLBACK(on_properties_changed), self); } - if (proxy->ayatana_request && proxy->valid) { - gboolean state = org_ayatana_indicator_power_battery_get_is_discharging(proxy->ayatana_request); - mce_charger_state_update(self, state ? MCE_CHARGER_STATE_OFF : MCE_CHARGER_STATE_ON); + if (proxy->upower_request && proxy->valid) { + enum upower_state state = org_freedesktop_upower_device_get_state(proxy->upower_request); + mce_charger_update_charging_state(self, state); } } @@ -274,7 +303,7 @@ mce_charger_finalize( MceChargerPriv* priv = self->priv; if (priv->charger_state_ind_id) { - g_signal_handler_disconnect(priv->proxy->ayatana_request, + g_signal_handler_disconnect(priv->proxy->upower_request, priv->charger_state_ind_id); } mce_proxy_remove_handler(priv->proxy, priv->proxy_valid_id); diff --git a/src/mce_proxy.c b/src/mce_proxy.c index e2b279a..9ff7e07 100644 --- a/src/mce_proxy.c +++ b/src/mce_proxy.c @@ -39,18 +39,17 @@ /* Generated headers */ #include "com.canonical.Unity.Screen.h" -#include "org.ayatana.indicator.power.Battery.h" +#include "org.freedesktop.UPower.Device.h" GLOG_MODULE_DEFINE("mce"); struct mce_proxy_priv { GDBusConnection* bus; - GDBusConnection* session_bus; guint mce_watch_id; - guint ayatana_watch_id; + guint upower_watch_id; gboolean unity_valid; - gboolean ayatana_valid; + gboolean upower_valid; }; enum mce_proxy_signal { @@ -63,8 +62,8 @@ enum mce_proxy_signal { #define MCE_SERVICE "com.canonical.Unity.Screen" #define MCE_REQUEST_PATH "/com/canonical/Unity/Screen" -#define AYATANA_SERVICE "org.ayatana.indicator.power" -#define AYATANA_REQUEST_PATH "/org/ayatana/indicator/power/Battery" +#define UPOWER_SERVICE "org.freedesktop.UPower" +#define UPOWER_REQUEST_PATH "/org/freedesktop/UPower/devices/DisplayDevice" static guint mce_proxy_signals[SIGNAL_COUNT] = { 0 }; @@ -120,9 +119,9 @@ mce_proxy_init_check( MCE_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, mce_name_appeared, mce_name_vanished, self, NULL); } - if (self->ayatana_request && !priv->ayatana_watch_id) { - priv->ayatana_watch_id = g_bus_watch_name_on_connection(priv->session_bus, - AYATANA_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, + if (self->upower_request && !priv->upower_watch_id) { + priv->upower_watch_id = g_bus_watch_name_on_connection(priv->bus, + UPOWER_SERVICE, G_BUS_NAME_WATCHER_FLAGS_NONE, mce_name_appeared, mce_name_vanished, self, NULL); } } @@ -150,7 +149,7 @@ mce_proxy_request_proxy_new_finished( static void -mce_proxy_request_proxy_session_new_finished( +mce_proxy_request_proxy_upower_new_finished( GObject* object, GAsyncResult* result, gpointer arg) @@ -158,12 +157,12 @@ mce_proxy_request_proxy_session_new_finished( MceProxy* self = MCE_PROXY(arg); GError* error = NULL; - GASSERT(!self->ayatana_request); - self->ayatana_request = org_ayatana_indicator_power_battery_proxy_new_finish(result, &error); - if (self->ayatana_request) { + GASSERT(!self->upower_request); + self->upower_request = org_freedesktop_upower_device_proxy_new_finish(result, &error); + if (self->upower_request) { mce_proxy_init_check(self); } else { - GERR("Failed to initialize MCE ayatana request proxy: %s", GERRMSG(error)); + GERR("Failed to initialize MCE upower request proxy: %s", GERRMSG(error)); g_error_free(error); } mce_proxy_unref(self); @@ -187,6 +186,11 @@ mce_proxy_bus_get_finished( MCE_SERVICE, MCE_REQUEST_PATH, NULL, mce_proxy_request_proxy_new_finished, mce_proxy_ref(self)); + org_freedesktop_upower_device_proxy_new(priv->bus, + G_DBUS_PROXY_FLAGS_NONE, + UPOWER_SERVICE, UPOWER_REQUEST_PATH, NULL, + mce_proxy_request_proxy_upower_new_finished, + mce_proxy_ref(self)); } else { GERR("Failed to attach to system bus: %s", GERRMSG(error)); g_error_free(error); @@ -194,31 +198,6 @@ mce_proxy_bus_get_finished( mce_proxy_unref(self); } -static -void -mce_proxy_session_bus_get_finished( - GObject* object, - GAsyncResult* result, - gpointer arg) -{ - MceProxy* self = MCE_PROXY(arg); - MceProxyPriv* priv = self->priv; - GError* error = NULL; - - priv->session_bus = g_bus_get_finish(result, &error); - if (priv->session_bus) { - org_ayatana_indicator_power_battery_proxy_new(priv->session_bus, - G_DBUS_PROXY_FLAGS_NONE, - AYATANA_SERVICE, AYATANA_REQUEST_PATH, NULL, - mce_proxy_request_proxy_session_new_finished, - mce_proxy_ref(self)); - } else{ - GERR("Failed to attach to session bus: %s", GERRMSG(error)); - g_error_free(error); - } - mce_proxy_unref(self); -} - MceProxy* mce_proxy_new() { @@ -233,8 +212,6 @@ mce_proxy_new() mce_proxy_instance = g_object_new(MCE_PROXY_TYPE, NULL); g_bus_get(G_BUS_TYPE_SYSTEM, NULL, mce_proxy_bus_get_finished, mce_proxy_ref(mce_proxy_instance)); - g_bus_get(G_BUS_TYPE_SESSION, NULL, mce_proxy_session_bus_get_finished, - mce_proxy_ref(mce_proxy_instance)); g_object_add_weak_pointer(G_OBJECT(mce_proxy_instance), (gpointer*)(&mce_proxy_instance)); } @@ -300,21 +277,18 @@ mce_proxy_finalize( if (priv->mce_watch_id) { g_bus_unwatch_name(priv->mce_watch_id); } - if (priv->ayatana_watch_id) { - g_bus_unwatch_name(priv->ayatana_watch_id); + if (priv->upower_watch_id) { + g_bus_unwatch_name(priv->upower_watch_id); } if (self->unity_request) { g_object_unref(self->unity_request); } - if (self->ayatana_request) { - g_object_unref(self->ayatana_request); + if (self->upower_request) { + g_object_unref(self->upower_request); } if (priv->bus) { g_object_unref(priv->bus); } - if (priv->session_bus) { - g_object_unref(priv->session_bus); - } G_OBJECT_CLASS(PARENT_CLASS)->finalize(object); } diff --git a/src/mce_proxy.h b/src/mce_proxy.h index f02a137..c8e329c 100644 --- a/src/mce_proxy.h +++ b/src/mce_proxy.h @@ -43,14 +43,14 @@ typedef struct mce_proxy_priv MceProxyPriv; struct _ComCanonicalUnityScreen; -struct _OrgAyatanaIndicatorPowerBattery; +struct _OrgFreedesktopUPowerDevice; typedef struct mce_proxy { GObject object; MceProxyPriv* priv; gboolean valid; struct _ComCanonicalUnityScreen* unity_request; - struct _OrgAyatanaIndicatorPowerBattery* ayatana_request; + struct _OrgFreedesktopUPowerDevice* upower_request; } MceProxy; typedef void From 0165d7a37d11ec5abee2bcdf40b012ef2b474fbd Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Fri, 9 Aug 2024 07:14:40 +0000 Subject: [PATCH 34/34] d/ubports.skip_distro: skip building on Debian --- debian/ubports.skip_distro | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 debian/ubports.skip_distro diff --git a/debian/ubports.skip_distro b/debian/ubports.skip_distro new file mode 100644 index 0000000..5ff05c3 --- /dev/null +++ b/debian/ubports.skip_distro @@ -0,0 +1,3 @@ +# libglibutil is not packaged in both Debian and UBports `devel-debian`. +# There's not point in this package in Debian anyway. +devel-debian