qthighway/xqservice/src/xqserviceipcmarshal.h
branchRCL_3
changeset 10 cd2778e5acfe
parent 9 5d007b20cfd0
child 11 19a54be74e5e
equal deleted inserted replaced
9:5d007b20cfd0 10:cd2778e5acfe
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 * 
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not, 
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:                                                         
       
    19 *
       
    20 */
       
    21 
       
    22 #ifndef XQSERVICEIPCMARSHAL_H
       
    23 #define XQSERVICEIPCMARSHAL_H
       
    24 
       
    25 #include <xqserviceglobal.h>
       
    26 
       
    27 #include <qvariant.h>
       
    28 #include <qmetatype.h>
       
    29 #include <qdatastream.h>
       
    30 #include <qatomic.h>
       
    31 #include <quuid.h>
       
    32 
       
    33 /// @cond
       
    34 /*!
       
    35     Excluded from documentation.
       
    36 */
       
    37 
       
    38 template <typename T>
       
    39 struct QMetaTypeRegister
       
    40 {
       
    41     static int registerType() { return 1; }
       
    42 };
       
    43 
       
    44 /// @endcond
       
    45 
       
    46 #ifdef Q_CC_GNU
       
    47 # define _QATOMIC_ONCE() do {} while(0)
       
    48 #else
       
    49 # define _QATOMIC_ONCE()                \
       
    50     static QAtomicInt once;             \
       
    51     if ( once.fetchAndStoreOrdered(1) ) \
       
    52         return 1
       
    53 #endif
       
    54 
       
    55 #define Q_DECLARE_USER_METATYPE_NO_OPERATORS(TYPE) \
       
    56     Q_DECLARE_METATYPE(TYPE) \
       
    57     template<> \
       
    58     struct QMetaTypeRegister< TYPE > \
       
    59     { \
       
    60         static int registerType() \
       
    61         { \
       
    62             _QATOMIC_ONCE(); \
       
    63             int id = qMetaTypeId( reinterpret_cast<TYPE *>(0) ); \
       
    64             if ( id >= static_cast<int>(QMetaType::User) ) \
       
    65                 qRegisterMetaTypeStreamOperators< TYPE >( #TYPE ); \
       
    66             return 1; \
       
    67         } \
       
    68         static int __init_variable__; \
       
    69     };
       
    70 
       
    71 #define Q_DECLARE_USER_METATYPE(TYPE) \
       
    72     Q_DECLARE_USER_METATYPE_NO_OPERATORS(TYPE) \
       
    73     QDataStream &operator<<(QDataStream &stream, const TYPE &var); \
       
    74     QDataStream &operator>>( QDataStream &stream, TYPE &var );
       
    75 
       
    76 #define Q_DECLARE_USER_METATYPE_TYPEDEF(TAG,TYPE)       \
       
    77     template <typename T> \
       
    78     struct QMetaTypeRegister##TAG \
       
    79     { \
       
    80         static int registerType() { return 1; } \
       
    81     }; \
       
    82     template<> struct QMetaTypeRegister##TAG< TYPE > { \
       
    83         static int registerType() { \
       
    84             _QATOMIC_ONCE(); \
       
    85             qRegisterMetaType< TYPE >( #TYPE ); \
       
    86             qRegisterMetaTypeStreamOperators< TYPE >( #TYPE ); \
       
    87             return 1; \
       
    88         } \
       
    89         static int __init_variable__; \
       
    90     };
       
    91 
       
    92 #define Q_DECLARE_USER_METATYPE_ENUM(TYPE)      \
       
    93     Q_DECLARE_USER_METATYPE(TYPE)
       
    94 
       
    95 #define Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(TYPE) \
       
    96     int QMetaTypeRegister< TYPE >::__init_variable__ = \
       
    97         QMetaTypeRegister< TYPE >::registerType();
       
    98 
       
    99 #define Q_IMPLEMENT_USER_METATYPE(TYPE) \
       
   100     QDataStream &operator<<(QDataStream &stream, const TYPE &var) \
       
   101     { \
       
   102         var.serialize(stream); \
       
   103         return stream; \
       
   104     } \
       
   105     \
       
   106     QDataStream &operator>>( QDataStream &stream, TYPE &var ) \
       
   107     { \
       
   108         var.deserialize(stream); \
       
   109         return stream; \
       
   110     } \
       
   111     Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(TYPE)
       
   112 
       
   113 #define Q_IMPLEMENT_USER_METATYPE_TYPEDEF(TAG,TYPE)     \
       
   114     int QMetaTypeRegister##TAG< TYPE >::__init_variable__ = \
       
   115         QMetaTypeRegister##TAG< TYPE >::registerType();
       
   116 
       
   117 #define Q_IMPLEMENT_USER_METATYPE_ENUM(TYPE)    \
       
   118     QDataStream& operator<<( QDataStream& stream, const TYPE &v ) \
       
   119     { \
       
   120         stream << static_cast<qint32>(v); \
       
   121         return stream; \
       
   122     } \
       
   123     QDataStream& operator>>( QDataStream& stream, TYPE& v ) \
       
   124     { \
       
   125         qint32 _v; \
       
   126         stream >> _v; \
       
   127         v = static_cast<TYPE>(_v); \
       
   128         return stream; \
       
   129     } \
       
   130     Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(TYPE)
       
   131 
       
   132 #define Q_REGISTER_USER_METATYPE(TYPE)  \
       
   133     QMetaTypeRegister< TYPE >::registerType()
       
   134 
       
   135 
       
   136 Q_DECLARE_USER_METATYPE_NO_OPERATORS(QUuid)
       
   137 
       
   138 #endif