summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric@efl.so>2013-11-10 08:51:42 +0100
committerCedric BAIL <cedric.bail@samsung.com>2013-12-17 19:37:05 +0900
commit0a1cc79a917b770ef66afe8b99731f6d5754ca44 (patch)
tree99d52907af9d893cb1fc08d75cd1b9f2ab2bfd0c /src
parent99e3ce489adbdc711571fa7d71acbd03a413ec00 (diff)
Ecore_Avahi: initial commit.
TODO: - Add tests, how ? - Integrate with Eo, needed ?
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile_Ecore_Avahi.am16
-rw-r--r--src/examples/ecore_avahi/.gitignore1
-rw-r--r--src/examples/ecore_avahi/Makefile.am35
-rw-r--r--src/examples/ecore_avahi/ecore_avahi_example.c187
-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.h88
-rw-r--r--src/lib/ecore_avahi/ecore_avahi.c247
9 files changed, 598 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2d7fdd1..e797d57 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,6 +44,7 @@ include Makefile_Ecore_IMF.am
44include Makefile_Ecore_IMF_Evas.am 44include Makefile_Ecore_IMF_Evas.am
45include Makefile_Ecore_Evas.am 45include Makefile_Ecore_Evas.am
46include Makefile_Ecore_Audio.am 46include Makefile_Ecore_Audio.am
47include Makefile_Ecore_Avahi.am
47include Makefile_Embryo.am 48include Makefile_Embryo.am
48include Makefile_Eio.am 49include Makefile_Eio.am
49include Makefile_Eldbus.am 50include Makefile_Eldbus.am
@@ -74,6 +75,7 @@ examples/eo \
74examples/eet \ 75examples/eet \
75examples/evas \ 76examples/evas \
76examples/ecore \ 77examples/ecore \
78examples/ecore_avahi \
77examples/eio \ 79examples/eio \
78examples/eldbus \ 80examples/eldbus \
79examples/ephysics \ 81examples/ephysics \
diff --git a/src/Makefile_Ecore_Avahi.am b/src/Makefile_Ecore_Avahi.am
new file mode 100644
index 0000000..3dba43e
--- /dev/null
+++ b/src/Makefile_Ecore_Avahi.am
@@ -0,0 +1,16 @@
1
2### Library
3
4lib_LTLIBRARIES += lib/ecore_avahi/libecore_avahi.la
5
6installed_ecoreavahimainheadersdir = $(includedir)/ecore-avahi-@VMAJ@
7dist_installed_ecoreavahimainheaders_DATA = \
8lib/ecore_avahi/Ecore_Avahi.h
9
10lib_ecore_avahi_libecore_avahi_la_SOURCES = \
11lib/ecore_avahi/ecore_avahi.c
12
13lib_ecore_avahi_libecore_avahi_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl @ECORE_AVAHI_CFLAGS@
14lib_ecore_avahi_libecore_avahi_la_LIBADD = @ECORE_AVAHI_LIBS@
15lib_ecore_avahi_libecore_avahi_la_DEPENDENCIES = @ECORE_AVAHI_INTERNAL_LIBS@
16lib_ecore_avahi_libecore_avahi_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@
diff --git a/src/examples/ecore_avahi/.gitignore b/src/examples/ecore_avahi/.gitignore
new file mode 100644
index 0000000..7190ca0
--- /dev/null
+++ b/src/examples/ecore_avahi/.gitignore
@@ -0,0 +1 @@
ecore_avahi_example
diff --git a/src/examples/ecore_avahi/Makefile.am b/src/examples/ecore_avahi/Makefile.am
new file mode 100644
index 0000000..d447d65
--- /dev/null
+++ b/src/examples/ecore_avahi/Makefile.am
@@ -0,0 +1,35 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I$(top_builddir)/src/lib/efl \
5-I$(top_srcdir)/src/lib/eina \
6-I$(top_srcdir)/src/lib/eo \
7-I$(top_srcdir)/src/lib/ecore \
8-I$(top_srcdir)/src/lib/ecore_avahi\
9-I$(top_builddir)/src/lib/eina \
10-I$(top_builddir)/src/lib/eo \
11-I$(top_builddir)/src/lib/ecore \
12-I$(top_builddir)/src/lib/ecore_avahi \
13@AVAHI_CLIENT_CFLAGS@
14
15EXTRA_PROGRAMS = \
16ecore_avahi_example
17
18ecore_avahi_example_SOURCES = ecore_avahi_example.c
19ecore_avahi_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la \
20$(top_builddir)/src/lib/ecore_avahi/libecore_avahi.la \
21$(top_builddir)/src/lib/eo/libeo.la \
22$(top_builddir)/src/lib/eina/libeina.la \
23@AVAHI_CLIENT_LIBS@
24
25examples: $(EXTRA_PROGRAMS)
26
27clean-local:
28 rm -f $(EXTRA_PROGRAMS)
29
30install-examples:
31 mkdir -p $(datadir)/ecore_avahi/examples
32 $(install_sh_DATA) -c ecore_avahi_example.c $(datadir)/ecore_avahi/examples
33
34uninstall-local:
35 rm -f $(datadir)/ecore_avahi/examples/ecore_avahi_example.c
diff --git a/src/examples/ecore_avahi/ecore_avahi_example.c b/src/examples/ecore_avahi/ecore_avahi_example.c
new file mode 100644
index 0000000..f9f247e
--- /dev/null
+++ b/src/examples/ecore_avahi/ecore_avahi_example.c
@@ -0,0 +1,187 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#ifdef HAVE_AVAHI
9
10#include <avahi-client/client.h>
11#include <avahi-client/lookup.h>
12#include <avahi-client/publish.h>
13
14#include <avahi-common/simple-watch.h>
15#include <avahi-common/malloc.h>
16#include <avahi-common/error.h>
17#include <avahi-common/alternative.h>
18#include <avahi-common/timeval.h>
19
20#include <Ecore.h>
21#include <Ecore_Avahi.h>
22
23typedef struct _Ecore_Avahi_Example Ecore_Avahi_Example;
24struct _Ecore_Avahi_Example
25{
26 AvahiClient *client;
27 AvahiEntryGroup *group;
28 const char *server;
29 int port;
30};
31
32static void
33_ecore_avahi_group_cb(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata)
34{
35 Ecore_Avahi_Example *example = userdata;
36
37 switch (state)
38 {
39 case AVAHI_ENTRY_GROUP_ESTABLISHED :
40 /* The entry group has been established successfully */
41 fprintf(stderr, "Service '%s' successfully established.\n", example->server);
42 break;
43
44 case AVAHI_ENTRY_GROUP_COLLISION :
45 fprintf(stderr, "Service name collision.\n");
46 ecore_main_loop_quit();
47 break;
48
49 case AVAHI_ENTRY_GROUP_FAILURE :
50
51 fprintf(stderr, "Entry group failure: %s\n", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));
52 /* Some kind of failure happened while we were registering our services */
53 ecore_main_loop_quit();
54 break;
55
56 case AVAHI_ENTRY_GROUP_UNCOMMITED:
57 case AVAHI_ENTRY_GROUP_REGISTERING:
58 ;
59 }
60}
61
62static void
63_ecore_avahi_service_create(AvahiClient *c, Ecore_Avahi_Example *example)
64{
65 int error;
66
67 example->group = avahi_entry_group_new(c, _ecore_avahi_group_cb, example);
68 if (!example->group)
69 {
70 fprintf(stderr, "avahi_entry_group_new() failed: %s\n", avahi_strerror(avahi_client_errno(c)));
71 goto fail;
72 }
73
74 /* If the group is empty (either because it was just created, or
75 * because it was reset previously, add our entries. */
76 if (!avahi_entry_group_is_empty(example->group)) return ;
77
78 error = avahi_entry_group_add_service(example->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0,
79 example->server, "_ipp._tcp", NULL, NULL, example->port, "name=ThisIsATest", NULL);
80 if (error < 0)
81 {
82 fprintf(stderr, "Failed to add _ipp._tcp service with error: %s.\n", avahi_strerror(error));
83 goto fail;
84 }
85
86 error = avahi_entry_group_commit(example->group);
87 if (error < 0)
88 {
89 fprintf(stderr, "Failed to commit entry group with error: %s\n", avahi_strerror(error));
90 goto fail;
91 }
92
93 return ;
94
95 fail:
96 ecore_main_loop_quit();
97}
98
99static void
100_ecore_avahi_client_cb(AvahiClient *c, AvahiClientState state, void * userdata)
101{
102 Ecore_Avahi_Example *example = userdata;
103
104 switch (state)
105 {
106 case AVAHI_CLIENT_S_RUNNING:
107 /* The server has started successfully and registered its host
108 * name on the network, so it's time to create our services */
109 _ecore_avahi_service_create(c, example);
110 break;
111 case AVAHI_CLIENT_FAILURE:
112 fprintf(stderr, "Avahi client failure: %s\n", avahi_strerror(avahi_client_errno(c)));
113 break;
114 case AVAHI_CLIENT_S_COLLISION:
115 /* Let's drop our registered services. When the server is back
116 * in AVAHI_SERVER_RUNNING state we will register them
117 * again with the new host name. */
118 case AVAHI_CLIENT_S_REGISTERING:
119 /* The server records are now being established. This
120 * might be caused by a host name change. We need to wait
121 * for our own records to register until the host name is
122 * properly esatblished. */
123 if (example->group) avahi_entry_group_reset(example->group);
124 break;
125 case AVAHI_CLIENT_CONNECTING:
126 ;
127 }
128}
129
130int
131main(int argc, char **argv)
132{
133 Ecore_Avahi_Example example = { 0 };
134 Ecore_Avahi *handler;
135 const AvahiPoll *poll_api;
136 int exit_code = 0;
137 int error = 0;
138
139 if (argc < 3)
140 {
141 fprintf(stderr, "Usage : %s name port\n", argv[0]);
142 return -1;
143 }
144
145 eina_init();
146 ecore_init();
147
148 handler = ecore_avahi_add();
149 poll_api = ecore_avahi_poll_get(handler);
150
151 if (!poll_api)
152 {
153 fprintf(stderr, "Build EFL with Avahi support.\n");
154 exit_code = -1;
155 goto fail;
156 }
157
158 example.server = eina_stringshare_add(argv[1]);
159 example.port = atoi(argv[2]);
160 example.client = avahi_client_new(poll_api, AVAHI_CLIENT_NO_FAIL, _ecore_avahi_client_cb, &example, &error);
161
162 if (!example.client)
163 {
164 fprintf(stderr, "Failed to create avahi client: %s.\n", avahi_strerror(error));
165 exit_code = -1;
166 goto fail;
167 }
168
169 ecore_main_loop_begin();
170
171 avahi_client_free(example.client);
172
173 fail:
174 eina_stringshare_del(example.server);
175
176 ecore_shutdown();
177 eina_shutdown();
178
179 return exit_code;
180}
181#else
182int
183main(int argc, char **argv)
184{
185 fprintf(stderr, "This example require Avahi to be build !\n");
186}
187#endif
diff --git a/src/lib/ecore/Ecore_Legacy.h b/src/lib/ecore/Ecore_Legacy.h
index d7d01ce..f1a73c1 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);
179EAPI void ecore_timer_interval_set(Ecore_Timer *timer, double in); 179EAPI void ecore_timer_interval_set(Ecore_Timer *timer, double in);
180EAPI double ecore_timer_interval_get(Ecore_Timer *timer); 180EAPI double ecore_timer_interval_get(Ecore_Timer *timer);
181EAPI void ecore_timer_freeze(Ecore_Timer *timer); 181EAPI void ecore_timer_freeze(Ecore_Timer *timer);
182EAPI Eina_Bool ecore_timer_freeze_get(Ecore_Timer *timer);
182EAPI void ecore_timer_thaw(Ecore_Timer *timer); 183EAPI void ecore_timer_thaw(Ecore_Timer *timer);
183EAPI void ecore_timer_delay(Ecore_Timer *timer, double add); 184EAPI void ecore_timer_delay(Ecore_Timer *timer, double add);
184EAPI void ecore_timer_reset(Ecore_Timer *timer); 185EAPI void ecore_timer_reset(Ecore_Timer *timer);
diff --git a/src/lib/ecore/ecore_timer.c b/src/lib/ecore/ecore_timer.c
index 5c03e80..e6e488c 100644
--- a/src/lib/ecore/ecore_timer.c
+++ b/src/lib/ecore/ecore_timer.c
@@ -485,6 +485,26 @@ unlock:
485 _ecore_unlock(); 485 _ecore_unlock();
486} 486}
487 487
488EAPI Eina_Bool
489ecore_timer_freeze_get(Ecore_Timer *timer)
490{
491 int r = 0;
492
493 eo_do(timer, eo_event_freeze_get(&r));
494 return !!r;
495}
496
497static void
498_timer_freeze_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
499{
500 EINA_MAIN_LOOP_CHECK_RETURN;
501
502 Ecore_Timer_Private_Data *timer = _pd;
503 int *r = va_arg(*list, int*);
504
505 if (r) *r = timer->frozen;
506}
507
488/** 508/**
489 * Resumes a frozen (paused) timer. 509 * Resumes a frozen (paused) timer.
490 * 510 *
@@ -989,6 +1009,7 @@ _class_constructor(Eo_Class *klass)
989 1009
990 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE), _timer_freeze), 1010 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE), _timer_freeze),
991 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_THAW), _timer_thaw), 1011 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_THAW), _timer_thaw),
1012 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE_GET), _timer_freeze_get),
992 1013
993 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_DELAY), _timer_delay), 1014 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_DELAY), _timer_delay),
994 EO_OP_FUNC(ECORE_TIMER_ID(ECORE_TIMER_SUB_ID_RESET), _timer_reset), 1015 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 0000000..a085e07
--- /dev/null
+++ b/src/lib/ecore_avahi/Ecore_Avahi.h
@@ -0,0 +1,88 @@
1/**
2 @brief Ecore Avahi integration Library Public API Calls
3
4 These routines are used for integrating Avahi with Ecore main loop
5 */
6
7#ifndef _ECORE_AVAHI_H
8# define _ECORE_AVAHI_H
9
10#ifdef EAPI
11# undef EAPI
12#endif
13
14#ifdef _WIN32
15# ifdef EFL_ECORE_BUILD
16# ifdef DLL_EXPORT
17# define EAPI __declspec(dllexport)
18# else
19# define EAPI
20# endif /* ! DLL_EXPORT */
21# else
22# define EAPI __declspec(dllimport)
23# endif /* ! EFL_ECORE_BUILD */
24#else
25# ifdef __GNUC__
26# if __GNUC__ >= 4
27# define EAPI __attribute__ ((visibility("default")))
28# else
29# define EAPI
30# endif
31# else
32# define EAPI
33# endif
34#endif /* ! _WIN32 */
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/**
41 * @defgroup Ecore_Avahi Ecore main loop integration function.
42 * @ingroup Ecore
43 *
44 * @{
45 */
46
47/**
48 * @since 1.9
49 */
50typedef struct _Ecore_Avahi Ecore_Avahi; /**< A handle for an Avahi instance. */
51
52/**
53 * @brief Create an AvahiPoll context and integrate it within Ecore main loop.
54 *
55 * @return A handler that reference the AvahiPoll context
56 * @since 1.9
57 */
58EAPI Ecore_Avahi *ecore_avahi_add(void);
59
60/**
61 * @brief Delete the specified handler of an AvahiPoll.
62 *
63 * @param handler The actual handler to destroy.
64 * @since 1.9
65 *
66 * Be aware there should not be any reference still using that handler before
67 * destroying it.
68 */
69EAPI void ecore_avahi_del(Ecore_Avahi *handler);
70
71/**
72 * @brief Get the AvahiPoll structure to integrate with Ecore main loop.
73 *
74 * @param handler The handler to get the AvahiPoll structure from.
75 * @return return the actual AvahiPoll structure to use with Avahi.
76 * @since 1.9
77 */
78EAPI const void *ecore_avahi_poll_get(Ecore_Avahi *handler); // return AvahiPoll
79
80/**
81 * @}
82 */
83
84#ifdef __cplusplus
85}
86#endif
87
88#endif
diff --git a/src/lib/ecore_avahi/ecore_avahi.c b/src/lib/ecore_avahi/ecore_avahi.c
new file mode 100644
index 0000000..93c5301
--- /dev/null
+++ b/src/lib/ecore_avahi/ecore_avahi.c
@@ -0,0 +1,247 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Ecore.h>
7
8#include "Ecore_Avahi.h"
9
10#ifdef HAVE_AVAHI
11#include <avahi-common/watch.h>
12
13typedef struct _Ecore_Avahi_Watch Ecore_Avahi_Watch;
14typedef struct _Ecore_Avahi_Timeout Ecore_Avahi_Timeout;
15
16struct _Ecore_Avahi_Watch
17{
18 Ecore_Fd_Handler *handler;
19 Ecore_Avahi *parent;
20
21 AvahiWatchCallback callback;
22 void *callback_data;
23};
24
25struct _Ecore_Avahi_Timeout
26{
27 Ecore_Timer *timer;
28 Ecore_Avahi *parent;
29
30 AvahiTimeoutCallback callback;
31 void *callback_data;
32};
33
34struct _Ecore_Avahi
35{
36 AvahiPoll api;
37
38 Eina_List *watches;
39 Eina_List *timeouts;
40};
41
42static Ecore_Fd_Handler_Flags
43_ecore_avahi_events2ecore(AvahiWatchEvent events)
44{
45 return (events & AVAHI_WATCH_IN ? ECORE_FD_READ : 0) |
46 (events & AVAHI_WATCH_OUT ? ECORE_FD_WRITE : 0) |
47 (events & AVAHI_WATCH_ERR ? ECORE_FD_ERROR : 0);
48}
49
50static Eina_Bool
51_ecore_avahi_watch_cb(void *data, Ecore_Fd_Handler *fd_handler)
52{
53 Ecore_Avahi_Watch *watch = data;
54 AvahiWatchEvent flags = 0;
55
56 flags = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ) ? AVAHI_WATCH_IN : 0;
57 flags |= ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE) ? AVAHI_WATCH_OUT : 0;
58 flags |= ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR) ? AVAHI_WATCH_ERR : 0;
59
60 watch->callback((AvahiWatch*) watch, ecore_main_fd_handler_fd_get(fd_handler), flags, watch->callback_data);
61
62 return ECORE_CALLBACK_RENEW;
63}
64
65static AvahiWatch *
66_ecore_avahi_watch_new(const AvahiPoll *api,
67 int fd, AvahiWatchEvent events,
68 AvahiWatchCallback callback, void *userdata)
69{
70 Ecore_Avahi_Watch *watch;
71 Ecore_Avahi *ea;
72
73 ea = api->userdata;
74 watch = calloc(1, sizeof (Ecore_Avahi_Watch));
75 if (!watch) return NULL;
76
77 watch->handler = ecore_main_fd_handler_add(fd, _ecore_avahi_events2ecore(events),
78 _ecore_avahi_watch_cb, watch, NULL, NULL);
79 watch->callback = callback;
80 watch->callback_data = userdata;
81 watch->parent = ea;
82
83 ea->watches = eina_list_append(ea->watches, watch);
84
85 return (AvahiWatch*) watch;
86}
87
88static void
89_ecore_avahi_watch_update(AvahiWatch *w, AvahiWatchEvent events)
90{
91 Ecore_Avahi_Watch *watch = (Ecore_Avahi_Watch *) w;
92
93 ecore_main_fd_handler_active_set(watch->handler, _ecore_avahi_events2ecore(events));
94}
95
96static void
97_ecore_avahi_watch_free(AvahiWatch *w)
98{
99 Ecore_Avahi_Watch *watch = (Ecore_Avahi_Watch *) w;
100
101 ecore_main_fd_handler_del(watch->handler);
102 watch->parent->watches = eina_list_remove(watch->parent->watches, watch);
103 free(watch);
104}
105
106static AvahiWatchEvent
107_ecore_avahi_watch_get_events(AvahiWatch *w)
108{
109 Ecore_Avahi_Watch *watch = (Ecore_Avahi_Watch *) w;
110 AvahiWatchEvent flags = 0;
111
112 flags = ecore_main_fd_handler_active_get(watch->handler, ECORE_FD_READ) ? AVAHI_WATCH_IN : 0;
113 flags |= ecore_main_fd_handler_active_get(watch->handler, ECORE_FD_WRITE) ? AVAHI_WATCH_OUT : 0;
114 flags |= ecore_main_fd_handler_active_get(watch->handler, ECORE_FD_ERROR) ? AVAHI_WATCH_ERR : 0;
115
116 return flags;
117}
118
119static double
120_ecore_avahi_timeval2double(const struct timeval *tv)
121{
122 if (!tv) return 3600;
123 return tv->tv_sec + (double) tv->tv_usec / 1000000;
124}
125
126static Eina_Bool
127_ecore_avahi_timeout_cb(void *data)
128{
129 Ecore_Avahi_Timeout *timeout = data;
130
131 ecore_timer_freeze(timeout->timer);
132 timeout->callback((AvahiTimeout*) timeout, timeout->callback_data);
133
134 return ECORE_CALLBACK_RENEW;
135}
136
137static AvahiTimeout *
138_ecore_avahi_timeout_new(const AvahiPoll *api, const struct timeval *tv,
139 AvahiTimeoutCallback callback, void *userdata)
140{
141 Ecore_Avahi_Timeout *timeout;
142 Ecore_Avahi *ea;
143
144 ea = api->userdata;
145 timeout = calloc(1, sizeof (Ecore_Avahi_Timeout));
146 if (!timeout) return NULL;
147
148 timeout->timer = ecore_timer_add(_ecore_avahi_timeval2double(tv), _ecore_avahi_timeout_cb, timeout);
149 if (!tv) ecore_timer_freeze(timeout->timer);
150 timeout->callback = callback;
151 timeout->callback_data = userdata;
152 timeout->parent = ea;
153
154 ea->timeouts = eina_list_append(ea->timeouts, timeout);
155
156 return (AvahiTimeout*) timeout;
157}
158
159static void
160_ecore_avahi_timeout_update(AvahiTimeout *t, const struct timeval *tv)
161{
162 Ecore_Avahi_Timeout *timeout = (Ecore_Avahi_Timeout *) t;
163
164 if (tv)
165 {
166 ecore_timer_interval_set(timeout->timer, _ecore_avahi_timeval2double(tv));
167 if (ecore_timer_freeze_get(timeout->timer))
168 ecore_timer_thaw(timeout->timer);
169 }
170 else
171 {
172 ecore_timer_freeze(timeout->timer);
173 }
174}
175
176static void
177_ecore_avahi_timeout_free(AvahiTimeout *t)
178{
179 Ecore_Avahi_Timeout *timeout = (Ecore_Avahi_Timeout *) t;
180
181 ecore_timer_del(timeout->timer);
182 timeout->parent->timeouts = eina_list_remove(timeout->parent->timeouts, timeout);
183 free(timeout);
184}
185#endif
186
187EAPI Ecore_Avahi *
188ecore_avahi_add(void)
189{
190#ifdef HAVE_AVAHI
191 Ecore_Avahi *handler;
192
193 handler = calloc(1, sizeof (Ecore_Avahi));
194 if (!handler) return NULL;
195
196 handler->api.userdata = handler;
197 handler->api.watch_new = _ecore_avahi_watch_new;
198 handler->api.watch_free = _ecore_avahi_watch_free;
199 handler->api.watch_update = _ecore_avahi_watch_update;
200 handler->api.watch_get_events = _ecore_avahi_watch_get_events;
201
202 handler->api.timeout_new = _ecore_avahi_timeout_new;
203 handler->api.timeout_free = _ecore_avahi_timeout_free;
204 handler->api.timeout_update = _ecore_avahi_timeout_update;
205
206 return handler;
207#else
208 return NULL;
209#endif
210}
211
212EAPI void
213ecore_avahi_del(Ecore_Avahi *handler)
214{
215#ifdef HAVE_AVAHI
216 Ecore_Avahi_Timeout *timeout;
217 Ecore_Avahi_Watch *watch;
218
219 EINA_LIST_FREE(handler->watches, watch)
220 {
221 ecore_main_fd_handler_del(watch->handler);
222 free(watch);
223 }
224
225 EINA_LIST_FREE(handler->timeouts, timeout)
226 {
227 ecore_timer_del(timeout->timer);
228 free(timeout);
229 }
230
231 free(handler);
232#else
233 (void) handler;
234#endif
235}
236
237EAPI const void *
238ecore_avahi_poll_get(Ecore_Avahi *handler)
239{
240#ifdef HAVE_AVAHI
241 if (!handler) return NULL;
242 return &handler->api;
243#else
244 return NULL;
245#endif
246}
247