GDBusMethodInvocation *invocation,
gpointer user_data) {
RequestBroker* broker = static_cast<RequestBroker*>(user_data);
- GVariant *reply_body = NULL;
- char *serialized = NULL;
+ GVariant *reply_body = nullptr;
int command;
+ char *serialized = nullptr;
g_variant_get(parameters, "(i&s)", &command, &serialized);
Command cmd = static_cast<Command>(command);
bool RequestBroker::Init() {
GError* error = nullptr;
- connection_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (connection_ == NULL) {
- if (error != NULL) {
+ connection_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
+ if (connection_ == nullptr) {
+ if (error != nullptr) {
LOG(ERROR) << "Failed to get dbus [" << error->message << "]";
g_error_free(error);
}
" </method>"
" </interface>"
" </node>";
- GError *error = NULL;
+ GError *error = nullptr;
GDBusNodeInfo *introspection_data =
g_dbus_node_info_new_for_xml(introspection_xml, &error);
if (!introspection_data) {
LOG(ERROR) << "g_dbus_node_info_new_for_xml is failed";
- if (error != NULL) {
+ if (error != nullptr) {
LOG(ERROR) << "g_dbus_node_info_new_for_xml err ["
<< error->message << "]";
g_error_free(error);
registration_id_ = g_dbus_connection_register_object(
connection_,
THEME_MANAGER_OBJECT_PATH, introspection_data->interfaces[0],
- &interface_vtable, this, NULL, NULL);
+ &interface_vtable, this, nullptr, nullptr);
g_dbus_node_info_unref(introspection_data);
if (registration_id_ == 0) {
LOGE("register object fail");
return false;
}
- int owner_id = g_bus_own_name_on_connection(connection_, THEME_MANAGER_DBUS_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- NULL, NULL, NULL, NULL);
+ int owner_id = g_bus_own_name_on_connection(connection_,
+ THEME_MANAGER_DBUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ nullptr, nullptr,
+ nullptr, nullptr);
if (!owner_id) {
g_object_unref(connection_);
LOG(ERROR) << "g_bus_own_name_on_connection error";
GVariant* parameters,
void* user_data) {
RequestBroker* broker = static_cast<RequestBroker*>(user_data);
- char *serialized = NULL;
+ char *serialized = nullptr;
int command;
g_variant_get(parameters, "(i&s)", &command, &serialized);
}
bool RequestBroker::Subscribe() {
- subscribe_id_ = g_dbus_connection_signal_subscribe(connection_, NULL,
- THEME_MANAGER_INTERFACE_NAME, NULL, THEME_MANAGER_OBJECT_PATH, NULL,
- G_DBUS_SIGNAL_FLAGS_NONE, OnReceiveDbusSignal, this, NULL);
+ subscribe_id_ = g_dbus_connection_signal_subscribe(connection_, nullptr,
+ THEME_MANAGER_INTERFACE_NAME, nullptr, THEME_MANAGER_OBJECT_PATH, nullptr,
+ G_DBUS_SIGNAL_FLAGS_NONE, OnReceiveDbusSignal, this, nullptr);
return subscribe_id_ > 0;
}
);
GDBusMessage* reply = g_dbus_connection_send_message_with_reply_sync(
- connection_, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+ connection_, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1, nullptr, nullptr, &err);
GVariant *reply_body = g_dbus_message_get_body(reply);
char *raw;
g_variant_get(reply_body, "(s)", &raw);
return result;
}
+void RequestBroker::OnResultReceivedCb(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data) {
+ GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(source_object);
+ GError* err = nullptr;
+ GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn,
+ res, &err);
+ if (!reply) {
+ LOG(ERROR) << "No reply . err[" << (err ? err->message : "Unknown") << "]";
+ return;
+ }
+
+ int command;
+ char *serialized = nullptr;
+
+ GVariant* reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i&s)", &command, &serialized);
+ RequestBroker* broker = static_cast<RequestBroker*>(user_data);
+ Command cmd = static_cast<Command>(command);
+ tizen_base::Bundle b(serialized);
+ g_object_unref(reply);
+
+ auto it = broker->filters_.find(cmd);
+ if (it == broker->filters_.end())
+ return;
+
+ it->second.GetHandler()->OnRequest(cmd, b);
+}
+
void RequestBroker::SendDataAsync(Command cmd, tizen_base::Bundle& data) {
+ GDBusMessage* msg = g_dbus_message_new_method_call(
+ THEME_MANAGER_DBUS_NAME, THEME_MANAGER_OBJECT_PATH,
+ THEME_MANAGER_INTERFACE_NAME, "SendData");
+ if (!msg) {
+ LOG(ERROR) << "Can't allocate new method call";
+ return;
+ }
+
+ g_dbus_message_set_body(msg,
+ g_variant_new("(is)",
+ static_cast<int>(cmd),
+ reinterpret_cast<char*>(data.ToRaw().first.get())
+ )
+ );
+ g_dbus_connection_send_message_with_reply(connection_, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr,
+ nullptr, OnResultReceived, this);
}
} // namespace dbus