Parcourir la source

[time] Define an API for getting the current time

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown il y a 12 ans
Parent
révision
846bde90e6

+ 12
- 0
src/arch/i386/include/bits/time.h Voir le fichier

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_TIME_H
2
+#define _BITS_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * i386-specific time API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#endif /* _BITS_TIME_H */

+ 12
- 0
src/arch/x86_64/include/bits/time.h Voir le fichier

@@ -0,0 +1,12 @@
1
+#ifndef _BITS_TIME_H
2
+#define _BITS_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * x86_64-specific time API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#endif /* _BITS_TIME_H */

+ 1
- 0
src/config/defaults/efi.h Voir le fichier

@@ -18,6 +18,7 @@
18 18
 #define SANBOOT_NULL
19 19
 #define BOFM_EFI
20 20
 #define ENTROPY_NULL
21
+#define TIME_NULL
21 22
 
22 23
 #define	IMAGE_EFI		/* EFI image support */
23 24
 #define	IMAGE_SCRIPT		/* iPXE script image support */

+ 1
- 0
src/config/defaults/linux.h Voir le fichier

@@ -15,6 +15,7 @@
15 15
 #define SMBIOS_LINUX
16 16
 #define SANBOOT_NULL
17 17
 #define ENTROPY_LINUX
18
+#define TIME_NULL
18 19
 
19 20
 #define DRIVERS_LINUX
20 21
 

+ 1
- 0
src/config/defaults/pcbios.h Voir le fichier

@@ -19,6 +19,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
19 19
 #define SMBIOS_PCBIOS
20 20
 #define SANBOOT_PCBIOS
21 21
 #define ENTROPY_RTC
22
+#define TIME_NULL
22 23
 
23 24
 #define	IMAGE_ELF		/* ELF image support */
24 25
 #define	IMAGE_MULTIBOOT		/* MultiBoot image support */

+ 16
- 0
src/config/time.h Voir le fichier

@@ -0,0 +1,16 @@
1
+#ifndef CONFIG_TIME_H
2
+#define CONFIG_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * Time API configuration
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <config/defaults.h>
13
+
14
+#include <config/local/time.h>
15
+
16
+#endif /* CONFIG_TIME_H */

+ 29
- 0
src/core/null_time.c Voir le fichier

@@ -0,0 +1,29 @@
1
+/*
2
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+FILE_LICENCE ( GPL2_OR_LATER );
20
+
21
+/** @file
22
+ *
23
+ * Nonexistent time source
24
+ *
25
+ */
26
+
27
+#include <ipxe/time.h>
28
+
29
+PROVIDE_TIME_INLINE ( null, time_now );

+ 23
- 0
src/include/ipxe/null_time.h Voir le fichier

@@ -0,0 +1,23 @@
1
+#ifndef _IPXE_NULL_TIME_H
2
+#define _IPXE_NULL_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * Nonexistent time source
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#ifdef TIME_NULL
13
+#define TIME_PREFIX_null
14
+#else
15
+#define TIME_PREFIX_null __null_
16
+#endif
17
+
18
+static inline __always_inline time_t
19
+TIME_INLINE ( null, time_now ) ( void ) {
20
+	return 0;
21
+}
22
+
23
+#endif /* _IPXE_NULL_TIME_H */

+ 58
- 0
src/include/ipxe/time.h Voir le fichier

@@ -0,0 +1,58 @@
1
+#ifndef _IPXE_TIME_H
2
+#define _IPXE_TIME_H
3
+
4
+/** @file
5
+ *
6
+ * Time source
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+#include <sys/time.h>
13
+#include <ipxe/api.h>
14
+#include <config/time.h>
15
+
16
+/**
17
+ * Calculate static inline time API function name
18
+ *
19
+ * @v _prefix		Subsystem prefix
20
+ * @v _api_func		API function
21
+ * @ret _subsys_func	Subsystem API function
22
+ */
23
+#define TIME_INLINE( _subsys, _api_func ) \
24
+	SINGLE_API_INLINE ( TIME_PREFIX_ ## _subsys, _api_func )
25
+
26
+/**
27
+ * Provide a time API implementation
28
+ *
29
+ * @v _prefix		Subsystem prefix
30
+ * @v _api_func		API function
31
+ * @v _func		Implementing function
32
+ */
33
+#define PROVIDE_TIME( _subsys, _api_func, _func ) \
34
+	PROVIDE_SINGLE_API ( TIME_PREFIX_ ## _subsys, _api_func, _func )
35
+
36
+/**
37
+ * Provide a static inline time API implementation
38
+ *
39
+ * @v _prefix		Subsystem prefix
40
+ * @v _api_func		API function
41
+ */
42
+#define PROVIDE_TIME_INLINE( _subsys, _api_func ) \
43
+	PROVIDE_SINGLE_API_INLINE ( TIME_PREFIX_ ## _subsys, _api_func )
44
+
45
+/* Include all architecture-independent time API headers */
46
+#include <ipxe/null_time.h>
47
+
48
+/* Include all architecture-dependent time API headers */
49
+#include <bits/time.h>
50
+
51
+/**
52
+ * Get current time in seconds
53
+ *
54
+ * @ret time		Time, in seconds
55
+ */
56
+time_t time_now ( void );
57
+
58
+#endif /* _IPXE_TIME_H */

+ 16
- 0
src/include/time.h Voir le fichier

@@ -7,6 +7,7 @@
7 7
  */
8 8
 
9 9
 #include <sys/time.h>
10
+#include <ipxe/time.h>
10 11
 
11 12
 /** Broken-down time */
12 13
 struct tm {
@@ -30,6 +31,21 @@ struct tm {
30 31
 	int tm_isdst;
31 32
 };
32 33
 
34
+/**
35
+ * Get current time in seconds since the Epoch
36
+ *
37
+ * @v t			Time to fill in, or NULL
38
+ * @ret time		Current time
39
+ */
40
+static inline time_t time ( time_t *t ) {
41
+	time_t now;
42
+
43
+	now = time_now();
44
+	if ( t )
45
+		*t = now;
46
+	return now;
47
+}
48
+
33 49
 extern time_t mktime ( struct tm *tm );
34 50
 
35 51
 #endif /* _TIME_H */

Chargement…
Annuler
Enregistrer