|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QMAILIPC_H |
|
43 #define QMAILIPC_H |
|
44 |
|
45 #ifndef QTOPIAMAIL_OMIT_QCOP |
|
46 #include "qcopadaptor.h" |
|
47 #include "qcopchannel.h" |
|
48 #include "qcopserver.h" |
|
49 #endif |
|
50 #include <QDataStream> |
|
51 #include <QVariant> |
|
52 |
|
53 template <typename T> |
|
54 struct QMetaTypeRegister |
|
55 { |
|
56 static int registerType() { return 1; } |
|
57 }; |
|
58 |
|
59 #ifdef Q_CC_GNU |
|
60 # define _QATOMIC_ONCE() do {} while(0) |
|
61 #else |
|
62 # define _QATOMIC_ONCE() \ |
|
63 static QAtomicInt once; \ |
|
64 if ( once.fetchAndStoreOrdered(1) ) \ |
|
65 return 1 |
|
66 #endif |
|
67 |
|
68 #define Q_DECLARE_USER_METATYPE_NO_OPERATORS(TYPE) \ |
|
69 Q_DECLARE_METATYPE(TYPE) \ |
|
70 template<> \ |
|
71 struct QMetaTypeRegister< TYPE > \ |
|
72 { \ |
|
73 static int registerType() \ |
|
74 { \ |
|
75 _QATOMIC_ONCE(); \ |
|
76 int id = qMetaTypeId( reinterpret_cast<TYPE *>(0) ); \ |
|
77 if ( id >= static_cast<int>(QMetaType::User) ) \ |
|
78 qRegisterMetaTypeStreamOperators< TYPE >( #TYPE ); \ |
|
79 return 1; \ |
|
80 } \ |
|
81 static int __init_variable__; \ |
|
82 }; |
|
83 |
|
84 #define Q_DECLARE_USER_METATYPE(TYPE) \ |
|
85 Q_DECLARE_USER_METATYPE_NO_OPERATORS(TYPE) \ |
|
86 QTOPIAMAIL_EXPORT QDataStream &operator<<(QDataStream &stream, const TYPE &var); \ |
|
87 QTOPIAMAIL_EXPORT QDataStream &operator>>( QDataStream &stream, TYPE &var ); |
|
88 |
|
89 #define Q_DECLARE_USER_METATYPE_TYPEDEF(TAG,TYPE) \ |
|
90 template <typename T> \ |
|
91 struct QMetaTypeRegister##TAG \ |
|
92 { \ |
|
93 static int registerType() { return 1; } \ |
|
94 }; \ |
|
95 template<> struct QMetaTypeRegister##TAG< TYPE > { \ |
|
96 static int registerType() { \ |
|
97 _QATOMIC_ONCE(); \ |
|
98 qRegisterMetaType< TYPE >( #TYPE ); \ |
|
99 qRegisterMetaTypeStreamOperators< TYPE >( #TYPE ); \ |
|
100 return 1; \ |
|
101 } \ |
|
102 static int __init_variable__; \ |
|
103 }; |
|
104 |
|
105 #define Q_DECLARE_USER_METATYPE_ENUM(TYPE) \ |
|
106 Q_DECLARE_USER_METATYPE(TYPE) |
|
107 |
|
108 #define Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(TYPE) \ |
|
109 int QMetaTypeRegister< TYPE >::__init_variable__ = \ |
|
110 QMetaTypeRegister< TYPE >::registerType(); |
|
111 |
|
112 #define Q_IMPLEMENT_USER_METATYPE(TYPE) \ |
|
113 QDataStream &operator<<(QDataStream &stream, const TYPE &var) \ |
|
114 { \ |
|
115 var.serialize(stream); \ |
|
116 return stream; \ |
|
117 } \ |
|
118 \ |
|
119 QDataStream &operator>>( QDataStream &stream, TYPE &var ) \ |
|
120 { \ |
|
121 var.deserialize(stream); \ |
|
122 return stream; \ |
|
123 } \ |
|
124 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(TYPE) |
|
125 |
|
126 #define Q_IMPLEMENT_USER_METATYPE_TYPEDEF(TAG,TYPE) \ |
|
127 int QMetaTypeRegister##TAG< TYPE >::__init_variable__ = \ |
|
128 QMetaTypeRegister##TAG< TYPE >::registerType(); |
|
129 |
|
130 #define Q_IMPLEMENT_USER_METATYPE_ENUM(TYPE) \ |
|
131 QDataStream& operator<<( QDataStream& stream, const TYPE &v ) \ |
|
132 { \ |
|
133 stream << static_cast<qint32>(v); \ |
|
134 return stream; \ |
|
135 } \ |
|
136 QDataStream& operator>>( QDataStream& stream, TYPE& v ) \ |
|
137 { \ |
|
138 qint32 _v; \ |
|
139 stream >> _v; \ |
|
140 v = static_cast<TYPE>(_v); \ |
|
141 return stream; \ |
|
142 } \ |
|
143 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(TYPE) |
|
144 |
|
145 #endif //QMAILIPC_H |
|
146 |