summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Roberto de Souza <zehortigoza@gmail.com>2014-12-05 01:01:37 -0200
committerChris Michael <cp.michael@samsung.com>2014-12-05 09:53:08 -0500
commit8b193c145ec0d9ecc9e9a16dbec335c9f209c0a3 (patch)
treeb388c71674151b89261bb6b283b8ba002be3001e
parent44f0f3e1707f0ade71eb7ccab5ecc70494c00ad8 (diff)
eldbus: Fix _eldbus_connection_send_and_block()
Some problems with the actual implementation: - the reply should not be writable, as it can only be read. - if an error happen dbus_connection_send_with_reply_and_block() will return NULL so we need check before use it - all other send calls remove one reference of the message Now also it is creating a error message, so the caller can know why it fail. @fix Signed-off-by: Chris Michael <cp.michael@samsung.com>
-rw-r--r--src/lib/eldbus/eldbus_pending.c29
-rw-r--r--src/lib/eldbus/eldbus_proxy.h8
2 files changed, 21 insertions, 16 deletions
diff --git a/src/lib/eldbus/eldbus_pending.c b/src/lib/eldbus/eldbus_pending.c
index 87049c5..67c478d 100644
--- a/src/lib/eldbus/eldbus_pending.c
+++ b/src/lib/eldbus/eldbus_pending.c
@@ -161,26 +161,33 @@ _eldbus_connection_send(Eldbus_Connection *conn, Eldbus_Message *msg, Eldbus_Mes
161Eldbus_Message * 161Eldbus_Message *
162_eldbus_connection_send_and_block(Eldbus_Connection *conn, Eldbus_Message *msg) 162_eldbus_connection_send_and_block(Eldbus_Connection *conn, Eldbus_Message *msg)
163{ 163{
164 Eldbus_Message *reply; 164 Eldbus_Message *reply = NULL;
165 DBusError err;
166 DBusMessage *dbus_msg;
165 167
166 if (ecore_main_loop_nested_get()) 168 if (ecore_main_loop_nested_get())
167 WRN("Calling this function may result in dropped frames because the main loop is running"); 169 WRN("Calling this function may result in dropped frames because the main loop is running");
168 170
169 reply = eldbus_message_new(EINA_TRUE); 171 dbus_error_init(&err);
170 EINA_SAFETY_ON_NULL_GOTO(reply, fail); 172 dbus_msg = dbus_connection_send_with_reply_and_block(conn->dbus_conn,
171 173 msg->dbus_msg, -1, &err);
172 reply->dbus_msg = 174 EINA_SAFETY_ON_TRUE_GOTO(dbus_error_is_set(&err), dbus_error_set);
173 dbus_connection_send_with_reply_and_block(conn->dbus_conn, 175 dbus_error_free(&err);
174 msg->dbus_msg, -1, NULL);
175 176
176 dbus_message_iter_init_append(reply->dbus_msg, 177 reply = eldbus_message_new(EINA_FALSE);
177 &reply->iterator->dbus_iterator); 178 EINA_SAFETY_ON_NULL_GOTO(reply, fail);
178 179
180 reply->dbus_msg = dbus_msg;
181 dbus_message_iter_init(reply->dbus_msg, &reply->iterator->dbus_iterator);
182 eldbus_message_unref(msg);
179 return reply; 183 return reply;
180 184
185dbus_error_set:
186 reply = eldbus_message_error_new(msg, err.name, err.message);
187 dbus_error_free(&err);
181fail: 188fail:
182 eldbus_message_unref(reply); 189 eldbus_message_unref(msg);
183 return NULL; 190 return reply;
184} 191}
185 192
186EAPI void 193EAPI void
diff --git a/src/lib/eldbus/eldbus_proxy.h b/src/lib/eldbus/eldbus_proxy.h
index 3552378..69f5806 100644
--- a/src/lib/eldbus/eldbus_proxy.h
+++ b/src/lib/eldbus/eldbus_proxy.h
@@ -117,15 +117,13 @@ EAPI Eldbus_Message *eldbus_proxy_method_call_new(Eldbus_Proxy *proxy, co
117EAPI Eldbus_Pending *eldbus_proxy_send(Eldbus_Proxy *proxy, Eldbus_Message *msg, Eldbus_Message_Cb cb, const void *cb_data, double timeout) EINA_ARG_NONNULL(1, 2); 117EAPI Eldbus_Pending *eldbus_proxy_send(Eldbus_Proxy *proxy, Eldbus_Message *msg, Eldbus_Message_Cb cb, const void *cb_data, double timeout) EINA_ARG_NONNULL(1, 2);
118 118
119/** 119/**
120 * @brief Send a message and block while waiting for the reply 120 * @brief Send a message and block while waiting for the reply.
121 * 121 *
122 * @param proxy the msg will be send in connection that proxy belongs 122 * @param proxy the msg will be send in connection that proxy belongs
123 * @param msg message that will be send 123 * @param msg message that will be send
124 * @param cb if msg is a method call a callback should be passed
125 * @param cb_data data passed to callback
126 *
127 * @return A Eldbus_Pending object on the sent message.
128 * 124 *
125 * @return The reply message, error message or NULL.
126 * The returned Eldbus_Message need to be unref after read.
129 * @since 1.13 127 * @since 1.13
130 */ 128 */
131EAPI Eldbus_Message *eldbus_proxy_send_and_block(Eldbus_Proxy *proxy, Eldbus_Message *msg) EINA_ARG_NONNULL(1, 2); 129EAPI Eldbus_Message *eldbus_proxy_send_and_block(Eldbus_Proxy *proxy, Eldbus_Message *msg) EINA_ARG_NONNULL(1, 2);