Merge lp:~sjakthol/compiz/fix-749084 into lp:compiz/0.9.10

Proposed by Sami Jaktholm
Status: Merged
Approved by: MC Return
Approved revision: 3755
Merged at revision: 3758
Proposed branch: lp:~sjakthol/compiz/fix-749084
Merge into: lp:compiz/0.9.10
Diff against target: 942 lines (+360/-462)
2 files modified
plugins/dbus/src/dbus.cpp (+305/-461)
plugins/dbus/src/dbus.h (+55/-1)
To merge this branch: bzr merge lp:~sjakthol/compiz/fix-749084
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
MC Return Approve
Review via email: mp+172846@code.launchpad.net

Commit message

Port dbus introspection to compiz 0.9.
- move xml creation to a separate class (IntrospectionResponse) for easier
  memory management (allocate buffer and writer in ctor, free in dtor).
- move duplicated response sending code to a separate method that takes
  IntrospectionResponse and sends the resulting xml.
- Refactor handle*IntrospectMessage to work with compiz 0.9 interfaces.

This also fixes the broken list method which was a result of logic error. The
code to invoke list handler was never reached.

This fixes most of the issues noted in bug 749084.

Description of the change

The broken list method is fixed by change at line 834 of the diff. Cause was following code:
if (path.empty ()) ... else if (path.size () == 1) ... else if (path.size () < 2). If path was smaller than two, it either had a size of 1 or it was empty.

Please note that the plugin and option metadata is still unavailable.

To post a comment you must log in.
Revision history for this message
MC Return (mc-return) wrote :

Wow, great job !!!
Thanks a lot, Sami, for bringing this back to life.

I will test this ASAP.

Revision history for this message
MC Return (mc-return) wrote :

First review (just a few style issues):

You could use prefix here:

65 + nArgs--;

88 + nArgs--;

The newline here could be removed:

493 +

lp:~sjakthol/compiz/fix-749084 updated
3755. By Sami Jaktholm

Use prefix decrements and remove extra newline.

Revision history for this message
Sami Jaktholm (sjakthol) wrote :

Fixed.

Revision history for this message
MC Return (mc-return) wrote :

Looks good to me :)
Most stuff seems to show up again: http://uppix.com/f-D_Feet_D_Bus_deb51d5b87100134a82.png

Sami, 3 questions - you wrote:

"This fixes most of the issues noted in bug 749084."

Which are the open issues ?
Is there a bug report about those, or could you file one ?
Could you fix the remaining issues, or what do we need to do to fix them ?

Anyway, green light from me - top job, but we are currently waiting with merges as Ubuntu is testing 0.9.10 for Saucy and Sam is busy...
So the landing of this (and many other things) might still take a few days...

review: Approve
Revision history for this message
Sami Jaktholm (sjakthol) wrote :

> Which are the open issues ?
Plugin and option metadata are missing.

> Could you fix the remaining issues, or what do we need to do to fix them ?
Plugins and options no more carry their descriptions with them so we probably need to tap into libcompizconfig to get that information. That's all I know right now, I might investigate it when I have more time.

> Is there a bug report about those, or could you file one ?
Filed bug 1198024 for that one.

Revision history for this message
MC Return (mc-return) wrote :

