By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release. View | Details | Raw Unified | Return to bug 1597
Collapse All | Expand All

(-)a/CMakeLists.txt (-2 / +4 lines)
Lines 39-45 install( FILES Link Here
39
    tqdbuserror.h tqdbusmessage.h tqdbusconnection.h
39
    tqdbuserror.h tqdbusmessage.h tqdbusconnection.h
40
    tqdbusvariant.h tqdbusobject.h tqdbusproxy.h
40
    tqdbusvariant.h tqdbusobject.h tqdbusproxy.h
41
    tqdbusmacros.h tqdbusdata.h tqdbusdatalist.h
41
    tqdbusmacros.h tqdbusdata.h tqdbusdatalist.h
42
    tqdbusdatamap.h tqdbusobjectpath.h tqdbusdataconverter.h
42
    tqdbusdatamap.h tqdbusobjectpath.h tqdbusunixfd.h
43
    tqdbusdataconverter.h
43
  DESTINATION ${INCLUDE_INSTALL_DIR} )
44
  DESTINATION ${INCLUDE_INSTALL_DIR} )
44
45
45
46
Lines 84-90 tde_add_library( dbus-1-tqt SHARED AUTOMOC Link Here
84
    tqdbusconnection.cpp tqdbuserror.cpp tqdbusintegrator.cpp
85
    tqdbusconnection.cpp tqdbuserror.cpp tqdbusintegrator.cpp
85
    tqdbusmarshall.cpp tqdbusmessage.cpp tqdbusserver.cpp
86
    tqdbusmarshall.cpp tqdbusmessage.cpp tqdbusserver.cpp
86
    tqdbusproxy.cpp tqdbusdata.cpp tqdbusdatalist.cpp
87
    tqdbusproxy.cpp tqdbusdata.cpp tqdbusdatalist.cpp
87
    tqdbusobjectpath.cpp tqdbusdataconverter.cpp
88
    tqdbusobjectpath.cpp tqdbusunixfd.cpp
89
    tqdbusdataconverter.cpp
88
  VERSION 0.0.0
90
  VERSION 0.0.0
89
  LINK ${TQT_LIBRARIES} ${DBUS_LIBRARIES}
91
  LINK ${TQT_LIBRARIES} ${DBUS_LIBRARIES}
90
  DESTINATION ${LIB_INSTALL_DIR}
92
  DESTINATION ${LIB_INSTALL_DIR}
(-)a/tools/dbusxml2qt3/methodgen.cpp (+9 lines)
Lines 105-110 static bool parseDBusSignature(const TQString& signature, Argument& argument) Link Here
105
            argument.forwardDeclarations.append("class TQT_DBusObjectPath");
105
            argument.forwardDeclarations.append("class TQT_DBusObjectPath");
106
            argument.sourceIncludes["tqdbus"].append("<tqdbusobjectpath.h>");
106
            argument.sourceIncludes["tqdbus"].append("<tqdbusobjectpath.h>");
107
        }
107
        }
108
        else if (signature == "h")
109
        {
110
            argument.signature = "TQT_DBuxUnixFd";
111
            argument.accessor = "UnixFd";
112
            argument.isPrimitive = false;
113
114
            argument.forwardDeclarations.append("class TQT_DBusUnixFd");
115
            argument.sourceIncludes["tqdbus"].append("<tqdbusunixfd.h>");
116
        }
108
        else if (signature == "v")
117
        else if (signature == "v")
