summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Repository.h
blob: 66fe3ef83088c154c8a3116d3c790f1002870791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* -*- C++ -*- */
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/orbsvcs/ImplRepo_Service
//
// = FILENAME
//    Repository.h
//
// = DESCRIPTION
//    This class implements the Repository for the Implementation Repository.
//
// = AUTHOR
//    Darrell Brunsch <brunsch@cs.wustl.edu>
//
// ============================================================================


#ifndef REPOSITORY_H
#define REPOSITORY_H

#include "tao/PortableServer/ImplRepoC.h"
#include "tao/corba.h"

#include "ace/Functor.h"
#include "ace/Hash_Map_Manager.h"
#include "ace/Synch.h"
#include "ace/SString.h"
#include "ace/Configuration.h"

class Server_Info
  // = TITLE
  //   Information about IMR registered servers.
  //
  // = DESCRIPTION
  //   Contains all the necessary information about the server including
  //   Information on how to start it up and where it is running.
{
public:
  // = Constructors

  enum ActivationMode {NORMAL, MANUAL, PER_CLIENT, AUTO_START};

  Server_Info (const ACE_TString POA_name,
               const ACE_TString logical_server_name,
               const ACE_TString startup_command,
               const ImplementationRepository::EnvironmentList
                     environment_vars,
               const ACE_TString working_dir,
               const ActivationMode activation);
  // Initialize the command_line and working_dir.

  // = Destructors

  ~Server_Info ();
  // The only destructor there is.

  void update_running_info (const ACE_TString location,
                            const ACE_TString server_object_ior);
  // Updates information that is relevant only when an instance
  // of the server is running.

  void get_startup_info (ACE_TString &logical_server_name,
                         ACE_TString &startup_command,
                         ImplementationRepository::EnvironmentList
                            &environment_vars,
                         ACE_TString &working_dir,
                         ActivationMode &activation);
  // Returns startup information.

  void get_running_info (ACE_TString &location,
                         ACE_TString &server_object_ior);
  // Returns information about a running instance.

  // ActivationMode get_activation (void);
  // Get the activation mode.

  // @@ Does this belong here?
  //  int startup ();
  // Starts up the server based on the information.
  // Returns:  0  if successful
  //           -1 if there is no registration command (it has to be manually
  //              restarted)

  int starting_up_;
  // This is a flag to determine if the process has already been spawned
  // and we are just waiting for it to start up.

private:
  ACE_TString logical_server_name_;
  // Which server process this poa is grouped in.

  ACE_TString POA_name_;
  // The name of the POA.

  ACE_TString startup_command_;
  // The command line startup command (program and arguments).

  ImplementationRepository::EnvironmentList environment_vars_;
  // Environment Variables.

  ACE_TString working_dir_;
  // The working directory.

  ACE_TString location_;
  // Current endpoint used by the server.

  ACE_TString server_object_ior_;
  // IOR of the server object in the server.

  ActivationMode activation_;
  // The type of activation this supports.

  // No copying allowed.
  void operator= (Server_Info &);
  Server_Info (Server_Info &);
};




class Server_Repository
  // = TITLE
  //   Repository of Server_Infos.
  //
  // = DESCRIPTION
  //   Handles the storage, updating, and startup of servers.
{
public:
  Server_Repository ();
  // Default Constructor

  ~Server_Repository ();
  // Destructor

  typedef ACE_Hash_Map_Entry<ACE_TString,
                             Server_Info *> HASH_IMR_ENTRY;

  typedef ACE_Hash_Map_Manager_Ex<ACE_TString,
                                  Server_Info *,
                                  ACE_Hash<ACE_TString>,
                                  ACE_Equal_To<ACE_TString>,
                                  ACE_Null_Mutex> HASH_IMR_MAP;

  typedef ACE_Hash_Map_Iterator_Ex<ACE_TString,
                                   Server_Info *,
                                   ACE_Hash<ACE_TString>,
                                   ACE_Equal_To<ACE_TString>,
                                   ACE_Null_Mutex> HASH_IMR_ITER;

  int init ();
  // Initializes the Server Repository

  int add (const ACE_TString POA_name,
           const ACE_TString logical_server_name,
           const ACE_TString startup_command,
           const ImplementationRepository::EnvironmentList
                 environment_vars,
           const ACE_TString working_dir,
           const Server_Info::ActivationMode activation);
  // Add a new server to the Repository

  int update (const ACE_TString POA_name,
              const ACE_TString location,
              const ACE_TString server_object_ior);
  // Update the associated process information.

  int get_startup_info (const ACE_TString POA_name,
                        ACE_TString &logical_server_name,
                        ACE_TString &startup_command,
                        ImplementationRepository::EnvironmentList
                           &environment_vars,
                        ACE_TString &working_dir,
                        Server_Info::ActivationMode &activation);
  // Returns information related to startup.

  int get_running_info (const ACE_TString POA_name,
                        ACE_TString &location,
                        ACE_TString &server_object_ior);
  // Returns information related to a running copy.

  int starting_up (const ACE_TString POA_name, int new_value);
  // Checks the starting_up_ variable in the Server_Info and
  // returns the previous value or -1 if the POA_name wasn't found

  int starting_up (const ACE_TString POA_name);
  // Same as above but does not alter the value.

  int remove (const ACE_TString POA_name);
  // Removes the server from the Repository.

  HASH_IMR_ITER *new_iterator ();
  // Returns a new iterator that travels over the repository.

  size_t get_repository_size ();
  // Returns the number of entries in the repository.

private:
  HASH_IMR_MAP repository_;
  ACE_Configuration_Section_Key servers_;
};


#endif /* REPOSITORY_H */