1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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/** @file rs_time.rsh
18 *  \brief RenderScript time routines
19 *
20 *  This file contains RenderScript functions relating to time and date
21 *  manipulation.
22 */
23
24#ifndef __RS_TIME_RSH__
25#define __RS_TIME_RSH__
26
27/**
28 * Calendar time interpreted as seconds elapsed since the Epoch (00:00:00 on
29 * January 1, 1970, Coordinated Universal Time (UTC)).
30 */
31typedef int rs_time_t;
32
33/**
34 * Data structure for broken-down time components.
35 *
36 * tm_sec   - Seconds after the minute. This ranges from 0 to 59, but possibly
37 *            up to 60 for leap seconds.
38 * tm_min   - Minutes after the hour. This ranges from 0 to 59.
39 * tm_hour  - Hours past midnight. This ranges from 0 to 23.
40 * tm_mday  - Day of the month. This ranges from 1 to 31.
41 * tm_mon   - Months since January. This ranges from 0 to 11.
42 * tm_year  - Years since 1900.
43 * tm_wday  - Days since Sunday. This ranges from 0 to 6.
44 * tm_yday  - Days since January 1. This ranges from 0 to 365.
45 * tm_isdst - Flag to indicate whether daylight saving time is in effect. The
46 *            value is positive if it is in effect, zero if it is not, and
47 *            negative if the information is not available.
48 */
49typedef struct {
50    int tm_sec;     ///< seconds
51    int tm_min;     ///< minutes
52    int tm_hour;    ///< hours
53    int tm_mday;    ///< day of the month
54    int tm_mon;     ///< month
55    int tm_year;    ///< year
56    int tm_wday;    ///< day of the week
57    int tm_yday;    ///< day of the year
58    int tm_isdst;   ///< daylight savings time
59} rs_tm;
60
61/**
62 * Returns the number of seconds since the Epoch (00:00:00 UTC, January 1,
63 * 1970). If @p timer is non-NULL, the result is also stored in the memory
64 * pointed to by this variable. If an error occurs, a value of -1 is returned.
65 *
66 * @param timer Location to also store the returned calendar time.
67 *
68 * @return Seconds since the Epoch.
69 */
70extern rs_time_t __attribute__((overloadable))
71    rsTime(rs_time_t *timer);
72
73/**
74 * Converts the time specified by @p timer into broken-down time and stores it
75 * in @p local. This function also returns a pointer to @p local. If @p local
76 * is NULL, this function does nothing and returns NULL.
77 *
78 * @param local Broken-down time.
79 * @param timer Input time as calendar time.
80 *
81 * @return Pointer to broken-down time (same as input @p local).
82 */
83extern rs_tm * __attribute__((overloadable))
84    rsLocaltime(rs_tm *local, const rs_time_t *timer);
85
86/**
87 * Returns the current system clock (uptime) in milliseconds.
88 *
89 * @return Uptime in milliseconds.
90 */
91extern int64_t __attribute__((overloadable))
92    rsUptimeMillis(void);
93
94/**
95 * Returns the current system clock (uptime) in nanoseconds.
96 *
97 * @return Uptime in nanoseconds.
98 */
99extern int64_t __attribute__((overloadable))
100    rsUptimeNanos(void);
101
102/**
103 * Returns the time in seconds since this function was last called in this
104 * script.
105 *
106 * @return Time in seconds.
107 */
108extern float __attribute__((overloadable))
109    rsGetDt(void);
110
111#endif
112