summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Kasprzyk <onestone@opencompositing.org>2008-08-08 00:54:13 +0200
committerDennis kasprzyk <onestone@opencompositing.org>2008-08-08 00:54:13 +0200
commit51a6ee41ec7299191381de897f36d983ba12bdcc (patch)
tree9980ae2c91ef5d6fff90545da14c935d650c7c2e /src
parent860cc8ec6898fc33eda3aabb59eed7443a536e05 (diff)
downloadmobileperf-51a6ee41ec7299191381de897f36d983ba12bdcc.tar.gz
mobileperf-51a6ee41ec7299191381de897f36d983ba12bdcc.tar.bz2
Make CompObject smarter.
Diffstat (limited to 'src')
-rw-r--r--src/core.cpp17
-rw-r--r--src/display.cpp49
-rw-r--r--src/object.cpp128
-rw-r--r--src/plugin.cpp19
-rw-r--r--src/privateobject.h21
-rw-r--r--src/screen.cpp71
-rw-r--r--src/window.cpp65
7 files changed, 165 insertions, 205 deletions
diff --git a/src/core.cpp b/src/core.cpp
index 9e88618..7743aa6 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -107,7 +107,8 @@ freeCorePrivateIndex (int index)
((((tv1)->tv_sec - 1 - (tv2)->tv_sec) * 1000000) + \
(1000000 + (tv1)->tv_usec - (tv2)->tv_usec)) / 1000
-CompCore::CompCore ()
+CompCore::CompCore () :
+ CompObject (COMP_OBJECT_TYPE_CORE, "core")
{
priv = new PrivateCore (this);
assert (priv);
@@ -160,6 +161,13 @@ CompCore::~CompCore ()
}
+CompString
+CompCore::name ()
+{
+ return CompString ("");
+}
+
+
CompDisplay *
CompCore::displays()
{
@@ -553,17 +561,12 @@ CompCore::setOptionForPlugin (CompObject *object,
void
CompCore::objectAdd (CompObject *parent, CompObject *object)
-{
WRAPABLE_HND_FUNC(objectAdd, parent, object)
- object->parent = parent;
-}
+
void
CompCore::objectRemove (CompObject *parent, CompObject *object)
-{
WRAPABLE_HND_FUNC(objectRemove, parent, object)
- object->parent = NULL;
-}
void
CompCore::sessionEvent (CompSessionEvent event,
diff --git a/src/display.cpp b/src/display.cpp
index b78c0e9..2305c5e 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -114,44 +114,6 @@ freeDisplayObjectPrivateIndex (CompObject *parent,
freePrivateIndex (displayPrivateLen, displayPrivateIndices, index);
}
-CompBool
-forEachDisplayObject (CompObject *parent,
- ObjectCallBackProc proc,
- void *closure)
-{
- if (parent->type == COMP_OBJECT_TYPE_CORE)
- {
- CompDisplay *d;
-
- for (d = core->displays(); d; d = d->next)
- {
- if (!(*proc) (d, closure))
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-char *
-nameDisplayObject (CompObject *object)
-{
- return NULL;
-}
-
-CompObject *
-findDisplayObject (CompObject *parent,
- const char *name)
-{
- if (parent->type == COMP_OBJECT_TYPE_CORE)
- {
- if (!name || !name[0])
- return core->displays ();
- }
-
- return NULL;
-}
-
int
allocateDisplayPrivateIndex (void)
{
@@ -832,6 +794,7 @@ setDisplayAction (CompDisplay *display,
}
CompDisplay::CompDisplay () :
+ CompObject (COMP_OBJECT_TYPE_DISPLAY, "display"),
next (0),
screenPrivateIndices (0),
screenPrivateLen (0)
@@ -855,8 +818,6 @@ CompDisplay::~CompDisplay ()
while (priv->screens)
removeScreen (priv->screens);
- core->objectRemove (core, this);
-
objectFiniPlugins (this);
core->removeTimeout (priv->pingHandle);
@@ -1065,7 +1026,7 @@ CompDisplay::init (const char *name)
/* TODO: bailout properly when objectInitPlugins fails */
assert (objectInitPlugins (this));
- core->objectAdd (core, this);
+ core->addChild (this);
if (onlyCurrentScreen)
{
@@ -1125,6 +1086,12 @@ CompDisplay::init (const char *name)
return true;
}
+CompString
+CompDisplay::name ()
+{
+ return CompString ("");
+}
+
CompDisplay::Atoms
CompDisplay::atoms ()
{
diff --git a/src/object.cpp b/src/object.cpp
index e9717c6..7db8f37 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -23,7 +23,10 @@
* Author: David Reveman <davidr@novell.com>
*/
+#include <algorithm>
+
#include <compiz-core.h>
+#include "privateobject.h"
typedef CompBool (*AllocObjectPrivateIndexProc) (CompObject *parent);
@@ -43,38 +46,23 @@ struct _CompObjectInfo {
const char *name;
AllocObjectPrivateIndexProc allocPrivateIndex;
FreeObjectPrivateIndexProc freePrivateIndex;
- ForEachObjectProc forEachObject;
- NameObjectProc nameObject;
- FindObjectProc findObject;
} objectInfo[] = {
{
"core",
allocCoreObjectPrivateIndex,
- freeCoreObjectPrivateIndex,
- forEachCoreObject,
- nameCoreObject,
- findCoreObject
+ freeCoreObjectPrivateIndex
}, {
"display",
allocDisplayObjectPrivateIndex,
- freeDisplayObjectPrivateIndex,
- forEachDisplayObject,
- nameDisplayObject,
- findDisplayObject
+ freeDisplayObjectPrivateIndex
}, {
"screen",
allocScreenObjectPrivateIndex,
- freeScreenObjectPrivateIndex,
- forEachScreenObject,
- nameScreenObject,
- findScreenObject
+ freeScreenObjectPrivateIndex
}, {
"window",
allocWindowObjectPrivateIndex,
- freeWindowObjectPrivateIndex,
- forEachWindowObject,
- nameWindowObject,
- findWindowObject
+ freeWindowObjectPrivateIndex
}
};
@@ -83,9 +71,7 @@ compObjectInit (CompObject *object,
CompPrivate *privates,
CompObjectType type)
{
- object->type = type;
object->privates = privates;
- object->parent = NULL;
}
int
@@ -103,19 +89,17 @@ compObjectFreePrivateIndex (CompObject *parent,
(*objectInfo[type].freePrivateIndex) (parent, index);
}
-CompBool
-compObjectForEach (CompObject *parent,
- CompObjectType type,
- ObjectCallBackProc proc,
- void *closure)
+
+const char *
+compObjectTypeName (CompObjectType type)
{
- return (*objectInfo[type].forEachObject) (parent, proc, closure);
+ return objectInfo[type].name;
}
CompBool
-compObjectForEachType (CompObject *parent,
+compObjectForEachType (CompObject *parent,
ObjectTypeCallBackProc proc,
- void *closure)
+ void *closure)
{
int i;
@@ -126,22 +110,88 @@ compObjectForEachType (CompObject *parent,
return TRUE;
}
+
+PrivateObject::PrivateObject () :
+ typeName (0),
+ parent (NULL),
+ children (0)
+{
+}
+
+
+CompObject::CompObject (CompObjectType type, const char* typeName) :
+ privates (0)
+{
+ priv = new PrivateObject ();
+ assert (priv);
+
+ priv->type = type;
+ priv->typeName = typeName;
+}
+
+CompObject::~CompObject ()
+{
+ std::list<CompObject *>::iterator it;
+
+ while (!priv->children.empty ())
+ {
+ CompObject *o = priv->children.front ();
+ priv->children.pop_front ();
+ o->priv->parent = NULL;
+ core->objectRemove (this, o);
+ delete o;
+ }
+ if (priv->parent)
+ {
+ it = std::find (priv->parent->priv->children.begin (),
+ priv->parent->priv->children.end (),
+ this);
+
+ if (it != priv->parent->priv->children.end ())
+ {
+ priv->parent->priv->children.erase (it);
+ core->objectRemove (priv->parent, this);
+ }
+ }
+}
+
const char *
-compObjectTypeName (CompObjectType type)
+CompObject::typeName ()
{
- return objectInfo[type].name;
+ return priv->typeName;
+}
+
+CompObjectType
+CompObject::type ()
+{
+ return priv->type;
}
-char *
-compObjectName (CompObject *object)
+void
+CompObject::addChild (CompObject *object)
{
- return (*objectInfo[object->type].nameObject) (object);
+ if (!object)
+ return;
+ object->priv->parent = this;
+ priv->children.push_back (object);
+ core->objectAdd (this, object);
}
-CompObject *
-compObjectFind (CompObject *parent,
- CompObjectType type,
- const char *name)
+bool
+CompObject::forEachChild (ObjectCallBackProc proc,
+ void *closure,
+ CompObjectType type)
{
- return (*objectInfo[type].findObject) (parent, name);
+ bool rv = true;
+
+ std::list<CompObject *>::iterator it;
+ for (it = priv->children.begin (); it != priv->children.end (); it++)
+ {
+ if (type > 0 && (*it)->type () != type)
+ continue;
+ rv &= (*proc) ((*it), closure);
+ }
+
+ return rv;
}
+
diff --git a/src/plugin.cpp b/src/plugin.cpp
index d81b320..8762ad8 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -30,6 +30,7 @@
#include <dirent.h>
#include <compiz-core.h>
+#include <compobject.h>
CompPlugin *plugins = 0;
@@ -319,15 +320,15 @@ typedef struct _InitObjectTypeContext {
CompObjectType type;
} InitObjectTypeContext;
-static CompBool
+static bool
initObjectTree (CompObject *object,
void *closure);
-static CompBool
+static bool
finiObjectTree (CompObject *object,
void *closure);
-static CompBool
+static bool
initObjectsWithType (CompObjectType type,
CompObject *parent,
void *closure)
@@ -340,9 +341,9 @@ initObjectsWithType (CompObjectType type,
ctx.plugin = pCtx->plugin;
ctx.object = NULL;
- if (!compObjectForEach (parent, type, initObjectTree, (void *) &ctx))
+ if (!parent->forEachChild (initObjectTree, (void *) &ctx, type))
{
- compObjectForEach (parent, type, finiObjectTree, (void *) &ctx);
+ parent->forEachChild (finiObjectTree, (void *) &ctx, type);
return FALSE;
}
@@ -350,7 +351,7 @@ initObjectsWithType (CompObjectType type,
return TRUE;
}
-static CompBool
+static bool
finiObjectsWithType (CompObjectType type,
CompObject *parent,
void *closure)
@@ -365,12 +366,12 @@ finiObjectsWithType (CompObjectType type,
ctx.plugin = pCtx->plugin;
ctx.object = NULL;
- compObjectForEach (parent, type, finiObjectTree, (void *) &ctx);
+ parent->forEachChild (finiObjectTree, (void *) &ctx, type);
return TRUE;
}
-static CompBool
+static bool
initObjectTree (CompObject *object,
void *closure)
{
@@ -413,7 +414,7 @@ initObjectTree (CompObject *object,
return TRUE;
}
-static CompBool
+static bool
finiObjectTree (CompObject *object,
void *closure)
{
diff --git a/src/privateobject.h b/src/privateobject.h
new file mode 100644
index 0000000..a8f8eca
--- /dev/null
+++ b/src/privateobject.h
@@ -0,0 +1,21 @@
+#ifndef _PRIVATEOBJECT_H
+#define _PRIVATEOBJECT_H
+
+#include <list>
+#include <compiz-core.h>
+#include <compobject.h>
+
+class PrivateObject {
+ public :
+ PrivateObject ();
+
+ CompObjectType type;
+
+ const char *typeName;
+
+ CompObject *parent;
+ std::list<CompObject *> children;
+};
+
+
+#endif \ No newline at end of file
diff --git a/src/screen.cpp b/src/screen.cpp
index 2a02d0b..edee063 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <assert.h>
#include <limits.h>
+#include <algorithm>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@@ -94,58 +95,6 @@ freeScreenObjectPrivateIndex (CompObject *parent,
index);
}
-CompBool
-forEachScreenObject (CompObject *parent,
- ObjectCallBackProc proc,
- void *closure)
-{
- if (parent->type == COMP_OBJECT_TYPE_DISPLAY)
- {
- CompScreen *s;
-
- CORE_DISPLAY (parent);
-
- for (s = d->screens(); s; s = s->next)
- {
- if (!(*proc) (s, closure))
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-char *
-nameScreenObject (CompObject *object)
-{
- char tmp[256];
-
- CORE_SCREEN (object);
-
- snprintf (tmp, 256, "%d", s->screenNum ());
-
- return strdup (tmp);
-}
-
-CompObject *
-findScreenObject (CompObject *parent,
- const char *name)
-{
- if (parent->type == COMP_OBJECT_TYPE_DISPLAY)
- {
- CompScreen *s;
- int screenNum = atoi (name);
-
- CORE_DISPLAY (parent);
-
- for (s = d->screens(); s; s = s->next)
- if (s->screenNum () == screenNum)
- return s;
- }
-
- return NULL;
-}
-
int
allocateScreenPrivateIndex (CompDisplay *display)
{
@@ -1490,7 +1439,8 @@ CompScreen::initWindowWalker (CompWalker *walker)
walker->prev = walkPrev;
}
-CompScreen::CompScreen ()
+CompScreen::CompScreen ():
+ CompObject (COMP_OBJECT_TYPE_SCREEN, "screen")
{
WRAPABLE_INIT_HND(preparePaint);
WRAPABLE_INIT_HND(donePaint);
@@ -2329,7 +2279,7 @@ CompScreen::init (CompDisplay *display,
/* TODO: bailout properly when objectInitPlugins fails */
assert (objectInitPlugins (this));
- core->objectAdd (display, this);
+ display->addChild (this);
XQueryTree (dpy, priv->root,
&rootReturn, &parentReturn,
@@ -2405,8 +2355,6 @@ CompScreen::~CompScreen ()
while (priv->windows)
delete priv->windows;
- core->objectRemove (priv->display, this);
-
objectFiniPlugins (this);
XUngrabKey (priv->display->dpy (), AnyKey, AnyModifier, priv->root);
@@ -2465,6 +2413,17 @@ CompScreen::~CompScreen ()
delete priv;
}
+CompString
+CompScreen::name ()
+{
+ char tmp[256];
+
+ snprintf (tmp, 256, "%d", priv->screenNum);
+
+ return CompString (tmp);
+
+}
+
void
CompScreen::damageRegion (Region region)
{
diff --git a/src/window.cpp b/src/window.cpp
index 0e4524d..854e08f 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -87,58 +87,6 @@ freeWindowObjectPrivateIndex (CompObject *parent,
index);
}
-CompBool
-forEachWindowObject (CompObject *parent,
- ObjectCallBackProc proc,
- void *closure)
-{
- if (parent->type == COMP_OBJECT_TYPE_SCREEN)
- {
- CompWindow *w;
-
- CORE_SCREEN (parent);
-
- for (w = s->windows (); w; w = w->next)
- {
- if (!(*proc) (w, closure))
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-char *
-nameWindowObject (CompObject *object)
-{
- char tmp[256];
-
- CORE_WINDOW (object);
-
- snprintf (tmp, 256, "0x%lu", w->id ());
-
- return strdup (tmp);
-}
-
-CompObject *
-findWindowObject (CompObject *parent,
- const char *name)
-{
- if (parent->type == COMP_OBJECT_TYPE_SCREEN)
- {
- CompWindow *w;
- Window id = atoi (name);
-
- CORE_SCREEN (parent);
-
- for (w = s->windows (); w; w = w->next)
- if (w->id () == id)
- return w;
- }
-
- return NULL;
-}
-
int
allocateWindowPrivateIndex (CompScreen *screen)
{
@@ -4994,7 +4942,8 @@ CompWindow::paintAttrib ()
CompWindow::CompWindow (CompScreen *screen,
Window id,
- Window aboveId)
+ Window aboveId) :
+ CompObject (COMP_OBJECT_TYPE_WINDOW, "window")
{
WRAPABLE_INIT_HND(paint);
WRAPABLE_INIT_HND(draw);
@@ -5485,3 +5434,13 @@ PrivateWindow::~PrivateWindow ()
free (resClass);
}
+CompString
+CompWindow::name ()
+{
+ char tmp[256];
+
+ snprintf (tmp, 256, "0x%lu", priv->id);
+
+ return CompString (tmp);
+
+}