| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2004-2005 Mathieu Desnoyers |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program 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 |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * 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 <ltt/ltt-private.h> |
| 27 | #include <glib.h> |
| 28 | #include <ltt/time.h> |
| 29 | |
| 30 | |
| 31 | /***************************************************************************** |
| 32 | *Function name |
| 33 | * ltt_get_int64 : get a 64 bits integer number |
| 34 | *Input params |
| 35 | * ptr : pointer to the integer |
| 36 | *Return value |
| 37 | * gint64 : a 64 bits integer |
| 38 | * |
| 39 | * Takes care of endianness |
| 40 | * |
| 41 | ****************************************************************************/ |
| 42 | |
| 43 | static inline gint64 ltt_get_int64(gboolean reverse_byte_order, void *ptr) |
| 44 | { |
| 45 | guint64 value = *(guint64*)ptr; |
| 46 | return (gint64) (reverse_byte_order ? GUINT64_SWAP_LE_BE(value): value); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | static inline guint64 ltt_get_uint64(gboolean reverse_byte_order, void *ptr) |
| 51 | { |
| 52 | guint64 value = *(guint64*)ptr; |
| 53 | return (guint64) (reverse_byte_order ? GUINT64_SWAP_LE_BE(value): value); |
| 54 | } |
| 55 | |
| 56 | static inline gint32 ltt_get_int32(gboolean reverse_byte_order, void *ptr) |
| 57 | { |
| 58 | guint32 value = *(guint32*)ptr; |
| 59 | return (gint32) (reverse_byte_order ? GUINT32_SWAP_LE_BE(value): value); |
| 60 | } |
| 61 | |
| 62 | static inline guint32 ltt_get_uint32(gboolean reverse_byte_order, void *ptr) |
| 63 | { |
| 64 | guint32 value = *(guint32*)ptr; |
| 65 | return (guint32) (reverse_byte_order ? GUINT32_SWAP_LE_BE(value): value); |
| 66 | } |
| 67 | |
| 68 | static inline gint16 ltt_get_int16(gboolean reverse_byte_order, void *ptr) |
| 69 | { |
| 70 | guint16 value = *(guint16*)ptr; |
| 71 | return (gint16) (reverse_byte_order ? GUINT16_SWAP_LE_BE(value): value); |
| 72 | } |
| 73 | |
| 74 | static inline guint16 ltt_get_uint16(gboolean reverse_byte_order, void *ptr) |
| 75 | { |
| 76 | guint16 value = *(guint16*)ptr; |
| 77 | return (guint16) (reverse_byte_order ? GUINT16_SWAP_LE_BE(value): value); |
| 78 | } |
| 79 | |
| 80 | static inline LttTime ltt_get_time(gboolean reverse_byte_order, void *ptr) |
| 81 | { |
| 82 | LttTime output; |
| 83 | |
| 84 | output.tv_sec = ltt_get_uint64(reverse_byte_order, ptr); |
| 85 | ptr += sizeof(guint64); |
| 86 | output.tv_nsec = ltt_get_uint64(reverse_byte_order, ptr); |
| 87 | |
| 88 | return output; |
| 89 | } |
| 90 | |
| 91 | #endif // LTT_TYPES_H |