LCOV - code coverage report
Current view: top level - src/libvalent/notifications - valent-notifications-adapter.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 61.3 % 31 19
Test Date: 2024-04-23 06:02:46 Functions: 77.8 % 9 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31.2 % 16 5

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       2                 :             : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
       3                 :             : 
       4                 :             : #define G_LOG_DOMAIN "valent-notifications-adapter"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <libvalent-core.h>
       9                 :             : 
      10                 :             : #include "valent-notification.h"
      11                 :             : #include "valent-notifications-adapter.h"
      12                 :             : 
      13                 :             : 
      14                 :             : /**
      15                 :             :  * ValentNotificationsAdapter:
      16                 :             :  *
      17                 :             :  * An abstract base class for notification servers.
      18                 :             :  *
      19                 :             :  * `ValentNotificationsAdapter` is a base class for notification servers. This
      20                 :             :  * usually means monitoring a D-Bus service for notifications being sent and
      21                 :             :  * withdrawn.
      22                 :             :  *
      23                 :             :  * ## `.plugin` File
      24                 :             :  *
      25                 :             :  * Implementations may define the following extra fields in the `.plugin` file:
      26                 :             :  *
      27                 :             :  * - `X-NotificationsAdapterPriority`
      28                 :             :  *
      29                 :             :  *     An integer indicating the adapter priority. The implementation with the
      30                 :             :  *     lowest value will be used as the primary adapter.
      31                 :             :  *
      32                 :             :  * Since: 1.0
      33                 :             :  */
      34                 :             : 
      35                 :             : typedef struct
      36                 :             : {
      37                 :             :   GPtrArray *notifications;
      38                 :             : } ValentNotificationsAdapterPrivate;
      39                 :             : 
      40   [ +  +  +  - ]:         438 : G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ValentNotificationsAdapter, valent_notifications_adapter, VALENT_TYPE_EXTENSION)
      41                 :             : 
      42                 :             : /**
      43                 :             :  * ValentNotificationsAdapterClass:
      44                 :             :  * @add_notification: the virtual function pointer for valent_notifications_adapter_add_notification()
      45                 :             :  * @remove_notification: the virtual function pointer for valent_notifications_adapter_remove_notification()
      46                 :             :  * @notification_added: the class closure for `ValentNotificationsAdapter`::notification-added signal
      47                 :             :  * @notification_removed: the class closure for `ValentNotificationsAdapter`::notification-removed signal
      48                 :             :  *
      49                 :             :  * The virtual function table for `ValentNotificationsAdapter`.
      50                 :             :  */
      51                 :             : 
      52                 :             : enum {
      53                 :             :   NOTIFICATION_ADDED,
      54                 :             :   NOTIFICATION_REMOVED,
      55                 :             :   N_SIGNALS
      56                 :             : };
      57                 :             : 
      58                 :             : static guint signals[N_SIGNALS] = { 0, };
      59                 :             : 
      60                 :             : 
      61                 :             : /* LCOV_EXCL_START */
      62                 :             : static void
      63                 :             : valent_notifications_adapter_real_add_notification (ValentNotificationsAdapter *adapter,
      64                 :             :                                                     ValentNotification         *notification)
      65                 :             : {
      66                 :             : }
      67                 :             : 
      68                 :             : static void
      69                 :             : valent_notifications_adapter_real_remove_notification (ValentNotificationsAdapter *adapter,
      70                 :             :                                                        const char                 *id)
      71                 :             : {
      72                 :             : }
      73                 :             : /* LCOV_EXCL_STOP */
      74                 :             : 
      75                 :             : /*
      76                 :             :  * GObject
      77                 :             :  */
      78                 :             : static void
      79                 :          66 : valent_notifications_adapter_class_init (ValentNotificationsAdapterClass *klass)
      80                 :             : {
      81                 :          66 :   klass->add_notification = valent_notifications_adapter_real_add_notification;
      82                 :          66 :   klass->remove_notification = valent_notifications_adapter_real_remove_notification;
      83                 :             : 
      84                 :             :   /**
      85                 :             :    * ValentNotificationsAdapter::notification-added:
      86                 :             :    * @adapter: a `ValentNotificationsAdapter`
      87                 :             :    * @notification: a `ValentNotification`
      88                 :             :    *
      89                 :             :    * Emitted when a [class@Valent.Notification] is added to @adapter.
      90                 :             :    *
      91                 :             :    * Implementations must chain up if they override
      92                 :             :    * [vfunc@Valent.NotificationsAdapter.notification_added].
      93                 :             :    *
      94                 :             :    * Since: 1.0
      95                 :             :    */
      96                 :         132 :   signals [NOTIFICATION_ADDED] =
      97                 :          66 :     g_signal_new ("notification-added",
      98                 :             :                   G_TYPE_FROM_CLASS (klass),
      99                 :             :                   G_SIGNAL_RUN_LAST,
     100                 :             :                   G_STRUCT_OFFSET (ValentNotificationsAdapterClass, notification_added),
     101                 :             :                   NULL, NULL,
     102                 :             :                   g_cclosure_marshal_VOID__OBJECT,
     103                 :             :                   G_TYPE_NONE, 1, VALENT_TYPE_NOTIFICATION);
     104                 :          66 :   g_signal_set_va_marshaller (signals [NOTIFICATION_ADDED],
     105                 :             :                               G_TYPE_FROM_CLASS (klass),
     106                 :             :                               g_cclosure_marshal_VOID__OBJECTv);
     107                 :             : 
     108                 :             :   /**
     109                 :             :    * ValentNotificationsAdapter::notification-removed:
     110                 :             :    * @adapter: a `ValentNotificationsAdapter`
     111                 :             :    * @notification: a `ValentNotification`
     112                 :             :    *
     113                 :             :    * Emitted when a [class@Valent.Notification] is removed from @adapter.
     114                 :             :    *
     115                 :             :    * Implementations must chain up if they override
     116                 :             :    * [vfunc@Valent.NotificationsAdapter.notification_removed].
     117                 :             :    *
     118                 :             :    * Since: 1.0
     119                 :             :    */
     120                 :         132 :   signals [NOTIFICATION_REMOVED] =
     121                 :          66 :     g_signal_new ("notification-removed",
     122                 :             :                   G_TYPE_FROM_CLASS (klass),
     123                 :             :                   G_SIGNAL_RUN_LAST,
     124                 :             :                   G_STRUCT_OFFSET (ValentNotificationsAdapterClass, notification_removed),
     125                 :             :                   NULL, NULL,
     126                 :             :                   g_cclosure_marshal_VOID__STRING,
     127                 :             :                   G_TYPE_NONE, 1, G_TYPE_STRING);
     128                 :          66 :   g_signal_set_va_marshaller (signals [NOTIFICATION_REMOVED],
     129                 :             :                               G_TYPE_FROM_CLASS (klass),
     130                 :             :                               g_cclosure_marshal_VOID__STRINGv);
     131                 :          66 : }
     132                 :             : 
     133                 :             : static void
     134                 :           7 : valent_notifications_adapter_init (ValentNotificationsAdapter *adapter)
     135                 :             : {
     136                 :           7 : }
     137                 :             : 
     138                 :             : /**
     139                 :             :  * valent_notifications_adapter_notification_added:
     140                 :             :  * @adapter: a `ValentNotificationsAdapter`
     141                 :             :  * @notification: a `ValentNotification`
     142                 :             :  *
     143                 :             :  * Emit [signal@Valent.NotificationsAdapter::notification-added] on @adapter.
     144                 :             :  *
     145                 :             :  * This method should only be called by implementations of
     146                 :             :  * [class@Valent.NotificationsAdapter].
     147                 :             :  *
     148                 :             :  * Since: 1.0
     149                 :             :  */
     150                 :             : void
     151                 :          11 : valent_notifications_adapter_notification_added (ValentNotificationsAdapter *adapter,
     152                 :             :                                                  ValentNotification         *notification)
     153                 :             : {
     154         [ +  - ]:          11 :   g_return_if_fail (VALENT_IS_NOTIFICATIONS_ADAPTER (adapter));
     155                 :             : 
     156                 :          11 :   g_signal_emit (G_OBJECT (adapter), signals [NOTIFICATION_ADDED], 0, notification);
     157                 :             : }
     158                 :             : 
     159                 :             : /**
     160                 :             :  * valent_notifications_adapter_notification_removed:
     161                 :             :  * @adapter: a `ValentNotificationsAdapter`
     162                 :             :  * @id: a notification id
     163                 :             :  *
     164                 :             :  * Emit [signal@Valent.NotificationsAdapter::notification-removed] on @adapter.
     165                 :             :  *
     166                 :             :  * This method should only be called by implementations of
     167                 :             :  * [class@Valent.NotificationsAdapter].
     168                 :             :  *
     169                 :             :  * Since: 1.0
     170                 :             :  */
     171                 :             : void
     172                 :           6 : valent_notifications_adapter_notification_removed (ValentNotificationsAdapter *adapter,
     173                 :             :                                                    const char                 *id)
     174                 :             : {
     175         [ +  - ]:           6 :   g_return_if_fail (VALENT_IS_NOTIFICATIONS_ADAPTER (adapter));
     176                 :             : 
     177                 :           6 :   g_signal_emit (G_OBJECT (adapter), signals [NOTIFICATION_REMOVED], 0, id);
     178                 :             : }
     179                 :             : 
     180                 :             : /**
     181                 :             :  * valent_notifications_adapter_add_notification: (virtual add_notification)
     182                 :             :  * @adapter: a `ValentNotificationsAdapter`
     183                 :             :  * @notification: a `ValentNotification`
     184                 :             :  *
     185                 :             :  * Send @notification to the @adapter.
     186                 :             :  *
     187                 :             :  * Since: 1.0
     188                 :             :  */
     189                 :             : void
     190                 :           0 : valent_notifications_adapter_add_notification (ValentNotificationsAdapter *adapter,
     191                 :             :                                                ValentNotification         *notification)
     192                 :             : {
     193                 :           0 :   VALENT_ENTRY;
     194                 :             : 
     195         [ #  # ]:           0 :   g_return_if_fail (VALENT_IS_NOTIFICATIONS_ADAPTER (adapter));
     196         [ #  # ]:           0 :   g_return_if_fail (VALENT_IS_NOTIFICATION (notification));
     197                 :             : 
     198                 :           0 :   VALENT_NOTIFICATIONS_ADAPTER_GET_CLASS (adapter)->add_notification (adapter,
     199                 :             :                                                                       notification);
     200                 :             : 
     201                 :           0 :   VALENT_EXIT;
     202                 :             : }
     203                 :             : 
     204                 :             : /**
     205                 :             :  * valent_notifications_adapter_remove_notification: (virtual remove_notification)
     206                 :             :  * @adapter: a `ValentNotificationsAdapter`
     207                 :             :  * @id: a notification id
     208                 :             :  *
     209                 :             :  * Withdraw @id from @adapter.
     210                 :             :  *
     211                 :             :  * Since: 1.0
     212                 :             :  */
     213                 :             : void
     214                 :           0 : valent_notifications_adapter_remove_notification (ValentNotificationsAdapter *adapter,
     215                 :             :                                                   const char                 *id)
     216                 :             : {
     217                 :           0 :   VALENT_ENTRY;
     218                 :             : 
     219         [ #  # ]:           0 :   g_return_if_fail (VALENT_IS_NOTIFICATIONS_ADAPTER (adapter));
     220         [ #  # ]:           0 :   g_return_if_fail (id == NULL);
     221                 :             : 
     222                 :           0 :   VALENT_NOTIFICATIONS_ADAPTER_GET_CLASS (adapter)->remove_notification (adapter,
     223                 :             :                                                                          id);
     224                 :             : 
     225                 :           0 :   VALENT_EXIT;
     226                 :             : }
     227                 :             : 
        

Generated by: LCOV version 2.0-1