eldbus: refactor model code.
This commit is contained in:
parent
7019b8857b
commit
ddcf8d8b97
|
@ -10,7 +10,8 @@ eldbus_eolian_files = \
|
|||
lib/eldbus/eldbus_model_proxy.eo \
|
||||
lib/eldbus/eldbus_model_method.eo \
|
||||
lib/eldbus/eldbus_model_arguments.eo \
|
||||
lib/eldbus/eldbus_model_signal.eo
|
||||
lib/eldbus/eldbus_model_signal.eo \
|
||||
lib/eldbus/eldbus_model.eo
|
||||
|
||||
eldbus_eolian_c = $(eldbus_eolian_files:%.eo=%.eo.c)
|
||||
eldbus_eolian_h = $(eldbus_eolian_files:%.eo=%.eo.h) \
|
||||
|
@ -74,6 +75,7 @@ lib/eldbus/eldbus_model_proxy.c \
|
|||
lib/eldbus/eldbus_model_method.c \
|
||||
lib/eldbus/eldbus_model_arguments.c \
|
||||
lib/eldbus/eldbus_model_signal.c \
|
||||
lib/eldbus/eldbus_model.c \
|
||||
lib/eldbus/eldbus_introspection.c
|
||||
|
||||
lib_eldbus_libeldbus_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
|
|
|
@ -0,0 +1,192 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "eldbus_model_private.h"
|
||||
|
||||
#include <Ecore.h>
|
||||
#include <Eina.h>
|
||||
#include <Eldbus.h>
|
||||
|
||||
#define MY_CLASS ELDBUS_MODEL_CLASS
|
||||
#define MY_CLASS_NAME "Eldbus_Model"
|
||||
|
||||
static void
|
||||
eldbus_model_connect_do(Eldbus_Model_Data *pd)
|
||||
{
|
||||
if (pd->type == ELDBUS_CONNECTION_TYPE_ADDRESS)
|
||||
{
|
||||
if (pd->private)
|
||||
pd->connection = eldbus_address_connection_get(pd->address);
|
||||
else
|
||||
pd->connection = eldbus_private_address_connection_get(pd->address);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pd->private)
|
||||
pd->connection = eldbus_private_connection_get(pd->type);
|
||||
else
|
||||
pd->connection = eldbus_connection_get(pd->type);
|
||||
}
|
||||
|
||||
// TODO: Register for disconnection event
|
||||
if (!pd->connection)
|
||||
{
|
||||
DBG("Unable to setup a connection [%i - %s] %i",
|
||||
pd->type, pd->address, pd->private);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_eldbus_model_connect(Eo *obj EINA_UNUSED,
|
||||
Eldbus_Model_Data *pd,
|
||||
Eldbus_Connection_Type type,
|
||||
const char *address,
|
||||
Eina_Bool priv)
|
||||
{
|
||||
pd->type = type;
|
||||
pd->address = eina_stringshare_add(address);
|
||||
pd->private = priv;
|
||||
}
|
||||
|
||||
static void
|
||||
_eldbus_model_connection_set(Eo *obj EINA_UNUSED,
|
||||
Eldbus_Model_Data *pd,
|
||||
Eldbus_Connection *dbus)
|
||||
{
|
||||
eldbus_connection_ref(dbus);
|
||||
if (pd->connection) eldbus_connection_unref(pd->connection);
|
||||
pd->connection = dbus;
|
||||
}
|
||||
|
||||
static Eldbus_Connection *
|
||||
_eldbus_model_connection_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
|
||||
{
|
||||
return pd->connection;
|
||||
}
|
||||
|
||||
static Efl_Object *
|
||||
_eldbus_model_efl_object_finalize(Eo *obj, Eldbus_Model_Data *pd)
|
||||
{
|
||||
if (!pd->connection) eldbus_model_connect_do(pd);
|
||||
if (!pd->connection) return NULL;
|
||||
|
||||
return efl_finalize(efl_super(obj, ELDBUS_MODEL_CLASS));
|
||||
}
|
||||
|
||||
static void
|
||||
_eldbus_model_efl_object_destructor(Eo *obj, Eldbus_Model_Data *pd)
|
||||
{
|
||||
eina_stringshare_del(pd->unique_name);
|
||||
pd->unique_name = NULL;
|
||||
|
||||
eina_stringshare_del(pd->address);
|
||||
pd->address = NULL;
|
||||
|
||||
eldbus_connection_unref(pd->connection);
|
||||
pd->connection = NULL;
|
||||
|
||||
efl_destructor(efl_super(obj, MY_CLASS));
|
||||
}
|
||||
|
||||
static const char *
|
||||
_eldbus_model_address_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
|
||||
{
|
||||
return pd->address;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eldbus_model_private_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
|
||||
{
|
||||
return pd->private;
|
||||
}
|
||||
|
||||
static Eldbus_Connection_Type
|
||||
_eldbus_model_type_get(const Eo *obj EINA_UNUSED, Eldbus_Model_Data *pd)
|
||||
{
|
||||
return pd->type;
|
||||
}
|
||||
|
||||
static Eina_Future *
|
||||
_eldbus_model_efl_model_property_set(Eo *obj,
|
||||
Eldbus_Model_Data *pd EINA_UNUSED,
|
||||
const char *property,
|
||||
Eina_Value *value EINA_UNUSED)
|
||||
{
|
||||
Eina_Error err = EFL_MODEL_ERROR_READ_ONLY;
|
||||
|
||||
if (!strcmp(property, UNIQUE_NAME_PROPERTY))
|
||||
err = EFL_MODEL_ERROR_NOT_FOUND;
|
||||
return eina_future_rejected(efl_loop_future_scheduler_get(obj), err);
|
||||
}
|
||||
|
||||
static Eina_Value *
|
||||
_eldbus_model_efl_model_property_get(const Eo *obj,
|
||||
Eldbus_Model_Data *pd,
|
||||
const char *property)
|
||||
{
|
||||
DBG("(%p): property=%s", obj, property);
|
||||
|
||||
if (strcmp(property, UNIQUE_NAME_PROPERTY) != 0) goto on_error;
|
||||
|
||||
if (!pd->connection) eldbus_model_connect_do(pd);
|
||||
|
||||
if (pd->unique_name == NULL)
|
||||
{
|
||||
const char *unique_name;
|
||||
|
||||
unique_name = eldbus_connection_unique_name_get(pd->connection);
|
||||
if (!unique_name) goto on_error;
|
||||
pd->unique_name = eina_stringshare_add(unique_name);
|
||||
}
|
||||
|
||||
return eina_value_string_new(pd->unique_name);
|
||||
|
||||
on_error:
|
||||
return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND);
|
||||
}
|
||||
|
||||
static Eina_Array *
|
||||
_eldbus_model_efl_model_properties_get(const Eo *obj EINA_UNUSED,
|
||||
Eldbus_Model_Data *pd EINA_UNUSED)
|
||||
{
|
||||
Eina_Array *r;
|
||||
|
||||
r = eina_array_new(1);
|
||||
eina_array_push(r, UNIQUE_NAME_PROPERTY);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static Efl_Object *
|
||||
_eldbus_model_efl_model_child_add(Eo *obj EINA_UNUSED,
|
||||
Eldbus_Model_Data *pd EINA_UNUSED)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
_eldbus_model_efl_model_child_del(Eo *obj EINA_UNUSED,
|
||||
Eldbus_Model_Data *pd EINA_UNUSED,
|
||||
Efl_Object *child EINA_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
static Eina_Future *
|
||||
_eldbus_model_efl_model_children_slice_get(Eo *obj EINA_UNUSED,
|
||||
Eldbus_Model_Data *pd EINA_UNUSED,
|
||||
unsigned int start EINA_UNUSED,
|
||||
unsigned int count EINA_UNUSED)
|
||||
{
|
||||
return eina_future_rejected(efl_loop_future_scheduler_get(obj),
|
||||
EFL_MODEL_ERROR_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
_eldbus_model_efl_model_children_count_get(const Eo *obj EINA_UNUSED,
|
||||
Eldbus_Model_Data *pd EINA_UNUSED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "eldbus_model.eo.c"
|
|
@ -0,0 +1,61 @@
|
|||
import eldbus_types;
|
||||
|
||||
class Eldbus.Model (Efl.Object, Efl.Model) {
|
||||
methods {
|
||||
connect {
|
||||
[[Define connection parameters.
|
||||
|
||||
@since 1.21]]
|
||||
params {
|
||||
@in type: Eldbus.Connection.Type; [[The connection type]]
|
||||
@in address: string; [[Remote address of DBus]]
|
||||
@in priv: bool; [[Non shared dbus connection]]
|
||||
}
|
||||
}
|
||||
@property connection {
|
||||
[[Define the connection.
|
||||
|
||||
@since 1.21]]
|
||||
get { }
|
||||
set { }
|
||||
values {
|
||||
dbus: ptr(Eldbus.Connection); [[The connection]]
|
||||
}
|
||||
}
|
||||
@property type {
|
||||
[[Connection type]]
|
||||
get { }
|
||||
values {
|
||||
type: Eldbus.Connection.Type; [[Connection type]]
|
||||
}
|
||||
}
|
||||
@property address {
|
||||
[[Remote DBus address]]
|
||||
get { }
|
||||
values {
|
||||
address: string; [[Address]]
|
||||
}
|
||||
}
|
||||
@property private {
|
||||
[[Indicate if the DBus connection is shared or private]]
|
||||
get { }
|
||||
values {
|
||||
private_: bool; [[Private DBus connection]]
|
||||
}
|
||||
}
|
||||
}
|
||||
implements {
|
||||
Efl.Object.finalize;
|
||||
Efl.Object.destructor;
|
||||
Efl.Model.property { get; set; }
|
||||
Efl.Model.properties { get; }
|
||||
Efl.Model.child_add;
|
||||
Efl.Model.child_del;
|
||||
Efl.Model.children_slice_get;
|
||||
Efl.Model.children_count { get; }
|
||||
}
|
||||
constructors {
|
||||
.connect;
|
||||
.connection;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,8 @@ struct _Eldbus_Property_Promise
|
|||
Efl_Promise* promise;
|
||||
};
|
||||
|
||||
#define UNIQUE_NAME_PROPERTY "unique_name"
|
||||
|
||||
/* logging support */
|
||||
extern int eldbus_model_log_dom;
|
||||
|
||||
|
|
Loading…
Reference in New Issue