Merge lp:~smspillaz/compiz-libcompizconfig/refactor-context into lp:~compiz-team/compiz-libcompizconfig/0.9.8

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~smspillaz/compiz-libcompizconfig/refactor-context
Merge into: lp:~compiz-team/compiz-libcompizconfig/0.9.8
Prerequisite: lp:~smspillaz/compiz-libcompizconfig/ccs-object
Diff against target: 882 lines (+339/-96)
6 files modified
backend/src/ini.c (+2/-2)
include/ccs.h (+52/-12)
plugin/ccp/src/ccp.cpp (+6/-9)
src/ccs-private.h (+12/-1)
src/compiz.cpp (+15/-5)
src/main.c (+252/-67)
To merge this branch: bzr merge lp:~smspillaz/compiz-libcompizconfig/refactor-context
Reviewer Review Type Date Requested Status
Alan Griffiths Pending
Review via email: mp+104469@code.launchpad.net

This proposal supersedes a proposal from 2012-04-29.

Description of the change

This is all about bug 990690.

!! - It probably isn't a good idea to test this branch in isolation, as it is part of a pipeline to get compiz-libcompizconfig under test. If you want to test the result of this work, you should probably look at testing

lp:~smspillaz/compiz-libcompizconfig/setting-mock
lp:~smspillaz/compiz-compizconfig-python/compiz-compizconfig-python.setting-api
lp:~smspillaz/compiz-compizconfig-gconf/compiz-compizconfig-gconf.adapt-to-new-interfaces

.. that's all !!

Refactors CCSContext to indirect all variables behind a private ptr

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote : Posted in a previous version of this proposal

There's not much point to a structure that only contains a void pointer.

The pattern I'd expect is:

// *.h
typedef struct CCSContext CCSContext;
CCSContext* ccsContextCreate();
CCSPluginList ccsContextGetPlugins(CCSContext*);
...
void ccsContextDestroy(CCSContext*);

// *.cpp
struct CCSContext
{
    CCSBackend *backend;
    CCSPluginList plugins; /* list of plugins settings were loaded for */
    CCSPluginCategory *categories; /* list of plugin categories */
    void *privatePtr; /* private pointer that can be used by the caller */
    char *profile;
    Bool deIntegration;
    Bool pluginListAutoSort;

    unsigned int configWatchId;

    CCSSettingList changedSettings; /* list of settings changed since last settings write */

    unsigned int screenNum; /* screen number this context is assigned to */
    const CCSInterfaceTable *object_interfaces;
    const CCSContextInterface *interface;
} CCSContextPrivate;
...
CCSPluginList
ccsContextGetPluginsDefault (CCSContext* context)
{
  return context->plugins;
}
...

Maybe there is a reason for the extra complexity? But it escapes me.

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote : Posted in a previous version of this proposal

> There's not much point to a structure that only contains a void pointer.
>
> The pattern I'd expect is:
>
> // *.h
> typedef struct CCSContext CCSContext;
> CCSContext* ccsContextCreate();
> CCSPluginList ccsContextGetPlugins(CCSContext*);
> ...
> void ccsContextDestroy(CCSContext*);
>
> // *.cpp
> struct CCSContext
> {
> CCSBackend *backend;
> CCSPluginList plugins; /* list of plugins settings were loaded for */
> CCSPluginCategory *categories; /* list of plugin categories */
> void *privatePtr; /* private pointer that can be used by the caller */
> char *profile;
> Bool deIntegration;
> Bool pluginListAutoSort;
>
> unsigned int configWatchId;
>
> CCSSettingList changedSettings; /* list of settings changed since last
> settings write */
>
> unsigned int screenNum; /* screen number this context is assigned to */
> const CCSInterfaceTable *object_interfaces;
> const CCSContextInterface *interface;
> } CCSContextPrivate;

Cut&past error - that should be "> };"

> ...
> CCSPluginList
> ccsContextGetPluginsDefault (CCSContext* context)
> {
> return context->plugins;
> }
> ...
>
> Maybe there is a reason for the extra complexity? But it escapes me.

Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

Agreed, changing to opaque pointers was something I didn't remember to do yet. doing it now.

Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

> There's not much point to a structure that only contains a void pointer.
>
> The pattern I'd expect is:
>
> // *.h
> typedef struct CCSContext CCSContext;
> CCSContext* ccsContextCreate();
> CCSPluginList ccsContextGetPlugins(CCSContext*);
> ...
> void ccsContextDestroy(CCSContext*);
>
> // *.cpp
> struct CCSContext
> {
> CCSBackend *backend;
> CCSPluginList plugins; /* list of plugins settings were loaded for */
> CCSPluginCategory *categories; /* list of plugin categories */
> void *privatePtr; /* private pointer that can be used by the caller */
> char *profile;
> Bool deIntegration;
> Bool pluginListAutoSort;
>
> unsigned int configWatchId;
>
> CCSSettingList changedSettings; /* list of settings changed since last
> settings write */
>
> unsigned int screenNum; /* screen number this context is assigned to */
> const CCSInterfaceTable *object_interfaces;
> const CCSContextInterface *interface;
> } CCSContextPrivate;
> ...
> CCSPluginList
> ccsContextGetPluginsDefault (CCSContext* context)
> {
> return context->plugins;
> }
> ...
>
> Maybe there is a reason for the extra complexity? But it escapes me.

