Bundle serialized = info.Serialize();
GDBusMessage* reply = impl_->MethodCall(appid, method_name, serialized);
+ if (reply == nullptr)
+ return {};
+
+ auto reply_ptr = std::unique_ptr<GDBusMessage, decltype(g_object_unref)*>(
+ reply, g_object_unref);
+ GError* err = nullptr;
+ if (g_dbus_message_to_gerror(reply, &err)) {
+ LOGE("MethodCall() is failed. error(%s)", err->message);
+ if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
+ set_last_result(ERROR_PERMISSION_DENIED);
+ else
+ set_last_result(ERROR_IO_ERROR);
+
+ g_error_free(err);
+ return {};
+ }
+
GVariant *reply_body = g_dbus_message_get_body(reply);
+ if (reply_body == nullptr) {
+ LOGE("g_dbus_message_get_body() is failed");
+ set_last_result(ERROR_OUT_OF_MEMORY);
+ return {};
+ }
GVariantIter *iter = nullptr;
- list<Bundle> ret_list;
g_variant_get(reply_body, "(a(s))", &iter);
+ if (iter == nullptr) {
+ LOGE("Failed to get GVariantIter");
+ set_last_result(ERROR_OUT_OF_MEMORY);
+ return {};
+ }
+
+ list<Bundle> ret_list;
char* raw = nullptr;
while (g_variant_iter_loop(iter, "(&s)", &raw) && raw != nullptr) {
Bundle ret(raw);
ret_list.emplace_back(ret);
}
- if (iter)
- g_variant_iter_free(iter);
- if (reply)
- g_object_unref(reply);
+ g_variant_iter_free(iter);
+ set_last_result(ERROR_NONE);
return ret_list;
}
Bundle serialized = info.Serialize();
GDBusMessage* reply = impl_->MethodCall(appid, method_name, serialized);
+ if (reply == nullptr)
+ return 0;
+
+ auto reply_ptr = std::unique_ptr<GDBusMessage, decltype(g_object_unref)*>(
+ reply, g_object_unref);
+ GError* err = nullptr;
+ if (g_dbus_message_to_gerror(reply, &err)) {
+ LOGE("MethodCall() is failed. error(%s)", err->message);
+ if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
+ set_last_result(ERROR_PERMISSION_DENIED);
+ else
+ set_last_result(ERROR_IO_ERROR);
+
+ g_error_free(err);
+ return 0;
+ }
+
GVariant *reply_body = g_dbus_message_get_body(reply);
+ if (reply_body == nullptr) {
+ LOGE("g_dbus_message_get_body() is failed");
+ set_last_result(ERROR_OUT_OF_MEMORY);
+ return 0;
+ }
int num;
g_variant_get(reply_body, "(i)", &num);
- if (reply)
- g_object_unref(reply);
+ set_last_result(ERROR_NONE);
return num;
}