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

generic-capability-filter.h

    00001
    00023 #ifndef _TelepathyQt_generic_capability_filter_h_HEADER_GUARD_
    00024 #define _TelepathyQt_generic_capability_filter_h_HEADER_GUARD_
    00025
    00026 #ifndef IN_TP_QT_HEADER
    00027 #error IN_TP_QT_HEADER
    00028 #endif
    00029
    00030 #include <TelepathyQt/ConnectionCapabilities>
    00031 #include <TelepathyQt/Filter>
    00032 #include <TelepathyQt/Types>
    00033
    00034 namespace Tp
    00035 {
    00036
    00037 template <class T>
    00038 class GenericCapabilityFilter : public Filter<T>
    00039 {
    00040 public:
    00041     static SharedPtr<GenericCapabilityFilter<T> > create(
    00042             const RequestableChannelClassSpecList &rccSpecs = RequestableChannelClassSpecList())
    00043     {
    00044         return SharedPtr<GenericCapabilityFilter<T> >(new GenericCapabilityFilter<T>(
    00045                     rccSpecs));
    00046     }
    00047
    00048     inline virtual ~GenericCapabilityFilter() { }
    00049
    00050     inline virtual bool isValid() const { return true; }
    00051
    00052     inline virtual bool matches(const SharedPtr<T> &t) const
    00053     {
    00054         bool supportedRcc;
    00055         RequestableChannelClassSpecList objectRccSpecs = t->capabilities().allClassSpecs();
    00056         Q_FOREACH (const RequestableChannelClassSpec &filterRccSpec, mFilter) {
    00057             supportedRcc = false;
    00058
    00059             Q_FOREACH (const RequestableChannelClassSpec &objectRccSpec, objectRccSpecs) {
    00060                 /* check if fixed properties match */
    00061                 if (filterRccSpec.fixedProperties() == objectRccSpec.fixedProperties()) {
    00062                     supportedRcc = true;
    00063
    00064                     /* check if all allowed properties in the filter RCC
    00065                      * are in the object RCC allowed properties */
    00066                     Q_FOREACH (const QString &value, filterRccSpec.allowedProperties()) {
    00067                         if (!objectRccSpec.allowsProperty(value)) {
    00068                             /* one of the properties in the filter RCC
    00069                              * allowed properties is not in the object RCC
    00070                              * allowed properties */
    00071                             supportedRcc = false;
    00072                             break;
    00073                         }
    00074                     }
    00075
    00076                     /* this RCC is supported, no need to check anymore */
    00077                     if (supportedRcc) {
    00078                         break;
    00079                     }
    00080                 }
    00081             }
    00082
    00083             /* one of the filter RCC is not supported, this object
    00084              * won't match filter */
    00085             if (!supportedRcc) {
    00086                 return false;
    00087             }
    00088         }
    00089
    00090         return true;
    00091     }
    00092
    00093     inline RequestableChannelClassSpecList filter() const { return mFilter; }
    00094
    00095     inline void addRequestableChannelClassSubset(const RequestableChannelClassSpec &rccSpec)
    00096     {
    00097         mFilter.append(rccSpec.bareClass());
    00098     }
    00099
    00100     inline void setRequestableChannelClassesSubset(const RequestableChannelClassSpecList &rccSpecs)
    00101     {
    00102         mFilter = rccSpecs.bareClasses();
    00103     }
    00104
    00105 private:
    00106     GenericCapabilityFilter(const RequestableChannelClassSpecList &rccSpecs)
    00107         : Filter<T>(), mFilter(rccSpecs) { }
    00108
    00109     RequestableChannelClassSpecList mFilter;
    00110 };
    00111
    00112 } // Tp
    00113
    00114 #endif