See the next pipe - it contains a struct that contains a CCSObject (not by pointer). All this does is move the data behind an indirection pimpl.

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

A clarification - the way CCSObject works means that "object types" in libcompizconfig can't be behind opaque pointers is because at the moment we are just doing allocation manually (eg no fooNew ... yet as its nontrivial with the current design). In order to ensure that we get enough allocated for CCSObject and can access it easily from any object type is to make it the first member of the struct and then hide everything behind the priv pointer it provides.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote : Posted in a previous version of this proposal

I can think of no good reason that ccsPrivate is void* instead of CCSContextPrivate* - that would allow the implementation code to be simpler by removing the need for casts.

And I don't see why CONTEXT_PRIV and _CCSContextPrivate/CCSContextPrivate are defined in a header.

Which is "the next pipe"?

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Each of these branches is part of a pipeline (eg, changes are made in serial and each is dependent on the last). This can be traversed backwards from setting-mock.

At the moment, the pattern I'm using here is

1) Move private data behind a pimpl and use accessor methods to get at the data
2) Create an interface structure and make all method calls for that object go through that interface structure.

Hence the reason why ccsPrivate is void * (for the time being).

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

CONTEXT_PRIV and related things are defined in headers because they are used in multiple source files. This will be changed eventually, but in another branch (for the sake of /not/ rewriting libcompizconfig in one MP)

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> CONTEXT_PRIV and related things are defined in headers because they are used
> in multiple source files. This will be changed eventually, but in another
> branch (for the sake of /not/ rewriting libcompizconfig in one MP)

