Skip to content

Commit 951eb7f

Browse files
Nikolay Orliukkdopen
Nikolay Orliuk
authored andcommitted
extract out RTC interaction code
:Release Notes: Slight re-factoring/re-organization to ease further development. :Detailed Notes: Decompose timeout_alarm to have separate module for time change handling. Note that no actual changes were made in code. :Testing Performed: - desktop build :QA Notes: :Issues Addressed: [GF-6704] sleepd daemon looks unhappy Open-webOS-DCO-1.0-Signed-off-by: Nikolay Orliuk <[email protected]> Change-Id: I2c55544d067b6c6a0b920003703354e9f6985d1c Reviewed-on: https://g2g.palm.com/3859 Reviewed-by: Nikolay Orliuk <[email protected]> Reviewed-by: Build Verification Reviewed-by: Keith Derrick <[email protected]> Tested-by: Keith Derrick <[email protected]>
1 parent a6eafbe commit 951eb7f

File tree

4 files changed

+156
-87
lines changed

4 files changed

+156
-87
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ include_directories(${POWERD_INCLUDE_DIRS})
7474
webos_add_compiler_flags(ALL ${POWERD_CFLAGS_OTHER})
7575

7676
webos_add_compiler_flags(ALL -Wall)
77+
webos_add_compiler_flags(ALL -Werror=implicit-function-declaration)
7778

7879
# Allow developer to compile with -Werror, without potentially breaking a build
7980
set(WEBOS_USE_WERROR FALSE CACHE BOOL "Set to TRUE to enable -Werror")

include/internal/reference_time.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/****************************************************************
2+
* @@@LICENSE
3+
*
4+
* Copyright (c) 2013 LG Electronics, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* LICENSE@@@
19+
****************************************************************/
20+
21+
/**
22+
* @file reference_time.h
23+
*
24+
* Interfece to some reference time source built to address issues caused by
25+
* system time change.
26+
*/
27+
28+
#ifndef __REFERENCE_TIME_H
29+
#define __REFERENCE_TIME_H
30+
31+
#include <stdbool.h>
32+
#include <time.h>
33+
34+
/**
35+
* @brief Convert to rtc time.
36+
*
37+
* @param t
38+
*
39+
* @retval
40+
*/
41+
time_t to_rtc(time_t t);
42+
43+
/**
44+
* @brief Last wall time.
45+
*
46+
* @retval
47+
*/
48+
time_t rtc_wall_time(void);
49+
50+
/**
51+
* @brief Calculate the time difference between RTC time and wall time
52+
*/
53+
bool wall_rtc_diff(time_t *ret_delta);
54+
55+
/**
56+
* @brief Update the rtc and return the difference rtc changed by.
57+
*
58+
* @retval
59+
*/
60+
time_t update_rtc(time_t *ret_delta);
61+
62+
#endif

src/alarms/reference_time.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/****************************************************************
2+
* @@@LICENSE
3+
*
4+
* Copyright (c) 2013 LG Electronics, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* LICENSE@@@
19+
****************************************************************/
20+
21+
/**
22+
* @file reference_time.c
23+
*
24+
* Implmenetation of reference time source
25+
*/
26+
27+
#include <nyx/nyx_client.h>
28+
29+
#include "main.h"
30+
#include "reference_time.h"
31+
32+
static time_t rtc_to_wall = 0;
33+
34+
time_t to_rtc(time_t t)
35+
{
36+
return t - rtc_to_wall;
37+
}
38+
39+
time_t rtc_wall_time(void)
40+
{
41+
time_t rtctime = 0;
42+
nyx_system_query_rtc_time(GetNyxSystemDevice(), &rtctime);
43+
return rtctime + rtc_to_wall;
44+
}
45+
46+
bool
47+
wall_rtc_diff(time_t *ret_delta)
48+
{
49+
time_t rtc_time_now = 0;
50+
time_t wall_time_now = 0;
51+
52+
nyx_system_query_rtc_time(GetNyxSystemDevice(), &rtc_time_now);
53+
54+
time(&wall_time_now);
55+
56+
/* Calculate the time difference */
57+
time_t delta = wall_time_now - rtc_time_now;
58+
59+
if (ret_delta)
60+
{
61+
*ret_delta = delta;
62+
}
63+
64+
return true;
65+
}
66+
67+
time_t update_rtc(time_t *ret_delta)
68+
{
69+
bool retVal;
70+
time_t new_delta = 0;
71+
time_t delta = 0;
72+
73+
retVal = wall_rtc_diff(&new_delta);
74+
75+
if (!retVal)
76+
{
77+
return false;
78+
}
79+
80+
if (new_delta != rtc_to_wall)
81+
{
82+
delta = new_delta - rtc_to_wall;
83+
rtc_to_wall = new_delta;
84+
}
85+
86+
if (ret_delta)
87+
{
88+
*ret_delta = delta;
89+
}
90+
91+
return true;
92+
}

