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,
#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;
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;
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);