Skip to content

Commit

Permalink
Merge pull request #2278 from smartdevicelink/feature/boost_datetime_…
Browse files Browse the repository at this point in the history
…implementation

Feature/boost datetime implementation
  • Loading branch information
jacobkeeler authored Aug 28, 2018
2 parents ae9551d + 8411399 commit 721fcfe
Show file tree
Hide file tree
Showing 57 changed files with 499 additions and 677 deletions.
6 changes: 3 additions & 3 deletions src/3rd_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ else()
)
endif()

find_package(Boost 1.66.0 COMPONENTS system thread)
find_package(Boost 1.66.0 COMPONENTS system thread date_time)
set(BOOST_LIB_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/boost_src)
set(BOOST_LIBS_DIRECTORY ${3RD_PARTY_INSTALL_PREFIX}/lib)
SET_PROPERTY(GLOBAL PROPERTY GLOBAL_BOOST_LIBS ${BOOST_LIBS_DIRECTORY})
Expand All @@ -226,9 +226,9 @@ if (NOT ${Boost_FOUND})
URL https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
DOWNLOAD_DIR ${BOOST_LIB_SOURCE_DIRECTORY}
SOURCE_DIR ${BOOST_LIB_SOURCE_DIRECTORY}
CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=system,thread --prefix=${3RD_PARTY_INSTALL_PREFIX}
CONFIGURE_COMMAND ./bootstrap.sh --with-libraries=system,thread,date_time --prefix=${3RD_PARTY_INSTALL_PREFIX}
BUILD_COMMAND ./b2
INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} --with-system --with-thread --prefix=${3RD_PARTY_INSTALL_PREFIX} > boost_install.log
INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} --with-system --with-thread --with-date_time --prefix=${3RD_PARTY_INSTALL_PREFIX} > boost_install.log
INSTALL_DIR ${3RD_PARTY_INSTALL_PREFIX}
BUILD_IN_SOURCE true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class ApplicationImpl : public virtual Application,
/**
* @brief Defines number per time in seconds limits
*/
typedef std::pair<TimevalStruct, uint32_t> TimeToNumberLimit;
typedef std::pair<date_time::TimeDuration, uint32_t> TimeToNumberLimit;

/**
* @brief Defines specific command number per time in seconds limits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ class ApplicationManagerImpl
* @brief Map contains applications which
* will send TTS global properties to HMI after timeout
*/
std::map<uint32_t, TimevalStruct> tts_global_properties_app_list_;
std::map<uint32_t, date_time::TimeDuration> tts_global_properties_app_list_;

