Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Utils / Daemon / Daemon.ih
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Daemon internal header */
25
26 #ifndef IH_SENF_Utils_Daemon_Daemon_
27 #define IH_SENF_Utils_Daemon_Daemon_ 1
28
29 // Custom includes
30 #include <deque>
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>
36 #include <senf/Scheduler/FdEvent.hh>
37
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 namespace senf {
41 namespace detail {
42
43     /** \brief Internal: Watch daemon process for successful startup */
44     class DaemonWatcher
45         : boost::noncopyable
46     {
47     public:
48
49         DaemonWatcher(int pid, int coutpipe, int cerrpipe, int stdout, int stderr);
50
51         void run();
52
53     private:
54
55         class Forwarder
56         {
57         public:
58             typedef boost::function<void ()> Callback;
59
60             Forwarder(int src, Callback cb);
61             ~Forwarder();
62
63             void addTarget(int fd);
64
65         private:
66
67             // This is awkward ... we'll need to erase an element from the target list given
68             // only the target object. This is best implement using an intrusive container.
69             // However, this makes memory-management explicit and we'll need to be careful.
70             typedef std::deque<char> Buffer;
71             struct TargetListTag;
72             typedef boost::intrusive::ilist_base_hook<TargetListTag> TargetListBase;
73
74             struct Target : public TargetListBase
75             {
76                 Target(Forwarder & fwd, int fd);
77
78                 int fd;
79                 Buffer::size_type offset;
80                 scheduler::FdEvent writeevent;
81             };
82             typedef boost::intrusive::ilist<TargetListBase::value_traits<Target>,false> Targets;
83
84             struct DestroyDelete
85             {
86                 template <class T>
87                 void operator()(T * t) { delete t; }
88             };
89
90             void readData(int event);
91             void writeData(int event, Target * target);
92
93             Buffer buffer_;
94             int src_;
95             Targets targets_;
96             Callback cb_;
97             scheduler::FdEvent readevent_;
98         };
99
100         void pipeClosed(int id);
101         void sigChld(siginfo_t const &);
102         void childDied();
103         void childOk();
104
105         int childPid_;
106         int coutpipe_;
107         int cerrpipe_;
108         int stdout_;
109         int stderr_;
110         bool sigChld_;
111
112         scheduler::SignalEvent cldSignal_;
113         scheduler::TimerEvent timer_;
114         Forwarder coutForwarder_;
115         Forwarder cerrForwarder_;
116     };
117
118 }}
119
120 //-/////////////////////////////////////////////////////////////////////////////////////////////////
121 #endif
122
123 \f
124 // Local Variables:
125 // mode: c++
126 // fill-column: 100
127 // comment-column: 40
128 // c-file-style: "senf"
129 // indent-tabs-mode: nil
130 // ispell-local-dictionary: "american"
131 // compile-command: "scons -u test"
132 // End: