Advertisement
puneet

abstract-client.h

Mar 31st, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.73 KB | None | 0 0
  1. /**
  2.  * This file is part of TelepathyQt
  3.  *
  4.  * @copyright Copyright (C) 2009-2010 Collabora Ltd. <http://www.collabora.co.uk/>
  5.  * @copyright Copyright (C) 2009-2010 Nokia Corporation
  6.  * @license LGPL 2.1
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Lesser General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2.1 of the License, or (at your option) any later version.
  12.  *
  13.  * This library 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 GNU
  16.  * Lesser General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Lesser General Public
  19.  * License along with this library; if not, write to the Free Software
  20.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  21.  */
  22.  
  23. #ifndef _TelepathyQt_abstract_client_h_HEADER_GUARD_
  24. #define _TelepathyQt_abstract_client_h_HEADER_GUARD_
  25.  
  26. #ifndef IN_TP_QT_HEADER
  27. #error IN_TP_QT_HEADER
  28. #endif
  29.  
  30. #include <TelepathyQt/Constants>
  31. #include <TelepathyQt/SharedPtr>
  32. #include <TelepathyQt/Types>
  33.  
  34. #include <QList>
  35. #include <QObject>
  36. #include <QSharedDataPointer>
  37. #include <QString>
  38. #include <QVariantMap>
  39.  
  40. namespace Tp
  41. {
  42.  
  43. class ClientRegistrar;
  44. class ChannelClassSpecList;
  45.  
  46. class TP_QT_EXPORT AbstractClient : public RefCounted
  47. {
  48.     Q_DISABLE_COPY(AbstractClient)
  49.  
  50. public:
  51.     AbstractClient();
  52.     virtual ~AbstractClient();
  53.  
  54.     bool isRegistered() const;
  55.  
  56. private:
  57.     friend class ClientRegistrar;
  58.  
  59.     void setRegistered(bool registered);
  60.  
  61.     struct Private;
  62.     friend struct Private;
  63.     Private *mPriv;
  64. };
  65.  
  66. class TP_QT_EXPORT AbstractClientObserver : public virtual AbstractClient
  67. {
  68.     Q_DISABLE_COPY(AbstractClientObserver)
  69.  
  70. public:
  71.     class ObserverInfo
  72.     {
  73.     public:
  74.         ObserverInfo(const QVariantMap &info = QVariantMap());
  75.         ObserverInfo(const ObserverInfo &other);
  76.         ~ObserverInfo();
  77.  
  78.         ObserverInfo &operator=(const ObserverInfo &other);
  79.  
  80.         bool isRecovering() const { return qdbus_cast<bool>(allInfo().value(QLatin1String("recovering"))); }
  81.  
  82.         QVariantMap allInfo() const;
  83.  
  84.     private:
  85.         struct Private;
  86.         QSharedDataPointer<Private> mPriv;
  87.     };
  88.  
  89.     virtual ~AbstractClientObserver();
  90.  
  91.     ChannelClassSpecList observerFilter() const;
  92.  
  93.     bool shouldRecover() const;
  94.  
  95.     virtual void observeChannels(const MethodInvocationContextPtr<> &context,
  96.             const AccountPtr &account,
  97.             const ConnectionPtr &connection,
  98.             const QList<ChannelPtr> &channels,
  99.             const ChannelDispatchOperationPtr &dispatchOperation,
  100.             const QList<ChannelRequestPtr> &requestsSatisfied,
  101.             const ObserverInfo &observerInfo) = 0;
  102.  
  103. protected:
  104.     AbstractClientObserver(const ChannelClassSpecList &channelFilter, bool shouldRecover = false);
  105.  
  106. private:
  107.     struct Private;
  108.     friend struct Private;
  109.     Private *mPriv;
  110. };
  111.  
  112. class TP_QT_EXPORT AbstractClientApprover : public virtual AbstractClient
  113. {
  114.     Q_DISABLE_COPY(AbstractClientApprover)
  115.  
  116. public:
  117.     virtual ~AbstractClientApprover();
  118.  
  119.     ChannelClassSpecList approverFilter() const;
  120.  
  121.     virtual void addDispatchOperation(const MethodInvocationContextPtr<> &context,
  122.             const ChannelDispatchOperationPtr &dispatchOperation) = 0;
  123.  
  124. protected:
  125.     AbstractClientApprover(const ChannelClassSpecList &channelFilter);
  126.  
  127. private:
  128.     struct Private;
  129.     friend struct Private;
  130.     Private *mPriv;
  131. };
  132.  
  133. /*
  134.  * TODO: use case specific subclasses:
  135.  *  - StreamTubeHandler(QString(List) protocol(s))
  136.  *    - handleTube(DBusTubeChannelPtr, userActionTime)
  137.  *  - DBusTubeHandler(QString(List) serviceName(s))
  138.  *    - handleTube(DBusTubeChannelPtr, userActionTime)
  139.  */
  140. class TP_QT_EXPORT AbstractClientHandler : public virtual AbstractClient
  141. {
  142.     Q_DISABLE_COPY(AbstractClientHandler)
  143.  
  144. public:
  145.     class Capabilities
  146.     {
  147.     public:
  148.         Capabilities(const QStringList &tokens = QStringList());
  149.         Capabilities(const Capabilities &other);
  150.         ~Capabilities();
  151.  
  152.         Capabilities &operator=(const Capabilities &other);
  153.  
  154.         bool hasGTalkP2PNATTraversalToken() const
  155.         {
  156.             return hasToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  157.                 QLatin1String("/gtalk-p2p"));
  158.         }
  159.  
  160.         void setGTalkP2PNATTraversalToken()
  161.         {
  162.             setToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  163.                 QLatin1String("/gtalk-p2p"));
  164.         }
  165.  
  166.         void unsetGTalkP2PNATTraversalToken()
  167.         {
  168.             unsetToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  169.                 QLatin1String("/gtalk-p2p"));
  170.         }
  171.  
  172.         bool hasICEUDPNATTraversalToken() const
  173.         {
  174.             return hasToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  175.                 QLatin1String("/ice-udp"));
  176.         }
  177.  
  178.         void setICEUDPNATTraversalToken()
  179.         {
  180.             setToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  181.                 QLatin1String("/ice-udp"));
  182.         }
  183.  
  184.         void unsetICEUDPNATTraversalToken()
  185.         {
  186.             unsetToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  187.                 QLatin1String("/ice-udp"));
  188.         }
  189.  
  190.         bool hasWLM85NATTraversalToken() const
  191.         {
  192.             return hasToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  193.                 QLatin1String("/wlm-8.5"));
  194.         }
  195.  
  196.         void setWLM85NATTraversalToken()
  197.         {
  198.             setToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  199.                 QLatin1String("/wlm-8.5"));
  200.         }
  201.  
  202.         void unsetWLM85NATTraversalToken()
  203.         {
  204.             unsetToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  205.                 QLatin1String("/wlm-8.5"));
  206.         }
  207.  
  208.         bool hasWLM2009NATTraversalToken() const
  209.         {
  210.             return hasToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  211.                 QLatin1String("/wlm-2009"));
  212.         }
  213.  
  214.         void setWLM2009NATTraversalToken()
  215.         {
  216.             setToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  217.                 QLatin1String("/wlm-2009"));
  218.         }
  219.  
  220.         void unsetWLM2009NATTraversalToken()
  221.         {
  222.             unsetToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  223.                 QLatin1String("/wlm-2009"));
  224.         }
  225.  
  226.         bool hasAudioCodecToken(const QString &mimeSubType) const
  227.         {
  228.             return hasToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  229.                 QLatin1String("/audio/") + mimeSubType.toLower());
  230.         }
  231.  
  232.         void setAudioCodecToken(const QString &mimeSubType)
  233.         {
  234.             setToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  235.                 QLatin1String("/audio/") + mimeSubType.toLower());
  236.         }
  237.  
  238.         void unsetAudioCodecToken(const QString &mimeSubType)
  239.         {
  240.             unsetToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  241.                 QLatin1String("/audio/") + mimeSubType.toLower());
  242.         }
  243.  
  244.         bool hasVideoCodecToken(const QString &mimeSubType) const
  245.         {
  246.             return hasToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  247.                 QLatin1String("/video/") + mimeSubType.toLower());
  248.         }
  249.  
  250.         void setVideoCodecToken(const QString &mimeSubType)
  251.         {
  252.             setToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  253.                 QLatin1String("/video/") + mimeSubType.toLower());
  254.         }
  255.  
  256.         void unsetVideoCodecToken(const QString &mimeSubType)
  257.         {
  258.             unsetToken(TP_QT_IFACE_CHANNEL_INTERFACE_MEDIA_SIGNALLING +
  259.                 QLatin1String("/video/") + mimeSubType.toLower());
  260.         }
  261.  
  262.         bool hasToken(const QString &token) const;
  263.         void setToken(const QString &token);
  264.         void unsetToken(const QString &token);
  265.  
  266.         QStringList allTokens() const;
  267.  
  268.     private:
  269.         struct Private;
  270.         QSharedDataPointer<Private> mPriv;
  271.     };
  272.  
  273.     class HandlerInfo
  274.     {
  275.     public:
  276.         HandlerInfo(const QVariantMap &info = QVariantMap());
  277.         HandlerInfo(const HandlerInfo &other);
  278.         ~HandlerInfo();
  279.  
  280.         HandlerInfo &operator=(const HandlerInfo &other);
  281.  
  282.         QVariantMap allInfo() const;
  283.  
  284.     private:
  285.         struct Private;
  286.         QSharedDataPointer<Private> mPriv;
  287.     };
  288.  
  289.     virtual ~AbstractClientHandler();
  290.  
  291.     ChannelClassSpecList handlerFilter() const;
  292.  
  293.     Capabilities handlerCapabilities() const;
  294.  
  295.     virtual bool bypassApproval() const = 0;
  296.  
  297.     virtual void handleChannels(const MethodInvocationContextPtr<> &context,
  298.             const AccountPtr &account,
  299.             const ConnectionPtr &connection,
  300.             const QList<ChannelPtr> &channels,
  301.             const QList<ChannelRequestPtr> &requestsSatisfied,
  302.             const QDateTime &userActionTime,
  303.             const HandlerInfo &handlerInfo) = 0;
  304.  
  305.     bool wantsRequestNotification() const;
  306.     virtual void addRequest(const ChannelRequestPtr &request);
  307.     virtual void removeRequest(const ChannelRequestPtr &request,
  308.             const QString &errorName, const QString &errorMessage);
  309.  
  310. protected:
  311.     AbstractClientHandler(const ChannelClassSpecList &channelFilter,
  312.             const Capabilities &capabilities = Capabilities(),
  313.             bool wantsRequestNotification = false);
  314.  
  315. private:
  316.     struct Private;
  317.     friend struct Private;
  318.     Private *mPriv;
  319. };
  320.  
  321. } // Tp
  322.  
  323. Q_DECLARE_METATYPE(Tp::AbstractClientObserver::ObserverInfo);
  324. Q_DECLARE_METATYPE(Tp::AbstractClientHandler::Capabilities);
  325. Q_DECLARE_METATYPE(Tp::AbstractClientHandler::HandlerInfo);
  326.  
  327. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement