1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com>
4  *
5  * Licensed under the GNU Lesser General Public License Version 2.1
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21 
22 #ifndef __DNF_LOCK_H
23 #define __DNF_LOCK_H
24 
25 #include <glib-object.h>
26 
27 G_BEGIN_DECLS
28 
29 #define DNF_TYPE_LOCK (dnf_lock_get_type ())
30 G_DECLARE_DERIVABLE_TYPE (DnfLock, dnf_lock, DNF, LOCK, GObject)
31 
32 struct _DnfLockClass
33 {
34         GObjectClass            parent_class;
35         void                    (* state_changed)       (DnfLock        *lock,
36                                                          guint           state_bitfield);
37         /*< private >*/
38         void (*_dnf_reserved1)  (void);
39         void (*_dnf_reserved2)  (void);
40         void (*_dnf_reserved3)  (void);
41         void (*_dnf_reserved4)  (void);
42         void (*_dnf_reserved5)  (void);
43         void (*_dnf_reserved6)  (void);
44         void (*_dnf_reserved7)  (void);
45         void (*_dnf_reserved8)  (void);
46 };
47 
48 /**
49  * DnfLockType:
50  * @DNF_LOCK_TYPE_RPMDB:                        The rpmdb lock
51  * @DNF_LOCK_TYPE_REPO:                         The repodir lock
52  * @DNF_LOCK_TYPE_METADATA:                     The metadata lock
53  * @DNF_LOCK_TYPE_CONFIG:                       The config lock
54  *
55  * The lock type.
56  **/
57 typedef enum {
58         DNF_LOCK_TYPE_RPMDB,
59         DNF_LOCK_TYPE_REPO,
60         DNF_LOCK_TYPE_METADATA,
61         DNF_LOCK_TYPE_CONFIG,
62         /*< private >*/
63         DNF_LOCK_TYPE_LAST
64 } DnfLockType;
65 
66 /**
67  * DnfLockMode:
68  * @DNF_LOCK_MODE_THREAD:                       For all threads in this process
69  * @DNF_LOCK_MODE_PROCESS:                      For all processes
70  *
71  * The lock mode.
72  **/
73 typedef enum {
74         DNF_LOCK_MODE_THREAD,
75         DNF_LOCK_MODE_PROCESS,
76         /*< private >*/
77         DNF_LOCK_MODE_LAST
78 } DnfLockMode;
79 
80 DnfLock         *dnf_lock_new                   (void);
81 
82 /* getters */
83 guint            dnf_lock_get_state             (DnfLock        *lock);
84 void             dnf_lock_set_lock_dir          (DnfLock        *lock,
85                                                  const gchar    *lock_dir);
86 
87 /* object methods */
88 guint            dnf_lock_take                  (DnfLock        *lock,
89                                                  DnfLockType     type,
90                                                  DnfLockMode     mode,
91                                                  GError         **error);
92 gboolean         dnf_lock_release               (DnfLock        *lock,
93                                                  guint           id,
94                                                  GError         **error);
95 void             dnf_lock_release_noerror       (DnfLock        *lock,
96                                                  guint           id);
97 const gchar     *dnf_lock_type_to_string        (DnfLockType     lock_type);
98 
99 G_END_DECLS
100 
101 #endif /* __DNF_LOCK_H */
102