0e4e901531f9b6c84db95c0233f30a242da1fc68
[platform/upstream/dbus.git] / qt / qdbusintrospection_p.h
1 /* -*- C++ -*-
2  *
3  * Copyright (C) 2006 Trolltech AS. All rights reserved.
4  *    Author: Thiago Macieira <thiago.macieira@trolltech.com>
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  */
23
24 #ifndef QDBUSINTROSPECTION_H
25 #define QDBUSINTROSPECTION_H
26
27 #include <QtCore/qstring.h>
28 #include <QtCore/qlist.h>
29 #include <QtCore/qstringlist.h>
30 #include <QtCore/qmap.h>
31 #include <QtCore/qpair.h>
32 #include <QtCore/qshareddata.h>
33 #include "qdbusmacros.h"
34
35 class QDBUS_EXPORT QDBusIntrospection
36 {
37 public:
38     // forward declarations
39     struct Argument;
40     struct Method;
41     struct Signal;
42     struct Property;
43     struct Interface;
44     struct Object;
45     struct ObjectTree;
46
47     // typedefs
48     typedef QMap<QString, QString> Annotations;
49     typedef QList<Argument> Arguments;
50     typedef QMultiMap<QString, Method> Methods;
51     typedef QMultiMap<QString, Signal> Signals;
52     typedef QMap<QString, Property> Properties;
53     typedef QMap<QString, QSharedDataPointer<Interface> > Interfaces;
54     typedef QMap<QString, QSharedDataPointer<ObjectTree> > Objects;
55
56 public:
57     // the structs
58
59     struct Argument
60     {
61         QString type;
62         QString name;
63
64         inline bool operator==(const Argument& other) const
65         { return name == other.name && type == other.type; }
66     };
67     
68     struct Method
69     {
70         QString name;
71         Arguments inputArgs;
72         Arguments outputArgs;
73         Annotations annotations;
74
75         inline bool operator==(const Method& other) const
76         { return name == other.name && annotations == other.annotations &&
77                 inputArgs == other.inputArgs && outputArgs == other.outputArgs; }
78     };
79
80     struct Signal
81     {
82         QString name;
83         Arguments outputArgs;
84         Annotations annotations;
85
86         inline bool operator==(const Signal& other) const
87         { return name == other.name && annotations == other.annotations &&
88                 outputArgs == other.outputArgs; }
89     };
90
91     struct Property
92     {
93         enum Access { Read, Write, ReadWrite };
94         QString name;
95         QString type;
96         Access access;
97         Annotations annotations;
98
99         inline bool operator==(const Property& other) const
100         { return access == other.access && name == other.name &&
101                 annotations == other.annotations && type == other.type; }
102     };
103
104     struct Interface: public QSharedData
105     {
106         QString name;
107         QString introspection;
108
109         Annotations annotations;
110         Methods methods;
111         Signals signals_;
112         Properties properties;
113
114         inline bool operator==(const Interface &other) const
115         { return !name.isEmpty() && name == other.name; }
116     };
117
118     struct Object: public QSharedData
119     {
120         QString service;
121         QString path;
122         QString introspection;
123
124         QStringList interfaces;
125         QStringList childObjects;
126     };
127
128     struct ObjectTree: public Object
129     {
130         Interfaces interfaceData;
131         Objects childObjectData;
132     };
133
134 public:
135     static Interface parseInterface(const QString &xml);
136     static Interfaces parseInterfaces(const QString &xml);
137     static Object parseObject(const QString &xml, const QString &service = QString(),
138                               const QString &path = QString());
139     static ObjectTree parseObjectTree(const QString &xml,
140                                       const QString &service,
141                                       const QString &path);
142
143 private:
144     QDBusIntrospection();
145 };
146
147 #endif