bool audio_pass_thru_active_;
uint32_t audio_pass_thru_app_id_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct RequestInfo {
, app_id_(0)
, requst_type_(RequestNone)
, correlation_id_(0) {
start_time_ = date_time::DateTime::getCurrentTime();
start_time_ = date_time::getCurrentTime();
updateEndTime();
}
virtual ~RequestInfo() {}
Expand All @@ -71,14 +71,14 @@ struct RequestInfo {
const RequestType requst_type,
const uint64_t timeout_msec)
: request_(request), timeout_msec_(timeout_msec), correlation_id_(0) {
start_time_ = date_time::DateTime::getCurrentTime();
start_time_ = date_time::getCurrentTime();
updateEndTime();
requst_type_ = requst_type;
}

RequestInfo(RequestPtr request,
const RequestType requst_type,
const TimevalStruct& start_time,
const date_time::TimeDuration& start_time,
const uint64_t timeout_msec);

void updateEndTime();
Expand All @@ -87,11 +87,11 @@ struct RequestInfo {

bool isExpired();

TimevalStruct start_time() {
date_time::TimeDuration start_time() {
return start_time_;
}

void update_start_time(TimevalStruct start_time) {
void update_start_time(date_time::TimeDuration start_time) {
start_time_ = start_time;
}

Expand All @@ -103,7 +103,7 @@ struct RequestInfo {
timeout_msec_ = timeout;
}

TimevalStruct end_time() {
date_time::TimeDuration end_time() {
return end_time_;
}

Expand All @@ -128,9 +128,9 @@ struct RequestInfo {

protected:
RequestPtr request_;
TimevalStruct start_time_;
date_time::TimeDuration start_time_;
uint64_t timeout_msec_;
TimevalStruct end_time_;
date_time::TimeDuration end_time_;
uint32_t app_id_;
RequestType requst_type_;
uint32_t correlation_id_;
Expand All @@ -141,14 +141,14 @@ typedef std::shared_ptr<RequestInfo> RequestInfoPtr;
struct MobileRequestInfo : public RequestInfo {
MobileRequestInfo(RequestPtr request, const uint64_t timeout_msec);
MobileRequestInfo(RequestPtr request,
const TimevalStruct& start_time,
const date_time::TimeDuration& start_time,
const uint64_t timeout_msec);
};

struct HMIRequestInfo : public RequestInfo {
HMIRequestInfo(RequestPtr request, const uint64_t timeout_msec);
HMIRequestInfo(RequestPtr request,
const TimevalStruct& start_time,
const date_time::TimeDuration& start_time,
const uint64_t timeout_msec);
};

Expand Down Expand Up @@ -270,8 +270,8 @@ class RequestInfoSet {
* during time scale
*/
struct TimeScale {
TimeScale(const TimevalStruct& start,
const TimevalStruct& end,
TimeScale(const date_time::TimeDuration& start,
const date_time::TimeDuration& end,
const uint32_t& app_id)
: start_(start), end_(end), app_id_(app_id) {}

Expand All @@ -292,8 +292,8 @@ struct TimeScale {
}

private:
TimevalStruct start_;
TimevalStruct end_;
date_time::TimeDuration start_;
date_time::TimeDuration end_;
uint32_t app_id_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class RequestTracker {
const mobile_apis::HMILevel::eType level);

private:
typedef std::vector<TimevalStruct> RequestAddedAt;
typedef std::vector<date_time::TimeDuration> RequestAddedAt;
typedef std::map<ApplicationID, RequestAddedAt> ApplicationsRequestsTracker;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace application_manager {
class AMTelemetryObserver {
public:
struct MessageMetric {
TimevalStruct begin;
TimevalStruct end;
date_time::TimeDuration begin;
date_time::TimeDuration end;
std::shared_ptr<smart_objects::SmartObject> message;
};
typedef std::shared_ptr<MessageMetric> MessageMetricSharedPtr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class InteriorDataManagerImpl : public InteriorDataManager {
* @brief RequestsToHMIHistory mapping from module type to vector of time
* stamps
*/
typedef std::map<std::string, std::deque<TimevalStruct> >
typedef std::map<std::string, std::deque<date_time::TimeDuration> >
RequestsToHMIHistory;
RequestsToHMIHistory requests_to_hmi_history_;
mutable sync_primitives::Lock requests_to_hmi_history_lock_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void InteriorDataManagerImpl::StoreRequestToHMITime(
const std::string& module_type) {
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock autolock(requests_to_hmi_history_lock_);
requests_to_hmi_history_[module_type].push_back(
date_time::DateTime::getCurrentTime());
requests_to_hmi_history_[module_type].push_back(date_time::getCurrentTime());
}

bool InteriorDataManagerImpl::CheckRequestsToHMIFrequency(
Expand Down Expand Up @@ -129,9 +128,9 @@ void InteriorDataManagerImpl::UnsubscribeFromInteriorVehicleData(
void InteriorDataManagerImpl::ClearOldRequestsToHMIHistory() {
auto limit =
app_mngr_.get_settings().get_interior_vehicle_data_frequency().second;
uint32_t time_frame = limit * date_time::DateTime::MILLISECONDS_IN_SECOND;
auto lest_that_time_frame_ago = [time_frame](TimevalStruct time) {
auto span = date_time::DateTime::calculateTimeSpan(time);
uint32_t time_frame = limit * date_time::MILLISECONDS_IN_SECOND;
auto lest_that_time_frame_ago = [time_frame](date_time::TimeDuration time) {
auto span = date_time::calculateTimeSpan(time);
return span < time_frame;
};
for (auto& it : requests_to_hmi_history_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool AppLaunchDataJson::RefreshAppSessionTime(const ApplicationData& app_data) {
if (index != NotFound) {
if (json_data_list.empty() == false) {
json_data_list[index][strings::app_launch_last_session] =
static_cast<Json::Value::UInt64>(DateTime::getCurrentTime().tv_sec);
static_cast<Json::Value::UInt64>(getSecs(getCurrentTime()));
retVal = true;
}
}
Expand All @@ -150,7 +150,7 @@ bool AppLaunchDataJson::AddNewAppData(const ApplicationData& app_data) {
json_app_data[strings::app_id] = app_data.mobile_app_id_;
json_app_data[strings::bundle_id] = app_data.bundle_id_;
json_app_data[strings::app_launch_last_session] =
static_cast<Json::Value::UInt64>(DateTime::getCurrentTime().tv_sec);
static_cast<Json::Value::UInt64>(getSecs(getCurrentTime()));

LOG4CXX_DEBUG(logger_,
"New application data saved. Detatils device_id: "
Expand Down
20 changes: 11 additions & 9 deletions src/components/application_manager/src/application_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ ApplicationImpl::ApplicationImpl(
, button_lock_ptr_(std::make_shared<sync_primitives::Lock>())
, application_manager_(application_manager) {
cmd_number_to_time_limits_[mobile_apis::FunctionID::ReadDIDID] = {
date_time::DateTime::getCurrentTime(), 0};
date_time::getCurrentTime(), 0};
cmd_number_to_time_limits_[mobile_apis::FunctionID::GetVehicleDataID] = {
date_time::DateTime::getCurrentTime(), 0};
date_time::getCurrentTime(), 0};

set_mobile_app_id(mobile_app_id);
set_name(app_name);
Expand Down Expand Up @@ -806,7 +806,7 @@ HelpPromptManager& ApplicationImpl::help_prompt_manager() {

bool ApplicationImpl::AreCommandLimitsExceeded(
mobile_apis::FunctionID::eType cmd_id, TLimitSource source) {
TimevalStruct current = date_time::DateTime::getCurrentTime();
date_time::TimeDuration current = date_time::getCurrentTime();
switch (source) {
// In case of config file values there is COMMON limitations for number of
// commands per certain time in seconds, i.e. 5 requests per 10 seconds with
Expand Down Expand Up @@ -838,13 +838,14 @@ bool ApplicationImpl::AreCommandLimitsExceeded(

LOG4CXX_INFO(logger_,
"Time Info: "
<< "\n Current: " << current.tv_sec << "\n Limit: ("
<< limit.first.tv_sec << "," << limit.second
<< ")"
"\n frequency_restrictions: ("
<< "\n Current: " << date_time::getSecs(current)
<< "\n Limit: (" << date_time::getSecs(limit.first)
<< "," << limit.second << ")"
"\n frequency_restrictions: ("
<< frequency_restrictions.first << ","
<< frequency_restrictions.second << ")");
if (current.tv_sec < limit.first.tv_sec + frequency_restrictions.second) {
if (date_time::getSecs(current) <
date_time::getSecs(limit.first) + frequency_restrictions.second) {
if (limit.second < frequency_restrictions.first) {
++limit.second;
return false;
Expand Down Expand Up @@ -886,7 +887,8 @@ bool ApplicationImpl::AreCommandLimitsExceeded(
TimeToNumberLimit& limit = it->second;

// Checking even limitation for command
if (static_cast<uint32_t>(current.tv_sec - limit.first.tv_sec) <
if (static_cast<uint32_t>(date_time::getSecs(current) -
date_time::getSecs(limit.first)) <
minute / cmd_limit) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "utils/threads/thread.h"
#include "utils/file_system.h"
#include "utils/helpers.h"

#include "utils/timer_task_impl.h"
#include "smart_objects/enum_schema_item.h"
#include "interfaces/HMI_API_schema.h"
Expand Down Expand Up @@ -3088,14 +3087,14 @@ void ApplicationManagerImpl::OnTimerSendTTSGlobalProperties() {
std::vector<uint32_t> app_list;
{
sync_primitives::AutoLock lock(tts_global_properties_app_list_lock_);
std::map<uint32_t, TimevalStruct>::iterator it =
std::map<uint32_t, date_time::TimeDuration>::iterator it =
tts_global_properties_app_list_.begin();
std::map<uint32_t, TimevalStruct>::iterator it_end =
std::map<uint32_t, date_time::TimeDuration>::iterator it_end =
tts_global_properties_app_list_.end();
date_time::TimeCompare time_comp;
for (; it != it_end; ++it) {
time_comp = date_time::DateTime::compareTime(
date_time::DateTime::getCurrentTime(), it->second);
time_comp =
date_time::compareTime(date_time::getCurrentTime(), it->second);
if (date_time::GREATER == time_comp || date_time::EQUAL == time_comp) {
app_list.push_back(it->first);
}
Expand All @@ -3116,8 +3115,8 @@ void ApplicationManagerImpl::AddAppToTTSGlobalPropertiesList(
const uint32_t app_id) {
LOG4CXX_AUTO_TRACE(logger_);
uint16_t timeout = get_settings().tts_global_properties_timeout();
TimevalStruct current_time = date_time::DateTime::getCurrentTime();
current_time.tv_sec += timeout;
date_time::TimeDuration current_time = date_time::getCurrentTime();
current_time += date_time::seconds(timeout);
// please avoid AutoLock usage to avoid deadlock
tts_global_properties_app_list_lock_.Acquire();
if (tts_global_properties_app_list_.end() ==
Expand All @@ -3140,7 +3139,7 @@ void ApplicationManagerImpl::RemoveAppFromTTSGlobalPropertiesList(
LOG4CXX_AUTO_TRACE(logger_);
// please avoid AutoLock usage to avoid deadlock
tts_global_properties_app_list_lock_.Acquire();
std::map<uint32_t, TimevalStruct>::iterator it =
std::map<uint32_t, date_time::TimeDuration>::iterator it =
tts_global_properties_app_list_.find(app_id);
if (tts_global_properties_app_list_.end() != it) {
tts_global_properties_app_list_.erase(it);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,9 @@ void PolicyHandler::OnAppPermissionConsentInternal(

void policy::PolicyHandler::SetDaysAfterEpoch() {
POLICY_LIB_CHECK_VOID();
TimevalStruct current_time = date_time::DateTime::getCurrentTime();
date_time::TimeDuration current_time = date_time::getCurrentTime();
const int kSecondsInDay = 60 * 60 * 24;
int days_after_epoch = current_time.tv_sec / kSecondsInDay;
int days_after_epoch = date_time::getSecs(current_time) / kSecondsInDay;
PTUpdatedAt(Counters::DAYS_AFTER_EPOCH, days_after_epoch);
}

Expand Down Expand Up @@ -1458,7 +1458,7 @@ void PolicyHandler::OnSnapshotCreated(
std::string policy_snapshot_full_path;
if (SaveSnapshot(pt_string, policy_snapshot_full_path)) {
const uint32_t timeout_exchange_s =
timeout_exchange_ms / date_time::DateTime::MILLISECONDS_IN_SECOND;
timeout_exchange_ms / date_time::MILLISECONDS_IN_SECOND;
MessageHelper::SendPolicyUpdate(policy_snapshot_full_path,
timeout_exchange_s,
retry_delay_seconds,
Expand Down Expand Up @@ -1587,7 +1587,7 @@ uint32_t PolicyHandler::NextRetryTimeout() {
}

uint32_t PolicyHandler::TimeoutExchangeSec() const {
return TimeoutExchangeMSec() / date_time::DateTime::MILLISECONDS_IN_SECOND;
return TimeoutExchangeMSec() / date_time::MILLISECONDS_IN_SECOND;
}

uint32_t PolicyHandler::TimeoutExchangeMSec() const {
Expand Down
8 changes: 4 additions & 4 deletions src/components/application_manager/src/request_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ void RequestController::TimeoutThread() {
<< " request id: " << probably_expired->requestId()
<< " connection_key: " << probably_expired->app_id()
<< " NOT expired");
const TimevalStruct current_time = date_time::DateTime::getCurrentTime();
const TimevalStruct end_time = probably_expired->end_time();
const date_time::TimeDuration current_time = date_time::getCurrentTime();
const date_time::TimeDuration end_time = probably_expired->end_time();
if (current_time < end_time) {
const uint32_t msecs = static_cast<uint32_t>(
date_time::DateTime::getmSecs(end_time - current_time));
const uint32_t msecs =
static_cast<uint32_t>(date_time::getmSecs(end_time - current_time));
LOG4CXX_DEBUG(logger_, "Sleep for " << msecs << " millisecs");
timer_condition_.WaitFor(auto_lock, msecs);
}
Expand Down
Loading

0 comments on commit 721fcfe

Please # to comment.