AFAICS CONTEXT_PRIV, _CCSContextPrivate and CCSContextPrivate are only used in main.c (but that isn't the real point).

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I'm still struggling to identify the design goals here.

Indirecting calls via a CCSContextInterface member pointer gives the capability to change the implementation of individual functions on an instance by instance basis. Is this needed? Or just a seam for testing? If the latter, then there's no need for objects to carry around a pointer.

I also don't see what the additional indirection through CCSInterfaceTable* is for. The only use is ccsEmptyContextNew which assigns to object_interfaces, but where is it used? And what for?

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

On Fri, 4 May 2012, Alan Griffiths wrote:

> I'm still struggling to identify the design goals here.
>
> Indirecting calls via a CCSContextInterface member pointer gives the capability to change the implementation of individual functions on an instance by instance basis. Is this needed? Or just a seam for testing? If the latter, then there's no need for objects to carry around a pointer.
>

Sure, it is a seam for testing. However, its useful in that we can test by
having a real CCSPlugin, CCSContext and a mocked CCSSetting or vice-versa.
We may also want to test interactiosn between individual setting objects
themselves vis-a-vis keybinding conflicts.

> I also don't see what the additional indirection through CCSInterfaceTable* is for. The only use is ccsEmptyContextNew which assigns to object_interfaces, but where is it used? And what for?
>

At the moment, this is so that you can override the kind of objet that
might be constructed by a CCSContexted or CCSPlugin internally. This will
be replaced when the code is further refactored to truly do dependency
injection.

>
> --
> https://code.launchpad.net/~smspillaz/compiz-libcompizconfig/refactor-context/+merge/104469
> You are the owner of lp:~smspillaz/compiz-libcompizconfig/refactor-context.
>

437. By Sam Spilsbury

Merged ccs-object into refactor-context.

438. By Sam Spilsbury

Merged ccs-object into refactor-context.

439. By Sam Spilsbury

Merged ccs-object into refactor-context.

440. By Sam Spilsbury

Merged ccs-object into refactor-context.

441. By Sam Spilsbury

Merged ccs-object into refactor-context.

442. By Sam Spilsbury

Merged ccs-object into refactor-context.

Unmerged revisions

442. By Sam Spilsbury

Merged ccs-object into refactor-context.

441. By Sam Spilsbury

Merged ccs-object into refactor-context.

440. By Sam Spilsbury

Merged ccs-object into refactor-context.

439. By Sam Spilsbury

Merged ccs-object into refactor-context.

438. By Sam Spilsbury

Merged ccs-object into refactor-context.

437. By Sam Spilsbury

Merged ccs-object into refactor-context.

436. By Sam Spilsbury

Merged ccs-object into refactor-context.

435. By Sam Spilsbury

Merged ccs-object into refactor-context.

434. By Sam Spilsbury

Merged ccs-object into refactor-context.

433. By Sam Spilsbury

Merged ccs-object into refactor-context.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'backend/src/ini.c'
2--- backend/src/ini.c 2011-08-20 19:03:37 +0000
3+++ backend/src/ini.c 2012-05-04 19:29:21 +0000
4@@ -265,7 +265,7 @@
5 if (!data)
6 return;
7
8- asprintf (&keyName, "s%d_%s", context->screenNum, setting->name);
9+ asprintf (&keyName, "s%d_%s", ccsContextGetScreenNum (context), setting->name);
10
11 switch (setting->type)
12 {
13@@ -455,7 +455,7 @@
14 if (!data)
15 return;
16
17- asprintf (&keyName, "s%d_%s", context->screenNum, setting->name);
18+ asprintf (&keyName, "s%d_%s", ccsContextGetScreenNum (context), setting->name);
19
20 if (setting->isDefault)
21 {
22
23=== modified file 'include/ccs.h'
24--- include/ccs.h 2012-05-04 19:29:21 +0000
25+++ include/ccs.h 2012-05-04 19:29:21 +0000
26@@ -247,20 +247,60 @@
27 CCSREF_HDR (StrRestriction, CCSStrRestriction)
28 CCSREF_HDR (StrExtension, CCSStrExtension)
29
30+typedef struct _CCSInterfaceTable CCSInterfaceTable;
31+typedef struct _CCSContextInterface CCSContextInterface;
32+
33+struct _CCSInterfaceTable
34+{
35+ const CCSContextInterface *contextInterface;
36+};
37+
38+extern const CCSInterfaceTable ccsDefaultInterfaceTable;
39+
40+/* CCSContext interface */
41+typedef CCSPluginList (*CCSContextGetPluginsProc) (CCSContext *context);
42+typedef CCSPluginCategory * (*CCSContextGetCategories) (CCSContext *context);
43+typedef CCSSettingList (*CCSContextGetChangedSettings) (CCSContext *context);
44+typedef unsigned int (*CCSContextGetScreenNum) (CCSContext *context);
45+typedef Bool (*CCSContextAddChangedSetting) (CCSContext *context, CCSSetting *setting);
46+typedef Bool (*CCSContextClearChangedSettings) (CCSContext *context);
47+typedef CCSSettingList (*CCSContextStealChangedSettings) (CCSContext *context);
48+typedef void * (*CCSContextGetPrivatePtr) (CCSContext *context);
49+typedef void (*CCSContextSetPrivatePtr) (CCSContext *context, void *ptr);
50+
51+struct _CCSContextInterface
52+{
53+ CCSContextGetPluginsProc contextGetPlugins;
54+ CCSContextGetCategories contextGetCategories;
55+ CCSContextGetChangedSettings contextGetChangedSettings;
56+ CCSContextGetScreenNum contextGetScreenNum;
57+ CCSContextAddChangedSetting contextAddChangedSetting;
58+ CCSContextClearChangedSettings contextClearChangedSettings;
59+ CCSContextStealChangedSettings contextStealChangedSettings;
60+ CCSContextGetPrivatePtr contextGetPrivatePtr;
61+ CCSContextSetPrivatePtr contextSetPrivatePtr;
62+};
63+
64+/* CCSContext accessor functions */
65+CCSPluginList ccsContextGetPlugins (CCSContext *);
66+CCSPluginCategory * ccsContextGetCategories (CCSContext *);
67+CCSSettingList ccsContextGetChangedSettings (CCSContext *);
68+unsigned int ccsContextGetScreenNum (CCSContext *);
69+Bool ccsContextAddChangedSetting (CCSContext *context, CCSSetting *setting);
70+Bool ccsContextClearChangedSettings (CCSContext *context);
71+CCSSettingList ccsContextStealChangedSettings (CCSContext *context);
72+void * ccsContextGetPrivatePtr (CCSContext *context);
73+void ccsContextSetPrivatePtr (CCSContext *context, void *ptr);
74+
75+/* only for bindings */
76+void * ccsContextGetPluginsBindable (CCSContext *context);
77+void * ccsContextStealChangedSettingsBindable (CCSContext *context);
78+void * ccsContextGetChangedSettingsBindable (CCSContext *context);
79+
80 struct _CCSContext
81 {
82- CCSPluginList plugins; /* list of plugins settings
83- were loaded for */
84- CCSPluginCategory *categories; /* list of plugin categories */
85- void *privatePtr; /* private pointer that can be used
86- by the caller */
87 void *ccsPrivate; /* private pointer for compizconfig
88 internal usage */
89-
90- CCSSettingList changedSettings; /* list of settings changed since last
91- settings write */
92-
93- unsigned int screenNum; /* screen number this context is assigned to */
94 };
95
96 struct _CCSBackendInfo
97@@ -534,11 +574,11 @@
98
99 /* Creates a new context for the given screen.
100 All plugin settings are automatically enumerated. */
101-CCSContext* ccsContextNew (unsigned int screenNum);
102+CCSContext* ccsContextNew (unsigned int screenNum, const CCSInterfaceTable *);
103
104 /* Creates a new context without auto-enumerating any plugin or setting.
105 Behaves otherwise exactly like ccsContextNew. */
106-CCSContext* ccsEmptyContextNew (unsigned int screenNum);
107+CCSContext* ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *);
108
109 /* Destroys the allocated context. */
110 void ccsContextDestroy (CCSContext * context);
111
112=== modified file 'plugin/ccp/src/ccp.cpp'
113--- plugin/ccp/src/ccp.cpp 2011-08-20 19:03:37 +0000
114+++ plugin/ccp/src/ccp.cpp 2012-05-04 19:29:21 +0000
115@@ -429,15 +429,14 @@
116
117 ccsProcessEvents (mContext, flags);
118
119- if (ccsSettingListLength (mContext->changedSettings))
120+ CCSSettingList list = ccsContextStealChangedSettings (mContext);
121+
122+ if (ccsSettingListLength (list))
123 {
124- CCSSettingList list = mContext->changedSettings;
125 CCSSettingList l = list;
126 CCSSetting *s;
127 CompPlugin *p;
128 CompOption *o;
129-
130- mContext->changedSettings = NULL;
131
132 while (l)
133 {
134@@ -456,8 +455,7 @@
135 }
136
137 ccsSettingListFree (list, FALSE);
138- mContext->changedSettings =
139- ccsSettingListFree (mContext->changedSettings, FALSE);
140+ ccsContextClearChangedSettings (mContext);
141 }
142
143 return true;
144@@ -513,11 +511,10 @@
145 {
146 ccsSetBasicMetadata (TRUE);
147
148- mContext = ccsContextNew (screen->screenNum ());
149+ mContext = ccsContextNew (screen->screenNum (), &ccsDefaultInterfaceTable);
150 ccsReadSettings (mContext);
151
152- mContext->changedSettings =
153- ccsSettingListFree (mContext->changedSettings, FALSE);
154+ ccsContextClearChangedSettings (mContext);
155
156 mReloadTimer.start (boost::bind (&CcpScreen::reload, this), 0);
157 mTimeoutTimer.start (boost::bind (&CcpScreen::timeout, this),
158
159=== modified file 'src/ccs-private.h'
160--- src/ccs-private.h 2011-08-20 19:03:37 +0000
161+++ src/ccs-private.h 2012-05-04 19:29:21 +0000
162@@ -35,12 +35,23 @@
163 typedef struct _CCSContextPrivate
164 {
165 CCSBackend *backend;
166-
167+ CCSPluginList plugins; /* list of plugins settings
168+ were loaded for */
169+ CCSPluginCategory *categories; /* list of plugin categories */
170+ void *privatePtr; /* private pointer that can be used
171+ by the caller */
172 char *profile;
173 Bool deIntegration;
174 Bool pluginListAutoSort;
175
176 unsigned int configWatchId;
177+
178+ CCSSettingList changedSettings; /* list of settings changed since last
179+ settings write */
180+
181+ unsigned int screenNum; /* screen number this context is assigned to */
182+ const CCSInterfaceTable *object_interfaces;
183+ const CCSContextInterface *interface;
184 } CCSContextPrivate;
185
186 typedef struct _CCSPluginPrivate
187
188=== modified file 'src/compiz.cpp'
189--- src/compiz.cpp 2012-01-23 11:37:14 +0000
190+++ src/compiz.cpp 2012-05-04 19:29:21 +0000
191@@ -845,6 +845,8 @@
192 CCSPlugin *plugin;
193 CCSPluginPrivate *pPrivate;
194
195+ CONTEXT_PRIV (context);
196+
197 name = pluginInfoPB.name ().c_str ();
198
199 if (!strlen (name))
200@@ -908,7 +910,7 @@
201
202 initRulesFromPB (plugin, pluginInfoPB);
203
204- context->plugins = ccsPluginListAppend (context->plugins, plugin);
205+ cPrivate->plugins = ccsPluginListAppend (cPrivate->plugins, plugin);
206 }
207
208 static void
209@@ -923,6 +925,8 @@
210 if (ccsFindPlugin (context, "core"))
211 return;
212
213+ CONTEXT_PRIV (context);
214+
215 plugin = (CCSPlugin*) calloc (1, sizeof (CCSPlugin));
216 if (!plugin)
217 return;
218@@ -970,7 +974,7 @@
219 }
220
221 initRulesFromPB (plugin, pluginInfoPB);
222- context->plugins = ccsPluginListAppend (context->plugins, plugin);
223+ cPrivate->plugins = ccsPluginListAppend (cPrivate->plugins, plugin);
224 }
225
226 #endif
227@@ -2471,6 +2475,8 @@
228 CCSPlugin *plugin;
229 CCSPluginPrivate *pPrivate;
230
231+ CONTEXT_PRIV (context);
232+
233 if (!node)
234 return FALSE;
235
236@@ -2539,7 +2545,7 @@
237
238 initRulesFromRootNode (plugin, node, pluginInfoPBv);
239
240- context->plugins = ccsPluginListAppend (context->plugins, plugin);
241+ cPrivate->plugins = ccsPluginListAppend (cPrivate->plugins, plugin);
242 free (name);
243
244 return TRUE;
245@@ -2555,6 +2561,8 @@
246 CCSPlugin *plugin;
247 CCSPluginPrivate *pPrivate;
248
249+ CONTEXT_PRIV (context);
250+
251 if (!node)
252 return FALSE;
253
254@@ -2603,7 +2611,7 @@
255 #endif
256
257 initRulesFromRootNode (plugin, node, pluginInfoPBv);
258- context->plugins = ccsPluginListAppend (context->plugins, plugin);
259+ cPrivate->plugins = ccsPluginListAppend (cPrivate->plugins, plugin);
260
261 return TRUE;
262 }
263@@ -2899,6 +2907,8 @@
264 CCSPlugin *plugin;
265 CCSPluginPrivate *pPrivate;
266
267+ CONTEXT_PRIV (context);
268+
269 if (ccsFindPlugin (context, name))
270 return;
271
272@@ -2933,7 +2943,7 @@
273
274 pPrivate->loaded = TRUE;
275 collateGroups (pPrivate);
276- context->plugins = ccsPluginListAppend (context->plugins, plugin);
277+ cPrivate->plugins = ccsPluginListAppend (cPrivate->plugins, plugin);
278 }
279
280 static void
281
282=== modified file 'src/main.c'
283--- src/main.c 2012-05-04 19:29:21 +0000
284+++ src/main.c 2012-05-04 19:29:21 +0000
285@@ -260,7 +260,7 @@
286 }
287
288 CCSContext *
289-ccsEmptyContextNew (unsigned int screenNum)
290+ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_interfaces)
291 {
292 CCSContext *context;
293
294@@ -277,7 +277,9 @@
295
296 CONTEXT_PRIV (context);
297
298- context->screenNum = screenNum;
299+ cPrivate->object_interfaces = object_interfaces;
300+ cPrivate->interface = object_interfaces->contextInterface;
301+ cPrivate->screenNum = screenNum;
302
303 initGeneralOptions (context);
304 cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify);
305@@ -292,13 +294,198 @@
306 return context;
307 }
308
309+static void *
310+ccsContextGetPrivatePtrDefault (CCSContext *context)
311+{
312+ CONTEXT_PRIV (context);
313+
314+ return cPrivate->privatePtr;
315+}
316+
317+static void
318+ccsContextSetPrivatePtrDefault (CCSContext *context, void *ptr)
319+{
320+ CONTEXT_PRIV (context);
321+
322+ cPrivate->privatePtr = ptr;
323+}
324+
325+static CCSPluginList
326+ccsContextGetPluginsDefault (CCSContext *context)
327+{
328+ CONTEXT_PRIV (context);
329+
330+ return cPrivate->plugins;
331+}
332+
333+static CCSPluginCategory *
334+ccsContextGetCategoriesDefault (CCSContext *context)
335+{
336+ CONTEXT_PRIV (context);
337+
338+ return cPrivate->categories;
339+}
340+
341+static CCSSettingList
342+ccsContextGetChangedSettingsDefault (CCSContext *context)
343+{
344+ CONTEXT_PRIV (context);
345+
346+ return cPrivate->changedSettings;
347+}
348+
349+static unsigned int
350+ccsContextGetScreenNumDefault (CCSContext *context)
351+{
352+ CONTEXT_PRIV (context);
353+
354+ return cPrivate->screenNum;
355+}
356+
357+static Bool
358+ccsContextAddChangedSettingDefault (CCSContext *context, CCSSetting *setting)
359+{
360+ CONTEXT_PRIV (context);
361+
362+ cPrivate->changedSettings = ccsSettingListAppend (cPrivate->changedSettings, setting);
363+
364+ return TRUE;
365+}
366+
367+static Bool
368+ccsContextClearChangedSettingsDefault (CCSContext *context)
369+{
370+ CONTEXT_PRIV (context);
371+
372+ cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE);
373+
374+ return TRUE;
375+}
376+
377+static CCSSettingList
378+ccsContextStealChangedSettingsDefault (CCSContext *context)
379+{
380+ CONTEXT_PRIV (context);
381+
382+ CCSSettingList l = cPrivate->changedSettings;
383+
384+ cPrivate->changedSettings = NULL;
385+ return l;
386+}
387+
388+static const CCSContextInterface ccsDefaultContextInterface =
389+{
390+ ccsContextGetPluginsDefault,
391+ ccsContextGetCategoriesDefault,
392+ ccsContextGetChangedSettingsDefault,
393+ ccsContextGetScreenNumDefault,
394+ ccsContextAddChangedSettingDefault,
395+ ccsContextClearChangedSettingsDefault,
396+ ccsContextStealChangedSettingsDefault,
397+ ccsContextGetPrivatePtrDefault,
398+ ccsContextSetPrivatePtrDefault
399+};
400+
401+CCSPluginList
402+ccsContextGetPlugins (CCSContext *context)
403+{
404+ CONTEXT_PRIV (context);
405+
406+ return (*cPrivate->interface->contextGetPlugins) (context);
407+}
408+
409+CCSPluginCategory *
410+ccsContextGetCategories (CCSContext *context)
411+{
412+ CONTEXT_PRIV (context);
413+
414+ return (*cPrivate->interface->contextGetCategories) (context);
415+}
416+
417+CCSSettingList
418+ccsContextGetChangedSettings (CCSContext *context)
419+{
420+ CONTEXT_PRIV (context);
421+
422+ return (*cPrivate->interface->contextGetChangedSettings) (context);
423+}
424+
425+unsigned int
426+ccsContextGetScreenNum (CCSContext *context)
427+{
428+ CONTEXT_PRIV (context);
429+
430+ return (*cPrivate->interface->contextGetScreenNum) (context);
431+}
432+
433+Bool
434+ccsContextAddChangedSetting (CCSContext *context, CCSSetting *setting)
435+{
436+ CONTEXT_PRIV (context);
437+
438+ return (*cPrivate->interface->contextAddChangedSetting) (context, setting);
439+}
440+
441+Bool
442+ccsContextClearChangedSettings (CCSContext *context)
443+{
444+ CONTEXT_PRIV (context);
445+
446+ return (*cPrivate->interface->contextClearChangedSettings) (context);
447+}
448+
449+CCSSettingList
450+ccsContextStealChangedSettings (CCSContext *context)
451+{
452+ CONTEXT_PRIV (context);
453+
454+ return (*cPrivate->interface->contextStealChangedSettings) (context);
455+}
456+
457+void *
458+ccsContextGetPrivatePtr (CCSContext *context)
459+{
460+ CONTEXT_PRIV (context);
461+
462+ return (*cPrivate->interface->contextGetPrivatePtr) (context);
463+}
464+
465+void
466+ccsContextSetPrivatePtr (CCSContext *context, void *ptr)
467+{
468+ CONTEXT_PRIV (context);
469+
470+ return (*cPrivate->interface->contextSetPrivatePtr) (context, ptr);
471+}
472+
473+void *
474+ccsContextGetPluginsBindable (CCSContext *context)
475+{
476+ return (void *) ccsContextGetPlugins (context);
477+}
478+
479+void *
480+ccsContextStealChangedSettingsBindable (CCSContext *context)
481+{
482+ return (void *) ccsContextStealChangedSettings (context);
483+}
484+
485+void *
486+ccsContextGetChangedSettingsBindable (CCSContext *context)
487+{
488+ return (void *) ccsContextGetChangedSettings (context);
489+}
490+
491+
492 static void
493 ccsSetActivePluginList (CCSContext * context, CCSStringList list)
494 {
495 CCSPluginList l;
496 CCSPlugin *plugin;
497
498- for (l = context->plugins; l; l = l->next)
499+ CONTEXT_PRIV (context);
500+
501+ for (l = cPrivate->plugins; l; l = l->next)
502 {
503 PLUGIN_PRIV (l->data);
504 pPrivate->active = FALSE;
505@@ -325,10 +512,10 @@
506 }
507
508 CCSContext *
509-ccsContextNew (unsigned int screenNum)
510+ccsContextNew (unsigned int screenNum, const CCSInterfaceTable *iface)
511 {
512 CCSPlugin *p;
513- CCSContext *context = ccsEmptyContextNew (screenNum);
514+ CCSContext *context = ccsEmptyContextNew (screenNum, iface);
515 if (!context)
516 return NULL;
517
518@@ -367,7 +554,9 @@
519 if (!name)
520 name = "";
521
522- CCSPluginList l = context->plugins;
523+ CONTEXT_PRIV (context);
524+
525+ CCSPluginList l = cPrivate->plugins;
526 while (l)
527 {
528 if (!strcmp (l->data->name, name))
529@@ -502,14 +691,14 @@
530 if (cPrivate->configWatchId)
531 ccsRemoveFileWatch (cPrivate->configWatchId);
532
533- if (c->changedSettings)
534- ccsSettingListFree (c->changedSettings, FALSE);
535+ if (cPrivate->changedSettings)
536+ cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE);
537+
538+ ccsPluginListFree (cPrivate->plugins, TRUE);
539
540 if (c->ccsPrivate)
541 free (c->ccsPrivate);
542
543- ccsPluginListFree (c->plugins, TRUE);
544-
545 free (c);
546 }
547
548@@ -1135,9 +1324,7 @@
549 ccsFreeSettingValue (setting->value);
550
551 if (processChanged)
552- setting->parent->context->changedSettings =
553- ccsSettingListAppend (setting->parent->context->changedSettings,
554- setting);
555+ ccsContextAddChangedSetting (setting->parent->context, setting);
556 }
557
558 setting->value = &setting->defaultValue;
559@@ -1227,9 +1414,7 @@
560 setting->value->value.asInt = data;
561
562 if (processChanged)
563- setting->parent->context->changedSettings =
564- ccsSettingListAppend (setting->parent->context->changedSettings,
565- setting);
566+ ccsContextAddChangedSetting (setting->parent->context, setting);
567
568 return TRUE;
569 }
570@@ -1264,9 +1449,7 @@
571 setting->value->value.asFloat = data;
572
573 if (processChanged)
574- setting->parent->context->changedSettings =
575- ccsSettingListAppend (setting->parent->context->changedSettings,
576- setting);
577+ ccsContextAddChangedSetting (setting->parent->context, setting);
578
579 return TRUE;
580 }
581@@ -1300,9 +1483,7 @@
582 setting->value->value.asBool = data;
583
584 if (processChanged)
585- setting->parent->context->changedSettings =
586- ccsSettingListAppend (setting->parent->context->changedSettings,
587- setting);
588+ ccsContextAddChangedSetting (setting->parent->context, setting);
589
590 return TRUE;
591 }
592@@ -1338,9 +1519,7 @@
593 setting->value->value.asString = strdup (data);
594
595 if (processChanged)
596- setting->parent->context->changedSettings =
597- ccsSettingListAppend (setting->parent->context->changedSettings,
598- setting);
599+ ccsContextAddChangedSetting (setting->parent->context, setting);
600
601 return TRUE;
602 }
603@@ -1373,9 +1552,7 @@
604 setting->value->value.asColor = data;
605
606 if (processChanged)
607- setting->parent->context->changedSettings =
608- ccsSettingListAppend (setting->parent->context->changedSettings,
609- setting);
610+ ccsContextAddChangedSetting (setting->parent->context, setting);
611
612 return TRUE;
613 }
614@@ -1411,9 +1588,7 @@
615 setting->value->value.asMatch = strdup (data);
616
617 if (processChanged)
618- setting->parent->context->changedSettings =
619- ccsSettingListAppend (setting->parent->context->changedSettings,
620- setting);
621+ ccsContextAddChangedSetting (setting->parent->context, setting);
622
623 return TRUE;
624 }
625@@ -1447,9 +1622,7 @@
626 setting->value->value.asKey.keyModMask = data.keyModMask;
627
628 if (processChanged)
629- setting->parent->context->changedSettings =
630- ccsSettingListAppend (setting->parent->context->changedSettings,
631- setting);
632+ ccsContextAddChangedSetting (setting->parent->context, setting);
633
634 return TRUE;
635 }
636@@ -1484,9 +1657,7 @@
637 setting->value->value.asButton.edgeMask = data.edgeMask;
638
639 if (processChanged)
640- setting->parent->context->changedSettings =
641- ccsSettingListAppend (setting->parent->context->changedSettings,
642- setting);
643+ ccsContextAddChangedSetting (setting->parent->context, setting);
644
645 return TRUE;
646 }
647@@ -1517,9 +1688,7 @@
648 setting->value->value.asEdge = data;
649
650 if (processChanged)
651- setting->parent->context->changedSettings =
652- ccsSettingListAppend (setting->parent->context->changedSettings,
653- setting);
654+ ccsContextAddChangedSetting (setting->parent->context, setting);
655
656 return TRUE;
657 }
658@@ -1550,9 +1719,7 @@
659 setting->value->value.asBell = data;
660
661 if (processChanged)
662- setting->parent->context->changedSettings =
663- ccsSettingListAppend (setting->parent->context->changedSettings,
664- setting);
665+ ccsContextAddChangedSetting (setting->parent->context, setting);
666
667 return TRUE;
668 }
669@@ -1672,9 +1839,7 @@
670 }
671
672 if (processChanged)
673- setting->parent->context->changedSettings =
674- ccsSettingListAppend (setting->parent->context->changedSettings,
675- setting);
676+ ccsContextAddChangedSetting (setting->parent->context, setting);
677
678 return TRUE;
679 }
680@@ -1857,8 +2022,10 @@
681 CCSPluginList
682 ccsGetActivePluginList (CCSContext * context)
683 {
684+ CONTEXT_PRIV (context);
685+
686 CCSPluginList rv = NULL;
687- CCSPluginList l = context->plugins;
688+ CCSPluginList l = cPrivate->plugins;
689
690 while (l)
691 {
692@@ -2222,7 +2389,7 @@
693 if (!(*cPrivate->backend->vTable->readInit) (context))
694 return;
695
696- CCSPluginList pl = context->plugins;
697+ CCSPluginList pl = cPrivate->plugins;
698 while (pl)
699 {
700 PLUGIN_PRIV (pl->data);
701@@ -2290,7 +2457,7 @@
702 if (!(*cPrivate->backend->vTable->writeInit) (context))
703 return;
704
705- CCSPluginList pl = context->plugins;
706+ CCSPluginList pl = cPrivate->plugins;
707 while (pl)
708 {
709 PLUGIN_PRIV (pl->data);
710@@ -2308,8 +2475,8 @@
711 if (cPrivate->backend->vTable->writeDone)
712 (*cPrivate->backend->vTable->writeDone) (context);
713
714- context->changedSettings =
715- ccsSettingListFree (context->changedSettings, FALSE);
716+ cPrivate->changedSettings =
717+ ccsSettingListFree (cPrivate->changedSettings, FALSE);
718 }
719
720 void
721@@ -2330,9 +2497,9 @@
722 if (!(*cPrivate->backend->vTable->writeInit) (context))
723 return;
724
725- if (ccsSettingListLength (context->changedSettings))
726+ if (ccsSettingListLength (cPrivate->changedSettings))
727 {
728- CCSSettingList l = context->changedSettings;
729+ CCSSettingList l = cPrivate->changedSettings;
730
731 while (l)
732 {
733@@ -2344,8 +2511,8 @@
734 if (cPrivate->backend->vTable->writeDone)
735 (*cPrivate->backend->vTable->writeDone) (context);
736
737- context->changedSettings =
738- ccsSettingListFree (context->changedSettings, FALSE);
739+ cPrivate->changedSettings =
740+ ccsSettingListFree (cPrivate->changedSettings, FALSE);
741 }
742
743 Bool
744@@ -2409,6 +2576,8 @@
745 /* look if the plugin to be loaded requires a plugin not present */
746 sl = plugin->requiresPlugin;
747
748+ CONTEXT_PRIV (context);
749+
750 while (sl)
751 {
752 if (!ccsFindPlugin (context, ((CCSString *)sl->data)->value))
753@@ -2449,7 +2618,7 @@
754
755 while (sl)
756 {
757- pl = context->plugins;
758+ pl = cPrivate->plugins;
759 pl2 = NULL;
760
761 while (pl)
762@@ -2505,7 +2674,7 @@
763 sl = plugin->providesFeature;
764 while (sl)
765 {
766- pl = context->plugins;
767+ pl = cPrivate->plugins;
768 CCSPluginConflict *conflict = NULL;
769
770 while (pl)
771@@ -2549,7 +2718,7 @@
772 sl = plugin->conflictFeature;
773 while (sl)
774 {
775- pl = context->plugins;
776+ pl = cPrivate->plugins;
777 CCSPluginConflict *conflict = NULL;
778
779 while (pl)
780@@ -2623,8 +2792,10 @@
781 CCSPluginList pl;
782 CCSStringList sl;
783
784+ CONTEXT_PRIV (context);
785+
786 /* look if the plugin to be unloaded is required by another plugin */
787- pl = context->plugins;
788+ pl = cPrivate->plugins;
789
790 for (; pl; pl = pl->next)
791 {
792@@ -2672,7 +2843,7 @@
793 sl = plugin->providesFeature;
794 while (sl)
795 {
796- pl = context->plugins;
797+ pl = cPrivate->plugins;
798 for (; pl; pl = pl->next)
799 {
800 CCSStringList pluginList;
801@@ -2901,7 +3072,9 @@
802 if (!exportFile)
803 return FALSE;
804
805- for (p = context->plugins; p; p = p->next)
806+ CONTEXT_PRIV (context);
807+
808+ for (p = cPrivate->plugins; p; p = p->next)
809 {
810 plugin = p->data;
811 PLUGIN_PRIV (plugin);
812@@ -2917,7 +3090,7 @@
813 continue;
814
815 asprintf (&keyName, "s%d_%s",
816- context->screenNum, setting->name);
817+ cPrivate->screenNum, setting->name);
818
819 switch (setting->type)
820 {
821@@ -2996,7 +3169,9 @@
822 char *sectionName = strdup (setting->parent->name);
823 char *iniValue = NULL;
824
825- asprintf (&keyName, "+s%d_%s", context->screenNum, setting->name);
826+ CONTEXT_PRIV (context);
827+
828+ asprintf (&keyName, "+s%d_%s", cPrivate->screenNum, setting->name);
829 if (ccsIniGetString (dict, sectionName, keyName, &iniValue))
830 {
831 CCSSetting *newSetting = malloc (sizeof (CCSSetting));
832@@ -3148,7 +3323,9 @@
833 char *sectionName = strdup (setting->parent->name);
834 char *iniValue = NULL;
835
836- asprintf (&keyName, "-s%d_%s", context->screenNum, setting->name);
837+ CONTEXT_PRIV (context);
838+
839+ asprintf (&keyName, "-s%d_%s", cPrivate->screenNum, setting->name);
840 if (ccsIniGetString (dict, sectionName, keyName, &iniValue))
841 {
842 CCSSetting *newSetting = malloc (sizeof (CCSSetting));
843@@ -3294,8 +3471,10 @@
844 ccsProcessUpgrade (CCSContext *context,
845 CCSSettingsUpgrade *upgrade)
846 {
847+ CONTEXT_PRIV (context);
848+
849 IniDictionary *dict = ccsIniOpen (upgrade->file);
850- CCSPluginList pl = context->plugins;
851+ CCSPluginList pl = cPrivate->plugins;
852 CCSSettingList sl;
853
854 ccsSetProfile (context, upgrade->profile);
855@@ -3702,7 +3881,9 @@
856 if (!importFile)
857 return FALSE;
858
859- for (p = context->plugins; p; p = p->next)
860+ CONTEXT_PRIV (context);
861+
862+ for (p = cPrivate->plugins; p; p = p->next)
863 {
864 plugin = p->data;
865 PLUGIN_PRIV (plugin);
866@@ -3717,7 +3898,7 @@
867 continue;
868
869 asprintf (&keyName, "s%d_%s",
870- context->screenNum, setting->name);
871+ cPrivate->screenNum, setting->name);
872
873 switch (setting->type)
874 {
875@@ -3905,3 +4086,7 @@
876 return pPrivate->stringExtensions;
877 }
878
879+const CCSInterfaceTable ccsDefaultInterfaceTable =
880+{
881+ &ccsDefaultContextInterface
882+};

Subscribers

People subscribed via source and target branches