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

0001 /*
0002    Copyright (C) 2017 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 FOREIGNEVENTLOOPINTEGRATOR_H
0025 #define FOREIGNEVENTLOOPINTEGRATOR_H
0026 
0027 #include "export.h"
0028 
0029 class EventDispatcher;
0030 class ForeignEventLoopIntegratorPrivate;
0031 class IEventPoller;
0032 
0033 class DFERRY_EXPORT ForeignEventLoopIntegrator
0034 {
0035 public:
0036     ForeignEventLoopIntegrator();
0037     virtual ~ForeignEventLoopIntegrator();
0038 
0039     bool exiting() const;
0040 
0041     // Implement these to do what their names say; watched events are assumed to be level-triggered,
0042     // i.e. a file descriptor that is still ready after reading some part of the incoming data should
0043     // be considered immediately ready again in the next event loop iteration.
0044     virtual void watchTimeout(int msecs) = 0; // -1 means disable timeout
0045     virtual void setWatchRead(int fd, bool doWatch) = 0;
0046     virtual void setWatchWrite(int fd, bool doWatch) = 0;
0047 
0048     // Call these when the watched event occurs
0049     void handleTimeout();
0050     void handleReadyRead(int fd);
0051     void handleReadyWrite(int fd);
0052 
0053     // Call this in the destructor or other shutdown / reset code of the class that implements the pure
0054     // virtuals. They will be called as necessary to remove all existing watches (read, write, time).
0055     void removeAllWatches();
0056 
0057 private:
0058     friend class EventDispatcher;
0059     friend class ForeignEventLoopIntegratorPrivate;
0060     IEventPoller *connectToDispatcher(EventDispatcher *dispatcher);
0061     ForeignEventLoopIntegratorPrivate *d;
0062 };
0063 
0064 #endif // FOREIGNEVENTLOOPINTEGRATOR_H