// Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// As a special exception, if you include this header file into source
+// As a specialhttp://idunno.org/archive/2004/07/14/122.aspx exception, if you include this header file into source
// files to be compiled, this header file does not by itself cause
// the resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// 23-Jul-2007 SANGORRIN: create this file for debugging functions
// 31-Jul-2007 TELLERIA: Change "debug" for "trace"
// -----------------------------------------------------------------------
+#ifndef FRSH_DEBUG_H
+#define FRSH_DEBUG_H
+
#include <stdio.h> // for vprintf
#include <stdbool.h> // for bool
#include <stdarg.h> // for va_list, va_start and va_end
+#include "timespec_operations.h"
+#include "fosa_configuration_parameters.h" /* FOSA_CLOCK_REALTIME */
// Tune the following FLAGS to select the debugging messages to be generated
#define FRSH_TRACE_CALLBACKS false
+#define FRSH_TRACE_SERVICE_TH false
#define FRSH_TRACE_WATCHDOG false
#define FRSH_TRACE_TIMEDWAIT false
-#define FRSH_TRACE_SERVICE_TH false
#define FRSH_TRACE_SPORADIC_SERVER false
#define FRSH_TRACE_ROUND_ROBIN false
#define FRSH_TRACE_THREAD_INDEX false
#define FRSH_TRACE_VRES_INDEX false
+#define FRSH_TRACE_TS_MSECS
+
+/* These variables live defined in frsh_error.c */
+/************************************************/
+extern struct timespec frsh_trace_init_timespec;
+extern long frsh_trace_init_timemsec;
+
+
+static inline long int FRSH_GET_TIMESTAMP_MSECS()
+{
+ int terror = -1;
+ struct timespec current_time = {-1, -1};
+ long int current_time_msec = -1;
+ long int result = -1;
+
+ PRW( fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time) );
+ timespec2msec(¤t_time, ¤t_time_msec);
+
+ result = current_time_msec - frsh_trace_init_timemsec;
+
+ return result;
+}
+
+
static void inline FRSH_TRACE(bool is_active, const char *format, ...)
{
va_list args;
+#ifdef FRSH_TRACE_TS_MSECS
+ const int TS_LENGTH_MSECS = 10; /* Room for LONG_MAX 2147483648 */
+#endif
+
if (is_active) {
+
va_start(args, format);
+
+#ifdef FRSH_TRACE_TS_MSECS
+ printf("%*ld: ", TS_LENGTH_MSECS, FRSH_GET_TIMESTAMP_MSECS());
+#endif
vprintf(format, args);
va_end(args);
}
}
+
+
+
+#endif
static inline void timespec2msec(const struct timespec *timespec, long *msec)
{
- *msec = 0;
+
+ *msec = (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000;
+}
- /* We convert first the seconds checking for a possible overflow */
- if (timespec->tv_sec < 2147482)
- {
- *msec = timespec->tv_sec*1000;
- }
- else
- {
- *msec = -1;
- return;
- }
- /* Now we add the contribution from the msecs with a truncation */
- *msec += (timespec->tv_nsec/1000000);
+#define HOURS_IN_MSECS 3600000
+#define MINUTES_IN_MSECS 60000
+
+#define HOURS_IN_TS 1000000
+#define MINUTES_IN_TS 100000
+
+static inline long timespec2msects(const struct timespec *timespec)
+{
+ long msec_total = -1;
+ long minutes = -1;
+ long hours = -1;
+
+ long remainder_msecs = -1;
+ long timestamp = -1;
+
+ msec_total = (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000;
+
+ hours = msec_total / HOURS_IN_MSECS;
+ minutes = (msec_total % HOURS_IN_MSECS) / MINUTES_IN_MSECS;
+ remainder_msecs = ( (msec_total % HOURS_IN_MSECS) % MINUTES_IN_MSECS);
+
+ timestamp = hours*HOURS_IN_TS + minutes*MINUTES_IN_TS + remainder_msecs;
+ return timestamp;
}
+
//------------------------//
// timespec_lessthan_msec //