/***********************************************************************
               Copyright (c) 2000-2002 SKY Computers, Inc.

 Redistribution and use in source and binary forms are permitted
 provided that this notice is preserved and that due credit is given to
 SKY Computers, Inc. The name of SKY Computers, Inc. may not be used to
 endorse or promote products derived from this software without
 specific prior written permission. This software is provided ``as is''
 without express or implied warranty.
************************************************************************/

#ifndef _time_trac_h_
#define _time_trac_h_

#ifdef  __cplusplus
extern "C"
{
#endif

  typedef enum
    {
      /* The following are bit fields */
      TT_SAVE_WHEN_BUFFER_FULL = 0x0001,	/* When the event buffer is full of unsaved events then save them. */
      TT_NO_AUTO_SAVE = 0x0002	/* Never automatically save events to a file, only manually */
    }
  TTSaveEventsEnum;

  typedef enum
    {
      /* The following are bit fields */
      TT_OVERWRITE_FILE = 0x0001,
      TT_APPEND_TO_FILE = 0x0002
    }
  TTSaveModeEnum;

  typedef enum
    {
      /* The following are bit fields */
      TT_CREATE_FILE = 0x0001,	/* create file, if it exists just truncate it to zero */
      TT_CREATE_FILE_EXCLUSIVE = 0x0002		/* create file, error if it already exists */
    }
  TTFileOpenModeEnum;

  typedef int TTEventHandle;
  typedef int TTContextHandle;

#define TT_EVENT_IDLE_START 0
#define TT_EVENT_IDLE_END   1

  typedef enum
    {
      TTE_SUCCESS,		/* No errors. */
      TTE_HANDLE_INVALID,	/* The trace handle is NULL or the wrong format. */
      TTE_EVENT_HANDLE_INVALID,	/* The TimeTrac event handle is not valid. */
      TTE_CONTEXT_HANDLE_INVALID,	/* The TimeTrac context handle is not valid. */
      TTE_NO_MEMORY,		/* Can't allocate memory. */
      TTE_INVALID_FILENAME,	/* Filename must not be NULL. */
      TTE_INVALID_CARDINAL,	/* The value for 'num_events' is invalid, must be an integer greater than 0. */
      TTE_INVALID_SAVE_VALUES,	/* 'save_when' must be TT_SAVE_WHEN_BUFFER_FULL or TT_NO_AUTO_SAVE. */
      TTE_INVALID_FILE_OPEN_MODE,	/* 'file_open_mode' must be set to TT_CREATE_FILE, or TT_CREATE_FILE_EXCLUSIVE. */
      TTE_INVALID_TIME_SPEC,	/* The value for 'milli_seconds' is invalid, must be an integer greater than 0. */
      TTE_CONTEXT_DEPTH_INVALID,	/* The value for 'maximum_context_depth' must be a positive number. */
      TTE_INVALID_EVENT_HANDLE,	/* The event handle was not registered with the corresponding trace handle. */
      TTE_CANT_OPEN_FILE,	/* Can't open file to save events. */
      TTE_NULL_NAME,		/* Name can not be NULL. */
      TTE_BAD_COLOR,		/* The name specified for color is not valid. */
      TTE_BAD_GROUP,		/* The value for group should be a single bit, and it may not be the MSB. */
      TTE_BAD_GROUP_MASK,	/* The value for group_msk should be the set of bits that represent the groups to be recorded. */
      TTE_NAME_IN_USE,		/* The event/context name is already in use. */
      TTE_REGISTRY_FULL,	/* More than 32766 events have been registered. */
      TTE_INVALID_CONTEXT_HANDLE,	/* The context handle was not registered in this trace session. */
      TTE_CONTEXT_DEPTH_EXCEEDED,	/* Tried to push onto a full context list, time_trac_pop() required to clean up. */
      TTE_POPPING_EMPTY_CONTEXT_LIST,	/* Tried to pop an empty context list. */
      TTE_POPPING_EXCEEDED_CONTEXT_LIST,	/* Context list was previously exceeded with a time_trac_push. Ignoring this pop. */
      TTE_MUTEX_NOT_CREATED,	/* Could not create the mutex for file saving and threads. */
      TTE_COULD_NOT_OBTAIN_MUTEX,	/* Could not obtain the mutex required to maintain thread safeness. */
      TTE_SAVE_REENTERED	/* time_trac_save() has been reentered, maybe via interrupt handler. Ignoring this call. */
    }
  TTErrorEnum;

  typedef struct _TTHandle TTHandleRec, *TTHandle;

#ifdef TIME_TRAC
  int time_trac_open (const char *filename, int thread_safe_required, int num_events, unsigned group_mask, TTSaveEventsEnum save_when, TTFileOpenModeEnum file_open_mode, int maximum_context_depth, TTHandle * handle_ret);
  int time_trac_save (TTHandle handle, TTSaveModeEnum file_save_mode);
  int time_trac_reg_range_event (TTHandle handle, const char *event_name, const char *color, unsigned group, TTEventHandle * start_handle, TTEventHandle * finished_handle);
  int time_trac_reg_single_event (TTHandle handle, const char *event_name, const char *color, unsigned group, TTEventHandle * event_handle);
  int time_trac_reg_context (TTHandle handle, const char *context_name, TTContextHandle * context_handle);
  int time_trac_close (TTHandle handle);
  int time_trac_record (TTHandle handle, TTEventHandle event_handle, float value);
  int time_trac_push_context (TTHandle handle, TTContextHandle context_handle);
  int time_trac_pop_context (TTHandle handle);
  int time_trac_pause (TTHandle handle);
  int time_trac_continue (TTHandle handle);
  void time_trac_perror (int status);

#else
#define time_trac_open(a,b,c,d,e,f,g,h) TTE_SUCCESS
#define time_trac_save(a,b) TTE_SUCCESS
#define time_trac_reg_range_event(a,b,c,d,e,f) TTE_SUCCESS
#define time_trac_reg_single_event(a,b,c,d,e) TTE_SUCCESS
#define time_trac_reg_context(a,b,c) TTE_SUCCESS
#define time_trac_close(a) TTE_SUCCESS
#define time_trac_record(a,b,c) TTE_SUCCESS
#define time_trac_push_context(a,b) TTE_SUCCESS
#define time_trac_pop_context(a) TTE_SUCCESS
#define time_trac_pause(a) TTE_SUCCESS
#define time_trac_continue(a) TTE_SUCCESS
#define time_trac_perror(a) TTE_SUCCESS
#endif

#ifdef  __cplusplus
}
#endif

#endif

