/*
* Copyright (c) 2018 TOYOTA MOTOR CORPORATION
+ * Copyright (c) 2018 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <algorithm>
#include <json-c/json.h>
#include "policy_manager.hpp"
+#include "util.hpp"
#include "hmi-debug.h"
extern "C"
int PolicyManager::setStateTransitionProcessToSystemd(int event_id, uint64_t delay_ms, std::string role)
{
+ struct sd_event_source *event_source;
HMI_DEBUG("wm:pm", "event_id:0x%x delay:%d role:%s", event_id, delay_ms, role.c_str());
- // Store requested role
- this->req_role_list[event_id] = role;
-
if (0 == delay_ms)
{
- int ret = sd_event_add_defer(afb_daemon_get_event_loop(), NULL,
+ int ret = sd_event_add_defer(afb_daemon_get_event_loop(), &event_source,
&pm::transitionStateWrapper, new int(event_id));
if (0 > ret)
{
HMI_ERROR("wm:pm", "Faild to sd_event_add_defer: errno:%d", ret);
- this->req_role_list.erase(event_id);
return -1;
}
}
{
// Get current time
struct timespec time_spec;
- clock_gettime(CLOCK_MONOTONIC, &time_spec);
+ clock_gettime(CLOCK_BOOTTIME, &time_spec);
// Calculate timer fired time
uint64_t usec = (time_spec.tv_sec * 1000000) + (time_spec.tv_nsec / 1000) + (delay_ms * 1000);
// Set timer
- struct sd_event_source *event_source;
int ret = sd_event_add_time(afb_daemon_get_event_loop(), &event_source,
- CLOCK_MONOTONIC, usec, 1,
+ CLOCK_BOOTTIME, usec, 1,
&pm::timerEventWrapper, new int(event_id));
if (0 > ret)
{
HMI_ERROR("wm:pm", "Faild to sd_event_add_time: errno:%d", ret);
- this->req_role_list.erase(event_id);
return -1;
}
-
- // Store event source
- this->event_source_list[event_id] = event_source;
}
-
+ // Store event source
+ this->event_source_list[event_id] = event_source;
+ // Store requested role
+ this->req_role_list[event_id] = role;
return 0;
}
int PolicyManager::loadRoleDb()
{
- std::string file_name;
-
- // Get afm application installed dir
- char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
- HMI_DEBUG("wm:pm", "afm_app_install_dir:%s", afm_app_install_dir);
-
- if (!afm_app_install_dir)
- {
- HMI_ERROR("wm:pm", "AFM_APP_INSTALL_DIR is not defined");
- }
- else
- {
- file_name = std::string(afm_app_install_dir) + std::string("/etc/roles.db");
- }
+ std::string file_name(get_file_path("roles.db", "wm:pm"));
// Load roles.db
json_object *json_obj;
{
HMI_DEBUG("wm:pm", "Call");
- // Get afm application installed dir
- char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
- HMI_DEBUG("wm:pm", "afm_app_install_dir:%s", afm_app_install_dir);
-
- std::string file_name;
- if (!afm_app_install_dir)
- {
- HMI_ERROR("wm:pm", "AFM_APP_INSTALL_DIR is not defined");
- }
- else
- {
- file_name = std::string(afm_app_install_dir) + std::string("/etc/states.db");
- }
+ std::string file_name(get_file_path("states.db", "wm:pm"));
// Load states.db
json_object *json_obj;