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 Daemon internal header */
26 #ifndef IH_SENF_Utils_Daemon_Daemon_
27 #define IH_SENF_Utils_Daemon_Daemon_ 1
31 #include <senf/boost_intrusive/iset.hpp>
32 #include <senf/boost_intrusive/iset_hook.hpp>
33 #include <boost/utility.hpp>
34 #include <boost/function.hpp>
35 #include <senf/Scheduler/Scheduler.hh>
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 /** \brief Internal: Watch daemon process for successful startup */
48 DaemonWatcher(int pid, int coutpipe, int cerrpipe, int stdout, int stderr);
57 typedef boost::function<void ()> Callback;
59 Forwarder(int src, Callback cb);
62 void addTarget(int fd);
66 // This is awkward ... we'll need to erase an element from the target list given
67 // only the target object. This is best implement using an intrusive container.
68 // However, this makes memory-management explicit and we'll need to be careful.
69 typedef std::deque<char> Buffer;
71 typedef boost::intrusive::ilist_base_hook<TargetListTag> TargetListBase;
73 struct Target : public TargetListBase
75 Target(Forwarder & fwd, int fd);
78 Buffer::size_type offset;
79 scheduler::FdEvent writeevent;
81 typedef boost::intrusive::ilist<TargetListBase::value_traits<Target>,false> Targets;
86 void operator()(T * t) { delete t; }
89 void readData(int event);
90 void writeData(int event, Target * target);
96 scheduler::FdEvent readevent_;
99 void pipeClosed(int id);
100 void sigChld(siginfo_t const &);
111 scheduler::SignalEvent cldSignal_;
112 scheduler::TimerEvent timer_;
113 Forwarder coutForwarder_;
114 Forwarder cerrForwarder_;
119 //-/////////////////////////////////////////////////////////////////////////////////////////////////
126 // comment-column: 40
127 // c-file-style: "senf"
128 // indent-tabs-mode: nil
129 // ispell-local-dictionary: "american"
130 // compile-command: "scons -u test"