summaryrefslogtreecommitdiff
path: root/src/lib/eldbus/eldbus_service.c
diff options
context:
space:
mode:
authorJosé Roberto de Souza <jose.souza@intel.com>2013-08-23 16:54:12 -0300
committerJosé Roberto de Souza <jose.souza@intel.com>2013-08-26 15:16:18 -0300
commit36b71d867c6f6280af0955ae04e326afbecb7c22 (patch)
tree0b17ef796b05b563270f8e0b18aaab6212d35456 /src/lib/eldbus/eldbus_service.c
parent072c140201a3000aadd279f33f7529a0da332337 (diff)
eldbus: Send property changed signals before close connection
Diffstat (limited to 'src/lib/eldbus/eldbus_service.c')
-rw-r--r--src/lib/eldbus/eldbus_service.c207
1 files changed, 108 insertions, 99 deletions
diff --git a/src/lib/eldbus/eldbus_service.c b/src/lib/eldbus/eldbus_service.c
index 40a86b07d0..9402e3327d 100644
--- a/src/lib/eldbus/eldbus_service.c
+++ b/src/lib/eldbus/eldbus_service.c
@@ -974,6 +974,101 @@ fail:
974 return NULL; 974 return NULL;
975} 975}
976 976
977static Eina_Bool
978_idler_propschanged(void *data)
979{
980 Eldbus_Service_Interface *iface = data;
981 Eldbus_Message *msg;
982 Eldbus_Message_Iter *main_iter, *dict, *array_invalidate;
983 Eina_Hash *added = NULL;
984 Property *prop;
985
986 iface->idler_propschanged = NULL;
987
988 added = eina_hash_string_small_new(NULL);
989 msg = eldbus_message_signal_new(iface->obj->path, properties_iface->name,
990 properties_iface->signals[0].name);
991 EINA_SAFETY_ON_NULL_GOTO(msg, error);
992
993 main_iter = eldbus_message_iter_get(msg);
994 if (!eldbus_message_iter_arguments_append(main_iter, "sa{sv}", iface->name, &dict))
995 {
996 eldbus_message_unref(msg);
997 goto error;
998 }
999
1000 if (!iface->props_changed)
1001 goto invalidate;
1002 while ((prop = eina_array_pop(iface->props_changed)))
1003 {
1004 Eldbus_Message_Iter *entry, *var;
1005 Eldbus_Message *error_reply = NULL;
1006 Eina_Bool ret;
1007 Eldbus_Property_Get_Cb getter = NULL;
1008
1009 if (eina_hash_find(added, prop->property->name))
1010 continue;
1011 eina_hash_add(added, prop->property->name, prop);
1012
1013 if (prop->property->get_func)
1014 getter = prop->property->get_func;
1015 else if (iface->get_func)
1016 getter = iface->get_func;
1017
1018 if (!getter || prop->is_invalidate)
1019 continue;
1020
1021 EINA_SAFETY_ON_FALSE_GOTO(
1022 eldbus_message_iter_arguments_append(dict, "{sv}", &entry), error);
1023
1024 eldbus_message_iter_basic_append(entry, 's', prop->property->name);
1025 var = eldbus_message_iter_container_new(entry, 'v',
1026 prop->property->type);
1027
1028 ret = getter(iface, prop->property->name, var, NULL, &error_reply);
1029 if (!ret)
1030 {
1031 eldbus_message_unref(msg);
1032 if (error_reply)
1033 {
1034 ERR("Error reply was set without pass any input message.");
1035 eldbus_message_unref(error_reply);
1036 }
1037 ERR("Getter of property %s returned error.", prop->property->name);
1038 goto error;
1039 }
1040
1041 eldbus_message_iter_container_close(entry, var);
1042 eldbus_message_iter_container_close(dict, entry);
1043 }
1044invalidate:
1045 eldbus_message_iter_container_close(main_iter, dict);
1046
1047 eldbus_message_iter_arguments_append(main_iter, "as", &array_invalidate);
1048
1049 if (!iface->prop_invalidated)
1050 goto end;
1051 while ((prop = eina_array_pop(iface->prop_invalidated)))
1052 {
1053 if (!prop->is_invalidate)
1054 continue;
1055 eldbus_message_iter_basic_append(array_invalidate, 's',
1056 prop->property->name);
1057 }
1058end:
1059 eldbus_message_iter_container_close(main_iter, array_invalidate);
1060
1061 eldbus_service_signal_send(iface, msg);
1062error:
1063 if (added)
1064 eina_hash_free(added);
1065 if (iface->props_changed)
1066 eina_array_flush(iface->props_changed);
1067 if (iface->prop_invalidated)
1068 eina_array_flush(iface->prop_invalidated);
1069 return ECORE_CALLBACK_CANCEL;
1070}
1071
977static void 1072static void
978_interface_free(Eldbus_Service_Interface *interface) 1073_interface_free(Eldbus_Service_Interface *interface)
979{ 1074{
@@ -985,6 +1080,15 @@ _interface_free(Eldbus_Service_Interface *interface)
985 interface == objmanager) 1080 interface == objmanager)
986 return; 1081 return;
987 1082
1083 /**
1084 * flush props changes before remove interface
1085 */
1086 if (interface->idler_propschanged)
1087 {
1088 ecore_idler_del(interface->idler_propschanged);
1089 _idler_propschanged(interface);
1090 }
1091
988 eina_hash_free(interface->methods); 1092 eina_hash_free(interface->methods);
989 while ((sig = eina_array_pop(interface->sign_of_signals))) 1093 while ((sig = eina_array_pop(interface->sign_of_signals)))
990 eina_stringshare_del(sig); 1094 eina_stringshare_del(sig);
@@ -992,8 +1096,6 @@ _interface_free(Eldbus_Service_Interface *interface)
992 eina_hash_free(interface->properties); 1096 eina_hash_free(interface->properties);
993 if (interface->props_changed) 1097 if (interface->props_changed)
994 eina_array_free(interface->props_changed); 1098 eina_array_free(interface->props_changed);
995 if (interface->idler_propschanged)
996 ecore_idler_del(interface->idler_propschanged);
997 if (interface->prop_invalidated) 1099 if (interface->prop_invalidated)
998 eina_array_free(interface->prop_invalidated); 1100 eina_array_free(interface->prop_invalidated);
999 1101
@@ -1031,8 +1133,10 @@ _object_free(Eldbus_Service_Object *obj)
1031 1133
1032 /* Flush ObjectManager interface before the entire object goes away */ 1134 /* Flush ObjectManager interface before the entire object goes away */
1033 if (obj->idler_iface_changed) 1135 if (obj->idler_iface_changed)
1034 ecore_idler_del(obj->idler_iface_changed); 1136 {
1035 _object_manager_changes_process(obj); 1137 ecore_idler_del(obj->idler_iface_changed);
1138 _object_manager_changes_process(obj);
1139 }
1036 1140
1037 iterator = eina_hash_iterator_data_new(obj->interfaces); 1141 iterator = eina_hash_iterator_data_new(obj->interfaces);
1038 EINA_ITERATOR_FOREACH(iterator, iface) 1142 EINA_ITERATOR_FOREACH(iterator, iface)
@@ -1256,101 +1360,6 @@ eldbus_service_object_data_del(Eldbus_Service_Interface *iface, const char *key)
1256 return eldbus_data_del(&(((Eldbus_Service_Object *)iface->obj)->data), key); 1360 return eldbus_data_del(&(((Eldbus_Service_Object *)iface->obj)->data), key);
1257} 1361}
1258 1362
1259static Eina_Bool
1260_idler_propschanged(void *data)
1261{
1262 Eldbus_Service_Interface *iface = data;
1263 Eldbus_Message *msg;
1264 Eldbus_Message_Iter *main_iter, *dict, *array_invalidate;
1265 Eina_Hash *added = NULL;
1266 Property *prop;
1267
1268 iface->idler_propschanged = NULL;
1269
1270 added = eina_hash_string_small_new(NULL);
1271 msg = eldbus_message_signal_new(iface->obj->path, properties_iface->name,
1272 properties_iface->signals[0].name);
1273 EINA_SAFETY_ON_NULL_GOTO(msg, error);
1274
1275 main_iter = eldbus_message_iter_get(msg);
1276 if (!eldbus_message_iter_arguments_append(main_iter, "sa{sv}", iface->name, &dict))
1277 {
1278 eldbus_message_unref(msg);
1279 goto error;
1280 }
1281
1282 if (!iface->props_changed)
1283 goto invalidate;
1284 while ((prop = eina_array_pop(iface->props_changed)))
1285 {
1286 Eldbus_Message_Iter *entry, *var;
1287 Eldbus_Message *error_reply = NULL;
1288 Eina_Bool ret;
1289 Eldbus_Property_Get_Cb getter = NULL;
1290
1291 if (eina_hash_find(added, prop->property->name))
1292 continue;
1293 eina_hash_add(added, prop->property->name, prop);
1294
1295 if (prop->property->get_func)
1296 getter = prop->property->get_func;
1297 else if (iface->get_func)
1298 getter = iface->get_func;
1299
1300 if (!getter || prop->is_invalidate)
1301 continue;
1302
1303 EINA_SAFETY_ON_FALSE_GOTO(
1304 eldbus_message_iter_arguments_append(dict, "{sv}", &entry), error);
1305
1306 eldbus_message_iter_basic_append(entry, 's', prop->property->name);
1307 var = eldbus_message_iter_container_new(entry, 'v',
1308 prop->property->type);
1309
1310 ret = getter(iface, prop->property->name, var, NULL, &error_reply);
1311 if (!ret)
1312 {
1313 eldbus_message_unref(msg);
1314 if (error_reply)
1315 {
1316 ERR("Error reply was set without pass any input message.");
1317 eldbus_message_unref(error_reply);
1318 }
1319 ERR("Getter of property %s returned error.", prop->property->name);
1320 goto error;
1321 }
1322
1323 eldbus_message_iter_container_close(entry, var);
1324 eldbus_message_iter_container_close(dict, entry);
1325 }
1326invalidate:
1327 eldbus_message_iter_container_close(main_iter, dict);
1328
1329 eldbus_message_iter_arguments_append(main_iter, "as", &array_invalidate);
1330
1331 if (!iface->prop_invalidated)
1332 goto end;
1333 while ((prop = eina_array_pop(iface->prop_invalidated)))
1334 {
1335 if (!prop->is_invalidate)
1336 continue;
1337 eldbus_message_iter_basic_append(array_invalidate, 's',
1338 prop->property->name);
1339 }
1340end:
1341 eldbus_message_iter_container_close(main_iter, array_invalidate);
1342
1343 eldbus_service_signal_send(iface, msg);
1344error:
1345 if (added)
1346 eina_hash_free(added);
1347 if (iface->props_changed)
1348 eina_array_flush(iface->props_changed);
1349 if (iface->prop_invalidated)
1350 eina_array_flush(iface->prop_invalidated);
1351 return ECORE_CALLBACK_CANCEL;
1352}
1353
1354EAPI Eina_Bool 1363EAPI Eina_Bool
1355eldbus_service_property_changed(const Eldbus_Service_Interface *interface, const char *name) 1364eldbus_service_property_changed(const Eldbus_Service_Interface *interface, const char *name)
1356{ 1365{