109
        {
118
        {
110
            argument.signature = "TQT_DBusVariant";
119
            argument.signature = "TQT_DBusVariant";
(-)a/tqdbusdata.cpp (+77 lines)
Lines 27-32 Link Here
27
#include "tqdbusdatalist.h"
27
#include "tqdbusdatalist.h"
28
#include "tqdbusdatamap.h"
28
#include "tqdbusdatamap.h"
29
#include "tqdbusobjectpath.h"
29
#include "tqdbusobjectpath.h"
30
#include "tqdbusunixfd.h"
30
#include "tqdbusvariant.h"
31
#include "tqdbusvariant.h"
31
32
32
#include <tqshared.h>
33
#include <tqshared.h>
Lines 50-55 public: Link Here
50
                delete (TQT_DBusObjectPath*)value.pointer;
51
                delete (TQT_DBusObjectPath*)value.pointer;
51
                break;
52
                break;
52
53
54
            case TQT_DBusData::UnixFd:
55
                delete (TQT_DBusUnixFd*)value.pointer;
56
                break;
57
53
            case TQT_DBusData::List:
58
            case TQT_DBusData::List:
54
                delete (TQT_DBusDataList*)value.pointer;
59
                delete (TQT_DBusDataList*)value.pointer;
55
                break;
60
                break;
Lines 101-106 public: Link Here
101
                        delete (TQT_DBusDataMap<TQT_DBusObjectPath>*)value.pointer;
106
                        delete (TQT_DBusDataMap<TQT_DBusObjectPath>*)value.pointer;
102
                        break;
107
                        break;
103
108
109
                    case TQT_DBusData::UnixFd:
110
                        delete (TQT_DBusDataMap<TQT_DBusUnixFd>*)value.pointer;
111
                        break;
112
104
                    default:
113
                    default:
105
                        tqFatal("TQT_DBusData::Private: unhandled map key type %d(%s)",
114
                        tqFatal("TQT_DBusData::Private: unhandled map key type %d(%s)",
106
                               keyType, TQT_DBusData::typeName(keyType));
115
                               keyType, TQT_DBusData::typeName(keyType));
Lines 208-213 bool TQT_DBusData::operator==(const TQT_DBusData& other) const Link Here
208
            case TQT_DBusData::ObjectPath:
217
            case TQT_DBusData::ObjectPath:
209
                return toObjectPath() == other.toObjectPath();
218
                return toObjectPath() == other.toObjectPath();
210
219
220
            case TQT_DBusData::UnixFd:
221
                return toUnixFd() == other.toUnixFd();
222
211
            case TQT_DBusData::List:
223
            case TQT_DBusData::List:
212
                return toList() == other.toList();
224
                return toList() == other.toList();
213
225
Lines 257-262 bool TQT_DBusData::operator==(const TQT_DBusData& other) const Link Here
257
                        toObjectPathKeyMap() == other.toObjectPathKeyMap();
269
                        toObjectPathKeyMap() == other.toObjectPathKeyMap();
258
                        break;
270
                        break;
259
271
272
                    case TQT_DBusData::UnixFd:
273
                        toUnixFdKeyMap() == other.toUnixFdKeyMap();
274
                        break;
275
260
                    default:
276
                    default:
261
                        tqFatal("TQT_DBusData operator== unhandled map key type %d(%s)",
277
                        tqFatal("TQT_DBusData operator== unhandled map key type %d(%s)",
262
                               d->keyType, TQT_DBusData::typeName(d->keyType));
278
                               d->keyType, TQT_DBusData::typeName(d->keyType));
Lines 303-308 const char* TQT_DBusData::typeName(Type type) Link Here
303
        case TQT_DBusData::Double:     return "Double";
319
        case TQT_DBusData::Double:     return "Double";
304
        case TQT_DBusData::String:     return "String";
320
        case TQT_DBusData::String:     return "String";
305
        case TQT_DBusData::ObjectPath: return "ObjectPath";
321
        case TQT_DBusData::ObjectPath: return "ObjectPath";
322
        case TQT_DBusData::UnixFd:     return "UnixFd";
306
        case TQT_DBusData::List:       return "List";
323
        case TQT_DBusData::List:       return "List";
307
        case TQT_DBusData::Struct:     return "Struct";
324
        case TQT_DBusData::Struct:     return "Struct";
308
        case TQT_DBusData::Variant:    return "Variant";
325
        case TQT_DBusData::Variant:    return "Variant";
Lines 568-573 TQT_DBusObjectPath TQT_DBusData::toObjectPath(bool* ok) const Link Here
568
    return *((TQT_DBusObjectPath*)d->value.pointer);
585
    return *((TQT_DBusObjectPath*)d->value.pointer);
569
}
586
}
570
587
588
TQT_DBusData TQT_DBusData::fromUnixFd(const TQT_DBusUnixFd& value)
589
{
590
    TQT_DBusData data;
591
592
    if (value.isValid())
593
    {
594
        data.d->type = TQT_DBusData::UnixFd;
595
        data.d->value.pointer = new TQT_DBusUnixFd(value);
596
    }
597
598
    return data;
599
}
600
601
TQT_DBusUnixFd TQT_DBusData::toUnixFd(bool* ok) const
602
{
603
    if (d->type != TQT_DBusData::UnixFd)
604
    {
605
        if (ok != 0) *ok = false;
606
        return TQT_DBusUnixFd();
607
    }
608
609
    if (ok != 0) *ok = true;
610
611
    return *((TQT_DBusUnixFd*)d->value.pointer);
612
}
613
571
TQT_DBusData TQT_DBusData::fromList(const TQT_DBusDataList& list)
614
TQT_DBusData TQT_DBusData::fromList(const TQT_DBusDataList& list)
572
{
615
{
573
    TQT_DBusData data;
616
    TQT_DBusData data;
Lines 885-890 TQT_DBusDataMap<TQT_DBusObjectPath> TQT_DBusData::toObjectPathKeyMap(bool* ok) c Link Here
885
    return *((TQT_DBusDataMap<TQT_DBusObjectPath>*)d->value.pointer);
928
    return *((TQT_DBusDataMap<TQT_DBusObjectPath>*)d->value.pointer);
886
}
929
}
887
930
931
TQT_DBusData TQT_DBusData::fromUnixFdKeyMap(const TQT_DBusDataMap<TQT_DBusUnixFd>& map)
932
{
933
    TQT_DBusData data;
934
935
    data.d->type = TQT_DBusData::Map;
936
    data.d->keyType = map.keyType();
937
    data.d->value.pointer = new TQT_DBusDataMap<TQT_DBusUnixFd>(map);
938
939
    return data;
940
}
941
942
TQT_DBusDataMap<TQT_DBusUnixFd> TQT_DBusData::toUnixFdKeyMap(bool* ok) const
943
{
944
    if (d->type != TQT_DBusData::Map &&
945
        d->keyType != TQT_DBusDataMap<TQT_DBusUnixFd>::m_keyType)
946
    {
947
        if (ok != 0) *ok = false;
948
        return TQT_DBusDataMap<TQT_DBusUnixFd>();
949
    }
950
951
    if (ok != 0) *ok = true;
952
953
    return *((TQT_DBusDataMap<TQT_DBusUnixFd>*)d->value.pointer);
954
}
955
888
static const char* qDBusTypeForTQT_DBusType(TQT_DBusData::Type type)
956
static const char* qDBusTypeForTQT_DBusType(TQT_DBusData::Type type)
889
{
957
{
890
    switch (type)
958
    switch (type)
Lines 913-918 static const char* qDBusTypeForTQT_DBusType(TQT_DBusData::Type type) Link Here
913
            return DBUS_TYPE_STRING_AS_STRING;
981
            return DBUS_TYPE_STRING_AS_STRING;
914
        case TQT_DBusData::ObjectPath:
982
        case TQT_DBusData::ObjectPath:
915
            return DBUS_TYPE_OBJECT_PATH_AS_STRING;
983
            return DBUS_TYPE_OBJECT_PATH_AS_STRING;
984
        case TQT_DBusData::UnixFd:
985
            return DBUS_TYPE_UNIX_FD_AS_STRING;
916
        case TQT_DBusData::Variant:
986
        case TQT_DBusData::Variant:
917
            return DBUS_TYPE_VARIANT_AS_STRING;
987
            return DBUS_TYPE_VARIANT_AS_STRING;
918
        default:
988
        default:
Lines 1008-1013 TQCString TQT_DBusData::buildDBusSignature() const Link Here
1008
                    signature += qDBusSignatureForMapValue<TQT_DBusObjectPath>(
1078
                    signature += qDBusSignatureForMapValue<TQT_DBusObjectPath>(
1009
                        *((TQT_DBusDataMap<TQT_DBusObjectPath>*) d->value.pointer));
1079
                        *((TQT_DBusDataMap<TQT_DBusObjectPath>*) d->value.pointer));
1010
                    break;
1080
                    break;
1081
                case TQT_DBusData::UnixFd:
1082
                    signature += qDBusSignatureForMapValue<TQT_DBusUnixFd>(
1083
                        *((TQT_DBusDataMap<TQT_DBusUnixFd>*) d->value.pointer));
1084
                    break;
1011
                default:
1085
                default:
1012
                    break;
1086
                    break;
1013
            }
1087
            }
