1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2  *
3  * Copyright (C) 2014 Tomas Bzatek <tbzatek@redhat.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  */
20 
21 #include <config.h>
22 #include "udisksmoduleobject.h"
23 
24 
25 typedef UDisksModuleObjectIface UDisksModuleObjectInterface;
26 G_DEFINE_INTERFACE (UDisksModuleObject, udisks_module_object, G_TYPE_OBJECT);
27 
28 static void
udisks_module_object_default_init(UDisksModuleObjectIface * iface)29 udisks_module_object_default_init (UDisksModuleObjectIface *iface)
30 {
31 }
32 
33 /**
34  * udisks_module_object_process_uevent:
35  * @object: A #UDisksModuleObject.
36  * @action: uevent action, common values are <literal>add</literal>, <literal>change</literal> and <literal>remove</literal> or %NULL
37  * @device: A #UDisksLinuxDevice device object or %NULL if the device hasn't changed.
38  * @keep: A return value whether to keep the object around or not.
39  *
40  * A #UDisksModuleObject method that is called by #UDisksLinuxBlockObject,
41  * #UDisksLinuxDriveObject and #UDisksLinuxProvider to process a uevent on exported
42  * module objects and interfaces and control their validity.
43  *
44  * Upon receiving a uevent the object implementing the #UDisksModuleObject interface
45  * is responsible for processing updated information and indicate whether the @object
46  * is still valid or not.
47  *
48  * This function may be called quite often and since uevent processing is currently
49  * serialized by #UDisksLinuxProvider this method call should minimize its processing
50  * time as much as possible.
51  *
52  * See related udisks_module_new_object(), udisks_module_new_block_object_interface()
53  * and udisks_module_new_drive_object_interface() methods for information how uevent
54  * routing is done and what effect the return values have.
55  *
56  * Set @keep to %FALSE if the object or interface should be unexported and removed,
57  * %TRUE if the object or interface should be kept around. The return value of @keep
58  * is ignored when the return value from this method is %FALSE. These return values
59  * should align with the uevent @action, i.e. a @keep return value of %FALSE is
60  * expected for a <literal>remove</literal> @action. Note that the <literal>remove</literal>
61  * uevent is not always sent to block objects and the daemon may opt for direct
62  * object destruction (for which the @object should be prepared to perform proper
63  * cleanup within its destructor).
64  *
65  * Returns: %TRUE in case the uevent was processed, %FALSE when the @device is
66  *          not applicable for the object or interface.
67  *
68  * Since: 2.0
69  */
70 gboolean
udisks_module_object_process_uevent(UDisksModuleObject * object,const gchar * action,UDisksLinuxDevice * device,gboolean * keep)71 udisks_module_object_process_uevent (UDisksModuleObject  *object,
72                                      const gchar         *action,
73                                      UDisksLinuxDevice   *device,
74                                      gboolean            *keep)
75 {
76   return UDISKS_MODULE_OBJECT_GET_IFACE (object)->process_uevent (object, action, device, keep);
77 }
78 
79 /**
80  * udisks_module_object_housekeeping:
81  * @object: A #UDisksModuleObject.
82  * @secs_since_last: Number of seconds since the last housekeeping or 0 if the first housekeeping ever.
83  * @cancellable: A %GCancellable or %NULL.
84  * @error: Return location for error or %NULL.
85  *
86  * A #UDisksModuleObject method that is called periodically (every ten minutes or so)
87  * by #UDisksLinuxProvider to perform module housekeeping tasks such as refreshing
88  * <literal>ATA SMART</literal> data.
89  *
90  * The method runs in a dedicated thread and is allowed to perform
91  * blocking I/O.
92  *
93  * Long-running tasks should periodically check @cancellable to see if
94  * they have been cancelled.
95  *
96  * Returns: %TRUE if the operation succeeded, %FALSE if @error is set.
97  *
98  * Since: 2.0
99  */
100 gboolean
udisks_module_object_housekeeping(UDisksModuleObject * object,guint secs_since_last,GCancellable * cancellable,GError ** error)101 udisks_module_object_housekeeping (UDisksModuleObject  *object,
102                                    guint                secs_since_last,
103                                    GCancellable        *cancellable,
104                                    GError             **error)
105 {
106   return UDISKS_MODULE_OBJECT_GET_IFACE (object)->housekeeping (object, secs_since_last, cancellable, error);
107 }
108