Change to use RemoteMethod 04/164204/2
authoryeji01.kim <yeji01.kim@samsung.com>
Mon, 18 Dec 2017 05:26:22 +0000 (14:26 +0900)
committeryeji01.kim <yeji01.kim@samsung.com>
Tue, 19 Dec 2017 05:28:06 +0000 (14:28 +0900)
Change-Id: I31b1f560083e609594aea243dd6b9f7c6d98a8c7
Signed-off-by: yeji01.kim <yeji01.kim@samsung.com>
libs/client-handle.cpp
libs/policy-client.cpp
libs/policy-client.h

index d2ea116266a7635f539a2da7a8e6be0d4b4fbd5d..c46d74720364d577afddac4c742ee1c01f9d3739 100644 (file)
@@ -35,11 +35,6 @@ EXPORT_API device_policy_manager_h dpm_manager_create(void)
                return NULL;
        }
 
-       if (client->connect() < 0) {
-               delete client;
-               return NULL;
-       }
-
        return reinterpret_cast<device_policy_manager_h>(client);
 }
 
index 8febbf84c8b79041376d30818bd1fb21c29837db..5cddb2e2d9d35c110d77d2b9a4f45cc48009cdc1 100644 (file)
@@ -44,37 +44,14 @@ int GetPolicyEnforceMode()
 
 
 DevicePolicyClient::DevicePolicyClient() noexcept :
-       maintenanceMode(GetPolicyEnforceMode())
+       maintenanceMode(GetPolicyEnforceMode()), clientAddress(POLICY_MANAGER_ADDRESS)
 {
+       mainloop.reset(new ScopedGMainLoop);
 }
 
 DevicePolicyClient::~DevicePolicyClient() noexcept
 {
-       disconnect();
-}
-
-int DevicePolicyClient::connect(const std::string& address) noexcept
-{
-       try {
-               client.reset(new rmi::Client(address));
-               if (maintenanceMode) {
-                       client->connect();
-               }
-       } catch (runtime::Exception& e) {
-               return -1;
-       }
-
-       return 0;
-}
-
-int DevicePolicyClient::connect() noexcept
-{
-       return connect(POLICY_MANAGER_ADDRESS);
-}
-
-void DevicePolicyClient::disconnect() noexcept
-{
-       client.reset();
+       mainloop.reset();
 }
 
 int DevicePolicyClient::subscribeSignal(const std::string& name,
index bb66763c206c588196b23f343a522c44894d611c..51115e09bf401c56ed55a2ebdb88530abd38a46e 100644 (file)
@@ -22,7 +22,8 @@
 #include <functional>
 #include <cerrno>
 
-#include <klay/rmi/client.h>
+#include <klay/rmi/method.h>
+#include <klay/gmainloop.h>
 
 typedef std::function<void(const char*, const char*, void*)> SignalHandler;
 
@@ -31,10 +32,6 @@ public:
        DevicePolicyClient() noexcept;
        ~DevicePolicyClient() noexcept;
 
-       int connect() noexcept;
-       int connect(const std::string& address) noexcept;
-       void disconnect() noexcept;
-
        int subscribeSignal(const std::string& name,
                                                const SignalHandler& handler,
                                                void* data) noexcept;
@@ -43,20 +40,20 @@ public:
        template<typename Type, typename... Args>
        Type methodCall(const std::string& method, Args&&... args)
        {
-               try {
-                       if (maintenanceMode) {
-                               return client->methodCall<Type, Args...>(method, std::forward<Args>(args)...);
-                       }
-               } catch (...) {
+               if (!maintenanceMode) {
+                       errno = EPROTONOSUPPORT;
+                       return Type();
                }
 
-               errno = EPROTONOSUPPORT;
-               return Type();
+               rmi::Connection conn(clientAddress);
+               Type ret = rmi::RemoteMethod<>::invoke<Type, Args...>(conn, method, std::forward<Args>(args)...);
+               return ret;
        }
 
 private:
        int maintenanceMode;
-       std::unique_ptr<rmi::Client> client;
+       std::string clientAddress;
+       std::unique_ptr<ScopedGMainLoop> mainloop;
 };
 
 DevicePolicyClient& GetDevicePolicyClient(void* handle);