Lines 1052-1054 const TQT_DBusData::Type TQT_DBusDataMap<TQString>::m_keyType = TQT_DBusData::St Link Here
1052
template <>
1126
template <>
1053
const TQT_DBusData::Type TQT_DBusDataMap<TQT_DBusObjectPath>::m_keyType =
1127
const TQT_DBusData::Type TQT_DBusDataMap<TQT_DBusObjectPath>::m_keyType =
1054
        TQT_DBusData::ObjectPath;
1128
        TQT_DBusData::ObjectPath;
1129
1130
template <>
1131
const TQT_DBusData::Type TQT_DBusDataMap<TQT_DBusUnixFd>::m_keyType = TQT_DBusData::UnixFd;
(-)a/tqdbusdata.h (+73 lines)
Lines 31-36 class TQCString; Link Here
31
class TQT_DBusDataList;
31
class TQT_DBusDataList;
32
class TQT_DBusVariant;
32
class TQT_DBusVariant;
33
class TQT_DBusObjectPath;
33
class TQT_DBusObjectPath;
34
class TQT_DBusUnixFd;
34
class TQString;
35
class TQString;
35
36
36
template<typename T> class TQValueList;
37
template<typename T> class TQValueList;
Lines 172-177 public: Link Here
172
        ObjectPath,
173
        ObjectPath,
173
174
174
        /**
175
        /**
176
         * Type when encapsulating a D-Bus unix file handle.
177
         *
178
         * @see fromUnixFd(), toUnixFd()
179
         */
180
        UnixFd,
181
182
        /**
175
         * Type when encapsulating a list of values.
183
         * Type when encapsulating a list of values.
176
         *
184
         *
177
         * The D-Bus type this maps to is called @c array but since the TQt
185
         * The D-Bus type this maps to is called @c array but since the TQt
Lines 254-259 public: Link Here
254
         * - #UInt64
262
         * - #UInt64
255
         * - #String
263
         * - #String
256
         * - #ObjectPath
264
         * - #ObjectPath
265
         * - #UnixFd
257
         *
266
         *
258
         * All values need to be of the same type.
267
         * All values need to be of the same type.
259
         *
268
         *
Lines 266-271 public: Link Here
266
         * @see fromUInt64KeyMap(), toUInt64KeyMap()
275
         * @see fromUInt64KeyMap(), toUInt64KeyMap()
267
         * @see fromStringKeyMap(), toStringKeyMap()
276
         * @see fromStringKeyMap(), toStringKeyMap()
268
         * @see fromObjectPathKeyMap(), toObjectPathKeyMap()
277
         * @see fromObjectPathKeyMap(), toObjectPathKeyMap()
278
         * @see fromUnixFdKeyMap(), toUnixFdKeyMap()
269
         */
279
         */
270
        Map
280
        Map
271
    };
281
    };
Lines 685-690 public: Link Here
685
    TQT_DBusObjectPath toObjectPath(bool* ok = 0) const;
695
    TQT_DBusObjectPath toObjectPath(bool* ok = 0) const;
686
696
687
    /**
697
    /**
698
     * @brief Creates a data object for the given unix file handle @p value
699
     *
700
     * @param value the value to encapsulate
701
     *
702
     * @return a data object of type #UnixFd containing the @p value
703
     *
704
     * @see toUnixFd()
705
     */
706
    static TQT_DBusData fromUnixFd(const TQT_DBusUnixFd& value);
707
708
    /**
709
     * @brief Tries to get the encapsulated unix file handle value
710
     *
711
     * If the data object is not of type #UnixFd this will fail, i.e.
712
     * the parameter @p ok will be set to @c false if present.
713
     *
714
     * @param ok optional pointer to a bool variable to store the
715
     *        success information in, i.e. will be set to @c true on success
716
     *        and to @c false if the conversion failed (not of type #UnixFd)
717
     *
718
     * @return the encapsulated object path value or an empty and invalid object
719
     *         if it fails
720
     *
721
     * @see fromUnixFd()
722
     */
723
    TQT_DBusUnixFd toUnixFd(bool* ok = 0) const;
