File indexing completed on 2024-12-22 05:17:20

0001 /*
0002  * This file is part of the KDE wacomtablet project. For copyright
0003  * information and license terms see the AUTHORS and COPYING files
0004  * in the top-level directory of this distribution.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef TABLETBACKENDFACTORY_H
0021 #define TABLETBACKENDFACTORY_H
0022 
0023 #include "tabletbackendinterface.h"
0024 
0025 #include <QMap>
0026 #include <QString>
0027 
0028 namespace Wacom
0029 {
0030 class TabletBackendFactory
0031 {
0032 public:
0033     /**
0034      * Creates a new instance of the tablet backend. The tablet information
0035      * parameter already needs to contain some basic tablet information which
0036      * can be obtained by querying the underlying window system. This should
0037      * have been done by the event notifier.
0038      *
0039      * The returned tablet backend instance need to be deleted once you are
0040      * done with it.
0041      *
0042      * @param info Basic tablet information.
0043      *
0044      * @return A new tablet backend instance.
0045      */
0046     static TabletBackendInterface *createBackend(const TabletInformation &info);
0047 
0048     /**
0049      * Helper method for unit testing.
0050      *
0051      * Sets the mock object which will be returned by this factory. The mock
0052      * object will only be returned once as it has to be deleted by the caller.
0053      * So there is no point in returning the same pointer multiple times.
0054      *
0055      * @param mock The mock object returned by this factory, possible null.
0056      */
0057     static void setTabletBackendMock(TabletBackendInterface *mock);
0058 
0059     /**
0060      * Sets unit testing mode.
0061      *
0062      * In unit testing mode this factory will always return the tablet backend
0063      * mock or NULL.
0064      */
0065     static void setUnitTest(bool isUnitTest);
0066 
0067 protected:
0068     /**
0069      * Creates a tablet backend instance.
0070      *
0071      * @param info      The tablet information.
0072      *
0073      * @return A new instance of a tablet backend.
0074      */
0075     TabletBackendInterface *createInstance(const Wacom::TabletInformation &info);
0076 
0077 private:
0078     //! Private default constructor as this is a static class.
0079     TabletBackendFactory();
0080 
0081     //! Copy constructor which does nothing.
0082     TabletBackendFactory(const TabletBackendFactory &factory) = delete;
0083 
0084     //! Copy operator which does nothing.
0085     TabletBackendFactory &operator=(const TabletBackendFactory &factory) = delete;
0086 
0087     //! The mock object returned by this factory if it is set.
0088     static TabletBackendInterface *m_tabletBackendMock;
0089     static bool m_isUnitTest;
0090 
0091 }; // CLASS
0092 } // NAMESPACE
0093 #endif // HEADER PROTECTION