File indexing completed on 2024-05-05 17:50:03

0001 /*
0002    Copyright (C) 2013 Andreas Hartmetz <ahartmetz@gmail.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LGPL.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 
0019    Alternatively, this file is available under the Mozilla Public License
0020    Version 1.1.  You may obtain a copy of the License at
0021    http://www.mozilla.org/MPL/
0022 */
0023 
0024 #ifndef EVENTDISPATCHER_H
0025 #define EVENTDISPATCHER_H
0026 
0027 #include "export.h"
0028 
0029 class EventDispatcherPrivate;
0030 class ForeignEventLoopIntegrator;
0031 
0032 class DFERRY_EXPORT EventDispatcher
0033 {
0034 public:
0035 #ifndef DFERRY_NO_NATIVE_POLL
0036     EventDispatcher();
0037 #endif
0038     // Does not take ownership of (i.e. does not delete in ~EventDispatcher()) integrator
0039     EventDispatcher(ForeignEventLoopIntegrator *integrator);
0040     ~EventDispatcher();
0041     EventDispatcher(EventDispatcher &other) = delete;
0042     void operator=(EventDispatcher &other) = delete;
0043 
0044     bool poll(int timeout = -1); // returns false if interrupted by interrupt()
0045     // Asynchronously interrupt the waiting for events, i.e. at the current (if any) or next poll - this is
0046     // explicitly allowed to be called from any thread (including its own).
0047     void interrupt();
0048 
0049 private:
0050     friend class EventDispatcherPrivate;
0051     EventDispatcherPrivate *d;
0052 };
0053 
0054 #endif // EVENTDISPATCHER_H