> > Which are the open issues ?
> Plugin and option metadata are missing.
>
Sounds serious... :(

> > Could you fix the remaining issues, or what do we need to do to fix them ?
> Plugins and options no more carry their descriptions with them so we probably
> need to tap into libcompizconfig to get that information. That's all I know
> right now, I might investigate it when I have more time.
>
That would be great, thanks a lot for all your work. +1
IMHO you should get Compiz maintainer rights, Sami - are you interested ?

> > Is there a bug report about those, or could you file one ?
> Filed bug 1198024 for that one.

Thanks a lot, I've added this bug to the 0.9.10 milestone and have set it's importance to medium.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/dbus/src/dbus.cpp'
2--- plugins/dbus/src/dbus.cpp 2013-05-09 13:43:07 +0000
3+++ plugins/dbus/src/dbus.cpp 2013-07-04 02:12:22 +0000
4@@ -24,6 +24,7 @@
5 *
6 * Ported to Compiz 0.9 by:
7 * Copyright (C) 2009 Sam Spilsbury <smspillaz@gmail.com>
8+ * Copyright (C) 2013 Sami Jaktholm <sampo_75@windowslive.com> (introspection)
9 */
10
11 #include "dbus.h"
12@@ -32,6 +33,119 @@
13
14 CompOption::Vector emptyList;
15
16+const char*
17+IntrospectionResponse::finishAndGetXml ()
18+{
19+ xmlTextWriterEndDocument (xmlWriter);
20+ return reinterpret_cast <const char *> (xmlBuf->content);
21+}
22+
23+void
24+IntrospectionResponse::startInterface ()
25+{
26+ xmlTextWriterStartElement (xmlWriter, BAD_CAST "interface");
27+ xmlTextWriterWriteAttribute (xmlWriter, BAD_CAST "name",
28+ BAD_CAST COMPIZ_DBUS_SERVICE_NAME);
29+}
30+
31+void
32+IntrospectionResponse::endInterface ()
33+{
34+ xmlTextWriterEndElement (xmlWriter);
35+}
36+
37+void
38+IntrospectionResponse::addArgument (const char *type,
39+ const char *direction)
40+{
41+ xmlTextWriterStartElement (xmlWriter, BAD_CAST "arg");
42+ xmlTextWriterWriteAttribute (xmlWriter, BAD_CAST "type", BAD_CAST type);
43+ xmlTextWriterWriteAttribute (xmlWriter, BAD_CAST "direction",
44+ BAD_CAST direction);
45+ xmlTextWriterEndElement (xmlWriter);
46+}
47+
48+void
49+IntrospectionResponse::addMethod (const char *name,
50+ int nArgs,
51+ ...)
52+{
53+ va_list var_args;
54+ const char *type, *direction;
55+
56+ xmlTextWriterStartElement (xmlWriter, BAD_CAST "method");
57+ xmlTextWriterWriteAttribute (xmlWriter, BAD_CAST "name", BAD_CAST name);
58+
59+ va_start (var_args, nArgs);
60+ while (nArgs)
61+ {
62+ type = va_arg (var_args, const char *);
63+ direction = va_arg (var_args, const char *);
64+ addArgument (type, direction);
65+ --nArgs;
66+ }
67+ va_end (var_args);
68+
69+ xmlTextWriterEndElement (xmlWriter);
70+}
71+
72+void
73+IntrospectionResponse::addSignal (const char *name,
74+ int nArgs,
75+ ...)
76+{
77+ va_list var_args;
78+ const char *type;
79+
80+ xmlTextWriterStartElement (xmlWriter, BAD_CAST "signal");
81+ xmlTextWriterWriteAttribute (xmlWriter, BAD_CAST "name", BAD_CAST name);
82+
83+ va_start (var_args, nArgs);
84+ while (nArgs)
85+ {
86+ type = va_arg (var_args, const char *);
87+ addArgument (type, "out");
88+ --nArgs;
89+ }
90+ va_end (var_args);
91+
92+ xmlTextWriterEndElement (xmlWriter);
93+}
94+
95+void
96+IntrospectionResponse::addNode (const char *name)
97+{
98+ xmlTextWriterStartElement (xmlWriter, BAD_CAST "node");
99+ xmlTextWriterWriteAttribute (xmlWriter, BAD_CAST "name", BAD_CAST name);
100+ xmlTextWriterEndElement (xmlWriter);
101+}
102+
103+IntrospectionResponse::IntrospectionResponse ()
104+{
105+ xmlBuf = xmlBufferCreate ();
106+ xmlWriter = xmlNewTextWriterMemory (xmlBuf, 0);
107+
108+ /* Add introspection node. */
109+ xmlTextWriterStartElement (xmlWriter, BAD_CAST "node");
110+
111+ xmlTextWriterStartElement (xmlWriter, BAD_CAST "interface");
112+ xmlTextWriterWriteAttribute (xmlWriter, BAD_CAST "name",
113+ BAD_CAST "org.freedesktop.DBus.Introspectable");
114+
115+ addMethod ("Introspect", 1, "s", "out");
116+
117+ xmlTextWriterEndElement (xmlWriter);
118+}
119+
120+IntrospectionResponse::~IntrospectionResponse ()
121+{
122+ if (xmlWriter)
123+ xmlFreeTextWriter (xmlWriter);
124+
125+ if (xmlBuf)
126+ xmlBufferFree (xmlBuf);
127+}
128+
129 #ifdef __cplusplus
130 /* A simple wrapper for dbus to Compiz 0.9 */
131 extern "C"
132@@ -76,478 +190,213 @@
133 return p->vTable->getOptions ();
134 }
135
136-#if INTROSPECTION_XML_ENABLED
137-/* functions to create introspection XML */
138-static void
139-dbusIntrospectStartInterface (xmlTextWriterPtr writer)
140-{
141- xmlTextWriterStartElement (writer, BAD_CAST "interface");
142- xmlTextWriterWriteAttribute (writer, BAD_CAST "name",
143- BAD_CAST COMPIZ_DBUS_SERVICE_NAME);
144-}
145-
146-static void
147-dbusIntrospectEndInterface (xmlTextWriterPtr writer)
148-{
149- xmlTextWriterEndElement (writer);
150-}
151-
152-static void
153-dbusIntrospectAddArgument (xmlTextWriterPtr writer,
154- char *type,
155- char *direction)
156-{
157- xmlTextWriterStartElement (writer, BAD_CAST "arg");
158- xmlTextWriterWriteAttribute (writer, BAD_CAST "type", BAD_CAST type);
159- xmlTextWriterWriteAttribute (writer, BAD_CAST "direction",
160- BAD_CAST direction);
161- xmlTextWriterEndElement (writer);
162-}
163-
164-static void
165-dbusIntrospectAddMethod (xmlTextWriterPtr writer,
166- char *name,
167- int nArgs,
168- ...)
169-{
170- va_list var_args;
171- char *type, *direction;
172-
173- xmlTextWriterStartElement (writer, BAD_CAST "method");
174- xmlTextWriterWriteAttribute (writer, BAD_CAST "name", BAD_CAST name);
175-
176- va_start (var_args, nArgs);
177- while (nArgs)
178- {
179- type = va_arg (var_args, char *);
180- direction = va_arg (var_args, char *);
181- dbusIntrospectAddArgument (writer, type, direction);
182- nArgs--;
183- }
184- va_end (var_args);
185-
186- xmlTextWriterEndElement (writer);
187-}
188-
189-static void
190-dbusIntrospectAddSignal (xmlTextWriterPtr writer,
191- char *name,
192- int nArgs,
193- ...)
194-{
195- va_list var_args;
196- char *type;
197-
198- xmlTextWriterStartElement (writer, BAD_CAST "signal");
199- xmlTextWriterWriteAttribute (writer, BAD_CAST "name", BAD_CAST name);
200-
201- va_start (var_args, nArgs);
202- while (nArgs)
203- {
204- type = va_arg (var_args, char *);
205- dbusIntrospectAddArgument (writer, type, "out");
206- nArgs--;
207- }
208- va_end (var_args);
209-
210- xmlTextWriterEndElement (writer);
211-}
212-
213-static void
214-dbusIntrospectAddNode (xmlTextWriterPtr writer,
215- char *name)
216-{
217- xmlTextWriterStartElement (writer, BAD_CAST "node");
218- xmlTextWriterWriteAttribute (writer, BAD_CAST "name", BAD_CAST name);
219- xmlTextWriterEndElement (writer);
220-}
221-
222-static void
223-dbusIntrospectStartRoot (xmlTextWriterPtr writer)
224-{
225- xmlTextWriterStartElement (writer, BAD_CAST "node");
226-
227- xmlTextWriterStartElement (writer, BAD_CAST "interface");
228- xmlTextWriterWriteAttribute (writer, BAD_CAST "name",
229- BAD_CAST "org.freedesktop.DBus.Introspectable");
230-
231- dbusIntrospectAddMethod (writer, "Introspect", 1, "s", "out");
232-
233- xmlTextWriterEndElement (writer);
234-}
235-
236-static void
237-dbusIntrospectEndRoot (xmlTextWriterPtr writer)
238-{
239- xmlTextWriterEndDocument (writer);
240+bool
241+DbusScreen::sendIntrospectResponse (DBusConnection *connection,
242+ DBusMessage *message,
243+ IntrospectionResponse &response)
244+{
245+ DBusMessage *reply = dbus_message_new_method_return (message);
246+ if (!reply)
247+ return false;
248+
249+ DBusMessageIter args;
250+ dbus_message_iter_init_append (reply, &args);
251+
252+ const char* responseXml = response.finishAndGetXml ();
253+
254+ if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING, &responseXml))
255+ return false;
256+
257+ if (!dbus_connection_send (connection, reply, NULL))
258+ return false;
259+
260+ dbus_connection_flush (connection);
261+ dbus_message_unref (reply);
262+
263+ return true;
264 }
265
266 /* introspection handlers */
267-static bool
268-dbusHandleRootIntrospectMessage (DBusConnection *connection,
269- DBusMessage *message)
270+bool
271+DbusScreen::handleRootIntrospectMessage (DBusConnection *connection,
272+ DBusMessage *message)
273 {
274- xmlTextWriterPtr writer;
275- xmlBufferPtr buf;
276-
277- buf = xmlBufferCreate ();
278- writer = xmlNewTextWriterMemory (buf, 0);
279-
280- dbusIntrospectStartRoot (writer);
281- dbusIntrospectStartInterface (writer);
282-
283- dbusIntrospectAddMethod (writer, COMPIZ_DBUS_GET_PLUGINS_MEMBER_NAME, 1,
284- "as", "out");
285- dbusIntrospectAddMethod (writer,
286- COMPIZ_DBUS_GET_PLUGIN_METADATA_MEMBER_NAME, 7,
287- "s", "in", "s", "out", "s", "out", "s", "out",
288- "b", "out", "as", "out", "as", "out");
289- dbusIntrospectAddSignal (writer,
290- COMPIZ_DBUS_PLUGINS_CHANGED_SIGNAL_NAME, 0);
291-
292- dbusIntrospectEndInterface (writer);
293-
294- const CompPlugin::List &plugins = CompPlugins::getPlugins ();
295- CompPlugin::List::const_iterator it = plugins.begin ();
296- if (it != plugins.end ())
297- {
298- for (; it != plugins.end (); ++it)
299- {
300- CompPlugin::VTable *v = it->vTable;
301- if (v)
302- dbusIntrospectAddNode (writer, v->name ().c_str());
303- }
304- }
305- else
306- {
307- xmlFreeTextWriter (writer);
308- xmlBufferFree (buf);
309- return false;
310- }
311-
312- dbusIntrospectEndRoot (writer);
313-
314- xmlFreeTextWriter (writer);
315-
316- DBusMessage *reply = dbus_message_new_method_return (message);
317- if (!reply)
318- {
319- xmlBufferFree (buf);
320- return false;
321- }
322-
323- DBusMessageIter args;
324- dbus_message_iter_init_append (reply, &args);
325-
326- if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING,
327- &buf->content))
328- {
329- xmlBufferFree (buf);
330- return false;
331- }
332-
333- xmlBufferFree (buf);
334-
335- if (!dbus_connection_send (connection, reply, NULL))
336- {
337- return false;
338- }
339-
340- dbus_connection_flush (connection);
341- dbus_message_unref (reply);
342-
343- return true;
344+
345+ IntrospectionResponse response;
346+ response.startInterface ();
347+
348+#if GET_PLUGIN_METADATA_ENABLED
349+ response.addMethod (COMPIZ_DBUS_GET_PLUGIN_METADATA_MEMBER_NAME, 7,
350+ "s", "in", "s", "out", "s", "out", "s", "out",
351+ "b", "out", "as", "out", "as", "out");
352+#endif
353+
354+ response.addSignal (COMPIZ_DBUS_PLUGINS_CHANGED_SIGNAL_NAME, 0);
355+ response.endInterface ();
356+
357+ const CompPlugin::List &plugins = CompPlugin::getPlugins ();
358+
359+ if (plugins.empty ())
360+ return false;
361+
362+ foreach (CompPlugin* p, plugins)
363+ {
364+ if (p->vTable)
365+ response.addNode (p->vTable->name ().c_str());
366+ }
367+
368+ return sendIntrospectResponse (connection, message, response);
369+
370 }
371
372 /* MULTIDPYERROR: only works with one or less displays present */
373 bool
374-DbusScreen::dbusHandlePluginIntrospectMessage (DBusConnection *connection,
375- DBusMessage *message,
376- char **path)
377+DbusScreen::handlePluginIntrospectMessage (DBusConnection *connection,
378+ DBusMessage *message)
379 {
380- CompScreen *s;
381 char screenName[256];
382-
383- xmlTextWriterPtr writer;
384- xmlBufferPtr buf;
385-
386- buf = xmlBufferCreate ();
387- writer = xmlNewTextWriterMemory (buf, 0);
388-
389- dbusIntrospectStartRoot (writer);
390-
391- for (d = core.displays; d; d = d->next)
392+ IntrospectionResponse response;
393+
394+ snprintf (screenName, 256, "screen%d", screen->screenNum ());
395+ response.addNode (screenName);
396+
397+ return sendIntrospectResponse (connection, message, response);
398+
399+}
400+
401+bool
402+DbusScreen::handleScreenIntrospectMessage (DBusConnection *connection,
403+ DBusMessage *message,
404+ std::vector<CompString>& path)
405+{
406+ IntrospectionResponse response;
407+
408+ response.startInterface ();
409+ response.addMethod (COMPIZ_DBUS_LIST_MEMBER_NAME, 1, "as", "out");
410+ response.endInterface ();
411+
412+ CompOption::Vector &options = getOptionsFromPath (path);
413+ if (!options.empty ())
414 {
415- dbusIntrospectAddNode (writer, "allscreens");
416-
417- for (s = d->screens; s; s = s->next)
418+ foreach (CompOption &option, options)
419 {
420- snprintf (screenName, 256, "screen%d", s->screenNum);
421- dbusIntrospectAddNode (writer, screenName);
422+ response.addNode (option.name ().c_str());
423 }
424 }
425
426- dbusIntrospectEndRoot (writer);
427-
428- xmlFreeTextWriter (writer);
429-
430- DBusMessage *reply = dbus_message_new_method_return (message);
431- if (!reply)
432- {
433- xmlBufferFree (buf);
434- return false;
435- }
436-
437- DBusMessageIter args;
438- dbus_message_iter_init_append (reply, &args);
439-
440- if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING,
441- &buf->content))
442- {
443- xmlBufferFree (buf);
444- return false;
445- }
446-
447- xmlBufferFree (buf);
448-
449- if (!dbus_connection_send (connection, reply, NULL))
450- {
451- return false;
452- }
453-
454- dbus_connection_flush (connection);
455- dbus_message_unref (reply);
456-
457- return true;
458+ return sendIntrospectResponse (connection, message, response);
459 }
460
461-static bool
462-dbusHandleScreenIntrospectMessage (DBusConnection *connection,
463- DBusMessage *message,
464- char **path)
465+bool
466+DbusScreen::handleOptionIntrospectMessage (DBusConnection *connection,
467+ DBusMessage *message,
468+ std::vector<CompString>& path)
469 {
470- CompOption *option = NULL;
471- int nOptions;
472-
473- xmlTextWriterPtr writer;
474- xmlBufferPtr buf;
475-
476- buf = xmlBufferCreate ();
477- writer = xmlNewTextWriterMemory (buf, 0);
478-
479- dbusIntrospectStartRoot (writer);
480- dbusIntrospectStartInterface (writer);
481-
482- dbusIntrospectAddMethod (writer, COMPIZ_DBUS_LIST_MEMBER_NAME, 1,
483- "as", "out");
484-
485- dbusIntrospectEndInterface (writer);
486-
487- option = dbusGetOptionsFromPath (path, NULL, NULL, &nOptions);
488+#if GET_PLUGIN_METADATA_ENABLED
489+ bool metadataHandled = false;
490+#endif
491+ bool isList = false;
492+ char type[3];
493+
494+ IntrospectionResponse response;
495+ CompOption::Type restrictionType;
496+
497+ CompOption::Vector &options = getOptionsFromPath (path);
498+ CompOption *option = CompOption::findOption (options, path[2]);
499+
500+ response.startInterface ();
501+
502 if (option)
503 {
504- while (nOptions--)
505- {
506- dbusIntrospectAddNode (writer, option->name);
507- option++;
508- }
509- }
510-
511- dbusIntrospectEndRoot (writer);
512-
513- xmlFreeTextWriter (writer);
514-
515- DBusMessage *reply = dbus_message_new_method_return (message);
516- if (!reply)
517- {
518- xmlBufferFree (buf);
519- return false;
520- }
521-
522- DBusMessageIter args;
523- dbus_message_iter_init_append (reply, &args);
524-
525- if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING,
526- &buf->content))
527- {
528- xmlBufferFree (buf);
529- return false;
530- }
531-
532- xmlBufferFree (buf);
533-
534- if (!dbus_connection_send (connection, reply, NULL))
535- {
536- return false;
537- }
538-
539- dbus_connection_flush (connection);
540- dbus_message_unref (reply);
541-
542- return true;
543-}
544-
545-static bool
546-dbusHandleOptionIntrospectMessage (DBusConnection *connection,
547- DBusMessage *message,
548- char **path)
549-{
550- CompOption *option;
551- int nOptions;
552- CompOptionType restrictionType;
553- bool metadataHandled;
554- char type[3];
555- xmlTextWriterPtr writer;
556- xmlBufferPtr buf;
557- bool isList = false;
558-
559- buf = xmlBufferCreate ();
560- writer = xmlNewTextWriterMemory (buf, 0);
561-
562- dbusIntrospectStartRoot (writer);
563- dbusIntrospectStartInterface (writer);
564-
565- option = dbusGetOptionsFromPath (path, NULL, NULL, &nOptions);
566- if (!option)
567- {
568- xmlFreeTextWriter (writer);
569- xmlBufferFree (buf);
570- return false;
571- }
572-
573- while (nOptions--)
574- {
575- if (strcmp (option->name, path[2]) == 0)
576- {
577- restrictionType = option->type;
578- if (restrictionType == CompOptionTypeList)
579- {
580- restrictionType = option->value.list.type;
581- isList = true;
582- }
583-
584- metadataHandled = false;
585- switch (restrictionType)
586- {
587- case CompOptionTypeInt:
588- if (isList)
589- strcpy (type, "ai");
590- else
591- strcpy (type, "i");
592-
593- dbusIntrospectAddMethod (writer,
594- COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
595- 6, "s", "out", "s", "out",
596- "b", "out", "s", "out",
597- "i", "out", "i", "out");
598- metadataHandled = true;
599- break;
600- case CompOptionTypeFloat:
601- if (isList)
602- strcpy (type, "ad");
603- else
604- strcpy (type, "d");
605-
606- dbusIntrospectAddMethod (writer,
607- COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
608- 7, "s", "out", "s", "out",
609- "b", "out", "s", "out",
610- "d", "out", "d", "out",
611- "d", "out");
612- metadataHandled = true;
613- break;
614- case CompOptionTypeString:
615- if (isList)
616- strcpy (type, "as");
617- else
618- strcpy (type, "s");
619-
620- dbusIntrospectAddMethod (writer,
621- COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
622- 5, "s", "out", "s", "out",
623- "b", "out", "s", "out",
624- "as", "out");
625- metadataHandled = true;
626- break;
627- case CompOptionTypeBool:
628- case CompOptionTypeBell:
629- if (isList)
630- strcpy (type, "ab");
631- else
632- strcpy (type, "b");
633-
634- break;
635- case CompOptionTypeColor:
636- case CompOptionTypeKey:
637- case CompOptionTypeButton:
638- case CompOptionTypeEdge:
639- case CompOptionTypeMatch:
640- if (isList)
641- strcpy (type, "as");
642- else
643- strcpy (type, "s");
644- break;
645- default:
646- continue;
647- }
648-
649- dbusIntrospectAddMethod (writer,
650- COMPIZ_DBUS_GET_MEMBER_NAME, 1,
651- type, "out");
652- dbusIntrospectAddMethod (writer,
653- COMPIZ_DBUS_SET_MEMBER_NAME, 1,
654- type, "in");
655- dbusIntrospectAddSignal (writer,
656- COMPIZ_DBUS_CHANGED_SIGNAL_NAME, 1,
657- type, "out");
658-
659- if (!metadataHandled)
660- dbusIntrospectAddMethod (writer,
661- COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
662- 4, "s", "out", "s", "out",
663- "b", "out", "s", "out");
664- break;
665- }
666-
667- option++;
668- }
669-
670- dbusIntrospectEndInterface (writer);
671- dbusIntrospectEndRoot (writer);
672-
673- xmlFreeTextWriter (writer);
674-
675- DBusMessage *reply = dbus_message_new_method_return (message);
676- if (!reply)
677- {
678- xmlBufferFree (buf);
679- return false;
680- }
681-
682- DBusMessageIter args;
683- dbus_message_iter_init_append (reply, &args);
684-
685- if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_STRING,
686- &buf->content))
687- {
688- xmlBufferFree (buf);
689- return false;
690- }
691-
692- xmlBufferFree (buf);
693-
694- if (!dbus_connection_send (connection, reply, NULL))
695- {
696- return false;
697- }
698-
699- dbus_connection_flush (connection);
700- dbus_message_unref (reply);
701-
702- return true;
703-}
704-
705-#endif
706+ restrictionType = option->type ();
707+ if (restrictionType == CompOption::TypeList)
708+ {
709+ restrictionType = option->value ().listType ();
710+ isList = true;
711+ }
712+
713+ switch (restrictionType)
714+ {
715+ case CompOption::TypeInt:
716+ if (isList)
717+ strcpy (type, "ai");
718+ else
719+ strcpy (type, "i");
720+#if GET_PLUGIN_METADATA_ENABLED
721+ response.addMethod (COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
722+ 6, "s", "out", "s", "out",
723+ "b", "out", "s", "out",
724+ "i", "out", "i", "out");
725+ metadataHandled = true;
726+#endif
727+ break;
728+ case CompOption::TypeFloat:
729+ if (isList)
730+ strcpy (type, "ad");
731+ else
732+ strcpy (type, "d");
733+#if GET_PLUGIN_METADATA_ENABLED
734+ response.addMethod (COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
735+ 7, "s", "out", "s", "out",
736+ "b", "out", "s", "out",
737+ "d", "out", "d", "out",
738+ "d", "out");
739+ metadataHandled = true;
740+#endif
741+ break;
742+ case CompOption::TypeString:
743+ if (isList)
744+ strcpy (type, "as");
745+ else
746+ strcpy (type, "s");
747+#if GET_PLUGIN_METADATA_ENABLED
748+ response.addMethod (COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
749+ 5, "s", "out", "s", "out",
750+ "b", "out", "s", "out",
751+ "as", "out");
752+ metadataHandled = true;
753+#endif
754+ break;
755+ case CompOption::TypeBool:
756+ case CompOption::TypeBell:
757+ if (isList)
758+ strcpy (type, "ab");
759+ else
760+ strcpy (type, "b");
761+
762+ break;
763+ case CompOption::TypeColor:
764+ case CompOption::TypeKey:
765+ case CompOption::TypeButton:
766+ case CompOption::TypeEdge:
767+ case CompOption::TypeMatch:
768+ if (isList)
769+ strcpy (type, "as");
770+ else
771+ strcpy (type, "s");
772+ break;
773+ default:
774+ break;
775+ }
776+
777+ response.addMethod (COMPIZ_DBUS_GET_MEMBER_NAME, 1,
778+ type, "out");
779+ response.addMethod (COMPIZ_DBUS_SET_MEMBER_NAME, 1,
780+ type, "in");
781+ response.addSignal (COMPIZ_DBUS_CHANGED_SIGNAL_NAME, 1,
782+ type, "out");
783+#if GET_PLUGIN_METADATA_ENABLED
784+ if (!metadataHandled)
785+ response.addMethod (COMPIZ_DBUS_GET_METADATA_MEMBER_NAME,
786+ 4, "s", "out", "s", "out",
787+ "b", "out", "s", "out");
788+#endif
789+ }
790+
791+ response.endInterface ();
792+
793+ return sendIntrospectResponse (connection, message, response);
794+}
795
796
797 /*
798@@ -1527,7 +1376,6 @@
799 /* root messages */
800 if (path.empty ())
801 {
802-#if GET_PLUGIN_METADATA_ENABLED
803 if (dbus_message_is_method_call (message,
804 DBUS_INTERFACE_INTROSPECTABLE,
805 "Introspect"))
806@@ -1535,6 +1383,7 @@
807 if (handleRootIntrospectMessage (connection, message))
808 return DBUS_HANDLER_RESULT_HANDLED;
809 }
810+#if GET_PLUGIN_METADATA_ENABLED
811 else if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE,
812 COMPIZ_DBUS_GET_PLUGIN_METADATA_MEMBER_NAME))
813 {
814@@ -1548,22 +1397,19 @@
815 /* plugin message */
816 else if (path.size () == 1)
817 {
818-#if INTROSPECTION_XML_ENABLED
819 if (dbus_message_is_method_call (message,
820 DBUS_INTERFACE_INTROSPECTABLE,
821 "Introspect"))
822 {
823- if (handlePluginIntrospectMessage (connection, message, path))
824+ if (handlePluginIntrospectMessage (connection, message))
825 return DBUS_HANDLER_RESULT_HANDLED;
826 }
827
828 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
829-#endif
830 }
831 /* screen message */
832- else if (path.size () < 2)
833+ else if (path.size () == 2)
834 {
835-#if INTROSPECTION_XML_ENABLED
836 if (dbus_message_is_method_call (message,
837 DBUS_INTERFACE_INTROSPECTABLE,
838 "Introspect"))
839@@ -1571,7 +1417,7 @@
840 if (handleScreenIntrospectMessage (connection, message, path))
841 return DBUS_HANDLER_RESULT_HANDLED;
842 }
843-#endif
844+
845 if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE,
846 COMPIZ_DBUS_LIST_MEMBER_NAME))
847 {
848@@ -1582,13 +1428,11 @@
849 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
850 }
851 /* option message */
852-#if INTROSPECT_XML_ENABLED
853 if (dbus_message_is_method_call (message, DBUS_INTERFACE_INTROSPECTABLE,
854 "Introspect"))
855 {
856 status = handleOptionIntrospectMessage (connection, message, path);
857 }
858-#endif
859
860 if (dbus_message_is_method_call (message, COMPIZ_DBUS_INTERFACE,
861 COMPIZ_DBUS_ACTIVATE_MEMBER_NAME))
862
863=== modified file 'plugins/dbus/src/dbus.h'
864--- plugins/dbus/src/dbus.h 2012-09-07 22:37:20 +0000
865+++ plugins/dbus/src/dbus.h 2013-07-04 02:12:22 +0000
866@@ -47,7 +47,6 @@
867 #define COMPIZ_DBUS_GET_MEMBER_NAME "get"
868 #define COMPIZ_DBUS_GET_METADATA_MEMBER_NAME "getMetadata"
869 #define COMPIZ_DBUS_LIST_MEMBER_NAME "list"
870-#define COMPIZ_DBUS_GET_PLUGINS_MEMBER_NAME "getPlugins"
871 #define COMPIZ_DBUS_GET_PLUGIN_METADATA_MEMBER_NAME "getPluginMetadata"
872
873 #define COMPIZ_DBUS_CHANGED_SIGNAL_NAME "changed"
874@@ -58,6 +57,38 @@
875 #define DBUS_FILE_WATCH_HOME 2
876 #define DBUS_FILE_WATCH_NUM 3
877
878+class IntrospectionResponse
879+{
880+ public:
881+ IntrospectionResponse ();
882+ ~IntrospectionResponse ();
883+
884+ void
885+ addArgument (const char *type,
886+ const char *direction);
887+
888+ void
889+ addMethod (const char *name,
890+ int nArgs,
891+ ...);
892+
893+ void
894+ addSignal (const char *name,
895+ int nArgs,
896+ ...);
897+
898+ void addNode (const char *name);
899+
900+ void startInterface ();
901+ void endInterface ();
902+
903+ const char* finishAndGetXml ();
904+
905+ private:
906+ xmlBufferPtr xmlBuf;
907+ xmlTextWriterPtr xmlWriter;
908+};
909+
910 class DbusScreen :
911 public PluginClassHandler <DbusScreen, CompScreen>,
912 public ScreenInterface
913@@ -83,6 +114,29 @@
914 CompOption::Vector &
915 getOptionsFromPath (const std::vector<CompString>& path);
916
917+ static bool
918+ sendIntrospectResponse (DBusConnection *connection,
919+ DBusMessage *message,
920+ IntrospectionResponse &response);
921+
922+ bool
923+ handleRootIntrospectMessage (DBusConnection *connection,
924+ DBusMessage *message);
925+
926+ bool
927+ handlePluginIntrospectMessage (DBusConnection *connection,
928+ DBusMessage *message);
929+
930+ bool
931+ handleScreenIntrospectMessage (DBusConnection *connection,
932+ DBusMessage *message,
933+ std::vector<CompString>& path);
934+
935+ bool
936+ handleOptionIntrospectMessage (DBusConnection *connection,
937+ DBusMessage *message,
938+ std::vector<CompString>& path);
939+
940 bool
941 handleActionMessage (DBusConnection *connection,
942 DBusMessage *message,

Subscribers

People subscribed via source and target branches