download diagnose.h
Language: C
LOC: 62
Project Info
grub.org - Distributed Internet Crawler(grub)
Server: SourceForge
Type: cvs
...ge\g\grub\grub\client\util\
   alt_ftw.c
   alt_ftw.h
   bin_test_util.dsp
   clog.cpp
   clog.h
   ConfigFileInfo.h
   crc.h
   crc_32.c
   crc_32.cpp
   crc_32.h
   crc_test.c
   crc_test.cpp
   crc32.c
   crc32.h
   dbl_list.c
   dbl_list.h
   delay.cpp
   delay.h
   diagnose.h
   fc32.c
   file_data.c
   file_data.h
   getopt.c
   getopt.h
   grubconf.c
   grubconf.h
   GrubExp.cpp
   GrubExp.h
   Gui.cpp
   Gui.h
   intl.h
   lib_util.dsp
   lockfile.cpp
   lockfile.h
   Makefile.am
   parsecfg.c
   parsecfg.h
   platform.h
   rmfiles.c
   rmfiles.h
   ServerSettings.cpp
   ServerSettings.h
   sniptype.h
   StatusInterface.cpp
   StatusInterface.h
   strip_url.c
   strip_url.h
   test_util.cpp

#ifndef _DIAGNOSE_H_
#define _DIAGNOSE_H_

/* diagnose feature works only in UNIX */
#ifdef GRUB_UNIX
#include <stdio.h>
#include <pthread.h>

/* Prints raw data to a log file.  To enable it it, define DIAG_ENABLE */

#define DIAG_MUTEX(diagname) diag_##diagname##_mutex

/* User must define mutex here */
#ifdef DIAG_ENABLE
#define DIAG_DEFINE(_diagname_) \
	static pthread_mutex_t DIAG_MUTEX(_diagname_) = PTHREAD_MUTEX_INITIALIZER
#else
#define DIAG_DEFINE(_diagname_)
#endif

#define DIAG_LOCK(mutex) \
	do { \
		pthread_mutex_lock(&mutex); \
	} while(0)

#define DIAG_UNLOCK(mutex) \
	do { \
		pthread_mutex_unlock(&mutex); \
	} while(0)

#define DIAG_LOGFILE(diagname) #diagname ".log"

#define DIAG_OPEN(logfile) \
	{ \
		FILE *diag_fp = NULL; \
		diag_fp = fopen(logfile, "ab"); \
		if ( diag_fp == NULL ) { \
			perror("DIAG_OPEN: fopen"); \
			exit(1); \
		}

#define DIAG_WRITE(buf, len) \
		fwrite(buf, 1, len, diag_fp)

#define DIAG_CLOSE() \
		fclose(diag_fp); \
	}

/* User must call DIAG_LOG to log */
#ifdef DIAG_ENABLE
#define DIAG_LOG(_diagname_, _buf_, _len_) \
	do { \
		DIAG_LOCK(DIAG_MUTEX(_diagname_)); \
		DIAG_OPEN(DIAG_LOGFILE(_diagname_)) \
		DIAG_WRITE((_buf_), (_len_)); \
		DIAG_CLOSE() \
		DIAG_UNLOCK(DIAG_MUTEX(_diagname_)); \
	} while (0)
#else
#define DIAG_LOG(_diagname_, _buf_, _len_) \
	do { \
	} while (0)
#endif

#else  /* if GRUB_UNIX */
/* Windows version does not support DIAG_LOG features */
#define DIAG_DEFINE(_diagname_)
#define DIAG_LOG(_diagname_, _buf_, _len_)
#endif  /* if ! GRUB_UNIX */

#endif  /* _DIAGNOSE_H_ */

#if 0
DIAG_DEFINE(testing);

int main()
{
	DIAG_LOG(testing, "igor\n", 4);
	DIAG_LOG(testing, "igor\n", 5);

	return 0;
}

#endif

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us