namespace ttm {
namespace dbus {
-void RequestBroker::OnReceiveDbusMethod(GDBusConnection *conn,
- const gchar *sender, const gchar *object_path,
- const gchar *iface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
- gpointer user_data) {
+void RequestBroker::OnReceiveDbusMethod(GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data) {
RequestBroker* broker = static_cast<RequestBroker*>(user_data);
GVariant *reply_body = NULL;
char *serialized = NULL;
Command cmd = static_cast<Command>(command);
tizen_base::Bundle b(serialized);
- if (broker->filters_.count(cmd) == 0) {
+ auto it = broker->filters_.find(cmd);
+ if (it == broker->filters_.end()) {
LOG(ERROR) << "UnKnown command";
g_dbus_method_invocation_return_value(invocation, nullptr);
return;
}
- tizen_base::Bundle result =
- broker->filters_.find(cmd)->second.GetHandler()->OnRequest(cmd, b);
+ tizen_base::Bundle result = it->second.GetHandler()->OnRequest(cmd, b);
reply_body = g_variant_new("(s)", result.ToRaw().first.get());
g_dbus_method_invocation_return_value(invocation, reply_body);
}
gchar introspection_xml[] =
" <node>"
" <interface name='org.tizen.theme_manager'>"
- " <method name='Get'>"
+ " <method name='SendData'>"
" <arg type='i' name='command' direction='in'/>"
" <arg type='s' name='serialized' direction='in'/>"
" <arg type='s' name='serialized' direction='out'/>"
return true;
}
+void RequestBroker::OnReceiveDbusSignal(GDBusConnection* connection,
+ const gchar* sender_name,
+ const gchar* object_path,
+ const gchar* interface_name,
+ const gchar* signal_name,
+ GVariant* parameters,
+ void* user_data) {
+ RequestBroker* broker = static_cast<RequestBroker*>(user_data);
+ char *serialized = NULL;
+ int command;
+ g_variant_get(parameters, "(i&s)", &command, &serialized);
+
+ Command cmd = static_cast<Command>(command);
+ tizen_base::Bundle b(serialized);
+
+ auto it = broker->filters_.find(cmd);
+ if (it == broker->filters_.end())
+ return;
+
+ tizen_base::Bundle result = it->second.GetHandler()->OnRequest(cmd, b);
+}
+
+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);
+
+ return subscribe_id_ > 0;
+}
+
tizen_base::Bundle RequestBroker::SendData(Command cmd,
tizen_base::Bundle& data) {
GError* err = nullptr;
GDBusMessage* msg = g_dbus_message_new_method_call(
THEME_MANAGER_DBUS_NAME, THEME_MANAGER_OBJECT_PATH,
- THEME_MANAGER_INTERFACE_NAME, "Get");
+ THEME_MANAGER_INTERFACE_NAME, "SendData");
if (!msg) {
LOGE("Can't allocate new method call");
return {};
return result;
}
-void RequestBroker::SendDataAsync(Command cmd, tizen_base::Bundle&) {
+void RequestBroker::SendDataAsync(Command cmd, tizen_base::Bundle& data) {
+
}
} // namespace dbus
int RegisterRequestFilter(RequestFilter filter);
bool Listen();
+ bool Subscribe();
tizen_base::Bundle SendData(Command cmd, tizen_base::Bundle&);
void SendDataAsync(Command cmd, tizen_base::Bundle&);
private:
- static void OnReceiveDbusMethod(GDBusConnection *conn, const gchar *sender,
+ static void OnReceiveDbusMethod(GDBusConnection *connection,
+ const gchar *sender,
const gchar *object_path,
- const gchar *iface_name,
+ const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data);
+
+ static void OnReceiveDbusSignal(GDBusConnection* connection,
+ const gchar* sender_name,
+ const gchar* object_path,
+ const gchar* interface_name,
+ const gchar* signal_name,
+ GVariant* parameters,
+ void* user_data);
RequestBroker() = default;
~RequestBroker() = default;
bool Init();
+
+ int registration_id_ = 0;
+ int subscribe_id_ = 0;
GDBusConnection* connection_ = nullptr;
std::map<Command, RequestFilter> filters_;
- int registration_id_ = 0;
};
} // namespace dbus