724
725
    /**
688
     * @brief Creates a data object for the given @p list
726
     * @brief Creates a data object for the given @p list
689
     *
727
     *
690
     * \note The list is allowed to be empty but is required to have a valid type
728
     * \note The list is allowed to be empty but is required to have a valid type
Lines 1129-1134 public: Link Here
1129
    TQT_DBusDataMap<TQT_DBusObjectPath> toObjectPathKeyMap(bool* ok = 0) const;
1167
    TQT_DBusDataMap<TQT_DBusObjectPath> toObjectPathKeyMap(bool* ok = 0) const;
1130
1168
1131
    /**
1169
    /**
1170
     * @brief Creates a data object for the given @p map
1171
     *
1172
     * \note The map is allowed to be empty but is required to have a valid
1173
     *       value type
1174
     *
1175
     * The resulting data object will have the keyType() set to #UnixFd.
1176
     *
1177
     * @param map the map to encapsulate
1178
     *
1179
     * @return a data object of type #Map containing the @p map or
1180
     *         an #Invalid object if the map's value type is #Invalid
1181
     *
1182
     * @see toUnixFdhKeyMap()
1183
     */
1184
    static TQT_DBusData fromUnixFdKeyMap(const TQT_DBusDataMap<TQT_DBusUnixFd>& map);
1185
1186
    /**
1187
     * @brief Tries to get the encapsulated map
1188
     *
1189
     * If the data object is not of type #Map or if its value type is not
1190
     * #UnixFd this will fail, i.e. the parameter @p ok will be set to
1191
     * @c false if present.
1192
     *
1193
     * @param ok optional pointer to a bool variable to store the
1194
     *        success information in, i.e. will be set to @c true on success
1195
     *        and to @c false if the conversion failed (not of type #Map or
1196
     *        value type not #UnixFd)
1197
     *
1198
     * @return the encapsulated map or an empty and #Invalid map if it fails
1199
     *
1200
     * @see fromUnixFdKeyMap()
1201
     */
1202
    TQT_DBusDataMap<TQT_DBusUnixFd> toUnixFdKeyMap(bool* ok = 0) const;
1203
1204
    /**
1132
     * @brief Creates the data objects D-Bus signature
1205
     * @brief Creates the data objects D-Bus signature
1133
     *
1206
     *
1134
     * Recursivly builds the D-Bus signature of the data object if it holds a
1207
     * Recursivly builds the D-Bus signature of the data object if it holds a
(-)a/tqdbusdatalist.cpp (+38 lines)
Lines 23-28 Link Here
23
23
24
#include "tqdbusdatalist.h"
24
#include "tqdbusdatalist.h"
25
#include "tqdbusobjectpath.h"
25
#include "tqdbusobjectpath.h"
26
#include "tqdbusunixfd.h"
26
#include "tqdbusvariant.h"
27
#include "tqdbusvariant.h"
27
28
28
#include <tqstringlist.h>
29
#include <tqstringlist.h>
Lines 281-286 TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQT_DBusObjectPath>& other) Link Here
281
    }
282
    }
282
}
283
}
283
284
285
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQT_DBusUnixFd>& other)
286
    : d(new Private())
287
{
288
    d->type = TQT_DBusData::UnixFd;
289
290
    if (other.isEmpty()) return;
291
292
    TQValueList<TQT_DBusUnixFd>::const_iterator it    = other.begin();
293
    TQValueList<TQT_DBusUnixFd>::const_iterator endIt = other.end();
294
    for (; it != endIt; ++it)
295
    {
296
        d->list << TQT_DBusData::fromUnixFd(*it);
297
    }
298
}
299
284
TQT_DBusDataList::~TQT_DBusDataList()
300
TQT_DBusDataList::~TQT_DBusDataList()
285
{
301
{
286
    delete d;
302
    delete d;
Lines 725-730 TQValueList<TQT_DBusObjectPath> TQT_DBusDataList::toObjectPathList(bool* ok) con Link Here
725
    return result;
741
    return result;
726
}
742
}
727
743
744
TQValueList<TQT_DBusUnixFd> TQT_DBusDataList::toUnixFdList(bool* ok) const
745
{
746
    if (d->type != TQT_DBusData::UnixFd)
747
    {
748
        if (ok != 0) *ok = false;
749
        return TQValueList<TQT_DBusUnixFd>();
750
    }
751
752
    TQValueList<TQT_DBusUnixFd> result;
753
754
    TQValueList<TQT_DBusData>::const_iterator it    = d->list.begin();
755
    TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
756
    for (; it != endIt; ++it)
757
    {
758
        result << (*it).toUnixFd();
759
    }
760
761
    if (ok != 0) *ok = true;
762
763
    return result;
764
}
765
728
TQValueList<TQT_DBusVariant> TQT_DBusDataList::toVariantList(bool* ok) const
766
TQValueList<TQT_DBusVariant> TQT_DBusDataList::toVariantList(bool* ok) const
729
{
767
{
730
    if (d->type != TQT_DBusData::Variant)
768
    if (d->type != TQT_DBusData::Variant)
(-)a/tqdbusdatalist.h (+33 lines)
Lines 29-34 Link Here
29
template <typename T> class TQValueList;
29
template <typename T> class TQValueList;
30
class TQT_DBusObjectPath;
30
class TQT_DBusObjectPath;
31
class TQT_DBusVariant;
31
class TQT_DBusVariant;
32
class TQT_DBuxUnixFd;
32
class TQString;
33
class TQString;
33
class TQStringList;
34
class TQStringList;
34
35
Lines 299-304 public: Link Here
299
    TQT_DBusDataList(const TQValueList<TQT_DBusObjectPath>& other);
300
    TQT_DBusDataList(const TQValueList<TQT_DBusObjectPath>& other);
300
301
301
    /**
302
    /**
303
     * @brief Creates a list from the given TQValueList of unix file handle values
304
     *
305
     * Type information for the list object will be set to TQT_DBusData::UnixFd
306
     * also when the @p other list is empty, i.e. this allows to create an
307
     * empty but valid list object, comparable to using
308
     * TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::UnixFd
309
     *
310
     * @param other the TQValueList of unix file handle values to copy from
311
     *
312
     * @see toUnixFdList()
313
     */
