4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief FdDispatcher non-inline non-template implementation */
26 #include "FdDispatcher.hh"
27 #include "FdDispatcher.ih"
30 #include "../Utils/senfassert.hh"
32 //#include "FdDispatcher.mpp"
34 ///////////////////////////////cc.p////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////
37 // senf::scheduler::FdDispatcher
39 prefix_ senf::scheduler::FdDispatcher::~FdDispatcher()
41 for (FdMap::iterator i (fds_.begin()); i != fds_.end(); ++i) {
42 manager_.remove(i->first);
43 runner_.dequeue(static_cast<FdEvent::ReadTask*>(&i->second));
44 runner_.dequeue(static_cast<FdEvent::PrioTask*>(&i->second));
45 runner_.dequeue(static_cast<FdEvent::WriteTask*>(&i->second));
49 prefix_ bool senf::scheduler::FdDispatcher::add(std::string const & name, int fd,
50 Callback const & cb, int events)
55 FdMap::iterator i (fds_.find(fd));
56 if (i == fds_.end()) {
57 i = fds_.insert(std::make_pair(fd, FdEvent(name))).first;
58 runner_.enqueue(static_cast<FdEvent::ReadTask*>(&i->second));
59 runner_.enqueue(static_cast<FdEvent::PrioTask*>(&i->second));
60 runner_.enqueue(static_cast<FdEvent::WriteTask*>(&i->second));
62 FdEvent & event (i->second);
65 event.FdEvent::ReadTask::cb = cb;
67 event.FdEvent::PrioTask::cb = cb;
68 if (events & EV_WRITE)
69 event.FdEvent::WriteTask::cb = cb;
71 if (! manager_.set(fd, event.activeEvents(), &event)) {
72 runner_.dequeue(static_cast<FdEvent::ReadTask*>(&i->second));
73 runner_.dequeue(static_cast<FdEvent::PrioTask*>(&i->second));
74 runner_.dequeue(static_cast<FdEvent::WriteTask*>(&i->second));
82 prefix_ void senf::scheduler::FdDispatcher::remove(int fd, int events)
87 FdMap::iterator i (fds_.find(fd));
90 FdEvent & event (i->second);
93 event.FdEvent::ReadTask::cb = 0;
95 event.FdEvent::PrioTask::cb = 0;
96 if (events & EV_WRITE)
97 event.FdEvent::WriteTask::cb = 0;
99 int activeEvents (event.activeEvents());
100 if (! activeEvents) {
102 runner_.dequeue(static_cast<FdEvent::ReadTask*>(&i->second));
103 runner_.dequeue(static_cast<FdEvent::PrioTask*>(&i->second));
104 runner_.dequeue(static_cast<FdEvent::WriteTask*>(&i->second));
107 manager_.set(fd, activeEvents, &event);
110 ///////////////////////////////////////////////////////////////////////////
111 // senf::scheduler::FdDispatcher::FdEvent
113 prefix_ void senf::scheduler::FdDispatcher::FdEvent::signal(int e)
117 if (events & EV_READ)
118 ReadTask::runnable = true;
119 if (events & EV_PRIO)
120 PrioTask::runnable = true;
121 if (events & EV_WRITE)
122 WriteTask::runnable = true;
124 if ((events & (EV_ERR | EV_HUP)) && ! (events & (EV_READ | EV_PRIO | EV_WRITE))) {
125 if (ReadTask::cb) ReadTask::runnable = true;
126 if (PrioTask::cb) PrioTask::runnable = true;
127 if (WriteTask::cb) WriteTask::runnable = true;
131 ///////////////////////////////cc.e////////////////////////////////////////
133 //#include "FdDispatcher.mpp"
139 // comment-column: 40
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"