Add Subscribe function to RequestBroker for client
authorIlho Kim <ilho159.kim@samsung.com>
Wed, 20 May 2020 04:24:20 +0000 (13:24 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 25 May 2020 04:28:15 +0000 (13:28 +0900)
This function for listening the theme event signal

Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/theme/dbus/request_broker.cc
src/theme/dbus/request_broker.h

index 75b93e3..5be4040 100644 (file)
 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;
@@ -41,14 +44,14 @@ void RequestBroker::OnReceiveDbusMethod(GDBusConnection *conn,
   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);
 }
@@ -92,7 +95,7 @@ bool RequestBroker::Listen() {
   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'/>"
@@ -134,12 +137,42 @@ bool RequestBroker::Listen() {
   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 {};
@@ -162,7 +195,8 @@ tizen_base::Bundle RequestBroker::SendData(Command cmd,
   return result;
 }
 
-void RequestBroker::SendDataAsync(Command cmd, tizen_base::Bundle&) {
+void RequestBroker::SendDataAsync(Command cmd, tizen_base::Bundle& data) {
+
 }
 
 }  // namespace dbus
index 0bd2d09..ecf7744 100644 (file)
@@ -34,23 +34,35 @@ class RequestBroker {
 
   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