4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Daemon internal header */
31 #ifndef IH_SENF_Utils_Daemon_Daemon_
32 #define IH_SENF_Utils_Daemon_Daemon_ 1
36 #include <senf/boost_intrusive/iset.hpp>
37 #include <senf/boost_intrusive/iset_hook.hpp>
38 #include <boost/utility.hpp>
39 #include <boost/function.hpp>
40 #include <senf/Scheduler/Scheduler.hh>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 /** \brief Internal: Watch daemon process for successful startup */
53 DaemonWatcher(int pid, int coutpipe, int cerrpipe, int stdout, int stderr);
62 typedef boost::function<void ()> Callback;
64 Forwarder(int src, Callback cb);
67 void addTarget(int fd);
71 // This is awkward ... we'll need to erase an element from the target list given
72 // only the target object. This is best implement using an intrusive container.
73 // However, this makes memory-management explicit and we'll need to be careful.
74 typedef std::deque<char> Buffer;
76 typedef boost::intrusive::ilist_base_hook<TargetListTag> TargetListBase;
78 struct Target : public TargetListBase
80 Target(Forwarder & fwd, int fd);
83 Buffer::size_type offset;
84 scheduler::FdEvent writeevent;
86 typedef boost::intrusive::ilist<TargetListBase::value_traits<Target>,false> Targets;
91 void operator()(T * t) { delete t; }
94 void readData(int event);
95 void writeData(int event, Target * target);
101 scheduler::FdEvent readevent_;
104 void pipeClosed(int id);
105 void sigChld(siginfo_t const &);
116 scheduler::SignalEvent cldSignal_;
117 scheduler::TimerEvent timer_;
118 Forwarder coutForwarder_;
119 Forwarder cerrForwarder_;
124 //-/////////////////////////////////////////////////////////////////////////////////////////////////
131 // comment-column: 40
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"