903f5a216c9ff9602527c98ff6544878f85b9001
[apps/home/clock.git] / stopwatch / src / stopwatch_util.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   * 
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   * 
8   *     http://www.tizenopensource.org/license
9   * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include "stopwatch_util.h"
18
19 //
20 #define UPTIME_FILE  "/proc/uptime"
21 /**
22 * send
23 * This function is  used to get system time
24 * @param           NULL
25 * @return          double
26 * @exception
27 */
28 double stw_get_systime()
29 {
30         double sys_time = 0;
31         FILE *pFile = fopen(UPTIME_FILE, "r");
32         if (pFile) {
33                 fscanf(pFile, "%lf", &sys_time);
34                 fclose(pFile);
35         }
36         return sys_time;
37 }
38
39 /**
40 * send
41 * This function is  used to get time_t time
42 * @param           dval[in]  double value, time
43 * @param           type[in] STW_TIME_TYPE_USEC/STW_TIME_TYPE_SEC
44 * @return          time_t
45 * @exception
46 */
47 time_t stw_systime_double_to_time_t(double dval, STW_TIME_TYPE type)
48 {
49         if (IS_EQUAL(0, dval)) {
50                 return 0;
51         }
52         switch (type) {
53         case STW_TIME_TYPE_SEC:
54                 return (int)dval;
55         case STW_TIME_TYPE_USEC:
56                 {
57                         time_t res = 0;
58                         char array[32];
59                         double dval_dec = dval - (int)dval;
60                         snprintf(array, sizeof(array), "%.2f", dval_dec);
61                         res = (time_t) atoi(&array[2]);
62                         return res;
63                 }
64         default:
65                 return 0;
66         }
67 }
68
69 /**
70 * send
71 * This function is  used to set pm state
72 * @param           isLock[in]           a Eina_Bool value
73 *        EINA_TRUE means lock power state, EINA_FALSE means unlock
74 * @return          void
75 * @exception
76 */
77 void stw_util_pm_state_set(Eina_Bool isLock)
78 {
79         if (EINA_TRUE == isLock) {
80                 pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0);
81         } else {
82                 pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
83         }
84 }