summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/RepositoryManager/RepositoryManager_Impl.h
blob: 0c371d7c758313290dbfd82420a5044db40122b1 (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

/* -*- C++ -*- */

//======================================================================
/**
 * @file RepositoryManager_Impl.h
 *
 * $Id$
 *
 * Description:
 *  This file is the main implementation file for the RepositoryManager
 *  in CIAO. We have used a number of techniques in order to increase
 *  scalability of the RepoMan while still maintaining complience with
 *  the D&C spec
 *
 * @author Stoyan Paunov
 *         Shanshan Jiang <shanshan.jiang@vanderbilt.edu>
 */
//======================================================================

#ifndef REPOSITORYMANAGERI_H_
#define REPOSITORYMANAGERI_H_


//-----------------------------NOTE---------------------------------
//I need to disable all the code which has to do with interface
//type information because we currently do not support assembly
//interfaces which causes undesired behavior with respect to the
//hash tables because the specificType field in assembly interfaces
//is empty, so two unrelated intefaces appear to be related.


#include "RepositoryManagerDaemonS.h"

#include "ace/Hash_Map_Manager_T.h"      //for the ACE_Hash_Map_Manager
#include "ace/Hash_Multi_Map_Manager_T.h"      //for the ACE_Hash_MultiMap_Manager
#include "ace/Null_Mutex.h"          //for ACE_Null_Mutex
#include "ace/RW_Mutex.h"          //for ACE_RW_Mutex
#include "ace/OS_NS_string.h"        //for ACE_CString
#include "ace/SString.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

namespace
{
  static const size_t TEMP_LEN = 1024;
}

class  CIAO_RepositoryManagerDaemon_i :
  public virtual POA_CIAO::RepositoryManagerDaemon
{
public:
  /// Constructor
  CIAO_RepositoryManagerDaemon_i (CORBA::ORB_ptr the_orb,
                  const char* server = "localhost:5432",
                  const char* install_dir = "RepositoryManager");

  /// Destructor
  virtual ~CIAO_RepositoryManagerDaemon_i (void);

  virtual
  void shutdown (

    )
    ACE_THROW_SPEC ((
      CORBA::SystemException
    ));

  virtual
  void installPackage (
      const char * installationName,
      const char * location,
      ::CORBA::Boolean replace
    )
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      ::Deployment::NameExists,
      ::Deployment::PackageError
    ));

  virtual
  void createPackage (
      const char * installationName,
      const ::Deployment::PackageConfiguration & package,
      const char * baseLocation,
      ::CORBA::Boolean replace
    )
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      ::Deployment::NameExists,
      ::Deployment::PackageError
    ));

  virtual
  ::Deployment::PackageConfiguration * findPackageByName (
      const char * name
    )
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      ::Deployment::NoSuchName
    ));

  virtual
  ::Deployment::PackageConfiguration * findPackageByUUID (
      const char * UUID
    )
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      ::Deployment::NoSuchName
    ));

  virtual
  ::CORBA::StringSeq * findNamesByType (
      const char * type
    )
    ACE_THROW_SPEC ((
      CORBA::SystemException
    ));

  virtual
  ::CORBA::StringSeq * getAllNames (

    )
    ACE_THROW_SPEC ((
      CORBA::SystemException
    ));

  virtual
  ::CORBA::StringSeq * getAllTypes (

    )
    ACE_THROW_SPEC ((
      CORBA::SystemException
    ));

  virtual
  void deletePackage (
      const char * installationName
    )
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      ::Deployment::NoSuchName
    ));

