aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2014-08-28 14:17:16 +0100
committerTom Hacohen <tom@stosb.com>2014-09-01 12:35:22 +0100
commit0c9a1d8a99e8807833bdd320bd8cdacff26a0e52 (patch)
tree2a4176121a55a0936e6a639e8c6dd67b640dcb1d
parentevas/render: don't make children active unless the active object has the prox... (diff)
downloadefl-0c9a1d8a99e8807833bdd320bd8cdacff26a0e52.tar.gz
Ecore con: Add Connector class (the connecting variant of server).
This change also consists of cleaning up the server class and adding a constructor and a finalizer to it.
-rw-r--r--src/Makefile_Ecore_Con.am4
-rw-r--r--src/lib/ecore_con/Ecore_Con.h2
-rw-r--r--src/lib/ecore_con/Ecore_Con_Eo.h1
-rw-r--r--src/lib/ecore_con/Ecore_Con_Legacy.h1
-rw-r--r--src/lib/ecore_con/ecore_con.c148
-rw-r--r--src/lib/ecore_con/ecore_con_base.eo7
-rw-r--r--src/lib/ecore_con/ecore_con_connector.eo8
-rw-r--r--src/lib/ecore_con/ecore_con_server.eo18
8 files changed, 136 insertions, 53 deletions
diff --git a/src/Makefile_Ecore_Con.am b/src/Makefile_Ecore_Con.am
index 8eb5d475ac..3fecaa2fef 100644
--- a/src/Makefile_Ecore_Con.am
+++ b/src/Makefile_Ecore_Con.am
@@ -8,6 +8,8 @@ ecorecon_eobuiltheaders = \
lib/ecore_con/ecore_con_client.eo.legacy.h \
lib/ecore_con/ecore_con_server.eo.h \
lib/ecore_con/ecore_con_server.eo.legacy.h \
+ lib/ecore_con/ecore_con_connector.eo.h \
+ lib/ecore_con/ecore_con_connector.eo.legacy.h \
lib/ecore_con/ecore_con_url.eo.h \
lib/ecore_con/ecore_con_url.eo.legacy.h
@@ -16,6 +18,7 @@ BUILT_SOURCES += \
lib/ecore_con/ecore_con_base.eo.c \
lib/ecore_con/ecore_con_client.eo.c \
lib/ecore_con/ecore_con_server.eo.c \
+ lib/ecore_con/ecore_con_connector.eo.c \
lib/ecore_con/ecore_con_url.eo.c
ecoreconeolianfilesdir = $(datadir)/eolian/include/ecore-@VMAJ@
@@ -23,6 +26,7 @@ ecoreconeolianfiles_DATA = \
lib/ecore_con/ecore_con_base.eo \
lib/ecore_con/ecore_con_client.eo \
lib/ecore_con/ecore_con_server.eo \
+ lib/ecore_con/ecore_con_connector.eo \
lib/ecore_con/ecore_con_url.eo
EXTRA_DIST += \
diff --git a/src/lib/ecore_con/Ecore_Con.h b/src/lib/ecore_con/Ecore_Con.h
index 06f7bfdcad..4e012c527f 100644
--- a/src/lib/ecore_con/Ecore_Con.h
+++ b/src/lib/ecore_con/Ecore_Con.h
@@ -232,6 +232,8 @@ typedef Eo Ecore_Con;
*/
typedef struct Ecore_Con_Socks Ecore_Con_Socks;
+typedef enum _Ecore_Con_Type Ecore_Con_Type;
+
#ifndef EFL_NOLEGACY_API_SUPPORT
#include "Ecore_Con_Legacy.h"
#endif
diff --git a/src/lib/ecore_con/Ecore_Con_Eo.h b/src/lib/ecore_con/Ecore_Con_Eo.h
index f6cbcb801f..aa3719a018 100644
--- a/src/lib/ecore_con/Ecore_Con_Eo.h
+++ b/src/lib/ecore_con/Ecore_Con_Eo.h
@@ -1,4 +1,5 @@
#include "ecore_con_base.eo.h"
#include "ecore_con_server.eo.h"
+#include "ecore_con_connector.eo.h"
#include "ecore_con_client.eo.h"
#include "ecore_con_url.eo.h"
diff --git a/src/lib/ecore_con/Ecore_Con_Legacy.h b/src/lib/ecore_con/Ecore_Con_Legacy.h
index 150e4dfa3e..11fa2d1277 100644
--- a/src/lib/ecore_con/Ecore_Con_Legacy.h
+++ b/src/lib/ecore_con/Ecore_Con_Legacy.h
@@ -1,4 +1,5 @@
#include "ecore_con_base.eo.legacy.h"
#include "ecore_con_server.eo.legacy.h"
+#include "ecore_con_connector.eo.legacy.h"
#include "ecore_con_client.eo.legacy.h"
#include "ecore_con_url.eo.legacy.h"
diff --git a/src/lib/ecore_con/ecore_con.c b/src/lib/ecore_con/ecore_con.c
index b4346b1f30..1bc3ed6ff8 100644
--- a/src/lib/ecore_con/ecore_con.c
+++ b/src/lib/ecore_con/ecore_con.c
@@ -107,6 +107,14 @@ static void _ecore_con_lookup_done(void *data,
static const char *_ecore_con_pretty_ip(struct sockaddr *client_addr);
+#define EO_CONSTRUCTOR_CHECK_RETURN(obj) do { \
+ if (eo_do(obj, eo_finalized_get())) \
+ { \
+ ERR("This function is only allowed during construction."); \
+ return; \
+ } \
+} while (0)
+
#ifdef HAVE_SYSTEMD
int sd_fd_index = 0;
int sd_fd_max = 0;
@@ -282,33 +290,21 @@ _ecore_con_base_lookup(Eo *kls_obj EINA_UNUSED, void *pd EINA_UNUSED, const char
if (!name || !done_cb)
return EINA_FALSE;
- obj = eo_add(ECORE_CON_SERVER_CLASS, NULL);
- Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
- if (!svr)
- return EINA_FALSE;
+ obj = eo_add(ECORE_CON_CONNECTOR_CLASS, NULL,
+ ecore_con_server_obj_connection_type_set(ECORE_CON_REMOTE_TCP),
+ ecore_con_server_obj_name_set(name),
+ ecore_con_obj_port_set(1025));
lk = malloc(sizeof (Ecore_Con_Lookup));
if (!lk)
{
- free(svr);
return EINA_FALSE;
}
lk->done_cb = done_cb;
lk->data = data;
- svr->name = strdup(name);
- if (!svr->name)
- goto on_error;
-
- svr->type = ECORE_CON_REMOTE_TCP;
- svr->port = 1025;
- svr->data = lk;
- svr->created = EINA_TRUE;
- svr->reject_excess_clients = EINA_FALSE;
- svr->client_limit = -1;
- svr->clients = NULL;
- svr->ppid = getpid();
+ ecore_con_server_data_set(obj, lk);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
@@ -319,12 +315,10 @@ _ecore_con_base_lookup(Eo *kls_obj EINA_UNUSED, void *pd EINA_UNUSED, const char
hints.ai_next = NULL;
hints.ai_addr = NULL;
- if (ecore_con_info_get(obj, _ecore_con_lookup_done, svr,
+ if (ecore_con_info_get(obj, _ecore_con_lookup_done, obj,
&hints))
return EINA_TRUE;
- free(svr->name);
-on_error:
free(lk);
eo_del(obj);
return EINA_FALSE;
@@ -350,32 +344,46 @@ ecore_con_server_add(Ecore_Con_Type compl_type,
const void *data)
{
Ecore_Con_Server *obj;
- Ecore_Con_Type type;
-
- if (port < 0 || !name)
- return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */
/* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
/* remote system socket: TCP/IP: [name]:[port] */
- obj = eo_add(ECORE_CON_SERVER_CLASS, NULL);
- Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
+ obj = eo_add(ECORE_CON_SERVER_CLASS, NULL,
+ ecore_con_server_obj_connection_type_set(compl_type),
+ ecore_con_server_obj_name_set(name),
+ ecore_con_obj_port_set(port));
+
+ ecore_con_server_data_set(obj, (void *) data);
+
+ return obj;
+}
+
+EOLIAN static void
+_ecore_con_server_eo_base_constructor(Ecore_Con_Server *obj, Ecore_Con_Server_Data *svr)
+{
+ eo_do_super(obj, ECORE_CON_SERVER_CLASS, eo_constructor());
svr->fd = -1;
- svr->start_time = ecore_time_get();
- svr->type = compl_type;
- svr->port = port;
- svr->data = (void *)data;
- svr->created = EINA_TRUE;
- svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
svr->reject_excess_clients = EINA_FALSE;
svr->client_limit = -1;
svr->clients = NULL;
+}
+
+EOLIAN static Eo *
+_ecore_con_server_eo_base_finalize(Ecore_Con_Server *obj, Ecore_Con_Server_Data *svr)
+{
+ Ecore_Con_Type compl_type = svr->type;
+ Ecore_Con_Type type;
+
+ eo_do_super(obj, ECORE_CON_SERVER_CLASS, eo_finalize());
+
+ svr->created = EINA_TRUE;
svr->ppid = getpid();
+ svr->start_time = ecore_time_get();
+ svr->use_cert = (svr->type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
servers = eina_list_append(servers, obj);
- svr->name = strdup(name);
- if (!svr->name)
+ if (!svr->name || (svr->port < 0))
goto error;
if (ecore_con_ssl_server_prepare(obj, compl_type & ECORE_CON_SSL))
@@ -426,31 +434,35 @@ ecore_con_server_connect(Ecore_Con_Type compl_type,
const void *data)
{
Ecore_Con_Server *obj;
- Ecore_Con_Type type;
-
- if ((!name) || (!name[0]))
- return NULL;
/* local user socket: FILE: ~/.ecore/[name]/[port] */
/* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
/* remote system socket: TCP/IP: [name]:[port] */
- obj = eo_add(ECORE_CON_SERVER_CLASS, NULL);
+ obj = eo_add(ECORE_CON_CONNECTOR_CLASS, NULL,
+ ecore_con_server_obj_connection_type_set(compl_type),
+ ecore_con_server_obj_name_set(name),
+ ecore_con_obj_port_set(port));
+
+ ecore_con_server_data_set(obj, (void *) data);
+
+ return obj;
+}
+
+EOLIAN static Eo *
+_ecore_con_connector_eo_base_finalize(Ecore_Con_Server *obj, void *pd EINA_UNUSED)
+{
Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
+ Ecore_Con_Type compl_type = svr->type;
+ Ecore_Con_Type type;
+
+ /* XXX: We intentionally put SERVER class here and not connector, as we'd
+ * like to skip that one. */
+ eo_do_super(obj, ECORE_CON_SERVER_CLASS, eo_finalize());
- svr->fd = -1;
- svr->type = compl_type;
- svr->port = port;
- svr->data = (void *)data;
- svr->created = EINA_FALSE;
svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
svr->disable_proxy = (compl_type & ECORE_CON_SUPER_SSL & ECORE_CON_NO_PROXY) == ECORE_CON_NO_PROXY;
- svr->reject_excess_clients = EINA_FALSE;
- svr->clients = NULL;
- svr->client_limit = -1;
-
servers = eina_list_append(servers, obj);
- svr->name = strdup(name);
- if (!svr->name)
+ if (!svr->name || !(svr->name[0]))
goto error;
type = compl_type & ECORE_CON_TYPE;
@@ -479,7 +491,7 @@ ecore_con_server_connect(Ecore_Con_Type compl_type,
(type == ECORE_CON_REMOTE_CORK) ||
(type == ECORE_CON_REMOTE_UDP) ||
(type == ECORE_CON_REMOTE_BROADCAST)) &&
- (port < 0), error);
+ (svr->port < 0), error);
if ((type == ECORE_CON_LOCAL_USER) ||
(type == ECORE_CON_LOCAL_SYSTEM) ||
@@ -594,6 +606,31 @@ _ecore_con_server_clients_get(Eo *obj EINA_UNUSED, Ecore_Con_Server_Data *svr)
return svr->clients;
}
+EOLIAN static void
+_ecore_con_server_connection_type_set(Eo *obj, Ecore_Con_Server_Data *svr, Ecore_Con_Type type)
+{
+ EO_CONSTRUCTOR_CHECK_RETURN(obj);
+
+ svr->type = type;
+}
+
+EOLIAN static Ecore_Con_Type
+_ecore_con_server_connection_type_get(Eo *obj EINA_UNUSED, Ecore_Con_Server_Data *svr)
+{
+ return svr->type;
+}
+
+EOLIAN static void
+_ecore_con_server_name_set(Eo *obj EINA_UNUSED, Ecore_Con_Server_Data *svr, const char *name)
+{
+ EO_CONSTRUCTOR_CHECK_RETURN(obj);
+
+ if (svr->name)
+ free(svr->name);
+
+ svr->name = strdup(name);
+}
+
EOLIAN static const char *
_ecore_con_server_name_get(Eo *obj EINA_UNUSED, Ecore_Con_Server_Data *svr)
{
@@ -606,6 +643,14 @@ ecore_con_server_port_get(const Ecore_Con *obj)
return eo_do((Ecore_Con *)obj, ecore_con_obj_port_get());
}
+EOLIAN static void
+_ecore_con_server_ecore_con_base_port_set(Eo *obj EINA_UNUSED, Ecore_Con_Server_Data *svr, int port)
+{
+ EO_CONSTRUCTOR_CHECK_RETURN(obj);
+
+ svr->port = port;
+}
+
EOLIAN static int
_ecore_con_server_ecore_con_base_port_get(Eo *obj EINA_UNUSED, Ecore_Con_Server_Data *svr)
{
@@ -2781,3 +2826,4 @@ _ecore_con_lookup_done(void *data,
#include "ecore_con_base.eo.c"
#include "ecore_con_client.eo.c"
#include "ecore_con_server.eo.c"
+#include "ecore_con_connector.eo.c"
diff --git a/src/lib/ecore_con/ecore_con_base.eo b/src/lib/ecore_con/ecore_con_base.eo
index d1e38458d3..e6eed1b7e5 100644
--- a/src/lib/ecore_con/ecore_con_base.eo
+++ b/src/lib/ecore_con/ecore_con_base.eo
@@ -38,6 +38,9 @@ abstract Ecore.Con.Base (Eo.Base) {
* @brief Return the port that the obj is connected to
*
*/
+ set {
+ legacy: null;
+ }
get {
legacy: null;
}
@@ -195,7 +198,9 @@ type Ecore_Con_Dns_Cb: func void (const(char) *canonname,
* Add events (to all of the ecore con stuff, e.g url).
* Make server the father of the client - make sure I don't leak references.
*
-* Still need to add constructors to server/client, and most likely migrate ecore_con_eet.
+* Still need to add constructor client, and most likely migrate ecore_con_eet.
*
* Split server to two classes, listener and connector (or w/e).
+*
+* Mark the constructing properties all around.
*/
diff --git a/src/lib/ecore_con/ecore_con_connector.eo b/src/lib/ecore_con/ecore_con_connector.eo
new file mode 100644
index 0000000000..9952637c94
--- /dev/null
+++ b/src/lib/ecore_con/ecore_con_connector.eo
@@ -0,0 +1,8 @@
+class Ecore.Con.Connector (Ecore.Con.Server) {
+ legacy_prefix: null;
+ eo_prefix: ecore_con_connector_obj;
+ data: null;
+ implements {
+ Eo.Base.finalize;
+ }
+}
diff --git a/src/lib/ecore_con/ecore_con_server.eo b/src/lib/ecore_con/ecore_con_server.eo
index 8fbd0166a0..83151cc10f 100644
--- a/src/lib/ecore_con/ecore_con_server.eo
+++ b/src/lib/ecore_con/ecore_con_server.eo
@@ -1,4 +1,3 @@
-/* FIXME: make abstract. */
class Ecore.Con.Server (Ecore.Con.Base) {
eo_prefix: ecore_con_server_obj;
properties {
@@ -8,6 +7,9 @@ class Ecore.Con.Server (Ecore.Con.Base) {
*
* The name returned is the name used to connect on this server.
*/
+ set {
+ legacy: null;
+ }
get {
}
values {
@@ -52,11 +54,25 @@ class Ecore.Con.Server (Ecore.Con.Base) {
const(Eina_List <const(Ecore.Con.Client) *>) *clients; /*@ The list of clients on this server. */
}
}
+ connection_type {
+ get {
+ legacy: null;
+ }
+ set {
+ legacy: null;
+ }
+ values {
+ Ecore_Con_Type conn_type;
+ }
+ }
}
implements {
+ Eo.Base.constructor;
Eo.Base.destructor;
+ Eo.Base.finalize;
Ecore.Con.Base.ip.get;
Ecore.Con.Base.uptime.get;
+ Ecore.Con.Base.port.set;
Ecore.Con.Base.port.get;
Ecore.Con.Base.fd.get;
Ecore.Con.Base.connected.get;