32205e8708b903d658eb76cf46e66202742a0b19
[modest] / src / modest-cache-mgr.h
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30
31 #ifndef __MODEST_CACHE_MGR_H__
32 #define __MODEST_CACHE_MGR_H__
33
34 #include <glib-object.h>
35 G_BEGIN_DECLS
36
37 /* convenience macros */
38 #define MODEST_TYPE_CACHE_MGR         (modest_cache_mgr_get_type())
39 #define MODEST_CACHE_MGR(obj)         (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_CACHE_MGR,ModestCacheMgr))
40 #define MODEST_CACHE_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_CACHE_MGR,GObject))
41 #define MODEST_IS_CACHE_MGR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_CACHE_MGR))
42 #define MODEST_IS_CACHE_MGR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_CACHE_MGR))
43 #define MODEST_CACHE_MGR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_CACHE_MGR,ModestCacheMgrClass))
44
45 typedef struct _ModestCacheMgr      ModestCacheMgr;
46 typedef struct _ModestCacheMgrClass ModestCacheMgrClass;
47
48 struct _ModestCacheMgr {
49          GObject parent;
50         /* insert public members, if any */
51 };
52
53 struct _ModestCacheMgrClass {
54         GObjectClass parent_class;
55 };
56
57 /*
58  * the caches managed by this class
59  */
60 typedef enum {
61         MODEST_CACHE_MGR_CACHE_TYPE_DATE_STRING,       /* time_t => string */
62         MODEST_CACHE_MGR_CACHE_TYPE_DISPLAY_STRING,    /* gchar* => gchar* */
63         MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF,            /* gchar* => GdkPixbuf */
64
65         MODEST_CACHE_MGR_CACHE_TYPE_NUM
66 } ModestCacheMgrCacheType;
67
68
69 /**
70  * modest_cache_mgr_get_type:
71  * 
72  * get the GType for ModestCacheMgr
73  *  
74  * Returns: the GType
75  */
76 GType        modest_cache_mgr_get_type    (void) G_GNUC_CONST;
77
78
79 /**
80  * modest_cache_mgr_new:
81  *
82  * instantiate a new cache_mgr object
83  * 
84  * Returns: a new cache_mgr or NULL in case of error
85  */
86 ModestCacheMgr*    modest_cache_mgr_new          (void);
87
88 /**
89  * modest_cache_mgr_get_cache:
90  * @self: a valid cache mgr obj
91  * @type: a valid cache mgr cache type
92  * 
93  * get the cache (GHashTable) of the requested type
94  * 
95  * Returns: the requested cache (GHashTable) or NULL in case caching
96  * has been disabled (MODEST_DEBUG_DISABLE_CACHE); clients are supposed
97  * to handle that case
98  * 
99  * the returned  hashtable should NOT be destroyed or unref'd.
100  */
101 GHashTable*     modest_cache_mgr_get_cache    (ModestCacheMgr* self, ModestCacheMgrCacheType type);
102
103
104 /**
105  * modest_cache_mgr_flush
106  * @self: a valid cache mgr obj
107  * @type: a valid cache mgr cache type
108  *
109  * flush the cache (hashtable) of the given type  
110  */
111 void            modest_cache_mgr_flush        (ModestCacheMgr *self, ModestCacheMgrCacheType type);
112
113
114 /**
115  * modest_cache_mgr_flush
116  * @self: a valid cache mgr obj
117  *
118  * flush all caches  
119  */
120 void            modest_cache_mgr_flush_all    (ModestCacheMgr *self);
121
122
123 /**
124  * modest_cache_mgr_get_size
125  * @self: a valid cache mgr obj
126  * @type: a valid cache mgr cache type
127  *
128  * get the size (number of <key,value>-pairs) in the cache
129  * 
130  * Returns: the size of the give cache type 
131  */
132 guint           modest_cache_mgr_get_size     (ModestCacheMgr *self, ModestCacheMgrCacheType type);
133
134 G_END_DECLS
135
136 #endif /* __MODEST_CACHE_MGR_H__ */
137