summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@efl.so>2013-11-10 08:51:42 +0100
committerCedric BAIL <cedric@efl.so>2013-11-10 08:51:42 +0100
commitb824448a864796f24abebc81abcd63fd0005e5ce (patch)
treebae04b0a96cec0f5942afe8543e93691044d5e64
parent35228f32f189f90975729ca2dd0f3755f0e3db03 (diff)
downloadefl-devs/cedric/avahi.tar.gz
Ecore_Avahi: initial commit.devs/cedric/avahi
TODO: - Add tests - Integrate with Eo ? - Add documentation - Add example
-rw-r--r--Makefile.am1
-rw-r--r--configure.ac51
-rw-r--r--pc/.gitignore1
-rw-r--r--pc/ecore-avahi.pc.in12
-rw-r--r--src/Makefile.am1
-rw-r--r--src/Makefile_Ecore_Avahi.am16
-rw-r--r--src/lib/ecore/Ecore_Legacy.h1
-rw-r--r--src/lib/ecore/ecore_timer.c21
-rw-r--r--src/lib/ecore_avahi/Ecore_Avahi.h36
-rw-r--r--src/lib/ecore_avahi/ecore_avahi.c244
10 files changed, 384 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 85c1fa0835..cb6d032617 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -131,6 +131,7 @@ pc/ecore-input-evas.pc \
pc/ecore-imf.pc \
pc/ecore-imf-evas.pc \
pc/ecore-evas.pc \
+pc/ecore-avahi.pc \
pc/embryo.pc \
pc/eio.pc \
pc/eldbus.pc \
diff --git a/configure.ac b/configure.ac
index 6e32846fb8..afb81ec9a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2561,6 +2561,55 @@ AC_SUBST([ECORE_WIN32_LIBS])
EFL_LIB_END_OPTIONAL([Ecore_Win32])
#### End of Ecore_Win32
+#### Ecore_Avahi
+
+EFL_LIB_START([Ecore_Avahi])
+
+### Default values
+
+### Additional options to configure
+
+want_avahi="yes"
+
+AC_ARG_ENABLE([avahi],
+ [AC_HELP_STRING([--disable-avahi],
+ [disable avahi support. @<:@default=enabled@:>@])],
+ [
+ if test "x${enableval}" = "xyes" ; then
+ want_avahi="yes"
+ else
+ want_avahi="no"
+ fi
+ ], [
+ want_avahi="yes"
+ ])
+
+### Checks for programs
+
+### Checks for libraries
+EFL_INTERNAL_DEPEND_PKG([ECORE_AVAHI], [ecore])
+EFL_INTERNAL_DEPEND_PKG([ECORE_AVAHI], [eina])
+EFL_INTERNAL_DEPEND_PKG([ECORE_AVAHI], [eo])
+
+EFL_OPTIONAL_DEPEND_PKG([ECORE_AVAHI], [${want_avahi}], [AVAHI], [avahi-client])
+
+EFL_ADD_FEATURE([ECORE_AVAHI], [avahi-client], [${have_avahi}])
+
+### Checks for header files
+
+### Checks for types
+
+### Checks for structures
+
+### Checks for compiler characteristics
+
+### Checks for linker characteristics
+
+### Checks for library functions
+
+EFL_LIB_END([Ecore_Avahi])
+
+#### End of Ecore_Avahi
#### Ecore_WinCE
EFL_LIB_START_OPTIONAL([Ecore_WinCE], [test "${have_wince}" = "yes"])
@@ -3789,6 +3838,7 @@ pc/ecore-evas.pc
pc/ecore-imf.pc
pc/ecore-imf-evas.pc
pc/ecore-audio.pc
+pc/ecore-avahi.pc
pc/embryo.pc
pc/eio.pc
pc/eldbus.pc
@@ -3900,6 +3950,7 @@ echo "Ecore_Win32.....: $have_win32"
echo "Ecore_WinCE.....: $have_wince"
fi
echo "Ecore_Audio.....: ${efl_lib_optional_ecore_audio} (${features_ecore_audio})"
+echo "Ecore_Avahi.....: yes (${features_ecore_avahi})"
echo "Ecore_Evas......: yes (${features_ecore_evas})"
echo "Eeze............: ${efl_lib_optional_eeze} (${features_eeze})"
echo "EPhysics........: ${efl_lib_optional_ephysics}"
diff --git a/pc/.gitignore b/pc/.gitignore
index c9e1de0010..b6178fb51b 100644
--- a/pc/.gitignore
+++ b/pc/.gitignore
@@ -1,3 +1,4 @@
+/ecore-avahi.pc
/ecore-audio.pc
/ecore-cocoa.pc
/ecore-con.pc
diff --git a/pc/ecore-avahi.pc.in b/pc/ecore-avahi.pc.in
new file mode 100644
index 0000000000..a5a5ce9418
--- /dev/null
+++ b/pc/ecore-avahi.pc.in
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: ecore-avahi
+Description: E core library, avahi integration
+Requires.private: @requirements_pc_ecore_avahi@
+Version: @VERSION@
+Libs: -L${libdir} -lecore_avahi
+Libs.private: @requirements_libs_ecore_avahi@
+Cflags: -I${includedir}/efl-@VMAJ@ -I${includedir}/efl-@VMAJ@ -I${includedir}/ecore-avahi-@VMAJ@
diff --git a/src/Makefile.am b/src/Makefile.am
index 6ceedd2153..fdec425745 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,6 +44,7 @@ include Makefile_Ecore_IMF.am
include Makefile_Ecore_IMF_Evas.am
include Makefile_Ecore_Evas.am
include Makefile_Ecore_Audio.am
+include Makefile_Ecore_Avahi.am
include Makefile_Embryo.am
include Makefile_Eio.am
include Makefile_Eldbus.am
diff --git a/src/Makefile_Ecore_Avahi.am b/src/Makefile_Ecore_Avahi.am
new file mode 100644
index 0000000000..3dba43e6ca
--- /dev/null
+++ b/src/Makefile_Ecore_Avahi.am
@@ -0,0 +1,16 @@
+
+### Library
+
+lib_LTLIBRARIES += lib/ecore_avahi/libecore_avahi.la
+
+installed_ecoreavahimainheadersdir = $(includedir)/ecore-avahi-@VMAJ@
+dist_installed_ecoreavahimainheaders_DATA = \
+lib/ecore_avahi/Ecore_Avahi.h
+
+lib_ecore_avahi_libecore_avahi_la_SOURCES = \
+lib/ecore_avahi/ecore_avahi.c
+
+lib_ecore_avahi_libecore_avahi_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl @ECORE_AVAHI_CFLAGS@
+lib_ecore_avahi_libecore_avahi_la_LIBADD = @ECORE_AVAHI_LIBS@
+lib_ecore_avahi_libecore_avahi_la_DEPENDENCIES = @ECORE_AVAHI_INTERNAL_LIBS@
+lib_ecore_avahi_libecore_avahi_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
diff --git a/src/lib/ecore/Ecore_Legacy.h b/src/lib/ecore/Ecore_Legacy.h
index 0bc0009244..8585345465 100644
--- a/src/lib/ecore/Ecore_Legacy.h
+++ b/src/lib/ecore/Ecore_Legacy.h
@@ -179,6 +179,7 @@ EAPI void *ecore_timer_del(Ecore_Timer *timer);
EAPI void ecore_timer_interval_set(Ecore_Timer *timer, double in);
EAPI double ecore_timer_interval_get(Ecore_Timer *timer);
EAPI void ecore_timer_freeze(Ecore_Timer *timer);
+EAPI Eina_Bool ecore_timer_freeze_get(Ecore_Timer *timer);
EAPI void ecore_timer_thaw(Ecore_Timer *timer);
EAPI void ecore_timer_delay(Ecore_Timer *timer, double add);
EAPI void ecore_timer_reset(Ecore_Timer *timer);
diff --git a/src/lib/ecore/ecore_timer.c b/src/lib/ecore/ecore_timer.c
index 5c03e805b6..e6e488c67a 100644
--- a/src/lib/ecore/ecore_timer.c
+++ b/src/lib/ecore/ecore_timer.c
@@ -485,6 +485,26 @@ unlock:
_ecore_unlock();
}
+EAPI Eina_Bool
+ecore_timer_freeze_get(Ecore_Timer *timer)
+{
+ int r = 0;
+
+ eo_do(timer, eo_event_freeze_get(&r));
+ return !!r;
+}
+
+static void
+_timer_freeze_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
+{
+ EINA_MAIN_LOOP_CHECK_RETURN;
+
+ Ecore_Timer_Private_Data *timer = _pd;
+ int *r = va_arg(*list, int*);
+
+ if (r) *r = timer->frozen;
+}
+
/**
* Resumes a frozen (paused) timer.
*
@@ -989,6 +1009,7 @@ _class_constructor(Eo_Class *klass)
EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE), _timer_freeze),
EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_THAW), _timer_thaw),
+ EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE_GET), _timer_freeze_get),
EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_DELAY), _timer_delay),
EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_RESET), _timer_reset),
diff --git a/src/lib/ecore_avahi/Ecore_Avahi.h b/src/lib/ecore_avahi/Ecore_Avahi.h
new file mode 100644
index 0000000000..a80881adb4
--- /dev/null
+++ b/src/lib/ecore_avahi/Ecore_Avahi.h
@@ -0,0 +1,36 @@
+#ifndef _ECORE_AVAHI_H
+# define _ECORE_AVAHI_H
+
+#ifdef EAPI
+# undef EAPI
+#endif
+
+#ifdef _WIN32
+# ifdef EFL_ECORE_BUILD
+# ifdef DLL_EXPORT
+# define EAPI __declspec(dllexport)
+# else
+# define EAPI
+# endif /* ! DLL_EXPORT */
+# else
+# define EAPI __declspec(dllimport)
+# endif /* ! EFL_ECORE_BUILD */
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define EAPI __attribute__ ((visibility("default")))
+# else
+# define EAPI
+# endif
+# else
+# define EAPI
+# endif
+#endif /* ! _WIN32 */
+
+typedef struct _Ecore_Avahi Ecore_Avahi;
+
+EAPI Ecore_Avahi *ecore_avahi_add(void);
+EAPI void ecore_avahi_del(Ecore_Avahi *handler);
+EAPI const void *ecore_avahi_poll_get(Ecore_Avahi *handler); // return AvahiPoll
+
+#endif
diff --git a/src/lib/ecore_avahi/ecore_avahi.c b/src/lib/ecore_avahi/ecore_avahi.c
new file mode 100644
index 0000000000..a5a0ab058f
--- /dev/null
+++ b/src/lib/ecore_avahi/ecore_avahi.c
@@ -0,0 +1,244 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <Eina.h>
+#include <Ecore.h>
+
+#include "Ecore_Avahi.h"
+
+#ifdef HAVE_AVAHI
+#include <avahi-common/watch.h>
+
+typedef struct _Ecore_Avahi_Watch Ecore_Avahi_Watch;
+typedef struct _Ecore_Avahi_Timeout Ecore_Avahi_Timeout;
+
+struct _Ecore_Avahi_Watch
+{
+ Ecore_Fd_Handler *handler;
+ Ecore_Avahi *parent;
+
+ AvahiWatchCallback callback;
+ void *callback_data;
+};
+
+struct _Ecore_Avahi_Timeout
+{
+ Ecore_Timer *timer;
+ Ecore_Avahi *parent;
+
+ AvahiTimeoutCallback callback;
+ void *callback_data;
+};
+
+struct _Ecore_Avahi
+{
+ AvahiPoll api;
+
+ Eina_List *watches;
+ Eina_List *timeouts;
+};
+
+static Ecore_Fd_Handler_Flags
+_ecore_avahi_events2ecore(AvahiWatchEvent events)
+{
+ return (events & AVAHI_WATCH_IN ? ECORE_FD_READ : 0) |
+ (events & AVAHI_WATCH_OUT ? ECORE_FD_WRITE : 0) |
+ (events & AVAHI_WATCH_ERR ? ECORE_FD_ERROR : 0);
+}
+
+static Eina_Bool
+_ecore_avahi_watch_cb(void *data, Ecore_Fd_Handler *fd_handler)
+{
+ Ecore_Avahi_Watch *watch = data;
+ AvahiWatchEvent flags = 0;
+
+ flags = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ) ? AVAHI_WATCH_IN : 0;
+ flags |= ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE) ? AVAHI_WATCH_OUT : 0;
+ flags |= ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR) ? AVAHI_WATCH_ERR : 0;
+
+ watch->callback((AvahiWatch*) watch, ecore_main_fd_handler_fd_get(fd_handler), flags, watch->callback_data);
+
+ return ECORE_CALLBACK_RENEW;
+}
+
+static AvahiWatch *
+_ecore_avahi_watch_new(const AvahiPoll *api,
+ int fd, AvahiWatchEvent events,
+ AvahiWatchCallback callback, void *userdata)
+{
+ Ecore_Avahi_Watch *watch;
+ Ecore_Avahi *ea;
+
+ ea = api->userdata;
+ watch = calloc(1, sizeof (Ecore_Avahi_Watch));
+ if (!watch) return NULL;
+
+ watch->handler = ecore_main_fd_handler_add(fd, _ecore_avahi_events2ecore(events),
+ _ecore_avahi_watch_cb, watch, NULL, NULL);
+ watch->callback = callback;
+ watch->callback_data = userdata;
+ watch->parent = ea;
+
+ ea->watches = eina_list_append(ea->watches, watch);
+
+ return (AvahiWatch*) watch;
+}
+
+static void
+_ecore_avahi_watch_update(AvahiWatch *w, AvahiWatchEvent events)
+{
+ Ecore_Avahi_Watch *watch = (Ecore_Avahi_Watch *) w;
+
+ ecore_main_fd_handler_active_set(watch->handler, _ecore_avahi_events2ecore(events));
+}
+
+static void
+_ecore_avahi_watch_free(AvahiWatch *w)
+{
+ Ecore_Avahi_Watch *watch = (Ecore_Avahi_Watch *) w;
+
+ ecore_main_fd_handler_del(watch->handler);
+ watch->parent->watches = eina_list_remove(watch->parent->watches, watch);
+ free(watch);
+}
+
+static AvahiWatchEvent
+_ecore_avahi_watch_get_events(AvahiWatch *w)
+{
+ Ecore_Avahi_Watch *watch = (Ecore_Avahi_Watch *) w;
+ AvahiWatchEvent flags = 0;
+
+ flags = ecore_main_fd_handler_active_get(watch->handler, ECORE_FD_READ) ? AVAHI_WATCH_IN : 0;
+ flags |= ecore_main_fd_handler_active_get(watch->handler, ECORE_FD_WRITE) ? AVAHI_WATCH_OUT : 0;
+ flags |= ecore_main_fd_handler_active_get(watch->handler, ECORE_FD_ERROR) ? AVAHI_WATCH_ERR : 0;
+
+ return flags;
+}
+
+static double
+_ecore_avahi_timeval2double(const struct timeval *tv)
+{
+ return tv->tv_sec + (double) tv->tv_usec / 1000000;
+}
+
+static Eina_Bool
+_ecore_avahi_timeout_cb(void *data)
+{
+ Ecore_Avahi_Timeout *timeout = data;
+
+ ecore_timer_freeze(timeout->timer);
+ timeout->callback((AvahiTimeout*) timeout, timeout->callback_data);
+
+ return ECORE_CALLBACK_RENEW;
+}
+
+static AvahiTimeout *
+_ecore_avahi_timeout_new(const AvahiPoll *api, const struct timeval *tv,
+ AvahiTimeoutCallback callback, void *userdata)
+{
+ Ecore_Avahi_Timeout *timeout;
+ Ecore_Avahi *ea;
+
+ ea = api->userdata;
+ timeout = calloc(1, sizeof (Ecore_Avahi_Timeout));
+ if (!timeout) return NULL;
+
+ timeout->timer = ecore_timer_add(_ecore_avahi_timeval2double(tv), _ecore_avahi_timeout_cb, timeout);
+ timeout->callback = callback;
+ timeout->callback_data = userdata;
+ timeout->parent = ea;
+
+ ea->timeouts = eina_list_append(ea->timeouts, timeout);
+
+ return (AvahiTimeout*) timeout;
+}
+
+static void
+_ecore_avahi_timeout_update(AvahiTimeout *t, const struct timeval *tv)
+{
+ Ecore_Avahi_Timeout *timeout = (Ecore_Avahi_Timeout *) t;
+
+ if (tv)
+ {
+ ecore_timer_interval_set(timeout->timer, _ecore_avahi_timeval2double(tv));
+ if (ecore_timer_freeze_get(timeout->timer))
+ ecore_timer_thaw(timeout->timer);
+ }
+ else
+ {
+ ecore_timer_freeze(timeout->timer);
+ }
+}
+
+static void
+_ecore_avahi_timeout_free(AvahiTimeout *t)
+{
+ Ecore_Avahi_Timeout *timeout = (Ecore_Avahi_Timeout *) t;
+
+ ecore_timer_del(timeout->timer);
+ timeout->parent->timeouts = eina_list_remove(timeout->parent->timeouts, timeout);
+ free(timeout);
+}
+#endif
+
+EAPI Ecore_Avahi *
+ecore_avahi_add(void)
+{
+#ifdef HAVE_AVAHI
+ Ecore_Avahi *handler;
+
+ handler = calloc(1, sizeof (Ecore_Avahi));
+ if (!handler) return NULL;
+
+ handler->api.userdata = handler;
+ handler->api.watch_new = _ecore_avahi_watch_new;
+ handler->api.watch_free = _ecore_avahi_watch_free;
+ handler->api.watch_update = _ecore_avahi_watch_update;
+ handler->api.watch_get_events = _ecore_avahi_watch_get_events;
+
+ handler->api.timeout_new = _ecore_avahi_timeout_new;
+ handler->api.timeout_free = _ecore_avahi_timeout_free;
+ handler->api.timeout_update = _ecore_avahi_timeout_update;
+
+ return handler;
+#else
+ return NULL;
+#endif
+}
+
+EAPI void
+ecore_avahi_del(Ecore_Avahi *handler)
+{
+#ifdef HAVE_AVAHI
+ Ecore_Avahi_Timeout *timeout;
+ Ecore_Avahi_Watch *watch;
+
+ EINA_LIST_FREE(handler->watches, watch)
+ {
+ ecore_main_fd_handler_del(watch->handler);
+ free(watch);
+ }
+
+ EINA_LIST_FREE(handler->timeouts, timeout)
+ {
+ ecore_timer_del(timeout->timer);
+ free(timeout);
+ }
+
+ free(handler);
+#else
+ (void) handler;
+#endif
+}
+
+EAPI const void *
+ecore_avahi_poll_get(Ecore_Avahi *handler)
+{
+#ifdef HAVE_AVAHI
+ return &handler->api;
+#else
+ return NULL;
+#endif
+}
+