Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / ImplRepo_Service / ImR_Activator_i.h
blob86d8c7b604c4af69d2802f8c3c58b16c3d7881cc
1 // -*- C++ -*-
2 //=============================================================================
3 /**
4 * @file ImR_Activator_i.h
6 * @author Priyanka Gontla <gontla_p@ociweb.com>
7 * @author Darrell Brunsch <brunsch@cs.wustl.edu>
8 */
9 //=============================================================================
11 #ifndef IMR_ACTIVATOR_I_H
12 #define IMR_ACTIVATOR_I_H
14 #include "activator_export.h"
16 #include "ImR_ActivatorS.h"
17 #include "ImR_LocatorC.h"
19 #include "ace/Process_Manager.h"
20 #include "ace/Hash_Map_Manager.h"
21 #include "ace/Null_Mutex.h"
22 #include "ace/SString.h"
23 #if defined (ACE_WIN32)
24 # include "ace/Task.h"
25 #endif /* ACE_WIN32 */
27 #if !defined (ACE_LACKS_PRAGMA_ONCE)
28 # pragma once
29 #endif /* ACE_LACKS_PRAGMA_ONCE */
31 class Activator_Options;
33 // ace/Functor.h doesn't provide functors for every built in integer type.
34 // Depending on the platform and what pid_t maps to, the functors may be missing.
35 struct ACE_Hash_pid_t
37 unsigned long operator () (pid_t t) const
39 return t;
43 struct ACE_Equal_To_pid_t
45 int operator () (const pid_t lhs, const pid_t rhs) const
47 return lhs == rhs;
51 #if (ACE_SIZEOF_VOID_P == 8)
52 typedef ACE_INT64 Act_token_type;
53 #else
54 typedef ACE_INT32 Act_token_type;
55 #endif
57 #if defined (ACE_WIN32)
58 class Active_Pid_Setter;
60 class Activator_Export Watchdog : public ACE_Task_Base
62 public:
63 Watchdog (ACE_Process_Manager& procman);
64 virtual int svc ();
65 bool start ();
66 void stop ();
67 private:
68 bool stop_;
69 ACE_Process_Manager &procman_;
71 #endif /* ACE_WIN32 */
73 /**
74 * @class ImR_Activator_i
76 * @brief IMR Activator Interface.
78 * This class provides the interface for the various activities
79 * that can be done by the ImR_Activator.
82 class Activator_Export ImR_Activator_i : public POA_ImplementationRepository::ActivatorExt,
83 public ACE_Event_Handler
85 public:
86 friend class Active_Pid_Setter;
88 ImR_Activator_i (void);
90 void start_server (const char* name,
91 const char* cmdline,
92 const char* dir,
93 const ImplementationRepository::EnvironmentList & env);
95 CORBA::Boolean kill_server (const char* name, CORBA::Long pid, CORBA::Short signum);
97 CORBA::Boolean still_alive (CORBA::Long pid);
99 void shutdown(void);
101 /// Initialize the Server state - parsing arguments and waiting.
102 int init (Activator_Options& opts);
104 /// Cleans up any state created by init*.
105 int fini (void);
107 int handle_timeout (const ACE_Time_Value &, const void *tok);
109 /// Runs the orb.
110 int run (void);
112 /// Shutdown the orb.
113 void shutdown (bool signaled);
115 private:
116 int init_with_orb (CORBA::ORB_ptr orb, const Activator_Options& opts);
118 void register_with_imr(ImplementationRepository::Activator_ptr activator);
120 // Handles the death of the child processes of the ImR_Activator.
121 // Informs the ImR_Locator too.
122 int handle_exit (ACE_Process * process);
123 int handle_exit_i (pid_t pid);
125 bool still_running_i (const char *name, pid_t& pid);
127 bool in_upcall (void);
129 private:
130 typedef ACE_Unbounded_Set<ACE_CString> UniqueServerList;
132 typedef ACE_Hash_Map_Manager_Ex<pid_t,
133 ACE_CString,
134 ACE_Hash_pid_t,
135 ACE_Equal_To_pid_t,
136 ACE_Null_Mutex> ProcessMap;
138 ACE_Process_Manager process_mgr_;
140 PortableServer::POA_var root_poa_;
141 PortableServer::POA_var imr_poa_;
142 PortableServer::Current_var current_;
144 ImplementationRepository::Locator_var locator_;
146 /// We're given a token when registering with the locator, which
147 /// we must use when unregistering.
148 CORBA::Long registration_token_;
150 CORBA::ORB_var orb_;
152 unsigned int debug_;
154 bool notify_imr_;
156 unsigned int induce_delay_;
158 ACE_CString name_;
160 ProcessMap process_map_;
162 UniqueServerList running_server_list_;
163 UniqueServerList dying_server_list_;
165 /// The default environment buffer length
166 int env_buf_len_;
168 /// Maximum number of environment variables
169 int max_env_vars_;
171 bool detach_child_;
172 pid_t active_check_pid_;
173 #if defined (ACE_WIN32)
174 Watchdog process_watcher_;
175 #endif /* ACE_WIN32 */
178 #if defined (ACE_WIN32)
179 class Active_Pid_Setter
181 public:
182 Active_Pid_Setter(ImR_Activator_i &owner, pid_t pid);
183 ~Active_Pid_Setter();
185 ImR_Activator_i &owner_;
187 #endif /* ACE_WIN32 */
189 #endif /* IMR_ACTIVATOR_I_H */