Home · All Classes · All Namespaces · Modules · Functions · Files

connection.h

00001 /*
00002  * This file is part of TelepathyQt4
00003  *
00004  * Copyright (C) 2008, 2009 Collabora Ltd. <http://www.collabora.co.uk/>
00005  * Copyright (C) 2008, 2009 Nokia Corporation
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _TelepathyQt4_cli_connection_h_HEADER_GUARD_
00023 #define _TelepathyQt4_cli_connection_h_HEADER_GUARD_
00024 
00025 #ifndef IN_TELEPATHY_QT4_HEADER
00026 #error IN_TELEPATHY_QT4_HEADER
00027 #endif
00028 
00029 #include <TelepathyQt4/_gen/cli-connection.h>
00030 
00031 #include <TelepathyQt4/Contact>
00032 #include <TelepathyQt4/DBus>
00033 #include <TelepathyQt4/DBusProxy>
00034 #include <TelepathyQt4/OptionalInterfaceFactory>
00035 #include <TelepathyQt4/ReadinessHelper>
00036 #include <TelepathyQt4/ReadyObject>
00037 #include <TelepathyQt4/Types>
00038 #include <TelepathyQt4/SharedPtr>
00039 
00040 #include <TelepathyQt4/Constants>
00041 #include <TelepathyQt4/Types>
00042 
00043 #include <QSet>
00044 #include <QString>
00045 #include <QStringList>
00046 
00047 namespace Tp
00048 {
00049 
00050 class Channel;
00051 class Contact;
00052 class ContactManager;
00053 class PendingChannel;
00054 class PendingContactAttributes;
00055 class PendingHandles;
00056 class PendingOperation;
00057 class PendingReady;
00058 
00059 class Connection : public StatefulDBusProxy,
00060                    private OptionalInterfaceFactory<Connection>,
00061                    public ReadyObject,
00062                    public RefCounted
00063 {
00064     Q_OBJECT
00065     Q_DISABLE_COPY(Connection)
00066     Q_ENUMS(Status)
00067 
00068 public:
00069     static const Feature FeatureCore;
00070     static const Feature FeatureSelfContact;
00071     static const Feature FeatureSimplePresence;
00072     static const Feature FeatureRoster;
00073 
00074     enum Status {
00075         StatusDisconnected = ConnectionStatusDisconnected,
00076         StatusConnecting = ConnectionStatusConnecting,
00077         StatusConnected = ConnectionStatusConnected,
00078         StatusUnknown = 0xFFFFFFFF
00079     };
00080 
00081     static ConnectionPtr create(const QString &busName,
00082             const QString &objectPath);
00083     static ConnectionPtr create(const QDBusConnection &bus,
00084             const QString &busName, const QString &objectPath);
00085 
00086     ~Connection();
00087 
00088     uint status() const;
00089     uint statusReason() const;
00090 
00091     QStringList interfaces() const;
00092 
00093     uint selfHandle() const;
00094 
00095     SimpleStatusSpecMap allowedPresenceStatuses() const;
00096     PendingOperation *setSelfPresence(const QString &status, const QString &statusMessage);
00097 
00098     ContactPtr selfContact() const;
00099 
00100     template <class Interface>
00101     inline Interface *optionalInterface(
00102             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00103     {
00104         // Check for the remote object supporting the interface
00105         QString name(Interface::staticInterfaceName());
00106         if (check == CheckInterfaceSupported && !interfaces().contains(name)) {
00107             return 0;
00108         }
00109 
00110         // If present or forced, delegate to OptionalInterfaceFactory
00111         return OptionalInterfaceFactory<Connection>::interface<Interface>();
00112     }
00113 
00114     inline Client::ConnectionInterfaceAliasingInterface *aliasingInterface(
00115             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00116     {
00117         return optionalInterface<Client::ConnectionInterfaceAliasingInterface>(check);
00118     }
00119 
00120     inline Client::ConnectionInterfaceAvatarsInterface *avatarsInterface(
00121             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00122     {
00123         return optionalInterface<Client::ConnectionInterfaceAvatarsInterface>(check);
00124     }
00125 
00126     inline Client::ConnectionInterfaceCapabilitiesInterface *capabilitiesInterface(
00127             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00128     {
00129         return optionalInterface<Client::ConnectionInterfaceCapabilitiesInterface>(check);
00130     }
00131 
00132     inline Client::ConnectionInterfacePresenceInterface *presenceInterface(
00133             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00134     {
00135         return optionalInterface<Client::ConnectionInterfacePresenceInterface>(check);
00136     }
00137 
00138     inline Client::ConnectionInterfaceSimplePresenceInterface *simplePresenceInterface(
00139             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00140     {
00141         return optionalInterface<Client::ConnectionInterfaceSimplePresenceInterface>(check);
00142     }
00143 
00144     inline Client::ConnectionInterfaceRequestsInterface *requestsInterface(
00145             InterfaceSupportedChecking check = CheckInterfaceSupported) const
00146     {
00147         return optionalInterface<Client::ConnectionInterfaceRequestsInterface>(check);
00148     }
00149 
00150     inline Client::DBus::PropertiesInterface *propertiesInterface() const
00151     {
00152         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
00153     }
00154 
00155     PendingChannel *createChannel(const QVariantMap &request);
00156 
00157     PendingChannel *ensureChannel(const QVariantMap &request);
00158 
00159     PendingReady *requestConnect(const Features &requestedFeatures = Features());
00160 
00161     PendingOperation *requestDisconnect();
00162 
00163     PendingHandles *requestHandles(uint handleType, const QStringList &names);
00164 
00165     PendingHandles *referenceHandles(uint handleType, const UIntList &handles);
00166 
00167     PendingContactAttributes *getContactAttributes(const UIntList &handles,
00168             const QStringList &interfaces, bool reference = true);
00169     QStringList contactAttributeInterfaces() const;
00170     ContactManager *contactManager() const;
00171 
00172 Q_SIGNALS:
00173     void statusChanged(uint newStatus, uint newStatusReason);
00174     void selfHandleChanged(uint newHandle);
00175     // FIXME: might not need this when Renaming is fixed and mapped to Contacts
00176     void selfContactChanged();
00177 
00178 protected:
00179     Connection(const QString &busName, const QString &objectPath);
00180     Connection(const QDBusConnection &bus, const QString &busName,
00181             const QString &objectPath);
00182 
00183     Client::ConnectionInterface *baseInterface() const;
00184 
00185 private Q_SLOTS:
00186     void onStatusReady(uint);
00187     void onStatusChanged(uint, uint);
00188     void gotStatus(QDBusPendingCallWatcher *watcher);
00189     void gotInterfaces(QDBusPendingCallWatcher *watcher);
00190     void gotContactAttributeInterfaces(QDBusPendingCallWatcher *watcher);
00191     void gotSimpleStatuses(QDBusPendingCallWatcher *watcher);
00192     void gotSelfContact(Tp::PendingOperation *);
00193     void gotSelfHandle(QDBusPendingCallWatcher *watcher);
00194     void gotContactListsHandles(Tp::PendingOperation *);
00195     void gotContactListChannel(Tp::PendingOperation *);
00196     void contactListChannelReady();
00197 
00198     void doReleaseSweep(uint type);
00199 
00200     void onSelfHandleChanged(uint);
00201 
00202 private:
00203     void refHandle(uint type, uint handle);
00204     void unrefHandle(uint type, uint handle);
00205     void handleRequestLanded(uint type);
00206 
00207     struct Private;
00208     class PendingConnect;
00209     friend struct Private;
00210     friend class PendingChannel;
00211     friend class PendingConnect;
00212     friend class PendingContactAttributes;
00213     friend class PendingContacts;
00214     friend class PendingHandles;
00215     friend class ReferencedHandles;
00216     Private *mPriv;
00217 };
00218 
00219 } // Tp
00220 
00221 #endif


Copyright © 2009 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.1.8