314
    TQT_DBusDataList(const TQValueList<TQT_DBusUnixFd>& other);
315
316
    /**
302
     * @brief Destroys the list object
317
     * @brief Destroys the list object
303
     */
318
     */
304
    ~TQT_DBusDataList();
319
    ~TQT_DBusDataList();
Lines 717-722 public: Link Here
717
     */
732
     */
718
    TQValueList<TQT_DBusVariant> toVariantList(bool* ok = 0) const;
733
    TQValueList<TQT_DBusVariant> toVariantList(bool* ok = 0) const;
719
734
735
    /**
736
     * @brief Tries to get the list object's elements as a TQValueList of TQT_DBusUnixFd
737
     *
738
     * This is a convenience overload for the case when the list is of
739
     * type TQT_DBusData::UnixFd.
740
     *
741
     * @param ok optional pointer to a bool variable to store the
742
     *        success information in, i.e. will be set to @c true on success
743
     *        and to @c false if the conversion failed (not of type
744
     *        TQT_DBusData::UnixFd)
745
     *
746
     * @return a TQValueList of TQT_DBusUnixFd containing the list object's
747
     *         TQT_DBuxUnixFd elements or an empty list when converting fails
748
     *
749
     * @see TQT_DBusData::toUnixFd()
750
     */
751
    TQValueList<TQT_DBusUnixFd> toUnixFdList(bool* ok = 0) const;
752
720
private:
753
private:
721
    class Private;
754
    class Private;
722
    Private* d;
755
    Private* d;
(-)a/tqdbusdatamap.h (+59 lines)
Lines 29-34 Link Here
29
29
30
class TQT_DBusData;
30
class TQT_DBusData;
31
class TQT_DBusObjectPath;
31
class TQT_DBusObjectPath;
32
class TQT_DBusUnixFd;
32
class TQT_DBusVariant;
33
class TQT_DBusVariant;
33
34
34
/**
35
/**
Lines 439-444 public: Link Here
439
    }
440
    }
440
441
441
    /**
442
    /**
443
     * @brief Creates a map from the given TQMap of TQT_DBusUnixFd values
444
     *
445
     * Type information for the map object will be set to TQT_DBusData::UnixFd
446
     * also when the @p other map is empty, i.e. this allows to create an
447
     * empty but valid map object, comparable to using
448
     * TQT_DBusDataMap<T>(TQT_DBusData::Type) with TQT_DBusData::UnixFd
449
     *
450
     * @param other the TQMap of TQT_DBusUnixFd values to copy from
451
     *
452
     * @see toUnixFdMap()
453
     */
454
    TQT_DBusDataMap<T>(const TQMap<T, TQT_DBusUnixFd>& other)
455
        : TQMap<T, TQT_DBusData>(), m_valueType(TQT_DBusData::UnixFd)
456
    {
457
        typename TQMap<T, TQT_DBusUnixFd>::const_iterator it    = other.begin();
458
        typename TQMap<T, TQT_DBusUnixFd>::const_iterator endIt = other.end();
459
        for (; it != endIt; ++it)
460
        {
461
            insert(it.key(), TQT_DBusData::fromUnixFd(it.data()));
462
        }
463
    }
464
465
    /**
442
     * @brief Creates a map from the given TQMap of TQT_DBusVariant values
466
     * @brief Creates a map from the given TQMap of TQT_DBusVariant values
443
     *
467
     *
444
     * Type information for the map object will be set to TQT_DBusData::Variant
468
     * Type information for the map object will be set to TQT_DBusData::Variant
Lines 1175-1180 public: Link Here
1175
    }
1199
    }
1176
1200
1177
    /**
1201
    /**
1202
     * @brief Tries to get the map object's pairs as a TQMap of TQT_DBusUnixFd
1203
     *
1204
     * @param ok optional pointer to a bool variable to store the
1205
     *        success information in, i.e. will be set to @c true on success
1206
     *        and to @c false if the conversion failed (not of value type
1207
     *        TQT_DBusData::UnixFd)
1208
     *
1209
     * @return a TQMap of TQT_DBusUnixFd containing the map object's TQT_DBusUnixFd
1210
     *         values or an empty map when converting fails
1211
     *
1212
     * @see TQT_DBusData::toUnixFd()
1213
     */
1214
    TQMap<T, TQT_DBusObjectPath> toUnixFdMap(bool* ok = 0) const
1215
    {
1216
        if (m_valueType != TQT_DBusData::UnixFd)
1217
        {
1218
            if (ok != 0) *ok = false;
1219
            return TQMap<T, TQT_DBusUnixFd>();
1220
        }
1221
1222
        TQMap<T, TQT_DBusUnixFd> result;
1223
1224
        const_iterator it    = begin();
1225
        const_iterator endIt = end();
1226
        for (; it != endIt; ++it)
1227
        {
1228
            result.insert(it.key(), (*it).toUnixFd());
1229
        }
1230
1231
        if (ok != 0) *ok = true;
1232
1233
        return result;
1234
    }
