GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
A cache for a directory content. More...
Go to the source code of this file.
Data Structures | |
struct | gp_dir_entry |
A dir cache entry, represents a file or a directory. More... | |
struct | gp_dir_cache |
A directory cache. More... | |
Typedefs | |
typedef struct gp_dir_entry | gp_dir_entry |
A dir cache entry, represents a file or a directory. | |
typedef enum gp_dir_cache_sort_type | gp_dir_cache_sort_type |
How should be the listing sorted. | |
typedef struct gp_dir_cache | gp_dir_cache |
A directory cache. | |
Enumerations | |
enum | gp_dir_cache_sort_type { GP_DIR_SORT_ASC = 0x00 , GP_DIR_SORT_DESC = 0x04 , GP_DIR_SORT_BY_NAME = 0x00 , GP_DIR_SORT_BY_SIZE = 0x01 , GP_DIR_SORT_BY_MTIME = 0x02 } |
How should be the listing sorted. More... | |
enum | gp_dir_cache_type { GP_DIR_CACHE_NONE = 0 , GP_DIR_CACHE_FILE = 1 , GP_DIR_CACHE_DIR = 2 } |
A cache entry lookup type. More... | |
Functions | |
gp_dir_cache * | gp_dir_cache_new (const char *path) |
Creates and populates a new directory cache. | |
void | gp_dir_cache_destroy (gp_dir_cache *self) |
Destroys a directory cache. | |
gp_dir_entry * | gp_dir_cache_add_entry (gp_dir_cache *self, size_t size, const char *name, mode_t mode, time_t mtime) |
Adds an entry to the directory cache. | |
int | gp_dir_cache_rem_entry_by_name (gp_dir_cache *self, const char *name) |
Removes an entry from directory cache. | |
gp_dir_entry * | gp_dir_cache_entry_lookup (gp_dir_cache *self, const char *name) |
Looks up an entry based on a file name. | |
int | gp_dir_cache_entry_name_contains (gp_dir_cache *self, const char *needle) |
Returns true if there is at least one entry with needle in the name. | |
void | gp_dir_cache_free_entries (gp_dir_cache *self) |
Frees all entries from directory cache. | |
void | gp_dir_cache_sort (gp_dir_cache *self, gp_dir_cache_sort_type sort_type) |
Sorts the directory cache entries. | |
static gp_dir_entry * | gp_dir_cache_get (gp_dir_cache *self, unsigned int pos) |
Returns an entry given a position. | |
static void | gp_dir_cache_set_filter (gp_dir_cache *self, unsigned int pos, int filter) |
Sets dir cache entry filter flag. | |
static size_t | gp_dir_cache_entries (gp_dir_cache *self) |
Returns number of entries. | |
static size_t | gp_dir_cache_entries_filter (gp_dir_cache *self) |
Returns number of not-filtered entries. | |
gp_dir_entry * | gp_dir_cache_get_filtered (gp_dir_cache *self, unsigned int pos) |
Returns entry on position pos ignoring filtered out elements. | |
int | gp_dir_cache_notify (gp_dir_cache *self) |
A change notify handler. | |
gp_fd * | gp_dir_cache_notify_fd (gp_dir_cache *self) |
Returns inotify fd if available. | |
int | gp_dir_cache_mkdir (gp_dir_cache *self, const char *dirname) |
Creates a directory and updates the cache. | |
unsigned int | gp_dir_cache_pos_by_name_filtered (gp_dir_cache *self, const char *name) |
Looks up a entry position by name. | |
enum gp_dir_cache_type | gp_dir_cache_lookup (gp_dir_cache *self, const char *name) |
Looks for a file in the directory the cache operates in. | |
A cache for a directory content.
This implements an data structure to cache a directory content so that it can be listed in an alphabetical order. It also listens for a inotify events so the list is updated whenever the directory content changes.
Definition in file gp_dir_cache.h.
How should be the listing sorted.
Definition at line 41 of file gp_dir_cache.h.
enum gp_dir_cache_type |
A cache entry lookup type.
Enumerator | |
---|---|
GP_DIR_CACHE_NONE | No element found. |
GP_DIR_CACHE_FILE | File type element found. |
GP_DIR_CACHE_DIR | A directory type element found. |
Definition at line 275 of file gp_dir_cache.h.
gp_dir_entry * gp_dir_cache_add_entry | ( | gp_dir_cache * | self, |
size_t | size, | ||
const char * | name, | ||
mode_t | mode, | ||
time_t | mtime | ||
) |
Adds an entry to the directory cache.
This function is called by the platform code.
self | A directory cache to add the entry to |
size | A file size in bytes |
name | A file name |
mode | A file mode |
mtime | A modification timestamp |
void gp_dir_cache_destroy | ( | gp_dir_cache * | self | ) |
Destroys a directory cache.
Closes all file descriptors, frees memory.
self | A directory cache to destroy. |
|
inlinestatic |
Returns number of entries.
self | A directory cache. |
Definition at line 202 of file gp_dir_cache.h.
References gp_dir_cache::used.
|
inlinestatic |
Returns number of not-filtered entries.
self | A directory cache. |
Definition at line 214 of file gp_dir_cache.h.
References gp_dir_cache::filtered, and gp_dir_cache::used.
gp_dir_entry * gp_dir_cache_entry_lookup | ( | gp_dir_cache * | self, |
const char * | name | ||
) |
Looks up an entry based on a file name.
self | A directory cache. |
name | An entry name to look for. |
int gp_dir_cache_entry_name_contains | ( | gp_dir_cache * | self, |
const char * | needle | ||
) |
Returns true if there is at least one entry with needle in the name.
self | A directory cache. |
needle | A (sub)string in the name to look for. |
void gp_dir_cache_free_entries | ( | gp_dir_cache * | self | ) |
Frees all entries from directory cache.
This function is called by the platform code.
self | A directory cache. |
|
inlinestatic |
Returns an entry given a position.
self | A directory cache. |
pos | Element position in the gp_dir_cache::entries array. |
Definition at line 166 of file gp_dir_cache.h.
References gp_dir_cache::entries, and gp_dir_cache::used.
gp_dir_entry * gp_dir_cache_get_filtered | ( | gp_dir_cache * | self, |
unsigned int | pos | ||
) |
Returns entry on position pos ignoring filtered out elements.
self | A directory cache. |
pos | Element position in the gp_dir_cache::entries array. |
enum gp_dir_cache_type gp_dir_cache_lookup | ( | gp_dir_cache * | self, |
const char * | name | ||
) |
Looks for a file in the directory the cache operates in.
self | A dir cache. |
name | A filename. |
int gp_dir_cache_mkdir | ( | gp_dir_cache * | self, |
const char * | dirname | ||
) |
Creates a directory and updates the cache.
self | A dir cache. |
dirname | A directory name. |
gp_dir_cache * gp_dir_cache_new | ( | const char * | path | ) |
Creates and populates a new directory cache.
Creates a directory cache and fills it with list of entries at the given path. If supported the directory is also set up to with an inotify watch in order to update the listing whenever the directory content changes.
path | A path to load the cache entries from. |
int gp_dir_cache_notify | ( | gp_dir_cache * | self | ) |
A change notify handler.
This function should be called to update the cache content when there are data to be read on inotify fd.
self | A directory cache. |
gp_fd * gp_dir_cache_notify_fd | ( | gp_dir_cache * | self | ) |
Returns inotify fd if available.
self | A direcotry cache. |
unsigned int gp_dir_cache_pos_by_name_filtered | ( | gp_dir_cache * | self, |
const char * | name | ||
) |
Looks up a entry position by name.
self | A dir cache. |
name | A directory or file name. |
int gp_dir_cache_rem_entry_by_name | ( | gp_dir_cache * | self, |
const char * | name | ||
) |
Removes an entry from directory cache.
This function is called by the platform code.
self | A directory cache to remove the entry from |
name | An entry name to be removed |
|
inlinestatic |
Sets dir cache entry filter flag.
If element has been set to be filtered it's ignored by functions with the _filter suffix.
self | A directory cache. |
pos | Element position in the gp_dir_cache::entries array. |
filter | Either 1 == filtered or 0 == not filtered. |
Definition at line 185 of file gp_dir_cache.h.
References gp_dir_cache::entries, gp_dir_entry::filtered, and gp_dir_cache::filtered.
void gp_dir_cache_sort | ( | gp_dir_cache * | self, |
gp_dir_cache_sort_type | sort_type | ||
) |
Sorts the directory cache entries.
self | A directory cache. |
sort_type | A requested sort order. |