forked from enlightenment/efl
- simplify the monitor code. still gets spanked on shutdown for some reason
SVN revision: 30546
This commit is contained in:
parent
563d1a104e
commit
d43f40e6c7
|
@ -12,7 +12,6 @@ config.status
|
||||||
config.sub
|
config.sub
|
||||||
configure
|
configure
|
||||||
depcomp
|
depcomp
|
||||||
efreet-config
|
|
||||||
install-sh
|
install-sh
|
||||||
libtool
|
libtool
|
||||||
ltmain.sh
|
ltmain.sh
|
||||||
|
|
|
@ -6,7 +6,5 @@ MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess \
|
||||||
stamp-h.in debian/changelog depcomp efreet_doxy_warnings.txt \
|
stamp-h.in debian/changelog depcomp efreet_doxy_warnings.txt \
|
||||||
debian/changelog
|
debian/changelog
|
||||||
|
|
||||||
bin_SCRIPTS =
|
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = efreet.pc efreet-mime.pc
|
pkgconfig_DATA = efreet.pc efreet-mime.pc
|
||||||
|
|
|
@ -6,17 +6,6 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
double
|
|
||||||
calc_time(const struct timeval *start, const struct timeval *end)
|
|
||||||
{
|
|
||||||
double s, e;
|
|
||||||
|
|
||||||
s = ((double)start->tv_sec) + ((double)start->tv_usec / 1000000.0);
|
|
||||||
e = ((double)end->tv_sec) + ((double)end->tv_usec / 1000000.0);
|
|
||||||
|
|
||||||
return e - s;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ef_mime_cb_get(void)
|
ef_mime_cb_get(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
static Ecore_List *globs = NULL; /* contains Efreet_Mime_Glob structs */
|
static Ecore_List *globs = NULL; /* contains Efreet_Mime_Glob structs */
|
||||||
static Ecore_List *magics = NULL; /* contains Efreet_Mime_Magic structs */
|
static Ecore_List *magics = NULL; /* contains Efreet_Mime_Magic structs */
|
||||||
static Ecore_List *monitors = NULL; /* contains Efreet_Mime_Monitor structs */
|
static Ecore_Hash *monitors = NULL; /* contains file monitors */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -28,13 +28,6 @@ static enum
|
||||||
*/
|
*/
|
||||||
#define EFREET_MIME_MAGIC_BUFFER_SIZE 512
|
#define EFREET_MIME_MAGIC_BUFFER_SIZE 512
|
||||||
|
|
||||||
typedef struct Efreet_Mime_Monitor Efreet_Mime_Monitor;
|
|
||||||
struct Efreet_Mime_Monitor
|
|
||||||
{
|
|
||||||
const char *file;
|
|
||||||
Ecore_File_Monitor *monitor;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Efreet_Mime_Glob
|
* Efreet_Mime_Glob
|
||||||
* @brief A parsed representation of a globs file
|
* @brief A parsed representation of a globs file
|
||||||
|
@ -81,10 +74,6 @@ static void efreet_mime_shared_mimeinfo_magic_load(const char *file);
|
||||||
static const char * efreet_mime_magic_check_priority(const char *file,
|
static const char * efreet_mime_magic_check_priority(const char *file,
|
||||||
unsigned int start,
|
unsigned int start,
|
||||||
unsigned int end);
|
unsigned int end);
|
||||||
static void efreet_mime_update_file_cb(void *data,
|
|
||||||
Ecore_File_Monitor *monitor,
|
|
||||||
Ecore_File_Event event,
|
|
||||||
const char *path);
|
|
||||||
static int efreet_mime_init_files(void);
|
static int efreet_mime_init_files(void);
|
||||||
static const char * efreet_mime_special_check(const char *file);
|
static const char * efreet_mime_special_check(const char *file);
|
||||||
static void efreet_mime_glob_free(void *data);
|
static void efreet_mime_glob_free(void *data);
|
||||||
|
@ -93,8 +82,11 @@ static int efreet_mime_glob_match(const char *str, const char *glob);
|
||||||
static int efreet_mime_glob_case_match(char *str, const char *glob);
|
static int efreet_mime_glob_case_match(char *str, const char *glob);
|
||||||
static int efreet_mime_endian_check(void);
|
static int efreet_mime_endian_check(void);
|
||||||
|
|
||||||
static void efreet_mime_monitor_del(const char *file);
|
static void efreet_mime_monitor_add(const char *file);
|
||||||
static void efreet_mime_monitor_free(void *data);
|
static void efreet_mime_cb_update_file(void *data,
|
||||||
|
Ecore_File_Monitor *monitor,
|
||||||
|
Ecore_File_Event event,
|
||||||
|
const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns 1 on success or 0 on failure
|
* @return Returns 1 on success or 0 on failure
|
||||||
|
@ -114,8 +106,10 @@ efreet_mime_init(void)
|
||||||
|
|
||||||
efreet_mime_endianess = efreet_mime_endian_check();
|
efreet_mime_endianess = efreet_mime_endian_check();
|
||||||
|
|
||||||
monitors = ecore_list_new();
|
monitors = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
||||||
ecore_list_set_free_cb(monitors, efreet_mime_monitor_free);
|
ecore_hash_set_free_key(monitors, ECORE_FREE_CB(free));
|
||||||
|
ecore_hash_set_free_value(monitors,
|
||||||
|
ECORE_FREE_CB(ecore_file_monitor_del));
|
||||||
|
|
||||||
if (!efreet_mime_init_files())
|
if (!efreet_mime_init_files())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -132,7 +126,7 @@ efreet_mime_shutdown(void)
|
||||||
{
|
{
|
||||||
IF_FREE_LIST(magics);
|
IF_FREE_LIST(magics);
|
||||||
IF_FREE_LIST(globs);
|
IF_FREE_LIST(globs);
|
||||||
IF_FREE_LIST(monitors);
|
IF_FREE_HASH(monitors);
|
||||||
|
|
||||||
efreet_shutdown();
|
efreet_shutdown();
|
||||||
ecore_file_shutdown();
|
ecore_file_shutdown();
|
||||||
|
@ -209,69 +203,22 @@ efreet_mime_endian_check(void)
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @param file: File to monitor
|
* @param file: File to monitor
|
||||||
* @return Returns the monitor, see Efreet_Mime_Monitor
|
* @return Returns no value.
|
||||||
* @brief Create/Add a new file monitor
|
* @brief Creates a new file monitor if we aren't already monitoring the
|
||||||
|
* given file
|
||||||
*/
|
*/
|
||||||
static Efreet_Mime_Monitor *
|
static void
|
||||||
efreet_mime_monitor_add(const char *file)
|
efreet_mime_monitor_add(const char *file)
|
||||||
{
|
{
|
||||||
Efreet_Mime_Monitor *mm = NULL;
|
|
||||||
Ecore_File_Monitor *fm = NULL;
|
Ecore_File_Monitor *fm = NULL;
|
||||||
|
|
||||||
efreet_mime_monitor_del(file);
|
/* if this is already in our hash then we're already monitoring so no
|
||||||
mm = NEW(Efreet_Mime_Monitor, 1);
|
* reason to re-monitor */
|
||||||
|
if (ecore_hash_get(monitors, file))
|
||||||
|
return;
|
||||||
|
|
||||||
if ((fm = ecore_file_monitor_add(file, efreet_mime_update_file_cb, mm)))
|
if ((fm = ecore_file_monitor_add(file, efreet_mime_cb_update_file, NULL)))
|
||||||
{
|
ecore_hash_set(monitors, strdup(file), fm);
|
||||||
mm->file = strdup(file);
|
|
||||||
mm->monitor = fm;
|
|
||||||
|
|
||||||
ecore_list_append(monitors, mm);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
FREE(mm);
|
|
||||||
|
|
||||||
return mm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
* @param file: File to discontinue monitoring
|
|
||||||
* @return Returns no value
|
|
||||||
* @brief Delete a file monitor
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
efreet_mime_monitor_del(const char *file)
|
|
||||||
{
|
|
||||||
Efreet_Mime_Monitor *mm = NULL;
|
|
||||||
|
|
||||||
ecore_list_goto_first(monitors);
|
|
||||||
while ((mm = ecore_list_current(monitors)))
|
|
||||||
{
|
|
||||||
if (!strcmp(mm->file, file))
|
|
||||||
{
|
|
||||||
ecore_list_remove_destroy(monitors);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ecore_list_next(monitors);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
* @param data: Pointer to the monitor to free
|
|
||||||
* @return Returns no value
|
|
||||||
* @brief Free a file monitor structure.
|
|
||||||
* Destroy callback for monitors.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
efreet_mime_monitor_free(void *data)
|
|
||||||
{
|
|
||||||
Efreet_Mime_Monitor *mm = NULL;
|
|
||||||
|
|
||||||
mm = data;
|
|
||||||
if (mm->monitor) ecore_file_monitor_del(mm->monitor);
|
|
||||||
FREE(mm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,7 +297,7 @@ efreet_mime_load_magics(Ecore_List *datadirs, const char *datahome)
|
||||||
* the globs are updated.
|
* the globs are updated.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
efreet_mime_update_file_cb(void *data __UNUSED__,
|
efreet_mime_cb_update_file(void *data __UNUSED__,
|
||||||
Ecore_File_Monitor *monitor __UNUSED__,
|
Ecore_File_Monitor *monitor __UNUSED__,
|
||||||
Ecore_File_Event event __UNUSED__,
|
Ecore_File_Event event __UNUSED__,
|
||||||
const char *path)
|
const char *path)
|
||||||
|
@ -366,7 +313,6 @@ efreet_mime_update_file_cb(void *data __UNUSED__,
|
||||||
|
|
||||||
if (strstr(path, "magic"))
|
if (strstr(path, "magic"))
|
||||||
efreet_mime_load_magics(datadirs, datahome);
|
efreet_mime_load_magics(datadirs, datahome);
|
||||||
|
|
||||||
else
|
else
|
||||||
efreet_mime_load_globs(datadirs, datahome);
|
efreet_mime_load_globs(datadirs, datahome);
|
||||||
}
|
}
|
||||||
|
@ -391,8 +337,10 @@ efreet_mime_init_files(void)
|
||||||
if (!(datadirs = efreet_data_dirs_get()))
|
if (!(datadirs = efreet_data_dirs_get()))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Add our file monitors */
|
/*
|
||||||
/* We watch the directories so we can watch for new files? */
|
* Add our file monitors
|
||||||
|
* We watch the directories so we can watch for new files
|
||||||
|
*/
|
||||||
datadir = datahome;
|
datadir = datahome;
|
||||||
ecore_list_goto_first(datadirs);
|
ecore_list_goto_first(datadirs);
|
||||||
while (datadir)
|
while (datadir)
|
||||||
|
|
Loading…
Reference in New Issue