Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

process.h

00001 #ifndef EDG_WORKLOAD_COMMON_PROCESS_PROCESS_H
00002 #define EDG_WORKLOAD_COMMON_PROCESS_PROCESS_H
00003 
00004 #include <sys/types.h>
00005 
00006 #include <list>
00007 
00008 #include <boost/function.hpp>
00009 #include <boost/shared_ptr.hpp>
00010 
00011 #include "edg/workload/common/common_namespace.h"
00012 
00013 COMMON_NAMESPACE_BEGIN {
00014 
00015 namespace process {
00016 
00017 class Subprocess; // Forward declaration
00018 
00019 class Functor {
00020 public:
00021   Functor( void ) {}
00022 
00023   virtual ~Functor( void ) {}
00024 
00025   virtual int run( void ) = 0;
00026 };
00027 
00028 class Process {
00029 public:
00030   Process( void );
00031   ~Process( void );
00032 
00033   inline bool is_son( void ) { return this->p_son; }
00034   inline bool is_daemon( void ) { return this->p_daemon; }
00035   inline bool have_stdstreams( void ) { return this->p_havestd; }
00036   inline pid_t pid( void ) { return this->p_pid; }
00037 
00038   void remove( Subprocess *proc );
00039   void wait_one( Subprocess *proc );
00040   int make_daemon( bool chdir = false, bool close = true );
00041   int drop_privileges_forever( const char *username );
00042   int drop_privileges( const char *username );
00043   int regain_privileges( void );
00044   pid_t parent( void );
00045   Subprocess *wait_first( void );
00046   Subprocess *fork( Functor &runner );
00047 
00048   inline static Process *self( void )
00049   { if( p_s_instance == NULL ) p_s_instance = new Process; return p_s_instance; }
00050 
00051 private:
00052   typedef boost::shared_ptr<Subprocess>   ProcPtr;
00053 
00054   bool                p_son, p_daemon, p_havestd;
00055   pid_t               p_pid;
00056   std::list<ProcPtr>  p_list;
00057 
00058   static Process  *p_s_instance;
00059 };
00060 
00061 }; // Namespace process
00062 
00063 } COMMON_NAMESPACE_END;
00064 
00065 #endif /* EDG_WORKLOAD_COMMON_PROCESS_PROCESS_H */
00066 
00067 // Local Variables:
00068 // mode: c++
00069 // End:

Generated on Fri May 14 14:18:26 2004 for COMMON API - configuration, jobid, ldif2classadi, logger, process, requestad, socket++i, task, utilities by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002