src/alarms/timeout_alarm.c

100755100644
Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "lunaservice_utils.h"
4141

4242
#include "timersource.h"
43+
#include "reference_time.h"
4344

4445
#include "timeout_alarm.h"
4546
#include "config.h"
@@ -134,89 +135,6 @@ CREATE INDEX IF NOT EXISTS expiry_index on AlarmTimeout (expiry);";
134135
* @{
135136
*/
136137

137-
138-
static time_t rtc_to_wall = 0;
139-
/**
140-
* @brief Convert to rtc time.
141-
*
142-
* @param t
143-
*
144-
* @retval
145-
*/
146-
static time_t to_rtc(time_t t)
147-
{
148-
return t - rtc_to_wall;
149-
}
150-
151-
/**
152-
* @brief Last wall time.
153-
*
154-
* @retval
155-
*/
156-
time_t rtc_wall_time(void)
157-
{
158-
time_t rtctime = 0;
159-
nyx_system_query_rtc_time(GetNyxSystemDevice(), &rtctime);
160-
return rtctime + rtc_to_wall;
161-
}
162-
163-
/**
164-
* @brief Calculate the time difference between RTC time and wall time
165-
*/
166-
167-
bool
168-
wall_rtc_diff(time_t *ret_delta)
169-
{
170-
time_t rtc_time_now = 0;
171-
time_t wall_time_now = 0;
172-
173-
nyx_system_query_rtc_time(GetNyxSystemDevice(), &rtc_time_now);
174-
175-
time(&wall_time_now);
176-
177-
/* Calculate the time difference */
178-
time_t delta = wall_time_now - rtc_time_now;
179-
180-
if (ret_delta)
181-
{
182-
*ret_delta = delta;
183-
}
184-
185-
return true;
186-
}
187-
188-
/**
189-
* @brief Update the rtc and return the difference rtc changed by.
190-
*
191-
* @retval
192-
*/
193-
static time_t update_rtc(time_t *ret_delta)
194-
{
195-
bool retVal;
196-
time_t new_delta = 0;
197-
time_t delta = 0;
198-
199-
retVal = wall_rtc_diff(&new_delta);
200-
201-
if (!retVal)
202-
{
203-
return false;
204-
}
205-
206-
if (new_delta != rtc_to_wall)
207-
{
208-
delta = new_delta - rtc_to_wall;
209-
rtc_to_wall = new_delta;
210-
}
211-
212-
if (ret_delta)
213-
{
214-
*ret_delta = delta;
215-
}
216-
217-
return true;
218-
}
219-
220138
static void
221139
_print_timeout(const char *message, const char *app_id, const char *key,
222140
bool public_bus, time_t expiry)
@@ -1569,10 +1487,6 @@ _alarms_timeout_init(void)
15691487
{
15701488
SLEEPDLOG_ERROR(MSGID_UPDATE_RTC_FAIL, 0, "could not get wall-rtc offset");
15711489
}
1572-
else
1573-
{
1574-
SLEEPDLOG_DEBUG("Initial WALL-RTC = %ld", rtc_to_wall);
1575-
}
15761490

15771491
GTimerSource *timer_rtc_check = g_timer_source_new_seconds(5 * 60);
15781492
g_source_set_callback((GSource *)timer_rtc_check,

0 commit comments

Comments
 (0)