summaryrefslogtreecommitdiff
path: root/src/lib/ecore_con/efl_net_dialer_simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ecore_con/efl_net_dialer_simple.c')
-rw-r--r--src/lib/ecore_con/efl_net_dialer_simple.c367
1 files changed, 367 insertions, 0 deletions
diff --git a/src/lib/ecore_con/efl_net_dialer_simple.c b/src/lib/ecore_con/efl_net_dialer_simple.c
new file mode 100644
index 0000000..178fe5d
--- /dev/null
+++ b/src/lib/ecore_con/efl_net_dialer_simple.c
@@ -0,0 +1,367 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Ecore.h"
6#include "Ecore_Con.h"
7#include "ecore_con_private.h"
8
9typedef struct
10{
11 const Efl_Class *inner_class;
12 Eina_Stringshare *proxy_url;
13 double dial_timeout;
14 double inactivity_timeout;
15 size_t max_queue_size_input;
16 size_t max_queue_size_output;
17 size_t read_chunk_size;
18 Eina_Slice line_delimiter;
19 struct {
20 Eina_Bool proxy_url;
21 Eina_Bool dial_timeout;
22 Eina_Bool inactivity_timeout;
23 Eina_Bool max_queue_size_input;
24 Eina_Bool max_queue_size_output;
25 Eina_Bool read_chunk_size;
26 Eina_Bool line_delimiter;
27 } pending;
28} Efl_Net_Dialer_Simple_Data;
29
30#define MY_CLASS EFL_NET_DIALER_SIMPLE_CLASS
31
32static void
33_efl_net_dialer_simple_inner_io_resolved(void *data, const Efl_Event *event)
34{
35 Eo *o = data;
36 efl_event_callback_call(o, EFL_NET_DIALER_EVENT_RESOLVED, event->info);
37}
38
39static void
40_efl_net_dialer_simple_inner_io_error(void *data, const Efl_Event *event)
41{
42 Eo *o = data;
43 efl_event_callback_call(o, EFL_NET_DIALER_EVENT_ERROR, event->info);
44 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_ERROR, event->info);
45}
46
47static void
48_efl_net_dialer_simple_inner_io_connected(void *data, const Efl_Event *event)
49{
50 Eo *o = data;
51 efl_event_callback_call(o, EFL_NET_DIALER_EVENT_CONNECTED, event->info);
52}
53
54EFL_CALLBACKS_ARRAY_DEFINE(_efl_net_dialer_simple_inner_io_cbs,
55 { EFL_NET_DIALER_EVENT_RESOLVED, _efl_net_dialer_simple_inner_io_resolved },
56 { EFL_NET_DIALER_EVENT_ERROR, _efl_net_dialer_simple_inner_io_error },
57 { EFL_NET_DIALER_EVENT_CONNECTED, _efl_net_dialer_simple_inner_io_connected });
58
59EOLIAN static Efl_Object *
60_efl_net_dialer_simple_efl_object_finalize(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
61{
62 if (efl_io_buffered_stream_inner_io_get(o)) goto end;
63
64 if (!pd->inner_class)
65 {
66 ERR("no valid dialer was set with efl_io_buffered_stream_inner_io_set() and no class set with efl_net_dialer_simple_inner_class_set()!");
67 return NULL;
68 }
69 else
70 {
71 Eo *dialer = efl_add(pd->inner_class, o);
72 EINA_SAFETY_ON_NULL_RETURN_VAL(dialer, NULL);
73
74 if (!efl_isa(dialer, EFL_NET_DIALER_INTERFACE))
75 {
76 ERR("class %s=%p doesn't implement Efl.Net.Dialer interface!", efl_class_name_get(pd->inner_class), pd->inner_class);
77 efl_del(dialer);
78 return NULL;
79 }
80 DBG("created new inner dialer %p (%s)", dialer, efl_class_name_get(efl_class_get(dialer)));
81
82 efl_io_buffered_stream_inner_io_set(o, dialer);
83 }
84
85 end:
86 return efl_finalize(efl_super(o, MY_CLASS));
87}
88
89EOLIAN static void
90_efl_net_dialer_simple_efl_object_destructor(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
91{
92 Eo *inner_io;
93
94 if (pd->inner_class) pd->inner_class = NULL;
95
96 eina_stringshare_replace(&pd->proxy_url, NULL);
97 if (pd->line_delimiter.mem)
98 {
99 free((void *)pd->line_delimiter.mem);
100 pd->line_delimiter.mem = NULL;
101 }
102
103 inner_io = efl_io_buffered_stream_inner_io_get(o);
104 if (inner_io)
105 {
106 efl_event_callback_array_del(inner_io, _efl_net_dialer_simple_inner_io_cbs(), o);
107 if (efl_parent_get(inner_io) == o)
108 efl_parent_set(inner_io, NULL);
109 }
110
111 efl_destructor(efl_super(o, EFL_NET_DIALER_SIMPLE_CLASS));
112}
113
114EOLIAN static void
115_efl_net_dialer_simple_efl_io_buffered_stream_inner_io_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, Efl_Object *io)
116{
117 EINA_SAFETY_ON_FALSE_RETURN(efl_isa(io, EFL_NET_DIALER_INTERFACE));
118 efl_io_buffered_stream_inner_io_set(efl_super(o, MY_CLASS), io);
119 efl_event_callback_array_add(io, _efl_net_dialer_simple_inner_io_cbs(), o);
120
121 /* apply pending dialer values */
122 if (pd->pending.proxy_url)
123 {
124 pd->pending.proxy_url = EINA_FALSE;
125 efl_net_dialer_proxy_set(io, pd->proxy_url);
126 eina_stringshare_replace(&pd->proxy_url, NULL);
127 }
128 if (pd->pending.dial_timeout)
129 {
130 pd->pending.dial_timeout = EINA_FALSE;
131 efl_net_dialer_timeout_dial_set(io, pd->dial_timeout);
132 }
133
134 /* apply pending io buffered stream (own) values */
135 if (pd->pending.inactivity_timeout)
136 {
137 pd->pending.inactivity_timeout = EINA_FALSE;
138 efl_io_buffered_stream_inactivity_timeout_set(o, pd->inactivity_timeout);
139 }
140 if (pd->pending.max_queue_size_input)
141 {
142 pd->pending.max_queue_size_input = EINA_FALSE;
143 efl_io_buffered_stream_max_queue_size_input_set(o, pd->max_queue_size_input);
144 }
145 if (pd->pending.max_queue_size_output)
146 {
147 pd->pending.max_queue_size_output = EINA_FALSE;
148 efl_io_buffered_stream_max_queue_size_output_set(o, pd->max_queue_size_output);
149 }
150 if (pd->pending.read_chunk_size)
151 {
152 pd->pending.read_chunk_size = EINA_FALSE;
153 efl_io_buffered_stream_read_chunk_size_set(o, pd->read_chunk_size);
154 }
155 if (pd->pending.line_delimiter)
156 {
157 pd->pending.line_delimiter = EINA_FALSE;
158 efl_io_buffered_stream_line_delimiter_set(o, &pd->line_delimiter);
159 free((void *)pd->line_delimiter.mem);
160 pd->line_delimiter.mem = NULL;
161 }
162}
163
164EOLIAN static Eina_Error
165_efl_net_dialer_simple_efl_net_dialer_dial(Eo *o, Efl_Net_Dialer_Simple_Data *pd EINA_UNUSED, const char *address)
166{
167 return efl_net_dialer_dial(efl_io_buffered_stream_inner_io_get(o), address);
168}
169
170EOLIAN static const char *
171_efl_net_dialer_simple_efl_net_dialer_address_dial_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd EINA_UNUSED)
172{
173 return efl_net_dialer_address_dial_get(efl_io_buffered_stream_inner_io_get(o));
174}
175
176EOLIAN static Eina_Bool
177_efl_net_dialer_simple_efl_net_dialer_connected_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd EINA_UNUSED)
178{
179 return efl_net_dialer_connected_get(efl_io_buffered_stream_inner_io_get(o));
180}
181
182EOLIAN static void
183_efl_net_dialer_simple_efl_net_dialer_proxy_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, const char *proxy_url)
184{
185 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
186
187 if (!inner_io)
188 {
189 eina_stringshare_replace(&pd->proxy_url, proxy_url);
190 pd->pending.proxy_url = EINA_TRUE;
191 return;
192 }
193 efl_net_dialer_proxy_set(inner_io, proxy_url);
194}
195
196EOLIAN static const char *
197_efl_net_dialer_simple_efl_net_dialer_proxy_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
198{
199 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
200 if (!inner_io) return pd->proxy_url;
201 return efl_net_dialer_proxy_get(inner_io);
202}
203
204EOLIAN static void
205_efl_net_dialer_simple_efl_net_dialer_timeout_dial_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, double seconds)
206{
207 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
208
209 if (!inner_io)
210 {
211 pd->dial_timeout = seconds;
212 pd->pending.dial_timeout = EINA_TRUE;
213 return;
214 }
215 efl_net_dialer_timeout_dial_set(inner_io, seconds);
216}
217
218EOLIAN static double
219_efl_net_dialer_simple_efl_net_dialer_timeout_dial_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
220{
221 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
222 if (!inner_io) return pd->dial_timeout;
223 return efl_net_dialer_timeout_dial_get(inner_io);
224}
225
226EOLIAN static void
227_efl_net_dialer_simple_efl_io_buffered_stream_inactivity_timeout_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, double seconds)
228{
229 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
230
231 if (!inner_io)
232 {
233 pd->inactivity_timeout = seconds;
234 pd->pending.inactivity_timeout = EINA_TRUE;
235 return;
236 }
237 efl_io_buffered_stream_inactivity_timeout_set(efl_super(o, MY_CLASS), seconds);
238}
239
240EOLIAN static double
241_efl_net_dialer_simple_efl_io_buffered_stream_inactivity_timeout_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
242{
243 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
244 if (!inner_io) return pd->inactivity_timeout;
245 return efl_io_buffered_stream_inactivity_timeout_get(efl_super(o, MY_CLASS));
246}
247
248EOLIAN static void
249_efl_net_dialer_simple_efl_io_buffered_stream_max_queue_size_input_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, size_t size)
250{
251 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
252
253 if (!inner_io)
254 {
255 pd->max_queue_size_input = size;
256 pd->pending.max_queue_size_input = EINA_TRUE;
257 return;
258 }
259 efl_io_buffered_stream_max_queue_size_input_set(efl_super(o, MY_CLASS), size);
260}
261
262EOLIAN static size_t
263_efl_net_dialer_simple_efl_io_buffered_stream_max_queue_size_input_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
264{
265 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
266 if (!inner_io) return pd->max_queue_size_input;
267 return efl_io_buffered_stream_max_queue_size_input_get(efl_super(o, MY_CLASS));
268}
269
270EOLIAN static void
271_efl_net_dialer_simple_efl_io_buffered_stream_max_queue_size_output_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, size_t size)
272{
273 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
274
275 if (!inner_io)
276 {
277 pd->max_queue_size_output = size;
278 pd->pending.max_queue_size_output = EINA_TRUE;
279 return;
280 }
281 efl_io_buffered_stream_max_queue_size_output_set(efl_super(o, MY_CLASS), size);
282}
283
284EOLIAN static size_t
285_efl_net_dialer_simple_efl_io_buffered_stream_max_queue_size_output_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
286{
287 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
288 if (!inner_io) return pd->max_queue_size_output;
289 return efl_io_buffered_stream_max_queue_size_output_get(efl_super(o, MY_CLASS));
290}
291
292EOLIAN static void
293_efl_net_dialer_simple_efl_io_buffered_stream_read_chunk_size_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, size_t size)
294{
295 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
296
297 if (!inner_io)
298 {
299 pd->read_chunk_size = size;
300 pd->pending.read_chunk_size = EINA_TRUE;
301 return;
302 }
303 efl_io_buffered_stream_read_chunk_size_set(efl_super(o, MY_CLASS), size);
304}
305
306EOLIAN static size_t
307_efl_net_dialer_simple_efl_io_buffered_stream_read_chunk_size_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
308{
309 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
310 if (!inner_io) return pd->read_chunk_size;
311 return efl_io_buffered_stream_read_chunk_size_get(efl_super(o, MY_CLASS));
312}
313
314
315EOLIAN static void
316_efl_net_dialer_simple_efl_io_buffered_stream_line_delimiter_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, const Eina_Slice *slice)
317{
318 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
319
320 if (!inner_io)
321 {
322 free((void *)pd->line_delimiter.mem);
323 if ((!slice) || (!slice->len))
324 {
325 pd->line_delimiter.mem = NULL;
326 pd->line_delimiter.len = 0;
327 }
328 else
329 {
330 char *mem;
331 pd->line_delimiter.mem = mem = malloc(slice->len + 1);
332 EINA_SAFETY_ON_NULL_RETURN(pd->line_delimiter.mem);
333 memcpy(mem, slice->mem, slice->len);
334 mem[slice->len] = '\0';
335 pd->line_delimiter.len = slice->len;
336 }
337
338 pd->pending.line_delimiter = EINA_TRUE;
339 return;
340 }
341 efl_io_buffered_stream_line_delimiter_set(efl_super(o, MY_CLASS), slice);
342}
343
344EOLIAN static const Eina_Slice *
345_efl_net_dialer_simple_efl_io_buffered_stream_line_delimiter_get(Eo *o, Efl_Net_Dialer_Simple_Data *pd)
346{
347 Eo *inner_io = efl_io_buffered_stream_inner_io_get(o);
348 if (!inner_io) return &pd->line_delimiter;
349 return efl_io_buffered_stream_line_delimiter_get(efl_super(o, MY_CLASS));
350}
351
352EOLIAN static void
353_efl_net_dialer_simple_inner_class_set(Eo *o, Efl_Net_Dialer_Simple_Data *pd, const Efl_Class *klass)
354{
355 EINA_SAFETY_ON_TRUE_RETURN(efl_finalized_get(o));
356 EINA_SAFETY_ON_NULL_RETURN(klass);
357 pd->inner_class = klass;
358 DBG("%p inner_class=%p %s", o, klass, efl_class_name_get(klass));
359}
360
361EOLIAN static const Efl_Class *
362_efl_net_dialer_simple_inner_class_get(Eo *o EINA_UNUSED, Efl_Net_Dialer_Simple_Data *pd)
363{
364 return pd->inner_class;
365}
366
367#include "efl_net_dialer_simple.eo.c"