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.
This commit is contained in:
Tom Hacohen 2014-08-28 14:17:16 +01:00
parent 4cc893f0af
commit 0c9a1d8a99
8 changed files with 137 additions and 54 deletions

View File

@ -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 += \

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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);
Ecore_Con_Server_Data *svr = eo_data_scope_get(obj, ECORE_CON_SERVER_CLASS);
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"

View File

@ -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.
*/

View File

@ -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;
}
}

View File

@ -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;