diff mbox

[PATCHv3,6/9] linux-generic: packet: add strong typing support

Message ID 1422749807-20228-9-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Feb. 1, 2015, 12:16 a.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 include/odp/api/packet.h                           | 25 ++++++++++++++++++++++
 .../linux-generic/include/odp/plat/packet_types.h  | 24 +++++++++++++++------
 platform/linux-generic/odp_packet.c                |  8 +++----
 3 files changed, 47 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/packet.h b/include/odp/api/packet.h
index 3c1c646..7cc923e 100644
--- a/include/odp/api/packet.h
+++ b/include/odp/api/packet.h
@@ -869,6 +869,31 @@  void odp_packet_print(odp_packet_t pkt);
  */
 int odp_packet_is_valid(odp_packet_t pkt);
 
+/**
+ * Get printable value for an odp_packet_t
+ *
+ * @param hdl  odp_packet_t handle to be printed
+ * @return     uint64_t value that can be used to print/display this
+ *             handle
+ *
+ * @note This routine is intended to be used for diagnostic purposes
+ * to enable applications to generate a printable value that represents
+ * an odp_packet_t handle.
+ */
+uint64_t odp_packet_t_print(odp_packet_t hdl);
+
+/**
+ * Get printable value for an odp_packet_seg_t
+ *
+ * @param hdl  odp_packet_seg_t handle to be printed
+ * @return     uint64_t value that can be used to print/display this
+ *             handle
+ *
+ * @note This routine is intended to be used for diagnostic purposes
+ * to enable applications to generate a printable value that represents
+ * an odp_packet_seg_t handle.
+ */
+uint64_t odp_packet_seg_t_print(odp_packet_seg_t hdl);
 
 /**
  * @}
diff --git a/platform/linux-generic/include/odp/plat/packet_types.h b/platform/linux-generic/include/odp/plat/packet_types.h
index 60d6443..86f12a5 100644
--- a/platform/linux-generic/include/odp/plat/packet_types.h
+++ b/platform/linux-generic/include/odp/plat/packet_types.h
@@ -18,23 +18,35 @@ 
 extern "C" {
 #endif
 
-
-#include <odp/plat/buffer_types.h>
+#include <odp/std_types.h>
+#include <odp/plat/strong_types.h>
 
 /** @addtogroup odp_packet ODP PACKET
  *  Operations on a packet.
  *  @{
  */
 
-typedef odp_buffer_t odp_packet_t;
+typedef odp_handle_t odp_packet_t;
 
-#define ODP_PACKET_INVALID ODP_BUFFER_INVALID
+#define ODP_PACKET_INVALID _odp_cast_scalar(odp_packet_t, 0xffffffff)
 
 #define ODP_PACKET_OFFSET_INVALID (0x0fffffff)
 
-typedef odp_buffer_t odp_packet_seg_t;
+typedef odp_handle_t odp_packet_seg_t;
+
+#define ODP_PACKET_SEG_INVALID _odp_cast_scalar(odp_packet_seg_t, 0xffffffff)
 
-#define ODP_PACKET_SEG_INVALID ODP_BUFFER_INVALID
+/** Get printable format of odp_packet_t */
+static inline uint64_t odp_packet_t_print(odp_packet_t hdl)
+{
+	return _odp_pri(hdl);
+}
+
+/** Get printable format of odp_packet_seg_t */
+static inline uint64_t odp_packet_seg_t_print(odp_packet_seg_t hdl)
+{
+	return _odp_pri(hdl);
+}
 
 /**
  * @}
diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c
index 04787e8..b0f9771 100644
--- a/platform/linux-generic/odp_packet.c
+++ b/platform/linux-generic/odp_packet.c
@@ -193,10 +193,10 @@  void *odp_packet_offset(odp_packet_t pkt, uint32_t offset, uint32_t *len,
 
 	if (addr != NULL && seg != NULL) {
 		odp_buffer_bits_t seghandle;
-		seghandle.handle = pkt;
+		seghandle.handle = (odp_buffer_t)pkt;
 		seghandle.seg = (pkt_hdr->headroom + offset) /
 			pkt_hdr->buf_hdr.segsize;
-		*seg = seghandle.handle;
+		*seg = (odp_packet_seg_t)seghandle.handle;
 	}
 
 	return addr;
@@ -325,9 +325,9 @@  odp_packet_seg_t odp_packet_last_seg(odp_packet_t pkt)
 	odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
 	odp_buffer_bits_t seghandle;
 
-	seghandle.handle = pkt;
+	seghandle.handle = (odp_buffer_t)pkt;
 	seghandle.seg = pkt_hdr->buf_hdr.segcount - 1;
-	return seghandle.handle;
+	return (odp_packet_seg_t)seghandle.handle;
 }
 
 odp_packet_seg_t odp_packet_next_seg(odp_packet_t pkt, odp_packet_seg_t seg)