// $Id$ // // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \file \brief Daemon internal header */ #ifndef IH_SENF_Utils_Daemon_Daemon_ #define IH_SENF_Utils_Daemon_Daemon_ 1 // Custom includes #include #include #include #include #include #include //-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { namespace detail { /** \brief Internal: Watch daemon process for successful startup */ class DaemonWatcher : boost::noncopyable { public: DaemonWatcher(int pid, int coutpipe, int cerrpipe, int stdout, int stderr); void run(); private: class Forwarder { public: typedef boost::function Callback; Forwarder(int src, Callback cb); ~Forwarder(); void addTarget(int fd); private: // This is awkward ... we'll need to erase an element from the target list given // only the target object. This is best implement using an intrusive container. // However, this makes memory-management explicit and we'll need to be careful. typedef std::deque Buffer; struct TargetListTag; typedef boost::intrusive::ilist_base_hook TargetListBase; struct Target : public TargetListBase { Target(Forwarder & fwd, int fd); int fd; Buffer::size_type offset; scheduler::FdEvent writeevent; }; typedef boost::intrusive::ilist,false> Targets; struct DestroyDelete { template void operator()(T * t) { delete t; } }; void readData(int event); void writeData(int event, Target * target); Buffer buffer_; int src_; Targets targets_; Callback cb_; scheduler::FdEvent readevent_; }; void pipeClosed(int id); void sigChld(siginfo_t const &); void childDied(); void childOk(); int childPid_; int coutpipe_; int cerrpipe_; int stdout_; int stderr_; bool sigChld_; scheduler::SignalEvent cldSignal_; scheduler::TimerEvent timer_; Forwarder coutForwarder_; Forwarder cerrForwarder_; }; }} //-///////////////////////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: