summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Support.h
blob: c46e04bcd3a53b4974954ca285fac92b19f814e7 (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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file    PG_Properties_Support.h
 *
 *  $Id$
 *
 *  This file declares classes to help manage the PortableGroup::Properties
 *  It serves roughly the same purpose as PG_PropertiesManager, but takes a
 *  different approach that suits the needs of FT CORBA.
 *  It would be possible to replace PG_PropertiesManager, or implement it in
 *  terms of PG_Properties_Support at some time in the future.
 *
 *  @author Dale Wilson <wilson_d@ociweb.com>
 */
//=============================================================================
#ifndef TAO_PG_PROPERTIES_SUPPORT_H
#define TAO_PG_PROPERTIES_SUPPORT_H

#include "PG_Property_Set.h"

namespace TAO
{
  /**
   *  This Properties Support object manages Property Sets (TAO::PG_Property_Set).
   *
   *  One set, default_properties_,
   *  acts as a "global" default set of properties.
   *
   *  The collection, properties_map_, contains a set of properties for each
   *  PortableGroup::type_id.  The default set acts as a "parent" for each of
   *  these type_id sets.
   *
   *  Expected use: When an object group is created that implements the interface
   *  identified by type_id, the corresponding typed_id propery set acts as a
   *  parent to the Property set contained in the PG_Object_Group.
   *
   *  This heirarchy of property sets provides the correct property behavior.  A
   *  request for a propery to an ObjectGroup will be satisfied from:
   *    by the object group group property set, or
   *    the typed_id property set, or
   *    the default property set, or
   *    the request will fail..
   *
   *  Note that changes to type_id or default properties will be visible
   *  immediately at the ObjectGroup level.
   */

  class TAO_PortableGroup_Export PG_Properties_Support
  {
    typedef ACE_Hash_Map_Manager<
      ACE_CString,
      ::TAO::PG_Property_Set *,
      TAO_SYNCH_MUTEX> Properties_Map;
    typedef ACE_Hash_Map_Iterator<
      ACE_CString,
      ::TAO::PG_Property_Set *,
      TAO_SYNCH_MUTEX> Properties_Map_Iterator;

  public:
    PG_Properties_Support ();
    ~PG_Properties_Support ();

    /**
     * Set a single default property.
     * Overwriting any value previously set for that property.
     * Leaving all other properties untouched.
     * @param name the name of the property to set
     * @value an Any containing the value.
     */
    void set_default_property (const char * name,
          const PortableGroup::Value & value
          ACE_ENV_ARG_DECL)
        ACE_THROW_SPEC ((CORBA::SystemException));

    /**
     * Update the default property set.
     *
     * Properties that appear in props are replaced in or added to the default
     * property set.  Properties that do not appear in props are unchanged.
     *
     * @param props the set of properties to update the defaults.
     */
    void set_default_properties (const PortableGroup::Properties & props);

    /**
     * Export the default properties in PortableGroup::Properties format.
     *
     * This produces the properties in a format suitable for use across
     * a CORBA interface.
     * The caller owns the resulting Properties and must release it to avoid
     * resource leaks.
     * @returns a newly allocated PortableGroup::Properties.
     */
    PortableGroup::Properties * get_default_properties (ACE_ENV_SINGLE_ARG_DECL)
      ACE_THROW_SPEC ( (CORBA::SystemException,
                   PortableGroup::InvalidProperty,
                   PortableGroup::UnsupportedProperty));

    /**
     * Undefine default properties that appear in props.
     *
     * Properties that are defined in props are removed from the default
     * property set.  Removal is done by name.  The property values do not
     * have to match.  There is no penalty for attempting to remove a property
     * that does not exist.
     * @param props a set of propertys to be removed by name.
     */
    void remove_default_properties (
        const PortableGroup::Properties & props
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /**
     * Override or define properties associated with a type_id.
     *
     * If a property set does not exist for type_id, a new one will be created.
     * Any property included in overrides will be set or replaced in the type_id
     * property set.  Any property not in overrides will be unchanged.
     *
     * Contrary to the "throws" specification, this method does not attempt
     * to validate the properties because doing so would unnecessarily constrain
     * the uses to which this class could be put (although one could strategize the
     * validation.)
     */
    void set_type_properties (
        const char *type_id,
        const PortableGroup::Properties & overrides
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ((
        CORBA::SystemException,
        PortableGroup::InvalidProperty,
        PortableGroup::UnsupportedProperty));

    /**
     * Export the property set in a PortableGroup::Properties format.
     *
     * This produces the properties associated with a type_id -- including
     * any default properties that have not been overridden at the type_id level
     * in a format suitable for use across a CORBA interface.
     *
     * The caller owns the resulting Properties and must release it to avoid
     * resource leaks.
     *
     * Compare this method to find_typeid_properties which returns a pointer
     * to the internal representation of the properties in TAO::PG_Property_Set
     * format.  This is more efficient, but suitable only for internal use.
     *
     * @param type_id identifies the set of properties to be exported.
     * @returns a newly allocated PortableGroup::Properties that must be released by the caller.
     */
    PortableGroup::Properties * get_type_properties (
        const char *type_id
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ( (CORBA::SystemException));

    /**
     * Export the property set in a PortableGroup::Properties format.
     *
     * This method is intended to provide a parent
     * for the property set in a newly-created Object Group of the given
     * type_id.
     *
     * Callers who intend to send the property set across a CORBA interface
     * should use the get_type_properties method.
     *
     * @param type_id identifies the set of properties to be found.
     * @returns a pointer to a Property_Set owned by this Properties_Support object.
     */
    TAO::PG_Property_Set *  TAO::PG_Properties_Support::find_typeid_properties (
        const char *type_id
        ACE_ENV_ARG_PARAMETER)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /**
     * Undefine default properties that appear in props.
     *
     * Properties that are defined in props are removed from the type_id
     * property set.  Removal is done by name.  The property values do not
     * have to match.  There is no penalty for attempting to remove a property
     * that does not exist.
     * @param props a set of propertys to be removed by name from the type_id set.
     */
    void remove_type_properties (
        const char *type_id,
        const PortableGroup::Properties & props
        ACE_ENV_ARG_DECL)
      ACE_THROW_SPEC ( (CORBA::SystemException));

    ///////////////
    // Data Members
  private:
    /**
     * Protect internal state.
     */
    TAO_SYNCH_MUTEX internals_;
    typedef ACE_Guard<TAO_SYNCH_MUTEX> InternalGuard;

    /// The default property set.
    TAO::PG_Property_Set default_properties_;

    /// A collection of property sets indexed by type_id.
    Properties_Map properties_map_;
  };
} //namespace TAO_PG

#endif // TAO_PG_PROPERTIES_SUPPORT_H