summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kasprzyk <onestone@opencompositing.org>2008-08-20 15:40:15 +0200
committerDennis kasprzyk <onestone@opencompositing.org>2008-08-20 15:40:15 +0200
commit682b0c5129f0fd88d259ca6f30e8ed469dc9a162 (patch)
tree21a1850a82b4191387dd4908299f09a2730b74ee
parentf4d3ba5048fd23ea455f8d50a81fca586bbc6197 (diff)
downloadunity-window-decorator-682b0c5129f0fd88d259ca6f30e8ed469dc9a162.tar.gz
unity-window-decorator-682b0c5129f0fd88d259ca6f30e8ed469dc9a162.tar.bz2
C++ port of CompMetadata.
-rw-r--r--include/compiz-core.h84
-rw-r--r--include/compiz.h37
-rw-r--r--include/compmetadata.h90
-rw-r--r--src/Makefile.am2
-rw-r--r--src/display.cpp8
-rw-r--r--src/fragment.cpp1
-rw-r--r--src/main.cpp62
-rw-r--r--src/metadata.cpp654
-rw-r--r--src/plugin.cpp2
-rw-r--r--src/privatedisplay.h2
-rw-r--r--src/privatescreen.h2
-rw-r--r--src/screen.cpp8
-rw-r--r--src/string.cpp2
13 files changed, 410 insertions, 544 deletions
diff --git a/include/compiz-core.h b/include/compiz-core.h
index 64510ea..d6fe46a 100644
--- a/include/compiz-core.h
+++ b/include/compiz-core.h
@@ -144,7 +144,7 @@ extern int pointerX;
extern int pointerY;
extern CompCore *core;
-extern CompMetadata coreMetadata;
+extern CompMetadata *coreMetadata;
#define RESTRICT_VALUE(value, min, max) \
(((value) < (min)) ? (min): ((value) > (max)) ? (max) : (value))
@@ -457,95 +457,17 @@ getPluginDisplayIndex (CompDisplay *d,
/* metadata.c */
-#define STRINGIFY(x) #x
-#define TOSTRING(x) STRINGIFY (x)
-#define MINTOSTRING(x) "<min>" TOSTRING (x) "</min>"
-#define MAXTOSTRING(x) "<max>" TOSTRING (x) "</max>"
-#define RESTOSTRING(min, max) MINTOSTRING (min) MAXTOSTRING (max)
-#include <compaction.h>
-
-typedef struct _CompMetadataOptionInfo {
- const char *name;
- const char *type;
- const char *data;
- CompAction::CallBack initiate;
- CompAction::CallBack terminate;
-} CompMetadataOptionInfo;
-
-struct _CompMetadata {
- char *path;
- xmlDoc **doc;
- int nDoc;
-};
-
-bool
-compInitPluginMetadataFromInfo (CompMetadata *metadata,
- const char *plugin,
- const CompMetadataOptionInfo *displayOptionInfo,
- int nDisplayOptionInfo,
- const CompMetadataOptionInfo *screenOptionInfo,
- int nScreenOptionInfo);
-
-bool
-compInitScreenOptionFromMetadata (CompScreen *screen,
- CompMetadata *metadata,
- CompOption *option,
- const char *name);
-
-bool
-compInitScreenOptionsFromMetadata (CompScreen *screen,
- CompMetadata *metadata,
- const CompMetadataOptionInfo *info,
- CompOption::Vector &options);
-
-
-bool
-compInitDisplayOptionFromMetadata (CompDisplay *display,
- CompMetadata *metadata,
- CompOption *option,
- const char *name);
-
-
-bool
-compInitDisplayOptionsFromMetadata (CompDisplay *display,
- CompMetadata *metadata,
- const CompMetadataOptionInfo *info,
- CompOption::Vector &options);
-
-
-char *
-compGetShortPluginDescription (CompMetadata *metadata);
-
-char *
-compGetLongPluginDescription (CompMetadata *metadata);
-
-char *
-compGetShortScreenOptionDescription (CompMetadata *metadata,
- CompOption *option);
-
-char *
-compGetLongScreenOptionDescription (CompMetadata *metadata,
- CompOption *option);
-char *
-compGetShortDisplayOptionDescription (CompMetadata *metadata,
- CompOption *option);
+#include <compaction.h>
-char *
-compGetLongDisplayOptionDescription (CompMetadata *metadata,
- CompOption *option);
-int
-compReadXmlChunkFromMetadataOptionInfo (const CompMetadataOptionInfo *info,
- int *offset,
- char *buffer,
- int length);
CompString compPrintf (const char *format, ...);
CompString compPrintf (const char *format, va_list ap);
+#include <compmetadata.h>
#include <comprect.h>
#include <compoutput.h>
#include <compobject.h>
diff --git a/include/compiz.h b/include/compiz.h
index ec212da..9e033d3 100644
--- a/include/compiz.h
+++ b/include/compiz.h
@@ -26,8 +26,6 @@
#ifndef _COMPIZ_H
#define _COMPIZ_H
-#include <libxml/parser.h>
-
#include <compiz-common.h>
#include <string>
@@ -41,7 +39,6 @@ typedef int CompBool;
typedef int CompTimeoutHandle;
typedef int CompWatchFdHandle;
-typedef struct _CompMetadata CompMetadata;
typedef struct _CompPlugin CompPlugin;
@@ -51,6 +48,7 @@ class CompScreen;
class CompWindow;
class CompObject;
class CompOption;
+class CompMetadata;
typedef union _CompPrivate {
void *ptr;
@@ -72,39 +70,6 @@ typedef enum {
-CompBool
-compInitMetadata (CompMetadata *metadata);
-
-CompBool
-compInitPluginMetadata (CompMetadata *metadata,
- const char *plugin);
-
-void
-compFiniMetadata (CompMetadata *metadata);
-
-CompBool
-compAddMetadataFromFile (CompMetadata *metadata,
- const char *file);
-
-CompBool
-compAddMetadataFromString (CompMetadata *metadata,
- const char *string);
-
-CompBool
-compAddMetadataFromIO (CompMetadata *metadata,
- xmlInputReadCallback ioread,
- xmlInputCloseCallback ioclose,
- void *ioctx);
-
-char *
-compGetStringFromMetadataPath (CompMetadata *metadata,
- const char *path);
-
-int
-compReadXmlChunk (const char *src,
- int *offset,
- char *buffer,
- int length);
diff --git a/include/compmetadata.h b/include/compmetadata.h
new file mode 100644
index 0000000..f102450
--- /dev/null
+++ b/include/compmetadata.h
@@ -0,0 +1,90 @@
+#ifndef _COMPMETADATA_H
+#define _COMPMETADATA_H
+
+#include <vector>
+
+#include <libxml/parser.h>
+
+#include <compaction.h>
+
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY (x)
+#define MINTOSTRING(x) "<min>" TOSTRING (x) "</min>"
+#define MAXTOSTRING(x) "<max>" TOSTRING (x) "</max>"
+#define RESTOSTRING(min, max) MINTOSTRING (min) MAXTOSTRING (max)
+
+class CompMetadata {
+ public:
+ struct OptionInfo {
+ const char *name;
+ const char *type;
+ const char *data;
+ CompAction::CallBack initiate;
+ CompAction::CallBack terminate;
+ };
+ public:
+ CompMetadata ();
+ CompMetadata (CompString plugin,
+ const OptionInfo *displayOptionInfo = NULL,
+ unsigned int nDisplayOptionInfo = 0,
+ const OptionInfo *screenOptionInfo = NULL,
+ unsigned int nScreenOptionInfo = 0);
+ ~CompMetadata ();
+
+ std::vector<xmlDoc *> &doc ();
+
+ bool addFromFile (CompString file);
+ bool addFromString (CompString string);
+ bool addFromIO (xmlInputReadCallback ioread,
+ xmlInputCloseCallback ioclose,
+ void *ioctx);
+
+ bool initScreenOption (CompScreen *screen,
+ CompOption *option,
+ CompString name);
+
+ bool initDisplayOption (CompDisplay *display,
+ CompOption *option,
+ CompString name);
+
+ bool initScreenOptions (CompScreen *screen,
+ const OptionInfo *info,
+ unsigned int nOptions,
+ CompOption::Vector &options);
+
+ bool initDisplayOptions (CompDisplay *display,
+ const OptionInfo *info,
+ unsigned int nOptions,
+ CompOption::Vector &options);
+
+ CompString getShortPluginDescription ();
+
+ CompString getLongPluginDescription ();
+
+ CompString getShortScreenOptionDescription (CompOption *option);
+
+ CompString getLongScreenOptionDescription (CompOption *option);
+
+ CompString getShortDisplayOptionDescription (CompOption *option);
+
+ CompString getLongDisplayOptionDescription (CompOption *option);
+
+ CompString getStringFromPath (CompString path);
+
+ static unsigned int readXmlChunk (const char *src,
+ unsigned int *offset,
+ char *buffer,
+ unsigned int length);
+
+ static unsigned int
+ readXmlChunkFromOptionInfo (const CompMetadata::OptionInfo *info,
+ unsigned int *offset,
+ char *buffer,
+ unsigned int length);
+
+ private:
+ CompString mPath;
+ std::vector<xmlDoc *> mDoc;
+};
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 8f514d4..4696106 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ bin_PROGRAMS = compiz
compiz_LDADD = @COMPIZ_LIBS@ @GL_LIBS@ -lm
compiz_LDFLAGS = -export-dynamic
compiz_SOURCES = \
+ metadata.cpp \
action.cpp \
option.cpp \
string.cpp \
@@ -29,7 +30,6 @@ compiz_SOURCES = \
plugin.cpp \
session.cpp \
matrix.cpp \
- metadata.cpp \
output.cpp \
rect.cpp \
size.cpp \
diff --git a/src/display.cpp b/src/display.cpp
index fffa756..e9df259 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -530,7 +530,7 @@ CompWindow::shade (CompDisplay *d,
return true;
}
-const CompMetadataOptionInfo coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM] = {
+const CompMetadata::OptionInfo coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM] = {
{ "abi", "int", 0, 0, 0 },
{ "active_plugins", "list", "<type>string</type>", 0, 0 },
{ "texture_filter", "int", RESTOSTRING (0, 2), 0, 0 },
@@ -783,10 +783,8 @@ CompDisplay::init (const char *name)
// priv->connection = XGetXCBConnection (priv->dpy);
- if (!compInitDisplayOptionsFromMetadata (this,
- &coreMetadata,
- coreDisplayOptionInfo,
- priv->opt))
+ if (!coreMetadata->initDisplayOptions (this, coreDisplayOptionInfo,
+ COMP_DISPLAY_OPTION_NUM, priv->opt))
return true;
priv->opt[COMP_DISPLAY_OPTION_ABI].value ().set ((int) CORE_ABIVERSION);
diff --git a/src/fragment.cpp b/src/fragment.cpp
index 963d5f5..cc0d390 100644
--- a/src/fragment.cpp
+++ b/src/fragment.cpp
@@ -35,6 +35,7 @@
#include <string.h>
#include <stdlib.h>
+#include <stdarg.h>
#define COMP_FUNCTION_TYPE_ARB 0
#define COMP_FUNCTION_TYPE_NUM 1
diff --git a/src/main.cpp b/src/main.cpp
index 8f06e24..7f6e5c5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -69,7 +69,7 @@ Bool onlyCurrentScreen = FALSE;
Bool useCow = TRUE;
#endif
-CompMetadata coreMetadata;
+CompMetadata *coreMetadata = NULL;
static void
usage (void)
@@ -122,10 +122,10 @@ signalHandler (int sig)
}
typedef struct _CompIOCtx {
- int offset;
- char *pluginData;
- char *textureFilterData;
- char *refreshRateData;
+ unsigned int offset;
+ char *pluginData;
+ char *textureFilterData;
+ char *refreshRateData;
} CompIOCtx;
static int
@@ -133,15 +133,16 @@ readCoreXmlCallback (void *context,
char *buffer,
int length)
{
- CompIOCtx *ctx = (CompIOCtx *) context;
- int offset = ctx->offset;
- int i, j;
+ CompIOCtx *ctx = (CompIOCtx *) context;
+ unsigned int offset = ctx->offset;
+ unsigned int i, j;
- i = compReadXmlChunk ("<compiz><core><display>", &offset, buffer, length);
+ i = CompMetadata::readXmlChunk ("<compiz><core><display>", &offset, buffer,
+ length);
for (j = 0; j < COMP_DISPLAY_OPTION_NUM; j++)
{
- CompMetadataOptionInfo info = coreDisplayOptionInfo[j];
+ CompMetadata::OptionInfo info = coreDisplayOptionInfo[j];
switch (j) {
case COMP_DISPLAY_OPTION_ACTIVE_PLUGINS:
@@ -155,18 +156,16 @@ readCoreXmlCallback (void *context,
break;
}
- i += compReadXmlChunkFromMetadataOptionInfo (&info,
- &offset,
- buffer + i,
- length - i);
+ i += CompMetadata::readXmlChunkFromOptionInfo (&info, &offset,
+ buffer + i, length - i);
}
- i += compReadXmlChunk ("</display><screen>", &offset,
- buffer + i, length - 1);
+ i += CompMetadata::readXmlChunk ("</display><screen>", &offset,
+ buffer + i, length - 1);
for (j = 0; j < COMP_SCREEN_OPTION_NUM; j++)
{
- CompMetadataOptionInfo info = coreScreenOptionInfo[j];
+ CompMetadata::OptionInfo info = coreScreenOptionInfo[j];
switch (j) {
case COMP_SCREEN_OPTION_REFRESH_RATE:
@@ -176,16 +175,14 @@ readCoreXmlCallback (void *context,
break;
}
- i += compReadXmlChunkFromMetadataOptionInfo (&info,
- &offset,
- buffer + i,
- length - i);
+ i += CompMetadata::readXmlChunkFromOptionInfo (&info, &offset,
+ buffer + i, length - i);
}
- i += compReadXmlChunk ("</screen></core></compiz>", &offset, buffer + i,
- length - i);
+ i += CompMetadata::readXmlChunk ("</screen></core></compiz>", &offset,
+ buffer + i, length - i);
- if (!offset && length > i)
+ if (!offset && length > (int)i)
buffer[i++] = '\0';
ctx->offset += i;
@@ -354,16 +351,9 @@ main (int argc, char **argv)
LIBXML_TEST_VERSION;
- if (!compInitMetadata (&coreMetadata))
- {
- compLogMessage (NULL, "core", CompLogLevelFatal,
- "Couldn't initialize core metadata");
- return 1;
- }
+ coreMetadata = new CompMetadata ();
- if (!compAddMetadataFromIO (&coreMetadata,
- readCoreXmlCallback, NULL,
- &ctx))
+ if (!coreMetadata->addFromIO (readCoreXmlCallback, NULL, &ctx))
return 1;
if (ctx.refreshRateData)
@@ -372,13 +362,13 @@ main (int argc, char **argv)
if (ctx.pluginData)
free (ctx.pluginData);
- compAddMetadataFromFile (&coreMetadata, "core");
+ coreMetadata->addFromFile ("core");
core = new CompCore();
if (!core)
return 1;
-
+
if (!core->init ())
return 1;
@@ -394,7 +384,7 @@ main (int argc, char **argv)
closeSession ();
delete core;
- compFiniMetadata (&coreMetadata);
+ delete coreMetadata;
xmlCleanupParser ();
diff --git a/src/metadata.cpp b/src/metadata.cpp
index 4c10463..bdcd37a 100644
--- a/src/metadata.cpp
+++ b/src/metadata.cpp
@@ -30,261 +30,102 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
+#include <boost/foreach.hpp>
+#define foreach BOOST_FOREACH
+
#include <compiz-core.h>
+#include <compmetadata.h>
#define HOME_METADATADIR ".compiz/metadata"
#define EXTENSION ".xml"
-Bool
-compInitMetadata (CompMetadata *metadata)
-{
- metadata->path = strdup ("core");
- if (!metadata->path)
- return FALSE;
-
- metadata->doc = NULL;
- metadata->nDoc = 0;
-
- return TRUE;
-}
-
-Bool
-compInitPluginMetadata (CompMetadata *metadata,
- const char *plugin)
-{
- char str[1024];
-
- snprintf (str, 1024, "plugin[@name=\"%s\"]", plugin);
-
- metadata->path = strdup (str);
- if (!metadata->path)
- return FALSE;
-
- metadata->doc = NULL;
- metadata->nDoc = 0;
-
- return TRUE;
-}
-
-void
-compFiniMetadata (CompMetadata *metadata)
-{
- int i;
-
- for (i = 0; i < metadata->nDoc; i++)
- xmlFreeDoc (metadata->doc[i]);
-
- if (metadata->doc)
- free (metadata->doc);
-
- free (metadata->path);
-}
-
static xmlDoc *
-readXmlFile (const char *path,
- const char *name)
+readXmlFile (CompString name,
+ CompString path = "")
{
- char *file;
- int length = strlen (name) + strlen (EXTENSION) + 1;
+ CompString file;
xmlDoc *doc = NULL;
FILE *fp;
- if (path)
- length += strlen (path) + 1;
-
- file = (char *) malloc (length);
- if (!file)
- return NULL;
-
- if (path)
- sprintf (file, "%s/%s%s", path, name, EXTENSION);
+ if (path.size ())
+ file = compPrintf ("%s/%s%s", path.c_str (), name.c_str (), EXTENSION);
else
- sprintf (file, "%s%s", name, EXTENSION);
+ file = compPrintf ("%s%s", name.c_str (), EXTENSION);
- fp = fopen (file, "r");
+ fp = fopen (file.c_str (), "r");
if (!fp)
{
- free (file);
return NULL;
}
fclose (fp);
- doc = xmlReadFile (file, NULL, 0);
-
- free (file);
+ doc = xmlReadFile (file.c_str (), NULL, 0);
return doc;
}
-static Bool
-addMetadataFromFilename (CompMetadata *metadata,
- const char *path,
- const char *file)
-{
- xmlDoc **d, *doc;
-
- doc = readXmlFile (path, file);
- if (!doc)
- return FALSE;
-
- d = (xmlDoc **) realloc (metadata->doc, (metadata->nDoc + 1) * sizeof (xmlDoc *));
- if (!d)
- {
- xmlFreeDoc (doc);
- return FALSE;
- }
-
- d[metadata->nDoc++] = doc;
- metadata->doc = d;
-
- return TRUE;
-}
-
-Bool
-compAddMetadataFromFile (CompMetadata *metadata,
- const char *file)
-{
- char *home;
- Bool status = FALSE;
-
- home = getenv ("HOME");
- if (home)
- {
- char *path;
-
- path = (char *) malloc (strlen (home) + strlen (HOME_METADATADIR) + 2);
- if (path)
- {
- sprintf (path, "%s/%s", home, HOME_METADATADIR);
- status |= addMetadataFromFilename (metadata, path, file);
- free (path);
- }
- }
-
- status |= addMetadataFromFilename (metadata, METADATADIR, file);
- if (!status)
- {
- compLogMessage (NULL, "core", CompLogLevelWarn,
- "Unable to parse XML metadata from file \"%s%s\"",
- file, EXTENSION);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-Bool
-compAddMetadataFromString (CompMetadata *metadata,
- const char *string)
-{
- xmlDoc **d, *doc;
-
- doc = xmlReadMemory (string, strlen (string), NULL, NULL, 0);
- if (!doc)
- {
- compLogMessage (NULL, "core", CompLogLevelWarn,
- "Unable to parse XML metadata");
-
- return FALSE;
- }
-
- d = (xmlDoc **) realloc (metadata->doc, (metadata->nDoc + 1) * sizeof (xmlDoc *));
- if (!d)
- {
- xmlFreeDoc (doc);
- return FALSE;
- }
-
- d[metadata->nDoc++] = doc;
- metadata->doc = d;
-
- return TRUE;
-}
-
-Bool
-compAddMetadataFromIO (CompMetadata *metadata,
- xmlInputReadCallback ioread,
- xmlInputCloseCallback ioclose,
- void *ioctx)
-{
- xmlDoc **d, *doc;
-
- doc = xmlReadIO (ioread, ioclose, ioctx, NULL, NULL, 0);
- if (!doc)
- {
- compLogMessage (NULL, "core", CompLogLevelWarn,
- "Unable to parse XML metadata");
-
- return FALSE;
- }
-
- d = (xmlDoc **) realloc (metadata->doc, (metadata->nDoc + 1) * sizeof (xmlDoc *));
- if (!d)
- {
- xmlFreeDoc (doc);
- return FALSE;
- }
-
- d[metadata->nDoc++] = doc;
- metadata->doc = d;
-
- return TRUE;
-}
-
typedef struct _CompIOCtx {
- int offset;
- const char *name;
- const CompMetadataOptionInfo *displayOInfo;
- int nDisplayOInfo;
- const CompMetadataOptionInfo *screenOInfo;
- int nScreenOInfo;
+ unsigned int offset;
+ const char *name;
+ const CompMetadata::OptionInfo *displayOInfo;
+ unsigned int nDisplayOInfo;
+ const CompMetadata::OptionInfo *screenOInfo;
+ unsigned int nScreenOInfo;
} CompIOCtx;
+typedef struct _CompXPath {
+ xmlXPathObjectPtr obj;
+ xmlXPathContextPtr ctx;
+ xmlDocPtr doc;
+} CompXPath;
+
+
static int
readPluginXmlCallback (void *context,
char *buffer,
int length)
{
- CompIOCtx *ctx = (CompIOCtx *) context;
- int offset = ctx->offset;
- int i, j;
+ CompIOCtx *ctx = (CompIOCtx *) context;
+ unsigned int offset = ctx->offset;
+ unsigned int i, j;
- i = compReadXmlChunk ("<compiz><plugin name=\"", &offset, buffer, length);
- i += compReadXmlChunk (ctx->name, &offset, buffer + i, length - i);
- i += compReadXmlChunk ("\">", &offset, buffer + i, length - i);
+ i = CompMetadata::readXmlChunk ("<compiz><plugin name=\"", &offset,
+ buffer, length);
+ i += CompMetadata::readXmlChunk (ctx->name, &offset, buffer + i,
+ length - i);
+ i += CompMetadata::readXmlChunk ("\">", &offset, buffer + i, length - i);
if (ctx->nDisplayOInfo)
{
- i += compReadXmlChunk ("<display>", &offset, buffer + i, length - i);
+ i += CompMetadata::readXmlChunk ("<display>", &offset, buffer + i,
+ length - i);
for (j = 0; j < ctx->nDisplayOInfo; j++)
- i += compReadXmlChunkFromMetadataOptionInfo (&ctx->displayOInfo[j],
- &offset,
- buffer + i,
- length - i);
+ i += CompMetadata::readXmlChunkFromOptionInfo (
+ &ctx->displayOInfo[j], &offset, buffer + i, length - i);
- i += compReadXmlChunk ("</display>", &offset, buffer + i, length - i);
+ i += CompMetadata::readXmlChunk ("</display>", &offset, buffer + i,
+ length - i);
}
if (ctx->nScreenOInfo)
{
- i += compReadXmlChunk ("<screen>", &offset, buffer + i, length - i);
+ i += CompMetadata::readXmlChunk ("<screen>", &offset, buffer + i,
+ length - i);
for (j = 0; j < ctx->nScreenOInfo; j++)
- i += compReadXmlChunkFromMetadataOptionInfo (&ctx->screenOInfo[j],
- &offset,
- buffer + i,
- length - i);
+ i += CompMetadata::readXmlChunkFromOptionInfo (
+ &ctx->screenOInfo[j], &offset, buffer + i, length - i);
- i += compReadXmlChunk ("</screen>", &offset, buffer + i, length - i);
+ i += CompMetadata::readXmlChunk ("</screen>", &offset, buffer + i,
+ length - i);
}
- i += compReadXmlChunk ("</plugin></compiz>", &offset, buffer + i,
- length - i);
+ i += CompMetadata::readXmlChunk ("</plugin></compiz>", &offset, buffer + i,
+ length - i);
- if (!offset && length > i)
+ if (!offset && length > (int)i)
buffer[i++] = '\0';
ctx->offset += i;
@@ -292,58 +133,17 @@ readPluginXmlCallback (void *context,
return i;
}
-bool
-compInitPluginMetadataFromInfo (CompMetadata *metadata,
- const char *plugin,
- const CompMetadataOptionInfo *displayOptionInfo,
- int nDisplayOptionInfo,
- const CompMetadataOptionInfo *screenOptionInfo,
- int nScreenOptionInfo)
-{
- if (!compInitPluginMetadata (metadata, plugin))
- return FALSE;
-
- if (nDisplayOptionInfo || nScreenOptionInfo)
- {
- CompIOCtx ctx;
-
- ctx.offset = 0;
- ctx.name = plugin;
- ctx.displayOInfo = displayOptionInfo;
- ctx.nDisplayOInfo = nDisplayOptionInfo;
- ctx.screenOInfo = screenOptionInfo;
- ctx.nScreenOInfo = nScreenOptionInfo;
-
- if (!compAddMetadataFromIO (metadata,
- readPluginXmlCallback, NULL,
- (void *) &ctx))
- {
- compFiniMetadata (metadata);
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-typedef struct _CompXPath {
- xmlXPathObjectPtr obj;
- xmlXPathContextPtr ctx;
- xmlDocPtr doc;
-} CompXPath;
-
-static Bool
+static bool
initXPathFromMetadataPath (CompXPath *xPath,
CompMetadata *metadata,
const xmlChar *path)
{
xmlXPathObjectPtr obj;
xmlXPathContextPtr ctx;
- int i;
- for (i = 0; i < metadata->nDoc; i++)
+ foreach (xmlDoc *doc, metadata->doc ())
{
- ctx = xmlXPathNewContext (metadata->doc[i]);
+ ctx = xmlXPathNewContext (doc);
if (ctx)
{
obj = xmlXPathEvalExpression (path, ctx);
@@ -353,9 +153,9 @@ initXPathFromMetadataPath (CompXPath *xPath,
{
xPath->ctx = ctx;
xPath->obj = obj;
- xPath->doc = metadata->doc[i];
+ xPath->doc = doc;
- return TRUE;
+ return true;
}
xmlXPathFreeObject (obj);
@@ -365,10 +165,10 @@ initXPathFromMetadataPath (CompXPath *xPath,
}
}
- return FALSE;
+ return false;
}
-static Bool
+static bool
initXPathFromMetadataPathElement (CompXPath *xPath,
CompMetadata *metadata,
const xmlChar *path,
@@ -803,11 +603,8 @@ stringFromMetadataPathElement (CompMetadata *metadata,
const char *path,
const char *element)
{
- char str[1024];
-
- snprintf (str, 1024, "%s/%s", path, element);
-
- return compGetStringFromMetadataPath (metadata, str);
+ return strdup (metadata->getStringFromPath (
+ compPrintf ("%s/%s", path, element)).c_str ());
}
static Bool
@@ -1103,183 +900,286 @@ initOptionFromMetadataPath (CompDisplay *d,
return TRUE;
}
-bool
-compInitScreenOptionFromMetadata (CompScreen *s,
- CompMetadata *m,
- CompOption *o,
- const char *name)
-{
- char str[1024];
- sprintf (str, "/compiz/%s/screen//option[@name=\"%s\"]", m->path, name);
- return initOptionFromMetadataPath (s->display (), m, o, BAD_CAST str);
+CompMetadata::CompMetadata () :
+ mPath ("core"),
+ mDoc (0)
+{
}
-bool
-compInitDisplayOptionFromMetadata (CompDisplay *d,
- CompMetadata *m,
- CompOption *o,
- const char *name)
+CompMetadata::CompMetadata (CompString plugin,
+ const OptionInfo *displayOptionInfo,
+ unsigned int nDisplayOptionInfo,
+ const OptionInfo *screenOptionInfo,
+ unsigned int nScreenOptionInfo) :
+ mPath (compPrintf ("plugin[@name=\"%s\"]", plugin.c_str ())),
+ mDoc (0)
{
- char str[1024];
+ if (nDisplayOptionInfo || nScreenOptionInfo)
+ {
+ CompIOCtx ctx;
+
+ ctx.offset = 0;
+ ctx.name = plugin.c_str ();
+ ctx.displayOInfo = displayOptionInfo;
+ ctx.nDisplayOInfo = nDisplayOptionInfo;
+ ctx.screenOInfo = screenOptionInfo;
+ ctx.nScreenOInfo = nScreenOptionInfo;
- sprintf (str, "/compiz/%s/display//option[@name=\"%s\"]", m->path, name);
+ addFromIO (readPluginXmlCallback, NULL, (void *) &ctx);
+ }
+}
- return initOptionFromMetadataPath (d, m, o, BAD_CAST str);
+CompMetadata::~CompMetadata ()
+{
+ foreach (xmlDoc *d, mDoc)
+ xmlFreeDoc (d);
}
+std::vector<xmlDoc *> &
+CompMetadata::doc ()
+{
+ return mDoc;
+}
bool
-compInitScreenOptionsFromMetadata (CompScreen *s,
- CompMetadata *m,
- const CompMetadataOptionInfo *info,
- CompOption::Vector &opt)
+CompMetadata::addFromFile (CompString file)
{
- for (unsigned int i = 0; i < opt.size (); i++)
+ xmlDoc *doc;
+ CompString home (getenv ("HOME"));
+ bool status = false;
+
+ home = getenv ("HOME");
+ if (home.size ())
{
- if (!compInitScreenOptionFromMetadata (s, m, &opt[i], info[i].name))
+ CompString path = compPrintf ("%s/%s", home.c_str (), HOME_METADATADIR);
+ doc = readXmlFile (file, path);
+ if (doc)
{
- CompOption::finiScreenOptions (s, opt);
- return false;
+ mDoc.push_back (doc);
+ status = true;
}
+ }
- if (info[i].initiate)
- opt[i].value ().action ().setInitiate (info[i].initiate);
+ doc = readXmlFile (file, CompString (METADATADIR));
+ if (doc)
+ {
+ mDoc.push_back (doc);
+ status |= true;
+ }
- if (info[i].terminate)
- opt[i].value ().action ().setTerminate (info[i].terminate);
+ if (!status)
+ {
+ compLogMessage (NULL, "core", CompLogLevelWarn,
+ "Unable to parse XML metadata from file \"%s%s\"",
+ file.c_str (), EXTENSION);
+
+ return false;
}
return true;
}
bool
-compInitDisplayOptionsFromMetadata (CompDisplay *d,
- CompMetadata *m,
- const CompMetadataOptionInfo *info,
- CompOption::Vector &opt)
+CompMetadata::addFromString (CompString string)
{
- for (unsigned int i = 0; i < opt.size (); i++)
+ xmlDoc *doc;
+
+ doc = xmlReadMemory (string.c_str (), string.size (), NULL, NULL, 0);
+ if (!doc)
{
- if (!compInitDisplayOptionFromMetadata (d, m, &opt[i], info[i].name))
- {
- CompOption::finiDisplayOptions (d, opt);
- return false;
- }
-
- if (info[i].initiate)
- opt[i].value ().action ().setInitiate (info[i].initiate);
+ compLogMessage (NULL, "core", CompLogLevelWarn,
+ "Unable to parse XML metadata");
- if (info[i].terminate)
- opt[i].value ().action ().setTerminate (info[i].terminate);
+ return false;
}
+ mDoc.push_back (doc);
+
return true;
}
-
-
-char *
-compGetStringFromMetadataPath (CompMetadata *metadata,
- const char *path)
+bool
+CompMetadata::addFromIO (xmlInputReadCallback ioread,
+ xmlInputCloseCallback ioclose,
+ void *ioctx)
{
- CompXPath xPath;
- char *v = NULL;
+ xmlDoc *doc;
- if (!initXPathFromMetadataPath (&xPath, metadata, BAD_CAST path))
- return NULL;
-
- xPath.obj = xmlXPathConvertString (xPath.obj);
+ doc = xmlReadIO (ioread, ioclose, ioctx, NULL, NULL, 0);
+ if (!doc)
+ {
+ compLogMessage (NULL, "core", CompLogLevelWarn,
+ "Unable to parse XML metadata");
- if (xPath.obj->type == XPATH_STRING && xPath.obj->stringval)
- v = strdup ((char *) xPath.obj->stringval);
+ return false;
+ }
- finiXPath (&xPath);
+ mDoc.push_back (doc);
- return v;
+ return true;
}
-char *
-compGetShortPluginDescription (CompMetadata *m)
+bool
+CompMetadata::initScreenOption (CompScreen *screen,
+ CompOption *option,
+ CompString name)
{
char str[1024];
- sprintf (str, "/compiz/%s/short/child::text()", m->path);
+ sprintf (str, "/compiz/%s/screen//option[@name=\"%s\"]",
+ mPath.c_str (), name.c_str ());
- return compGetStringFromMetadataPath (m, str);
+ return initOptionFromMetadataPath (screen->display (), this,
+ option, BAD_CAST str);
}
-char *
-compGetLongPluginDescription (CompMetadata *m)
+bool
+CompMetadata::initDisplayOption (CompDisplay *display,
+ CompOption *option,
+ CompString name)
{
char str[1024];
- sprintf (str, "/compiz/%s/long/child::text()", m->path);
+ sprintf (str, "/compiz/%s/display//option[@name=\"%s\"]",
+ mPath.c_str (), name.c_str ());
- return compGetStringFromMetadataPath (m, str);
+ return initOptionFromMetadataPath (display, this, option, BAD_CAST str);
}
-char *
-compGetShortScreenOptionDescription (CompMetadata *m,
- CompOption *o)
+bool
+CompMetadata::initScreenOptions (CompScreen *screen,
+ const OptionInfo *info,
+ unsigned int nOptions,
+ CompOption::Vector &opt)
{
- char str[1024];
+ if (opt.size () < nOptions)
+ opt.resize (nOptions);
- sprintf (str, "/compiz/%s/screen//option[@name=\"%s\"]/short/child::text()",
- m->path, o->name ().c_str ());
+ for (unsigned int i = 0; i < nOptions; i++)
+ {
+ if (!initScreenOption (screen, &opt[i], info[i].name))
+ {
+ CompOption::finiScreenOptions (screen, opt);
+ return false;
+ }
+
+ if (info[i].initiate)
+ opt[i].value ().action ().setInitiate (info[i].initiate);
+
+ if (info[i].terminate)
+ opt[i].value ().action ().setTerminate (info[i].terminate);
+ }
- return compGetStringFromMetadataPath (m, str);
+ return true;
}
-char *
-compGetLongScreenOptionDescription (CompMetadata *m,
- CompOption *o)
+bool
+CompMetadata::initDisplayOptions (CompDisplay *display,
+ const OptionInfo *info,
+ unsigned int nOptions,
+ CompOption::Vector &opt)
{
- char str[1024];
+ if (opt.size () < nOptions)
+ opt.resize (nOptions);
+
+ for (unsigned int i = 0; i < nOptions; i++)
+ {
+ if (!initDisplayOption (display, &opt[i], info[i].name))
+ {
+ CompOption::finiDisplayOptions (display, opt);
+ return false;
+ }
+
+ if (info[i].initiate)
+ opt[i].value ().action ().setInitiate (info[i].initiate);
+
+ if (info[i].terminate)
+ opt[i].value ().action ().setTerminate (info[i].terminate);
+ }
- sprintf (str, "/compiz/%s/screen//option[@name=\"%s\"]/long/child::text()",
- m->path, o->name ().c_str ());
+ return true;
+}
- return compGetStringFromMetadataPath (m, str);
+CompString
+CompMetadata::getShortPluginDescription ()
+{
+ return getStringFromPath (
+ compPrintf ("/compiz/%s/short/child::text()", mPath.c_str ()));
}
+CompString
+CompMetadata::getLongPluginDescription ()
+{
+ return getStringFromPath (
+ compPrintf ("/compiz/%s/long/child::text()", mPath.c_str ()));
+}
-char *
-compGetShortDisplayOptionDescription (CompMetadata *m,
- CompOption *o)
+CompString
+CompMetadata::getShortScreenOptionDescription (CompOption *option)
{
- char str[1024];
+ return getStringFromPath (
+ compPrintf (
+ "/compiz/%s/screen//option[@name=\"%s\"]/short/child::text()",
+ mPath.c_str (), option->name ().c_str ()));
+}
- sprintf (str,
- "/compiz/%s/display//option[@name=\"%s\"]/short/child::text()",
- m->path, o->name ().c_str ());
+CompString
+CompMetadata::getLongScreenOptionDescription (CompOption *option)
+{
+ return getStringFromPath (
+ compPrintf (
+ "/compiz/%s/screen//option[@name=\"%s\"]/long/child::text()",
+ mPath.c_str (), option->name ().c_str ()));
+}
- return compGetStringFromMetadataPath (m, str);
+CompString
+CompMetadata::getShortDisplayOptionDescription (CompOption *option)
+{
+ return getStringFromPath (
+ compPrintf (
+ "/compiz/%s/display//option[@name=\"%s\"]/short/child::text()",
+ mPath.c_str (), option->name ().c_str ()));
}
+CompString
+CompMetadata::getLongDisplayOptionDescription (CompOption *option)
+{
+ return getStringFromPath (
+ compPrintf (
+ "/compiz/%s/display//option[@name=\"%s\"]/long/child::text()",
+ mPath.c_str (), option->name ().c_str ()));
+}
-char *
-compGetLongDisplayOptionDescription (CompMetadata *m,
- CompOption *o)
+CompString
+CompMetadata::getStringFromPath (CompString path)
{
- char str[1024];
+ CompXPath xPath;
+ CompString v = "";
+
+ if (!initXPathFromMetadataPath (&xPath, this, BAD_CAST path.c_str ()))
+ return NULL;
+
+ xPath.obj = xmlXPathConvertString (xPath.obj);
+
+ if (xPath.obj->type == XPATH_STRING && xPath.obj->stringval)
+ v = (char *) xPath.obj->stringval;
- sprintf (str, "/compiz/%s/display//option[@name=\"%s\"]/long/child::text()",
- m->path, o->name ().c_str ());
+ finiXPath (&xPath);
- return compGetStringFromMetadataPath (m, str);
+ return v;
}
-int
-compReadXmlChunk (const char *src,
- int *offset,
- char *buffer,
- int length)
+unsigned int
+CompMetadata::readXmlChunk (const char *src,
+ unsigned int *offset,
+ char *buffer,
+ unsigned int length)
{
- int srcLength = strlen (src);
- int srcOffset = *offset;
+ unsigned int srcLength = strlen (src);
+ unsigned int srcOffset = *offset;
if (srcOffset > srcLength)
srcOffset = srcLength;
@@ -1302,32 +1202,32 @@ compReadXmlChunk (const char *src,
return 0;
}
-int
-compReadXmlChunkFromMetadataOptionInfo (const CompMetadataOptionInfo *info,
- int *offset,
- char *buffer,
- int length)
+unsigned int
+CompMetadata::readXmlChunkFromOptionInfo (const CompMetadata::OptionInfo *info,
+ unsigned int *offset,
+ char *buffer,
+ unsigned int length)
{
- int i;
+ unsigned int i;
- i = compReadXmlChunk ("<option name=\"", offset, buffer, length);
- i += compReadXmlChunk (info->name, offset, buffer + i, length - i);
+ i = readXmlChunk ("<option name=\"", offset, buffer, length);
+ i += readXmlChunk (info->name, offset, buffer + i, length - i);
if (info->type)
{
- i += compReadXmlChunk ("\" type=\"", offset, buffer + i, length - i);
- i += compReadXmlChunk (info->type, offset, buffer + i, length - i);
+ i += readXmlChunk ("\" type=\"", offset, buffer + i, length - i);
+ i += readXmlChunk (info->type, offset, buffer + i, length - i);
}
if (info->data)
{
- i += compReadXmlChunk ("\">", offset, buffer + i, length - i);
- i += compReadXmlChunk (info->data, offset, buffer + i, length - i);
- i += compReadXmlChunk ("</option>", offset, buffer + i, length - i);
+ i += readXmlChunk ("\">", offset, buffer + i, length - i);
+ i += readXmlChunk (info->data, offset, buffer + i, length - i);
+ i += readXmlChunk ("</option>", offset, buffer + i, length - i);
}
else
{
- i += compReadXmlChunk ("\"/>", offset, buffer + i, length - i);
+ i += readXmlChunk ("\"/>", offset, buffer + i, length - i);
}
return i;
diff --git a/src/plugin.cpp b/src/plugin.cpp
index cf0ff9c..7ebcd05 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -73,7 +73,7 @@ CorePluginVTable::fini ()
CompMetadata *
CorePluginVTable::getMetadata ()
{
- return &coreMetadata;
+ return coreMetadata;
}
CompOption::Vector &
diff --git a/src/privatedisplay.h b/src/privatedisplay.h
index bcd58f5..76c11f5 100644
--- a/src/privatedisplay.h
+++ b/src/privatedisplay.h
@@ -72,7 +72,7 @@
#define COMP_DISPLAY_OPTION_EDGE_DELAY 65
#define COMP_DISPLAY_OPTION_NUM 66
-extern const CompMetadataOptionInfo
+extern const CompMetadata::OptionInfo
coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM];
diff --git a/src/privatescreen.h b/src/privatescreen.h
index 0c26612..d6a48e4 100644
--- a/src/privatescreen.h
+++ b/src/privatescreen.h
@@ -43,7 +43,7 @@
#define COMP_SCREEN_DAMAGE_REGION_MASK (1 << 1)
#define COMP_SCREEN_DAMAGE_ALL_MASK (1 << 2)
-extern const CompMetadataOptionInfo
+extern const CompMetadata::OptionInfo
coreScreenOptionInfo[COMP_SCREEN_OPTION_NUM];
class PrivateScreen {
diff --git a/src/screen.cpp b/src/screen.cpp
index 163f797..8dca19a 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -488,7 +488,7 @@ CompScreen::setOption (const char *name,
return false;
}
-const CompMetadataOptionInfo coreScreenOptionInfo[COMP_SCREEN_OPTION_NUM] = {
+const CompMetadata::OptionInfo coreScreenOptionInfo[COMP_SCREEN_OPTION_NUM] = {
{ "detect_refresh_rate", "bool", 0, 0, 0 },
{ "lighting", "bool", 0, 0, 0 },
{ "refresh_rate", "int", "<min>1</min>", 0, 0 },
@@ -1681,10 +1681,8 @@ CompScreen::init (CompDisplay *display,
priv->display = display;
- if (!compInitScreenOptionsFromMetadata (this,
- &coreMetadata,
- coreScreenOptionInfo,
- priv->opt))
+ if (!coreMetadata->initScreenOptions (this, coreScreenOptionInfo,
+ COMP_SCREEN_OPTION_NUM, priv->opt))
return false;
priv->damage = XCreateRegion ();
diff --git a/src/string.cpp b/src/string.cpp
index 0276cbd..24efaf3 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -1,5 +1,7 @@
#include <compiz-core.h>
+#include <stdarg.h>
+
CompString compPrintf (const char *format, ...)
{
va_list ap;