| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2004-2005 Mathieu Desnoyers |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License Version 2.1 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This library is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU Lesser General Public |
| 14 | * License along with this library; if not, write to the |
| 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | * Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef LTT_TYPES_H |
| 20 | #define LTT_TYPES_H |
| 21 | |
| 22 | /* Set of functions to access the types portably, given the trace as parameter. |
| 23 | * */ |
| 24 | |
| 25 | #include <ltt/ltt.h> |
| 26 | #include <glib.h> |
| 27 | #include <ltt/time.h> |
| 28 | |
| 29 | |
| 30 | /***************************************************************************** |
| 31 | *Function name |
| 32 | * ltt_get_int64 : get a 64 bits integer number |
| 33 | *Input params |
| 34 | * ptr : pointer to the integer |
| 35 | *Return value |
| 36 | * gint64 : a 64 bits integer |
| 37 | * |
| 38 | * Takes care of endianness |
| 39 | * |
| 40 | ****************************************************************************/ |
| 41 | |
| 42 | static inline gint64 ltt_get_int64(gboolean reverse_byte_order, void *ptr) |
| 43 | { |
| 44 | guint64 value = *(guint64*)ptr; |
| 45 | return (gint64) (reverse_byte_order ? GUINT64_SWAP_LE_BE(value): value); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | static inline guint64 ltt_get_uint64(gboolean reverse_byte_order, void *ptr) |
| 50 | { |
| 51 | guint64 value = *(guint64*)ptr; |
| 52 | return (guint64) (reverse_byte_order ? GUINT64_SWAP_LE_BE(value): value); |
| 53 | } |
| 54 | |
| 55 | static inline gint32 ltt_get_int32(gboolean reverse_byte_order, void *ptr) |
| 56 | { |
| 57 | guint32 value = *(guint32*)ptr; |
| 58 | return (gint32) (reverse_byte_order ? GUINT32_SWAP_LE_BE(value): value); |
| 59 | } |
| 60 | |
| 61 | static inline guint32 ltt_get_uint32(gboolean reverse_byte_order, void *ptr) |
| 62 | { |
| 63 | guint32 value = *(guint32*)ptr; |
| 64 | return (guint32) (reverse_byte_order ? GUINT32_SWAP_LE_BE(value): value); |
| 65 | } |
| 66 | |
| 67 | static inline gint16 ltt_get_int16(gboolean reverse_byte_order, void *ptr) |
| 68 | { |
| 69 | guint16 value = *(guint16*)ptr; |
| 70 | return (gint16) (reverse_byte_order ? GUINT16_SWAP_LE_BE(value): value); |
| 71 | } |
| 72 | |
| 73 | static inline guint16 ltt_get_uint16(gboolean reverse_byte_order, void *ptr) |
| 74 | { |
| 75 | guint16 value = *(guint16*)ptr; |
| 76 | return (guint16) (reverse_byte_order ? GUINT16_SWAP_LE_BE(value): value); |
| 77 | } |
| 78 | |
| 79 | static inline LttTime ltt_get_time(gboolean reverse_byte_order, void *ptr) |
| 80 | { |
| 81 | LttTime output; |
| 82 | |
| 83 | output.tv_sec = ltt_get_uint32(reverse_byte_order, ptr); |
| 84 | ptr += sizeof(guint32); |
| 85 | output.tv_nsec = ltt_get_uint32(reverse_byte_order, ptr); |
| 86 | |
| 87 | return output; |
| 88 | } |
| 89 | |
| 90 | #endif // LTT_TYPES_H |