LCOV - code coverage report
Current view: top level - glib/gio/tests - gapplication-example-dbushooks.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 28 0.0 %
Date: 2024-04-23 05:16:05 Functions: 0 10 0.0 %
Branches: 0 8 0.0 %

           Branch data     Line data    Source code
       1                 :            : #include <gio/gio.h>
       2                 :            : #include <stdlib.h>
       3                 :            : #include <string.h>
       4                 :            : 
       5                 :            : static void
       6                 :          0 : activate (GApplication *application)
       7                 :            : {
       8                 :          0 :   g_print ("activated\n");
       9                 :            : 
      10                 :            :   /* Note: when doing a longer-lasting action here that returns
      11                 :            :    * to the mainloop, you should use g_application_hold() and
      12                 :            :    * g_application_release() to keep the application alive until
      13                 :            :    * the action is completed.
      14                 :            :    */
      15                 :          0 : }
      16                 :            : 
      17                 :            : typedef GApplication TestApplication;
      18                 :            : typedef GApplicationClass TestApplicationClass;
      19                 :            : 
      20                 :            : static GType test_application_get_type (void);
      21   [ #  #  #  #  :          0 : G_DEFINE_TYPE (TestApplication, test_application, G_TYPE_APPLICATION)
                   #  # ]
      22                 :            : 
      23                 :            : static gboolean
      24                 :          0 : test_application_dbus_register (GApplication    *application,
      25                 :            :                                 GDBusConnection *connection,
      26                 :            :                                 const gchar     *object_path,
      27                 :            :                                 GError         **error)
      28                 :            : {
      29                 :            :   /* We must chain up to the parent class */
      30         [ #  # ]:          0 :   if (!G_APPLICATION_CLASS (test_application_parent_class)->dbus_register (application,
      31                 :            :                                                                            connection,
      32                 :            :                                                                            object_path,
      33                 :            :                                                                            error))
      34                 :          0 :     return FALSE;
      35                 :            : 
      36                 :            :   /* Now we can do our own stuff here. For example, we could export some D-Bus objects */
      37                 :          0 :   return TRUE;
      38                 :            : }
      39                 :            : 
      40                 :            : static void
      41                 :          0 : test_application_dbus_unregister (GApplication    *application,
      42                 :            :                                   GDBusConnection *connection,
      43                 :            :                                   const gchar     *object_path)
      44                 :            : {
      45                 :            :   /* Do our own stuff here, e.g. unexport any D-Bus objects we exported in the dbus_register
      46                 :            :    * hook above. Be sure to check that we actually did export them, since the hook
      47                 :            :    * above might have returned early due to the parent class' hook returning FALSE!
      48                 :            :    */
      49                 :            : 
      50                 :            :   /* Lastly, we must chain up to the parent class */
      51                 :          0 :   G_APPLICATION_CLASS (test_application_parent_class)->dbus_unregister (application,
      52                 :            :                                                                         connection,
      53                 :            :                                                                         object_path);
      54                 :          0 : }
      55                 :            : 
      56                 :            : static void
      57                 :          0 : test_application_init (TestApplication *app)
      58                 :            : {
      59                 :          0 : }
      60                 :            : 
      61                 :            : static void
      62                 :          0 : test_application_class_init (TestApplicationClass *class)
      63                 :            : {
      64                 :          0 :   GApplicationClass *g_application_class = G_APPLICATION_CLASS (class);
      65                 :            : 
      66                 :          0 :   g_application_class->dbus_register = test_application_dbus_register;
      67                 :          0 :   g_application_class->dbus_unregister = test_application_dbus_unregister;
      68                 :          0 : }
      69                 :            : 
      70                 :            : static GApplication *
      71                 :          0 : test_application_new (const gchar       *application_id,
      72                 :            :                       GApplicationFlags  flags)
      73                 :            : {
      74                 :          0 :   g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
      75                 :            : 
      76                 :          0 :   return g_object_new (test_application_get_type (),
      77                 :            :                        "application-id", application_id,
      78                 :            :                        "flags", flags,
      79                 :            :                        NULL);
      80                 :            : }
      81                 :            : 
      82                 :            : int
      83                 :          0 : main (int argc, char **argv)
      84                 :            : {
      85                 :            :   GApplication *app;
      86                 :            :   int status;
      87                 :            : 
      88                 :          0 :   app = test_application_new ("org.gtk.TestApplication", 0);
      89                 :          0 :   g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
      90                 :          0 :   g_application_set_inactivity_timeout (app, 10000);
      91                 :            : 
      92                 :          0 :   status = g_application_run (app, argc, argv);
      93                 :            : 
      94                 :          0 :   g_object_unref (app);
      95                 :            : 
      96                 :          0 :   return status;
      97                 :            : }

Generated by: LCOV version 1.14