1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/**
* This file is part of TelepathyQt
*
* @copyright Copyright (C) 2008-2009 Collabora Ltd. <http://www.collabora.co.uk/>
* @copyright Copyright (C) 2008-2009 Nokia Corporation
* @license LGPL 2.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <TelepathyQt/OptionalInterfaceFactory>
#include <TelepathyQt/AbstractInterface>
#include "TelepathyQt/debug-internal.h"
#include <QMap>
#include <QString>
namespace Tp
{
#ifndef DOXYGEN_SHOULD_SKIP_THIS
struct TP_QT_NO_EXPORT OptionalInterfaceCache::Private
{
QObject *proxy;
QMap<QString, AbstractInterface*> interfaces;
Private(QObject *proxy);
};
OptionalInterfaceCache::Private::Private(QObject *proxy)
: proxy(proxy)
{
}
/**
* Class constructor.
*/
OptionalInterfaceCache::OptionalInterfaceCache(QObject *proxy)
: mPriv(new Private(proxy))
{
}
/**
* Class destructor.
*
* Frees all interface instances constructed by this factory.
*/
OptionalInterfaceCache::~OptionalInterfaceCache()
{
delete mPriv;
}
QObject *OptionalInterfaceCache::proxy() const
{
return mPriv->proxy;
}
AbstractInterface *OptionalInterfaceCache::getCached(const QString &name) const
{
if (mPriv->interfaces.contains(name)) {
return mPriv->interfaces.value(name);
} else {
return 0;
}
}
void OptionalInterfaceCache::cache(AbstractInterface *interface) const
{
QString name = interface->interface();
Q_ASSERT(!mPriv->interfaces.contains(name));
mPriv->interfaces[name] = interface;
}
#endif /* ifndef DOXYGEN_SHOULD_SKIP_THIS */
/**
* \class OptionalInterfaceFactory
* \ingroup clientsideproxies
* \headerfile TelepathyQt/optional-interface-factory.h <TelepathyQt/OptionalInterfaceFactory>
*
* \brief The OptionalInterfaceFactory class is a helper class for
* high-level D-Bus proxy classes willing to offer access to shared
* instances of interface proxies for optional interfaces.
*
* To use this helper in a subclass of DBusProxy (say, ExampleObject),
* ExampleObject should inherit from
* OptionalInterfaceFactory<ExampleObject>, and call
* OptionalInterfaceFactory(this) in its constructor's initialization list.
*
* \tparam DBusProxySubclass A subclass of DBusProxy
*/
/**
* \enum OptionalInterfaceFactory::InterfaceSupportedChecking
*
* Specifies if the interface being supported by the remote object should be
* checked by optionalInterface() and the convenience functions for it.
*
* \sa optionalInterface()
*/
/**
* \var OptionalInterfaceFactory::InterfaceSupportedChecking OptionalInterfaceFactory::CheckInterfaceSupported
*
* Don't return an interface instance unless it can be guaranteed that the
* remote object actually implements the interface.
*/
/**
* \var OptionalInterfaceFactory::InterfaceSupportedChecking OptionalInterfaceFactory::BypassInterfaceCheck
*
* Return an interface instance even if it can't be verified that the remote
* object supports the interface.
*/
/**
* \fn OptionalInterfaceFactory::OptionalInterfaceFactory(DBusProxySubclass *this_)
*
* Class constructor.
*
* \param this_ The class to which this OptionalInterfaceFactory is
* attached
*/
/**
* \fn OptionalInterfaceFactory::~OptionalInterfaceFactory()
*
* Class destructor.
*
* Frees all interface instances constructed by this factory.
*/
/**
* \fn OptionalInterfaceFactory::interfaces() const;
*
* Return a list of interfaces supported by this object.
*
* \return List of supported interfaces.
*/
/**
* \fn template <typename Interface> inline Interface *OptionalInterfaceFactory::interface() const
*
* Return a pointer to a valid instance of a interface class, associated
* with the same remote object as the given main interface instance. The
* given main interface must be of the class the optional interface is
* generated for (for eg. ChannelInterfaceGroupInterface this means
* ChannelInterface) or a subclass.
*
* First invocation of this method for a particular optional interface
* class will construct the instance; subsequent calls will return a
* pointer to the same instance.
*
* The returned instance is freed when the factory is destroyed; using
* it after destroying the factory will likely produce a crash. As the
* instance is shared, it should not be freed directly.
*
* \tparam Interface Class of the interface instance to get.
* \return A pointer to an optional interface instance.
*/
} // Tp
|