1235
1236
    /**
1178
     * @brief Tries to get the map object's pairs as a TQMap of TQT_DBusVariant
1237
     * @brief Tries to get the map object's pairs as a TQMap of TQT_DBusVariant
1179
     *
1238
     *
1180
     * This is a convenience overload for the case when the map is of
1239
     * This is a convenience overload for the case when the map is of
(-)a/tqdbusmarshall.cpp (+66 lines)
Lines 27-32 Link Here
27
#include "tqdbusdatalist.h"
27
#include "tqdbusdatalist.h"
28
#include "tqdbusdatamap.h"
28
#include "tqdbusdatamap.h"
29
#include "tqdbusobjectpath.h"
29
#include "tqdbusobjectpath.h"
30
#include "tqdbusunixfd.h"
30
#include "tqdbusvariant.h"
31
#include "tqdbusvariant.h"
31
32
32
#include <tqvariant.h>
33
#include <tqvariant.h>
Lines 62-67 static TQT_DBusData::Type qSingleTypeForDBusSignature(char signature) Link Here
62
        case 'o': return TQT_DBusData::ObjectPath;
63
        case 'o': return TQT_DBusData::ObjectPath;
63
        case 'g': return TQT_DBusData::String;
64
        case 'g': return TQT_DBusData::String;
64
        case 'v': return TQT_DBusData::Variant;
65
        case 'v': return TQT_DBusData::Variant;
66
        case 'h': return TQT_DBusData::UnixFd;
65
67
66
        default:
68
        default:
67
            break;
69
            break;
Lines 133-138 static TQValueList<TQT_DBusData> parseSignature(TQCString& signature) Link Here
133
                            result << TQT_DBusData::fromObjectPathKeyMap(
135
                            result << TQT_DBusData::fromObjectPathKeyMap(
134
                                TQT_DBusDataMap<TQT_DBusObjectPath>(valueType));
136
                                TQT_DBusDataMap<TQT_DBusObjectPath>(valueType));
135
                            break;
137
                            break;
138
                        case TQT_DBusData::UnixFd:
139
                            result << TQT_DBusData::fromUnixFdKeyMap(
140
                                TQT_DBusDataMap<TQT_DBusUnixFd>(valueType));
141
                            break;
136
                        default:
142
                        default:
137
                            tqWarning("TQT_DBusMarshall: unsupported map key type %s "
143
                            tqWarning("TQT_DBusMarshall: unsupported map key type %s "
138
                                     "at de-marshalling",
144
                                     "at de-marshalling",
Lines 186-191 static TQValueList<TQT_DBusData> parseSignature(TQCString& signature) Link Here
186
                            result << TQT_DBusData::fromObjectPathKeyMap(
192
                            result << TQT_DBusData::fromObjectPathKeyMap(
187
                                TQT_DBusDataMap<TQT_DBusObjectPath>(valueContainer[0]));
193
                                TQT_DBusDataMap<TQT_DBusObjectPath>(valueContainer[0]));
188
                            break;
194
                            break;
195
                        case TQT_DBusData::UnixFd:
196
                            result << TQT_DBusData::fromUnixFdKeyMap(
197
                                TQT_DBusDataMap<TQT_DBusUnixFd>(valueContainer[0]));
198
                            break;
189
                        default:
199
                        default:
190
                            tqWarning("TQT_DBusMarshall: unsupported map key type %s "
200
                            tqWarning("TQT_DBusMarshall: unsupported map key type %s "
191
                                     "at de-marshalling",
201
                                     "at de-marshalling",
Lines 273-278 static TQValueList<TQT_DBusData> parseSignature(TQCString& signature) Link Here
273
                            result << TQT_DBusData::fromObjectPath(
283
                            result << TQT_DBusData::fromObjectPath(
274
                                (TQT_DBusObjectPath()));
284
                                (TQT_DBusObjectPath()));
275
                            break;
285
                            break;
286
                        case TQT_DBusData::UnixFd:
287
                            result << TQT_DBusData::fromUnixFd(
288
                                (TQT_DBusUnixFd()));
289
                            break;
276
                        default:
290
                        default:
277
                            result << TQT_DBusData();
291
                            result << TQT_DBusData();
278
                            tqWarning("TQT_DBusMarshall: unsupported element type %s "
292
                            tqWarning("TQT_DBusMarshall: unsupported element type %s "
Lines 585-590 static TQT_DBusData qFetchParameter(DBusMessageIter *it) Link Here
585
599
586
        return TQT_DBusData::fromStruct(memberList);
600
        return TQT_DBusData::fromStruct(memberList);
587
    }
601
    }
602
    case DBUS_TYPE_UNIX_FD:
603
        return TQT_DBusData::fromUnixFd(TQT_DBusUnixFd(qIterGet<dbus_uint32_t>(it)));
588
#if 0
604
#if 0
589
    case DBUS_TYPE_INVALID:
605
    case DBUS_TYPE_INVALID:
590
        // TODO: check if there is better way to detect empty arrays
606
        // TODO: check if there is better way to detect empty arrays
Lines 627-632 static void tqAppendToMessage(DBusMessageIter *it, const TQT_DBusObjectPath &pat Link Here
627
    dbus_message_iter_append_basic(it, DBUS_TYPE_OBJECT_PATH, &cdata);
643
    dbus_message_iter_append_basic(it, DBUS_TYPE_OBJECT_PATH, &cdata);
628
}
644
}
629
645
646
static void tqAppendToMessage(DBusMessageIter *it, const TQT_DBusUnixFd &unixFd)
647
{
648
    const dbus_int32_t cdata = unixFd.fileDescriptor();
649
    dbus_message_iter_append_basic(it, DBUS_TYPE_UNIX_FD, &cdata);
650
}
651
630
static const char* qDBusTypeForTQT_DBusType(TQT_DBusData::Type type)
652
static const char* qDBusTypeForTQT_DBusType(TQT_DBusData::Type type)
631
{
653
{
632
    switch (type)
654
    switch (type)
Lines 678-683 static const char* qDBusTypeForTQT_DBusType(TQT_DBusData::Type type) Link Here
678
700
679
        case TQT_DBusData::Map:
701
        case TQT_DBusData::Map:
680
            return DBUS_TYPE_DICT_ENTRY_AS_STRING;
702
            return DBUS_TYPE_DICT_ENTRY_AS_STRING;
703
704
        case TQT_DBusData::UnixFd:
705
            return DBUS_TYPE_UNIX_FD_AS_STRING;
681
    }
706
    }
682
    return 0;
707
    return 0;
683
}
708
}
Lines 991-996 static void qDBusObjectPathKeyMapToIterator(DBusMessageIter* it, Link Here
991
    dbus_message_iter_close_container(it, &sub);
1016
    dbus_message_iter_close_container(it, &sub);
992
}
1017
}
993
1018
1019
static void qDBusUnixFdKeyMapToIterator(DBusMessageIter* it, const TQT_DBusData& var)
1020
{
1021
    DBusMessageIter sub;
1022
    TQCString sig;
1023
1024
    TQT_DBusDataMap<TQT_DBusUnixFd> map = var.toUnixFdKeyMap();
1025
1026
    sig += DBUS_DICT_ENTRY_BEGIN_CHAR;
1027
    sig += qDBusTypeForTQT_DBusType(map.keyType());
1028
1029
    if (map.hasContainerValueType())
1030
        sig += map.containerValueType().buildDBusSignature();
1031
    else
1032
        sig += qDBusTypeForTQT_DBusType(map.valueType());
1033
    sig += DBUS_DICT_ENTRY_END_CHAR;
1034
1035
    dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, sig.data(), &sub);
1036
1037
    TQT_DBusDataMap<TQT_DBusUnixFd>::const_iterator mit = map.begin();
1038
    for (; mit != map.end(); ++mit)
1039
    {
1040
        DBusMessageIter itemIterator;
1041
        dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY,
1042
                                         0, &itemIterator);
1043
1044
        dbus_message_iter_append_basic(it, DBUS_TYPE_UNIX_FD, &(mit.key()));
1045
        qDBusDataToIterator(&itemIterator, mit.data());
1046
1047
        dbus_message_iter_close_container(&sub, &itemIterator);
1048
    }
1049
1050
    dbus_message_iter_close_container(it, &sub);
1051
}
1052
994
static void qDBusDataToIterator(DBusMessageIter* it, const TQT_DBusData& var)
1053
static void qDBusDataToIterator(DBusMessageIter* it, const TQT_DBusData& var)
995
{
1054
{
996
    switch (var.type())
1055
    switch (var.type())
Lines 1048-1053 static void qDBusDataToIterator(DBusMessageIter* it, const TQT_DBusData& var) Link Here
1048
        case TQT_DBusData::ObjectPath:
1107
        case TQT_DBusData::ObjectPath:
1049
            tqAppendToMessage(it, var.toObjectPath());
1108
            tqAppendToMessage(it, var.toObjectPath());
1050
            break;
1109
            break;
1110
        case TQT_DBusData::UnixFd: {
1111
            tqAppendToMessage(it, var.toUnixFd());
1112
            break;
1113
        }
1051
        case TQT_DBusData::List: {
1114
        case TQT_DBusData::List: {
1052
            TQT_DBusDataList list = var.toList();
1115
            TQT_DBusDataList list = var.toList();
1053
1116
Lines 1100-1105 static void qDBusDataToIterator(DBusMessageIter* it, const TQT_DBusData& var) Link Here
1100
                case TQT_DBusData::ObjectPath:
1163
                case TQT_DBusData::ObjectPath:
1101
                    qDBusObjectPathKeyMapToIterator(it, var);
1164
                    qDBusObjectPathKeyMapToIterator(it, var);
1102
                    break;
1165
                    break;
1166
                case TQT_DBusData::UnixFd:
1167
                    qDBusUnixFdKeyMapToIterator(it, var);
1168
                    break;
1103
                default:
1169
                default:
1104
                    tqWarning("TQT_DBusMarshall: unhandled map key type %s "
1170
                    tqWarning("TQT_DBusMarshall: unhandled map key type %s "
1105
                             "at marshalling",
1171
                             "at marshalling",
(-)a/tqdbusunixfd.cpp (+95 lines)
Line 0 Link Here
1
/* tqdbusunixfd.cpp DBUS unix file handle data type
2
 *
3
 * Copyright (C) 2013 Slávek Banko <slavek.banko@axis.cz>
4
 *
5
 * Licensed under the Academic Free License version 2.1
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
 * USA.
21
 *
22
 */
23
24
#include <unistd.h> 
25
#include "tqdbusunixfd.h"
26
27
TQT_DBusUnixFd::TQT_DBusUnixFd() : d(new TQT_DBusUnixFdPrivate())
28
{
29
    d->ref();
30
    d->fd = -1;
31
};
32
33
TQT_DBusUnixFd::TQT_DBusUnixFd(const TQT_DBusUnixFd& other) : d(other.d)
34
{
35
    d->ref();
36
}
37
38
TQT_DBusUnixFd::TQT_DBusUnixFd(int other)
39
{
40
    setFileDescriptor(other);
41
}
42
43
TQT_DBusUnixFd::~TQT_DBusUnixFd()
44
{
45
    if (d && d->deref() ) {
46
        if ( isValid() ) {
47
            close(d->fd);
48
        }
49
        delete d;
50
    }
51
}
52
53
bool TQT_DBusUnixFd::isValid() const
54
{
55
    return d ? d->fd != -1 : false;
56
}
57
58
int TQT_DBusUnixFd::fileDescriptor() const
59
{
60
    return d ? d->fd : -1;
61
}
62
63
void TQT_DBusUnixFd::setFileDescriptor(int fileDescriptor)
64
{
65
    giveFileDescriptor(fileDescriptor != -1 ? dup(fileDescriptor) : -1);
66
}
67
68
void TQT_DBusUnixFd::giveFileDescriptor(int fileDescriptor) 
69
{
70
    if ( d && d->deref() ) {
71
        if ( isValid() ) {
72
            close(d->fd);
73
        }
74
    }
75
    else {
76
        d = new TQT_DBusUnixFdPrivate;
77
    }
78
    d->ref();
79
    d->fd = fileDescriptor;
80
}
81
82
TQT_DBusUnixFd &TQT_DBusUnixFd::operator=( const TQT_DBusUnixFd &other )
83
{
84
    if (other.d) {
85
        other.d->ref();
86
    }
87
    if ( d && d->deref() ) {
88
        if ( isValid() ) {
89
            close(d->fd);
90
        }
91
        delete d;
92
    }
93
    d = other.d;
94
    return *this;
95
}
(-)a/tqdbusunixfd.h (+149 lines)
Line 0 Link Here
1
/* tqdbusunixfd.h DBUS unix file handle data type
2
 *
3
 * Copyright (C) 2013 Slávek Banko <slavek.banko@axis.cz>
4
 *
5
 * Licensed under the Academic Free License version 2.1
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
 * USA.
21
 *
22
 */