protected:

  /// Function to parse and return the PackageConfiguration from a specified
  /// package
  Deployment::PackageConfiguration* retrieve_PC_from_package (char* package);

  /// Find out what the name of the PackageConfiguration file is
  void find_PC_name (char* package, ACE_CString& pcd_name);

  /// Function to parse and return the PackageConfiguration from the already
  /// extracted descriptor files
  Deployment::PackageConfiguration* retrieve_PC_from_descriptors (const char* pc_name,
                                                                  const char* descriptor_dir);


  /// Function to retrieve a file via HTTP
  /// stores the file in the passed preallocated ACE_Message_Block
  /// @retval 1 success
  /// @retval 0 error
  int HTTP_Get (const char* URL, ACE_Message_Block &mb);

  /// Function to extract all necessary files for parsing the
  /// PackageConfiguration descriptor and populating the idl struct.
  /// @retval 1 success
  /// @retval 0 error
  ///
  /// @note ACE_CString& pcd_name is an out parameter
  int extract_descriptor_files (char* package,
    ACE_CString& pcd_name);


  /// Function to remove the files extracted for parsing the PackageConfiguration
  /// descriptor and populating the idl struct. It reads the names of the files
  /// from the package. They correspond to the names on disk.
  /// @retval 1 on success
  /// @retval 0 on error
  int remove_descriptor_files (char* package);


  /// Function to remove the files extracted from the package upon istallation
  /// It reads the names of the files from the package. They correspond to the
  /// names on disk. It deletes each file, then it deletes the directories that
  /// contain them.
  /// @note extraction location is path/*archive_name*/
  /// @retval 1 on success
  /// @retval 0 on error
  int remove_extracted_package (const char* package_path, const char* extraction_location);

  /// Function to extract the type of the component from
  /// the PackageConfiguration and update the interface map
  /// @retval 1 on success
  /// @retval 0 on error
  int add_type (::Deployment::PackageConfiguration& pc,
                const char* name);

  /// Function to remove the interface type of the component
  /// being removed from the interface map
  /// @retval 1 on success
  /// @retval 0 on error
  int remove_type (::Deployment::PackageConfiguration& pc,
                   const char* name);

  /// Function to dump the state of the RepositoryManager
  void dump (void);

private:
  /// Cached information about the installed PackageConfigurations
  /// A separate map for the installation names and their UUID's
  /// Key:  PackageConfiguration name or its UUID (CString type)
  /// Value:  The location of the local copy of the package

  ///Based on the synchronization needed we can parametrize this with either
  ///ACE_Null_Mutex or ACE_RW_Mutex

  typedef ACE_Hash_Map_Manager_Ex<ACE_CString,
                                  ACE_CString,
                                  ACE_Hash<ACE_CString>,
                                  ACE_Equal_To<ACE_CString>,
                                  ACE_RW_Mutex> PCMap;

  typedef PCMap::ITERATOR PCMap_Iterator;
  typedef PCMap::ENTRY PCEntry;


  /// Cached information about the installed Component Interfaces
  /// A map which associates Component supportedType with the
  /// names of packages which implement this component type
  /// Key:  Component supportedType
  /// Value:  Unbounded set of the names of installed packages which
  ///      implement this component type

  ///Based on the synchronization needed we can parametrize this with either
  ///ACE_Null_Mutex or ACE_RW_Mutex

  typedef ACE_Hash_Multi_Map_Manager<ACE_CString,
                                     ACE_CString,
                                     ACE_Hash<ACE_CString>,
                                     ACE_Equal_To<ACE_CString>,
                                     ACE_RW_Mutex> CIMap;

  typedef CIMap::ITERATOR CIMap_Iterator;
  typedef CIMap::ENTRY CIEntry;
  typedef CIEntry::VALUE_SET CISet;
  typedef CIEntry::VALUE_SET_ITERATOR CISet_Iterator;

  /// A hash map that associates the names of
  /// PackageConfigurations with their location
  PCMap names_;

  /// a hash map that associates the UUIDs of
  /// PackageConfigurations with their location
  PCMap uuids_;

  /// a hash map which associates Component Interface
  /// UUIDs with their implementations
  CIMap types_;

  /// The ORB
  CORBA::ORB_var the_orb_;

  /// Will hold the current working directory
  char cwd_ [TEMP_LEN];

  /// Full path for the install directory
  ACE_CString install_root_;

  /// Location of the server
  ACE_CString HTTP_server_;

  /// Directory where the packages will be stored locally
  ACE_CString install_path;
};

#endif /* REPOSITORYMANAGER_H_  */