eldbus: Make properties_monitor() return a boolean indicating if props are already cached

This commit is contained in:
José Roberto de Souza 2013-08-30 10:15:35 -03:00
parent 8b69231897
commit 928f0e4f83
2 changed files with 25 additions and 19 deletions

View File

@ -98,9 +98,14 @@ EAPI Eldbus_Pending *eldbus_object_introspect(Eldbus_Object *obj, Eldbus_
* After enable you can call eldbus_proxy_property_local_get() or
* eldbus_proxy_property_local_get_all() to get cached properties.
*
* @note After enable, it will asynchrony get the properties values.
* @param proxy bus+path+interface that the properties belong
* @param enable enable or disable properties monitor
* @return EINA_TRUE if already have cached properties
* EINA_FALSE if it will asynchrony get the properties.
* You should listen for a ELDBUS_PROXY_EVENT_PROPERTY_LOADED
* to know when properties finish to load.
*/
EAPI void eldbus_proxy_properties_monitor(Eldbus_Proxy *proxy, Eina_Bool enable) EINA_ARG_NONNULL(1);
EAPI Eina_Bool eldbus_proxy_properties_monitor(Eldbus_Proxy *proxy, Eina_Bool enable) EINA_ARG_NONNULL(1);
EAPI Eldbus_Pending *eldbus_proxy_property_get(Eldbus_Proxy *proxy, const char *name, Eldbus_Message_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3);
EAPI Eldbus_Pending *eldbus_proxy_property_set(Eldbus_Proxy *proxy, const char *name, const char *sig, const void *value, Eldbus_Message_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3, 4);

View File

@ -757,28 +757,15 @@ _props_get_all(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EI
&event);
}
EAPI void
EAPI Eina_Bool
eldbus_proxy_properties_monitor(Eldbus_Proxy *proxy, Eina_Bool enable)
{
ELDBUS_PROXY_CHECK(proxy);
ELDBUS_PROXY_CHECK_RETVAL(proxy, EINA_FALSE);
if (proxy->monitor_enabled == enable)
return;
return proxy->props ? !!eina_hash_population(proxy->props) : EINA_FALSE;
proxy->monitor_enabled = enable;
if (enable)
{
if (!proxy->props)
proxy->props = eina_hash_string_superfast_new(_props_cache_free);
eldbus_proxy_property_get_all(proxy, _props_get_all, proxy);
if (proxy->properties_changed)
return;
proxy->properties_changed =
eldbus_proxy_properties_changed_callback_add(proxy,
_properties_changed,
proxy);
}
else
if (!enable)
{
Eldbus_Proxy_Context_Event *ce_prop_changed, *ce_prop_removed;
ce_prop_changed = proxy->event_handlers + ELDBUS_PROXY_EVENT_PROPERTY_CHANGED;
@ -794,7 +781,21 @@ eldbus_proxy_properties_monitor(Eldbus_Proxy *proxy, Eina_Bool enable)
eldbus_signal_handler_unref(proxy->properties_changed);
proxy->properties_changed = NULL;
}
return EINA_TRUE;
}
if (!proxy->props)
proxy->props = eina_hash_string_superfast_new(_props_cache_free);
eldbus_proxy_property_get_all(proxy, _props_get_all, proxy);
if (proxy->properties_changed)
return !!eina_hash_population(proxy->props);
proxy->properties_changed =
eldbus_proxy_properties_changed_callback_add(proxy,
_properties_changed,
proxy);
return !!eina_hash_population(proxy->props);
}
EAPI Eina_Value *