summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2008-09-01 09:17:00 +0200
committerDanny Baumann <dannybaumann@web.de>2008-09-01 09:17:00 +0200
commit1ad1aaecb4349398fc69f980fa7407f782f164f1 (patch)
treee557726a8a9b10aaac55ee506fdc1e3519bff6fd
parent894a9ca4f7b53dd602982cf7cd9e2780b9ede9eb (diff)
downloadfiledebug-1ad1aaecb4349398fc69f980fa7407f782f164f1.tar.gz
filedebug-1ad1aaecb4349398fc69f980fa7407f782f164f1.tar.bz2
Track core changes.
-rw-r--r--filedebug.c118
1 files changed, 80 insertions, 38 deletions
diff --git a/filedebug.c b/filedebug.c
index f41dd68..a0c3f37 100644
--- a/filedebug.c
+++ b/filedebug.c
@@ -30,18 +30,27 @@
#define FILEDEBUG_DISPLAY_OPTION_LOG_LEVEL_THRESHOLD 1
#define FILEDEBUG_DISPLAY_OPTION_NUM 2
+static int corePrivateIndex;
static int displayPrivateIndex;
static CompMetadata filedebugMetadata;
-typedef struct _FileDebugDisplay {
+typedef struct _FileDebugCore {
LogMessageProc logMessage;
FILE *debugFile;
+} FileDebugCore;
+typedef struct _FileDebugDisplay {
CompOption opt[FILEDEBUG_DISPLAY_OPTION_NUM];
} FileDebugDisplay;
+#define GET_FILEDEBUG_CORE(c) \
+ ((FileDebugCore *) (c)->base.privates[corePrivateIndex].ptr)
+
+#define FILEDEBUG_CORE(c) \
+ FileDebugCore *fc = GET_FILEDEBUG_CORE (c)
+
#define GET_FILEDEBUG_DISPLAY(d) \
((FileDebugDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
@@ -51,17 +60,17 @@ typedef struct _FileDebugDisplay {
#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
static void
-filedebugLogMessage (CompDisplay *d,
- const char *component,
+filedebugLogMessage (const char *component,
CompLogLevel level,
const char *message)
{
int threshold;
- FILEDEBUG_DISPLAY (d);
+ FILEDEBUG_CORE (&core);
+ FILEDEBUG_DISPLAY (core.displays);
threshold = fd->opt[FILEDEBUG_DISPLAY_OPTION_LOG_LEVEL_THRESHOLD].value.i;
- if (!fd->debugFile)
+ if (!fc->debugFile)
threshold = -1;
if (level <= threshold)
@@ -75,18 +84,18 @@ filedebugLogMessage (CompDisplay *d,
mytime = time (NULL);
tm = localtime (&mytime);
strftime (buffer, 256, "[%x %X] ", tm);
- fprintf(fd->debugFile, "%s", buffer);
+ fprintf(fc->debugFile, "%s", buffer);
}
- fprintf (fd->debugFile, "%s - %s : %s\n", component,
+ fprintf (fc->debugFile, "%s - %s : %s\n", component,
logLevelToString (level), message);
- fflush (fd->debugFile);
+ fflush (fc->debugFile);
}
- UNWRAP (fd, d, logMessage);
- (*d->logMessage) (d, component, level, message);
- WRAP (fd, d, logMessage, filedebugLogMessage);
+ UNWRAP (fc, &core, logMessage);
+ (*core.logMessage) (component, level, message);
+ WRAP (fc, &core, logMessage, filedebugLogMessage);
}
static const CompMetadataOptionInfo filedebugDisplayOptionInfo[] = {
@@ -95,15 +104,50 @@ static const CompMetadataOptionInfo filedebugDisplayOptionInfo[] = {
};
static Bool
-filedebugInitDisplay (CompPlugin *p,
- CompDisplay *d)
+filedebugInitCore (CompPlugin *p,
+ CompCore *c)
{
- FileDebugDisplay *fd;
- char *fileName = NULL;
+ FileDebugCore *fc;
+ char *fileName = NULL;
if (!checkPluginABI ("core", CORE_ABIVERSION))
return FALSE;
+ fc = malloc (sizeof (FileDebugCore));
+ if (!fc)
+ return FALSE;
+
+ displayPrivateIndex = allocateDisplayPrivateIndex ();
+ if (displayPrivateIndex < 0)
+ {
+ free (fc);
+ return FALSE;
+ }
+
+ asprintf (&fileName, "/tmp/compiz-debug-log-%d.log", getpid ());
+ if (!fileName)
+ {
+ freeDisplayPrivateIndex (displayPrivateIndex);
+ free (fc);
+ return FALSE;
+ }
+
+ fc->debugFile = fopen (fileName, "a+");
+ free (fileName);
+
+ WRAP (fc, c, logMessage, filedebugLogMessage);
+
+ c->base.privates[corePrivateIndex].ptr = fc;
+
+ return TRUE;
+}
+
+static Bool
+filedebugInitDisplay (CompPlugin *p,
+ CompDisplay *d)
+{
+ FileDebugDisplay *fd;
+
fd = malloc (sizeof (FileDebugDisplay));
if (!fd)
return FALSE;
@@ -118,22 +162,25 @@ filedebugInitDisplay (CompPlugin *p,
return FALSE;
}
- asprintf (&fileName, "/tmp/compiz-debug-log-%d.log", getpid ());
- if (!fileName)
- {
- compFiniDisplayOptions (d, fd->opt, FILEDEBUG_DISPLAY_OPTION_NUM);
- free (fd);
- return FALSE;
- }
+ d->base.privates[displayPrivateIndex].ptr = fd;
- fd->debugFile = fopen (fileName, "a+");
- free (fileName);
+ return TRUE;
+}
- d->base.privates[displayPrivateIndex].ptr = fd;
+static void
+filedebugFiniCore (CompPlugin *p,
+ CompCore *c)
+{
+ FILEDEBUG_CORE (c);
- WRAP (fd, d, logMessage, filedebugLogMessage);
+ UNWRAP (fc, c, logMessage);
- return TRUE;
+ if (fc->debugFile)
+ fclose (fc->debugFile);
+
+ freeDisplayPrivateIndex (displayPrivateIndex);
+
+ free (fc);
}
static void
@@ -142,12 +189,7 @@ filedebugFiniDisplay (CompPlugin *p,
{
FILEDEBUG_DISPLAY (d);
- UNWRAP (fd, d, logMessage);
-
- compFiniDisplayOptions (d, fd->opt, FILEDEBUG_DISPLAY_OPTION_NUM);
-
- if (fd->debugFile)
- fclose (fd->debugFile);
+ compFiniDisplayOptions (d, fd->opt, FILEDEBUG_DISPLAY_OPTION_NUM);
free (fd);
}
@@ -163,8 +205,8 @@ filedebugInit (CompPlugin *p)
0, 0))
return FALSE;
- displayPrivateIndex = allocateDisplayPrivateIndex ();
- if (displayPrivateIndex < 0)
+ corePrivateIndex = allocateCorePrivateIndex ();
+ if (corePrivateIndex < 0)
{
compFiniMetadata (&filedebugMetadata);
return FALSE;
@@ -206,7 +248,7 @@ filedebugSetDisplayOption (CompPlugin *p,
static void
filedebugFini (CompPlugin *p)
{
- freeDisplayPrivateIndex (displayPrivateIndex);
+ freeCorePrivateIndex (corePrivateIndex);
compFiniMetadata (&filedebugMetadata);
}
@@ -216,7 +258,7 @@ filedebugInitObject (CompPlugin *p,
CompObject *o)
{
static InitPluginObjectProc dispTab[] = {
- (InitPluginObjectProc) 0,
+ (InitPluginObjectProc) filedebugInitCore,
(InitPluginObjectProc) filedebugInitDisplay
};
@@ -228,7 +270,7 @@ filedebugFiniObject (CompPlugin *p,
CompObject *o)
{
static FiniPluginObjectProc dispTab[] = {
- (FiniPluginObjectProc) 0,
+ (FiniPluginObjectProc) filedebugFiniCore,
(FiniPluginObjectProc) filedebugFiniDisplay
};