summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/RepositoryManager/RepositoryManager_Impl.h
blob: 51648fbe5882675f6ab50d13e615ac515c57f213 (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

/* -*- 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
 * @author Shanshan Jiang <shanshan.jiang@vanderbilt.edu>
 * @author William R. Otte <wotte@dre.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;
}

namespace DAnCE
{
  class RepositoryManagerDaemon_i :
    public virtual POA_CIAO::RepositoryManagerDaemon
  {
  public:
    /// Constructor
    RepositoryManagerDaemon_i (CORBA::ORB_ptr the_orb,
                               const ACE_TCHAR* server = ACE_TEXT("localhost:5432"),
                               const ACE_TCHAR* install_dir = ACE_TEXT("RepositoryManager"));

    /// Destructor
    virtual ~RepositoryManagerDaemon_i (void);

    virtual void shutdown ();

    virtual
    void installPackage (const ACE_TCHAR * installationName,
                         const ACE_TCHAR * location,
                         ::CORBA::Boolean replace);

    virtual
    void createPackage (const ACE_TCHAR * installationName,
                        const ::Deployment::PackageConfiguration & package,
                        const ACE_TCHAR * baseLocation,
                        ::CORBA::Boolean replace);

    virtual
    ::Deployment::PackageConfiguration * findPackageByName (const ACE_TCHAR * name);

    virtual
    ::Deployment::PackageConfiguration * findPackageByUUID (const ACE_TCHAR * UUID);

    virtual
    ::CORBA::StringSeq * findNamesByType (const ACE_TCHAR * type);

    virtual
    ::CORBA::StringSeq * getAllNames ();

    virtual
    ::CORBA::StringSeq * getAllTypes ();

    virtual
    void deletePackage (const ACE_TCHAR * installationName);

  protected:

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

    /// Find out what the name of the PackageConfiguration file is
    void find_PC_name (ACE_TCHAR* 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 ACE_TCHAR* pc_name,
                                                                    const ACE_TCHAR* 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 ACE_TCHAR* 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 (ACE_TCHAR* 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 (ACE_TCHAR* 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 ACE_TCHAR* package_path);

    /// 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 ACE_TCHAR* 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 ACE_TCHAR* name);

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

    /// Function to save the package info of the RepositoryManager
    void save (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
  ACE_TCHAR 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_  */