Init basesystem source codes.
[staging/basesystem.git] / vehicleservice / positioning_base_library / library / src / _pbMisc.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 /*
18 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19  File name      : _pbMisc.cpp
20  System name    : 05 Integration Platform
21  Subsystem name : System common functions
22  Title          : System API Time-of-day operations related processing group
23 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
24 */
25
26 #include <vehicle_service/positioning_base_library.h>
27 #include "WPF_STD_private.h"
28
29 /*
30  Declaration of constant data type
31 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
32 typedef struct {
33     DWORD time_on_january1_1970;    /* Time on January 1, 1970 when it expressed */
34     /* with the total second number from January 1, 1601 */
35 } BTIME_INSTANCE;
36
37 /*
38  Internal function prototype declaration
39 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
40 static DWORD    FileTimeToSeonds(FILETIME* p_ft);
41
42 /*
43  Global Variable Definitions
44 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45 BTIME_INSTANCE            g_instance;    // NOLINT(readability/nolint)  global class instance
46
47 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
48  * MODULE    : MiscInit()
49  * ABSTRACT  : Time-related processing instance initialization processing
50  * NOTE      : Assign and hold 1/1/1970 to FILETIME variables
51  * ARGUMENT  : None
52  * RETURN    : RET_API        RET_NORMAL        Normal completion Note: Always this value
53  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
54 RET_API
55 MiscInit(void) {  // LCOV_EXCL_START 8:dead code
56     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
57     BTIME_INSTANCE    *p_inst = &g_instance;
58     SYSTEMTIME        st;
59     FILETIME          ft;
60     BOOL              bret;
61
62     /* Set the system time to the default value (January 1, 1970, 00:00:00). */
63     st.wYear            = 1970;
64     st.wMonth           = 1;
65     st.wDayOfWeek       = 0;
66     st.wDay             = 1;
67     st.wHour            = 0;
68     st.wMinute          = 0;
69     st.wSecond          = 0;
70     st.wMilliseconds    = 0;
71
72     /* Converting System Time to File Time */
73     bret = PbSystemTimeToFileTime(&st, &ft);
74     if (bret != TRUE) {
75         /* If the conversion fails, */
76         p_inst->time_on_january1_1970 = 0;                        /* Save to instance with zero elapsed seconds */
77     } else {
78         /* If the conversion is successful, */
79         p_inst->time_on_january1_1970 = FileTimeToSeonds(&ft);    /* Save File Time Elapsed Seconds to Instance */
80     }
81
82     return(RET_NORMAL);
83 }
84 // LCOV_EXCL_STOP
85
86 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
87  * MODULE    : FileTimeToSeonds()
88  * ABSTRACT  : File Time -> Time Conversion Processing
89  * NOTE      : Convert the file time to seconds
90  * ARGUMENT  : FILETIME        *p_ft        Pointer to the file time structure
91  * RETURN    : DWORD        Elapsing time(In seconds)
92  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
93 static DWORD
94 FileTimeToSeonds(FILETIME* p_ft) {  // LCOV_EXCL_START 8:dead code
95     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
96     return 0;
97 }
98 // LCOV_EXCL_STOP
99
100 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
101  * MODULE    : MiscTerm()
102  * ABSTRACT  : Time-related processing instance release processing
103  * NOTE      :
104  * ARGUMENT  : None
105  * RETURN    : RET_API        RET_NORMAL        Normal completion Note: Always this value
106  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
107 RET_API
108 MiscTerm(void) {  // LCOV_EXCL_START 8:dead code
109     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
110     return(RET_NORMAL);
111 }
112 // LCOV_EXCL_STOP
113
114 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
115  * MODULE    : Sleep()
116  * ABSTRACT  : Sleep Processing
117  * NOTE      : Cause the caller to sleep at the number of ticks specified by the argument
118  * ARGUMENT  : u_int32        ticks        Sleep time(Specify in ticks)
119  *           :                0            Sleep permanently
120  *           :                1            Discard the time slice
121  * RETURN    : RET_API        Normal completion Note: Always this value
122  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
123 RET_API
124 Sleep(u_int32 ticks) {  // LCOV_EXCL_START 8:dead code
125     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
126     DWORD        milliseconds;
127
128     switch (ticks) {
129         case 0:            /* infinite delay. */
130         {
131             milliseconds = INFINITE;
132             break;
133         }
134         case 1:            /* the thread to relinquish the remainder of its time slice */
135             /* to any other thread of equal priority that is ready to run. */
136             /* If there are no other threads of equal priority ready to run, */
137             /* the function returns immediately, and the thread continues execution. */
138         {
139             milliseconds = 0;
140             break;
141         }
142         default:        /* Time tranrate from per 10ms tick count to per milli second. */
143             milliseconds = (DWORD)ticks * 10;
144             break;
145     }
146     PbMilliSecSleep(static_cast<u_int32>(milliseconds));
147
148     return(RET_NORMAL);
149 }
150 // LCOV_EXCL_STOP
151
152 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
153  * MODULE    : PbMilliSecSleep()
154  * ABSTRACT  : Sleep Processing(Units of ms)
155  * NOTE      : Cause the caller to sleep at the number of ticks specified by the argument
156  * ARGUMENT  : u_int32        ul_mill_time    Sleep time(Specified in millimeters)
157  *           :                0            Discard the time slice
158  *           :                INFINITE    Sleep permanently
159  * RETURN    : RET_API        Normal completion Note: Always this value
160  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
161 RET_API PbMilliSecSleep(u_int32 ul_mill_time) {  // LCOV_EXCL_START 8:dead code
162     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
163     switch (ul_mill_time) {
164         case 0:
165         {
166             /* Discard the time slice */
167             sched_yield();
168             break;
169         }
170         case INFINITE:
171         {
172             /* Abort processing indefinitely */
173             while (1) {
174                 sleep(INFINITE);
175             }
176         }
177         default:
178             /* Sleep for Specified Time */
179             usleep(ul_mill_time * 1000);
180             break;
181     }
182
183     return RET_NORMAL;
184 }
185 // LCOV_EXCL_STOP
186
187 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
188  * MODULE    : SecSleep()
189  * ABSTRACT  : Sleep Processing(s unit)
190  * NOTE      : Cause the caller to sleep at the number of ticks specified by the argument
191  * ARGUMENT  : u_int32        ul_time        Sleep time(Specify in seconds)
192  *           :                0            Discard the time slice
193  *           :                INFINITE    Sleep permanently
194  * RETURN    : RET_API        Normal completion Note: Always this value
195  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
196 RET_API SecSleep(u_int32 ul_time) {  // LCOV_EXCL_START 8:dead code
197     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
198     switch (ul_time) {
199         case 0:
200         {
201             /* Discard the time slice */
202             sched_yield();
203             break;
204         }
205         case INFINITE:
206         {
207             /* Abort processing indefinitely */
208             while (1) {
209                 sleep(INFINITE);
210             }
211         }
212         default:
213             /* Sleep for Specified Time */
214             sleep(ul_time);
215             break;
216     }
217
218     return RET_NORMAL;
219 }
220 // LCOV_EXCL_STOP
221
222 /*
223 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
224  End of File : _sysMisc.cpp
225 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
226 */