#ifndef __ERROR_H__
#define __ERROR_H__

#include <errno.h>

#define ERROR_ARG    (-1) /* signifies error with argument */
#define ERROR_ASSERT (-2) /* signifies error with ASSERT */

extern int DEBUG_LEVEL; // defined in charger.c

#define DEBUG(level, str, ...) { \
          if (level <= DEBUG_LEVEL) { \
             fprintf (stderr, str, ## __VA_ARGS__); \
          } \
        }

#define ERROR(str, ...) { \
           fprintf (stderr, "%s:%d:", __FILE__, __LINE__); \
           fprintf (stderr, str, ## __VA_ARGS__); \
        }

#define ASSERT(exp) { \
           if (!(exp)) { \
              ERROR ("Assertion failed on line %d in file %s\n", \
                     __LINE__, __FILE__); \
              return ERROR_ASSERT; \
	   } \
        }

#endif /* __ERROR_H__ */
