#include "policy-client.h"
-#include <vconf.h>
-
#define VCONFKEY_DPM_MODE_STATE "db/dpm/mode_state"
namespace {
} // namespace
+void DevicePolicyClient::maintenanceModeDispatcher(keynode_t *node, void *data)
+{
+ int *mode = reinterpret_cast<int *>(data);
+ ::vconf_get_bool(VCONFKEY_DPM_MODE_STATE, mode);
+}
DevicePolicyClient::DevicePolicyClient() noexcept :
- clientAddress(POLICY_MANAGER_ADDRESS)
+ maintenanceMode(0), clientAddress(POLICY_MANAGER_ADDRESS)
{
mainloop.reset(new ScopedGMainLoop);
+ ::vconf_notify_key_changed(VCONFKEY_DPM_MODE_STATE, maintenanceModeDispatcher, reinterpret_cast<void*>(&this->maintenanceMode));
+ ::vconf_get_bool(VCONFKEY_DPM_MODE_STATE, &maintenanceMode);
}
DevicePolicyClient::~DevicePolicyClient() noexcept
{
mainloop.reset();
+ ::vconf_ignore_key_changed(VCONFKEY_DPM_MODE_STATE, maintenanceModeDispatcher);
}
int DevicePolicyClient::subscribeSignal(const std::string& name,
const SignalHandler& handler,
void* data) noexcept
{
- if (!getMaintenanceMode())
+ if (!maintenanceMode)
return 0;
int ret = -1;
int DevicePolicyClient::unsubscribeSignal(int id) noexcept
{
- if (!getMaintenanceMode())
+ if (!maintenanceMode)
return 0;
try {
return -1;
}
}
-
-int DevicePolicyClient::getMaintenanceMode()
-{
- int value = 0;
-
- ::vconf_get_bool(VCONFKEY_DPM_MODE_STATE, &value);
-
- return value;
-}
#include <functional>
#include <cerrno>
+#include <vconf.h>
+
#include <klay/rmi/method.h>
#include <klay/gmainloop.h>
const SignalHandler& handler,
void* data) noexcept;
int unsubscribeSignal(int subscriberId) noexcept;
- int getMaintenanceMode();
template<typename Type, typename... Args>
Type methodCall(const std::string& method, Args&&... args)
{
- if (!getMaintenanceMode()) {
+ if (!maintenanceMode) {
errno = EPROTONOSUPPORT;
return Type();
}
}
private:
+ static void maintenanceModeDispatcher(keynode_t *node, void *data);
+
+private:
+ int maintenanceMode;
std::string clientAddress;
std::unique_ptr<ScopedGMainLoop> mainloop;
};