23
24
#ifndef TQDBUSUNIXFD_H
25
#define TQDBUSUNIXFD_H
26
27
#include "dbus/dbus.h"
28
#ifndef QT_H
29
#include "ntqshared.h"
30
#endif // QT_H
31
32
33
#ifndef DBUS_TYPE_UNIX_FD
34
#define   DBUS_TYPE_UNIX_FD   ((int) 'h')
35
#endif
36
37
#ifndef DBUS_TYPE_UNIX_FD_AS_STRING
38
#define   DBUS_TYPE_UNIX_FD_AS_STRING   "h"
39
#endif
40
41
/**
42
 * @brief Class for representing D-Bus unix file handles
43
 *
44
 * This data type is necessary to correctly represent unix file handles in the
45
 * context of D-Bus messages, since normal strings have a different D-Bus
46
 * signature than unix file handles.
47
 *
48
 * @see @ref dbusconventions-unixfd
49
 */
50
class TQT_DBusUnixFd
51
{
52
public:
53
    /**
54
     * @brief Creates an empty and invalid unix file handle
55
     */
56
    TQT_DBusUnixFd();
57
58
    /**
59
     * @brief Creates copy of the given @p other unix file handle
60
     *
61
     * @param other the unix file handle to copy
62
     */
63
    TQT_DBusUnixFd(const TQT_DBusUnixFd& other);
64
65
    /**
66
     * @brief Creates copy of the given @p other unix file handle
67
     *
68
     * @param other the unix file handle to copy
69
     */
70
    TQT_DBusUnixFd(int other);
71
72
    /**
73
     * @brief Destroys the unix file handle
74
     */
75
    virtual ~TQT_DBusUnixFd();
76
77
    /**
78
     * @brief Returns whether the current content is considered a valid unix file handle
79
     *
80
     * @return \c true if the object's content describe a valid unix file handle,
81
     *         otherwise @c false
82
     *
83
     * @see @ref dbusconventions-unixfd
84
     */
85
    bool isValid() const;
86
87
    /**
88
     * @brief Get unix file handle
89
     *
90
     * @see @ref dbusconventions-unixfd
91
     */
92
    int fileDescriptor() const;
93
94
    /**
95
     * @brief Set new unix file handle
96
     *
97
     * @see @ref dbusconventions-unixfd
98
     */
99
    void setFileDescriptor(int fileDescriptor);
100
101
    /**
102
     * @brief Give unix file handle
103
     *
104
     * @see @ref dbusconventions-unixfd
105
     */
106
    void giveFileDescriptor(int fileDescriptor);
107
108
    /**
109
     * @brief Copy unix file handle from TQT_DBusUnixFd
110
     *
111
     * @see @ref dbusconventions-unixfd
112
     */
113
    TQT_DBusUnixFd &operator=( const TQT_DBusUnixFd &other );
114
115
    /**
116
     * @brief Checks if the given @p other variant is equal to this one
117
     *
118
     * @param other unix file handle to compare with
119
     *
120
     * @return @c true if both use same file handle, otherwise
121
     *         @c false
122
     */
123
    inline bool operator==(const TQT_DBusUnixFd& other) const
124
    {
125
        return (&other == this) || (other.d == d);
126
    }
127
128
    /**
129
     * @brief Checks if the given @p other variant is not equal to this one
130
     *
131
     * @param other unix file handle to compare with
132
     *
133
     * @return @c true if both use different file handle, otherwise
134
     *         @c false
135
     */
136
    inline bool operator!=(const TQT_DBusUnixFd& other) const
137
    {
138
        return (&other != this) && (other.d != d);
139
    }
140
 
141
142
protected:
143
    struct TQT_DBusUnixFdPrivate : public TQShared {
144
        int fd;
145
    } *d;
146
147
};
148
149
#endif

Return to bug 1597