aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorMaxim Uvarov <maxim.uvarov@linaro.org>2015-12-01 16:27:31 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2015-12-03 17:57:47 +0300
commit28a6ef9c0b4b4cce3e72fc27dbe3040683215b80 (patch)
treeb24409e7f943607b378046c07398f971ed427669 /helper
parent89701399735b08f8a8c90574c85a7589e51d2cdf (diff)
helper: strong types support
Add strong types support for helpers the same as we have for linux-generic. That should be useful for complex algorithms where type check is needed. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Tested-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Diffstat (limited to 'helper')
-rw-r--r--helper/Makefile.am1
-rw-r--r--helper/include/odp/helper/strong_types.h35
2 files changed, 36 insertions, 0 deletions
diff --git a/helper/Makefile.am b/helper/Makefile.am
index bed8683d2..1906ae285 100644
--- a/helper/Makefile.am
+++ b/helper/Makefile.am
@@ -15,6 +15,7 @@ helperinclude_HEADERS = \
$(srcdir)/include/odp/helper/icmp.h\
$(srcdir)/include/odp/helper/ip.h\
$(srcdir)/include/odp/helper/ipsec.h\
+ $(srcdir)/include/odp/helper/strong_types.h\
$(srcdir)/include/odp/helper/tcp.h\
$(srcdir)/include/odp/helper/table.h\
$(srcdir)/include/odp/helper/udp.h
diff --git a/helper/include/odp/helper/strong_types.h b/helper/include/odp/helper/strong_types.h
new file mode 100644
index 000000000..777e24d4d
--- /dev/null
+++ b/helper/include/odp/helper/strong_types.h
@@ -0,0 +1,35 @@
+/* Copyright (c) 2015, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/**
+ * @file
+ *
+ * ODP Strong Types. Common macros for implementing strong typing
+ * for ODP abstract data types
+ */
+
+#ifndef ODPH_STRONG_TYPES_H_
+#define ODPH_STRONG_TYPES_H_
+
+/** Use strong typing for ODP types */
+#ifdef __cplusplus
+#define ODPH_HANDLE_T(type) struct _##type { uint8_t unused_dummy_var; } *type
+#else
+#define odph_handle_t struct { uint8_t unused_dummy_var; } *
+/** C/C++ helper macro for strong typing */
+#define ODPH_HANDLE_T(type) odph_handle_t type
+#endif
+
+/** Internal macro to get value of an ODP handle */
+#define _odph_typeval(handle) ((uint32_t)(uintptr_t)(handle))
+
+/** Internal macro to get printable value of an ODP handle */
+#define _odph_pri(handle) ((uint64_t)_odph_typeval(handle))
+
+/** Internal macro to convert a scalar to a typed handle */
+#define _odph_cast_scalar(type, val) ((type)(uintptr_t)(val))
+
+#endif