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

0001 /*
0002    Copyright (C) 2018 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 #include "iioeventforwarder.h"
0025 
0026 #include <cassert>
0027 
0028 // The logic of add/removeIoListenerInternal is based on knowledge that one Connection or Server can only
0029 // have one I/O listener, which is the one ITransport connecting to the bus or peer.
0030 void IIoEventForwarder::addIoListenerInternal(IIoEventListener *iol, uint32 ioRw)
0031 {
0032     assert(!ioEventSource()); // since our clients are internal, they are expected to be well-behaved
0033     assert(!m_downstream);
0034     setIoInterest(ioRw);
0035     m_downstream = iol;
0036     m_upstream->addIoListener(this);
0037     assert(ioEventSource());
0038     assert(m_upstream == ioEventSource());
0039 }
0040 
0041 void IIoEventForwarder::removeIoListenerInternal(IIoEventListener * /* iol */)
0042 {
0043     assert(ioEventSource());
0044     assert(m_upstream == ioEventSource());
0045     assert(m_downstream);
0046     m_upstream->removeIoListener(this);
0047     m_downstream = nullptr;
0048     // (no need to change I/O interest, only upstream can see it and we have no upstream now)
0049     assert(!ioEventSource());
0050 }
0051 
0052 void IIoEventForwarder::updateIoInterestInternal(IIoEventListener * /*iol*/, uint32 ioRw)
0053 {
0054     setIoInterest(ioRw);
0055 }
0056 
0057 FileDescriptor IIoEventForwarder::fileDescriptor() const
0058 {
0059     return m_downstream->fileDescriptor();
0060 }
0061 
0062 IIoEventListener *IIoEventForwarder::downstreamListener()
0063 {
0064     return m_downstream;
0065 }
0066 
0067 #if 0
0068 // Sample implementation for subclasses
0069 IO::Status IIoEventForwarderSubclass::handleIoReady(IO::RW rw)
0070 {
0071     IO::Status result = m_ioEventSink->handleIoReady(rw);
0072     if (result != IO::Status::OK) {
0073         // error handling - connection teardown and notifying some other listeners, for example
0074     }
0075 }
0076 #endif