summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Property/CosPropertyService_i.cpp
blob: c116c4ff1d0444e494cc0826048d85e923b366ec (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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
// $Id$
// 
// ============================================================================
//
// = LIBRARY
//    cos
//
// = FILENAME
//   CosPropertyService_i.cpp
//
// = AUTHOR
//    Alexander Babu Arulanthu <alex@cs.wustl.edu>
//
// ============================================================================

#include "CosPropertyService_i.h"

TAO_PropertySetFactory::TAO_PropertySetFactory (void)
{
}

CosPropertyService::PropertySet_ptr
TAO_PropertySetFactory::create_propertyset (CORBA::Environment &env) 
{
  CosPropertyService::PropertySet_ptr return_val = 0;
  
  return return_val;
}

CosPropertyService::PropertySet_ptr
TAO_PropertySetFactory::create_constrained_propertyset (const CosPropertyService::PropertyTypes &allowed_property_types, 
                                                        const CosPropertyService::Properties &allowed_properties, 
                                                        CORBA::Environment &env)
{
  CosPropertyService::PropertySet_ptr return_val = 0;

  return return_val;
}  

CosPropertyService::PropertySet_ptr 
TAO_PropertySetFactory::create_initial_propertyset (const CosPropertyService::Properties &initial_properties, 
                                                    CORBA::Environment &env) 
{
  CosPropertyService::PropertySet_ptr return_val = 0;

  return return_val;
}

TAO_PropertySetFactory::~TAO_PropertySetFactory (void)
{
}

TAO_PropertySetDefFactory::TAO_PropertySetDefFactory (void)
{
}

TAO_PropertySetDefFactory::~TAO_PropertySetDefFactory (void)
{
}
  
CosPropertyService::PropertySetDef_ptr 
TAO_PropertySetDefFactory::create_propertysetdef ( CORBA::Environment &env)
{
  CosPropertyService::PropertySetDef_ptr return_val = 0;
  
  return return_val;
}  

CosPropertyService::PropertySetDef_ptr 
TAO_PropertySetDefFactory::create_constrained_propertysetdef (const CosPropertyService::PropertyTypes &allowed_property_types, 
                                                             const CosPropertyService::PropertyDefs &allowed_property_defs, 
                                                             CORBA::Environment &env)
{
  CosPropertyService::PropertySetDef_ptr return_val = 0;
  
  return return_val;
}

CosPropertyService::PropertySetDef_ptr  
TAO_PropertySetDefFactory::create_initial_propertysetdef (const CosPropertyService::PropertyDefs &initial_property_defs,
                                                          CORBA::Environment &env)
{
  CosPropertyService::PropertySetDef_ptr return_val = 0;

  return return_val;
}

// Makes default sized hash_table_.
TAO_PropertySet::TAO_PropertySet (void)
{
  ACE_DEBUG ((LM_DEBUG,
              "TAO_PropertySet Constructor-Hash_Map_Manager created::  CurntSize : %d , TotalSize : %d \n",
              this->hash_table_.current_size (),
              this->hash_table_.total_size ()));
}

// Destructor.
TAO_PropertySet::~TAO_PropertySet (void)
{
}

// Function to modify or add a property to the PropertySet  
// alex: Just adds the name value to the set... Doesn't check for
// Typecode overwriting, duplicate names, void names etc, yet.
// @@ Using  Normal mode as the default mode of properties, I need to
// change this based on the Initial set of allowed modes, if there is
// anything like that set by the client.
void 
TAO_PropertySet::define_property (const char *property_name,
                                  const CORBA::Any &property_value,
                                  CORBA::Environment &env)
{
  CosProperty_Hash_Key hash_key (property_name);
  CosProperty_Hash_Value hash_value (property_value,
                                     CosPropertyService::normal); 
  
  ACE_DEBUG ((LM_DEBUG,
              "define_property : property_name %s \n",
              property_name));
  
  int ret = this->hash_table_.bind (hash_key, hash_value);
  
  if (ret == 0)
    ACE_DEBUG ((LM_DEBUG,
                "define_property: retval : %d \n",
                ret));
}

// Defining a sequence of properties ( Need to check for overwriting,
// duplicate names, void names etc.
void 
TAO_PropertySet::define_properties (const CosPropertyService::Properties &nproperties,
                                    CORBA::Environment &env)
{
  for (int pi = 0; pi < nproperties.length (); pi++) 
    {
      this->define_property (nproperties [pi].property_name.in (),
                             nproperties [pi].property_value,
                             env);
    }
}

// Returns the current number of properties associated with this
// PropertySet.
CORBA::ULong 
TAO_PropertySet::get_number_of_properties ( CORBA::Environment &env)
{
  return this->hash_table_.current_size ();
}

//  Returns all of the property names currently defined in the
//  PropertySet. If the PropertySet contains more than how_many
//  property names, then the remaining property names are put into the
//  PropertyNamesIterator.
void
TAO_PropertySet::get_all_property_names (CORBA::ULong how_many, 
                                         CosPropertyService::PropertyNames_out property_names, 
                                         CosPropertyService::PropertyNamesIterator_out rest,
                                         CORBA::Environment &env)
{
  size_t num_of_properties = get_number_of_properties (env);
  if (num_of_properties == 0)
    // Nothing to do.
    return;
  // Set the length of the property_names appropriately.
  if (how_many > 0)
    {
      property_names = new CosPropertyService::PropertyNames;
      property_names->length ((how_many >= num_of_properties) ? 
                              num_of_properties : how_many);
    }
  // Iterate thru names and put them in the property_names.
  CosProperty_Hash_Entry_ptr entry_ptr;
  CosProperty_Hash_Iterator iterator (this->hash_table_);
  for (int ni = 0;
       ni < property_names->length ();
       ni++, iterator.advance ())
    if (iterator.next (entry_ptr) != 0)
      property_names [ni] = CORBA::string_dup (entry_ptr->ext_id_.pname_);
  
  // If there are some more properties, put them in the
  // iterator. How?? Make a new PropertSet and use that to create 
  // propertyNames Iterator.
  if (num_of_properties > how_many)
    {
      TAO_PropertySet *property_set = new TAO_PropertySet;
      for (size_t i = how_many;
           i < num_of_properties;
           i++, iterator.advance ())
        if (iterator.next (entry_ptr) != 0) 
          if (property_set->hash_table_.bind (entry_ptr->ext_id_,
                                              entry_ptr->int_id_) < 0)
            ACE_DEBUG ((LM_DEBUG, "Err: get_all_property_names\n"));
      // Make the NamesIterator out of this TAO_PropertySet.
      TAO_PropertyNamesIterator *names_iterator = new TAO_PropertyNamesIterator (*property_set);
      rest = CosPropertyService::PropertyNamesIterator::_duplicate (names_iterator->_this (env));
    }
}      

// Returns the value of a property in the PropertySet.
CORBA::Any * 
TAO_PropertySet::get_property_value (const char *property_name,
                                     CORBA::Environment &env)
{
  CosProperty_Hash_Key hash_key (CORBA::string_copy (property_name));
  CosProperty_Hash_Value hash_value;
  
  ACE_DEBUG ((LM_DEBUG, "get_prop_value: hash_key.pname_.in () : %s \n",
              hash_key.pname_.in ()));
  if (this->hash_table_.find (hash_key, hash_value) != 0) 
    ACE_ERROR ((LM_ERROR, "Find failed: \n"));
  else
    ACE_DEBUG ((LM_DEBUG, "Find succeeded \n"));
  return hash_value.pvalue_._retn ();
}

// Returns the values of the properties listed in property_names. When
// the boolean flag is true, the Properties parameter contains valid
// values for all requested property names. If false, then all
// properties with a value of type tk_void may have failed due to
// PropertyNotFound or InvalidPropertyName.
// A separate invocation of get_property for each such property name
// is necessary to determine the specific exception or to verify that
// tk_void is the correct any TypeCode for that property name. This
// approach was taken to avoid a complex, hard to program structure to
// carry mixed results. 
CORBA::Boolean
TAO_PropertySet::get_properties (const CosPropertyService::PropertyNames &property_names,
                                 CosPropertyService::Properties_out nproperties,
                                 CORBA::Environment &env)
{
  size_t n = property_names.length ();
  if (n == 0)
    return CORBA::B_FALSE;
  CORBA::Any_ptr any_ptr = 0;
  nproperties = new CosPropertyService::Properties;
  nproperties->length (n);
  CORBA::Boolean ret_val = CORBA::B_TRUE;
  for (size_t i = 0;  i < n; i++)
    if ((any_ptr = get_property_value (property_names [i], env)) != 0)
      { 
        // Property name is valid.
        nproperties [i].property_name = CORBA::string_dup (property_names [i]);
        nproperties [i].property_value = *any_ptr;
      }
    else 
      { 
        // Invalid name. Ret value is False. 
        ret_val = CORBA::B_FALSE;
        nproperties [i].property_name = CORBA::string_dup (property_names [i]);
        //nproperties [i].property_value = CORBA::tk_void;
      }
  return ret_val;
}

void 
TAO_PropertySet::get_all_properties (CORBA::ULong how_many,
                                     CosPropertyService::Properties_out nproperties, 
                                     CosPropertyService::PropertiesIterator_out rest,
                                     CORBA::Environment &env)
{
  size_t num_of_properties = hash_table_.current_size ();
  if (num_of_properties == 0)
    return;
  // Alloc memory for nproperties if how_many > 0.
  if (how_many > 0)
    {
      nproperties= new CosPropertyService::Properties;
      nproperties->length ((how_many >= num_of_properties) ? num_of_properties : how_many);
    }
  // Prepare an iterator and iterate thru the PropertySet. Retrive the
  // values.
  CosProperty_Hash_Iterator iterator (this->hash_table_);
  CosProperty_Hash_Entry_ptr entry_ptr = 0;
  for (size_t i = 0; i < nproperties->length (); i++, iterator.advance ())
    if (iterator.next (entry_ptr) != 0)
      {
        nproperties[i].property_name = CORBA::string_dup (entry_ptr->ext_id_.pname_);
        nproperties[i].property_value = entry_ptr->int_id_.pvalue_.in ();
      }

  // If there are more properties, put them in the PropertiesIterator.
  // Make a new TAO_PropertySet and use that to create an Properties
  // iterator.  put that in a iterator and assign that to the out
  // paramerter. 
  if (num_of_properties > how_many) 
    {
      TAO_PropertySet *prop_set = new TAO_PropertySet;
      for (size_t i = how_many; i < num_of_properties; i++, iterator.advance ())
        if (iterator.next (entry_ptr) != 0) 
          if (prop_set->hash_table_.bind (entry_ptr->ext_id_,
                                          entry_ptr->int_id_) < 0)
            ACE_DEBUG ((LM_DEBUG, "Err: get_all_properties\n"));
      // Make the iterator out of the new TAO_Propset.
      TAO_PropertiesIterator *prop_iterator = new TAO_PropertiesIterator (*prop_set);
      rest = CosPropertyService::PropertiesIterator::_duplicate (prop_iterator->_this (env));
    }
}
  
// Deletes the specified property if it exists from a PropertySet.
void 
TAO_PropertySet::delete_property (const char *property_name,
                                  CORBA::Environment &env)
{
  CosProperty_Hash_Key hash_key (CORBA::string_copy (property_name));
  
  ACE_DEBUG ((LM_DEBUG, "delete_property : hash_key.pname_.in() %s \n",
              hash_key.pname_.in()));
  // Doing unbinding.. Not getting CosProperty_Hash_Value
  // back... Problem if dynamic allocation is done.
  // @@ Is memory deallocation done?
  if (this->hash_table_.unbind (hash_key) != 0)
    ACE_ERROR ((LM_ERROR,
                "Unbind failed \n"));
}

// Deletes the properties defined in the property_names
// parameter. This  is a batch operation that returns the
// MultipleExceptions  exception if any delete failed. 
void 
TAO_PropertySet::delete_properties (const CosPropertyService::PropertyNames &property_names,
                                    CORBA::Environment &env)
{
  for (size_t pi = 0; pi < property_names.length (); pi++)
    delete_property (property_names[pi], env);
}

// Delete all the properties in the current ProperySet : Do it one by
// one. close () and then open ().
CORBA::Boolean
TAO_PropertySet::delete_all_properties (CORBA::Environment &env)
{
  if (hash_table_.close () != 0) 
    {
      ACE_DEBUG ((LM_DEBUG, "delete_all_properties:Error Closing the Hash_Map_Manager"));
      return CORBA::B_FALSE;
    }
  if (hash_table_.open () != 0) 
    {
      ACE_DEBUG ((LM_DEBUG, "Could not open Hash_Map_Manager"));
      return CORBA::B_FALSE;
    }
  return CORBA::B_TRUE;
}  

// Returns TRUE if the property is defined in the PropertySet.
CORBA::Boolean
TAO_PropertySet::is_property_defined (const char *property_name,  CORBA::Environment &env)
{
  CosProperty_Hash_Key hash_key (property_name);
  
  if (this->hash_table_.find (hash_key) == 0) 
    {
      ACE_DEBUG ((LM_DEBUG, "is_property_defined :find successfull \n"));
      return CORBA::B_TRUE;
    }
  else
    {
      ACE_DEBUG ((LM_DEBUG, "is_property_defined :find failed \n"));
      return CORBA::B_FALSE;
    }
}  

TAO_PropertySetDef::TAO_PropertySetDef (void)
{
}

TAO_PropertySetDef::~TAO_PropertySetDef (void)
{
}

void 
TAO_PropertySetDef::get_allowed_property_types (CosPropertyService::PropertyTypes_out property_types,
                                                CORBA::Environment &env)
{
}

void 
TAO_PropertySetDef::get_allowed_properties (CosPropertyService::PropertyDefs_out property_defs,
                                            CORBA::Environment &env)
{
}

void 
TAO_PropertySetDef::define_property_with_mode (const char *property_name,
                                               const CORBA::Any &property_value,
                                               CosPropertyService::PropertyModeType property_mode,
                                               CORBA::Environment &env)
{
}  

void 
TAO_PropertySetDef::define_properties_with_modes (const CosPropertyService::PropertyDefs &property_defs,
                                                  CORBA::Environment &env)
{
}

CosPropertyService::PropertyModeType 
TAO_PropertySetDef::get_property_mode (const char *property_name,
                                       CORBA::Environment &env)
{
  CosPropertyService::PropertyModeType return_val = CosPropertyService::undefined;

  return return_val;
}

CORBA::Boolean 
TAO_PropertySetDef::get_property_modes (const CosPropertyService::PropertyNames &property_names,
                                        CosPropertyService::PropertyModes_out property_modes,
                                        CORBA::Environment &env)
{
  CORBA::Boolean return_val = CORBA::B_FALSE;

  return return_val;
}  

void 
TAO_PropertySetDef::set_property_mode (const char *property_name,
                                       CosPropertyService::PropertyModeType property_mode, 
                                       CORBA::Environment &env)
{ 
}

void 
TAO_PropertySetDef::set_property_modes (const CosPropertyService::PropertyModes &property_modes,
                                        CORBA::Environment &env)
{  
}

// Constructor. Construct the iterator from the PropertySet object.
TAO_PropertyNamesIterator::TAO_PropertyNamesIterator (TAO_PropertySet &property_set)
  : iterator_ (property_set.hash_table_)
{
}  

// Destructor.
TAO_PropertyNamesIterator::~TAO_PropertyNamesIterator ()
{
}

// Resets the position in an iterator to the first property name, if
// one exists.
void 
TAO_PropertyNamesIterator::reset (CORBA::Environment &env)
{
  this->iterator_.reset ();
}

// The next_one operation returns true if an item exists at the
// current position in the iterator with an output parameter of a
// property name. A return of false signifies no more items in the iterator.
CORBA::Boolean
TAO_PropertyNamesIterator::next_one (CORBA::String_out property_name,
                                     CORBA::Environment &env)
{
  CosProperty_Hash_Entry_ptr entry_ptr;
  if (this->iterator_.next (entry_ptr) != 0)
    {
      property_name = CORBA::string_copy (entry_ptr->ext_id_.pname_);
      this->iterator_.advance ();
      return CORBA::B_TRUE;
    }
  else
    {
      property_name = 0;
      return CORBA::B_FALSE;
    }
}

CORBA::Boolean
TAO_PropertyNamesIterator::next_n (CORBA::ULong how_many,
                                   CosPropertyService::PropertyNames_out property_names, 
                                   CORBA::Environment &env)
{
  CosProperty_Hash_Entry_ptr entry_ptr = 0;
  if ((this->iterator_.next (entry_ptr) == 0) || (how_many == 0))
    return CORBA::B_FALSE;
  property_names = new CosPropertyService::PropertyNames;
  size_t size = this->iterator_.map().current_size ();
  property_names->length ((how_many <= size) ? how_many : size);
  for (size_t ni = 0;
       ni < property_names->length ();
       ni++, this->iterator_.advance ())
    if (this->iterator_.next (entry_ptr) != 0)
      property_names [ni] = CORBA::string_dup (entry_ptr->ext_id_.pname_);
  return CORBA::B_TRUE;
}

void 
TAO_PropertyNamesIterator::destroy (CORBA::Environment &env)
{    
}

TAO_PropertiesIterator::TAO_PropertiesIterator (TAO_PropertySet &property_set)
  : iterator_ (property_set.hash_table_)
{
}

TAO_PropertiesIterator::~TAO_PropertiesIterator ()
{
}

void 
TAO_PropertiesIterator::reset (CORBA::Environment &env)
{
  this->iterator_.reset ();
}

CORBA::Boolean
TAO_PropertiesIterator::next_one (CosPropertyService::Property_out aproperty,
                                  CORBA::Environment &env)
{   
  CosProperty_Hash_Entry_ptr entry_ptr;
  if (this->iterator_.next (entry_ptr) != 0)
    {
      aproperty = new CosPropertyService::Property ;
      aproperty->property_name = entry_ptr->ext_id_.pname_;
      aproperty->property_value = entry_ptr->int_id_.pvalue_.in ();
      return CORBA::B_TRUE;
    }
  else
    CORBA::B_FALSE;
}  

CORBA::Boolean
TAO_PropertiesIterator::next_n (CORBA::ULong how_many,
                                CosPropertyService::Properties_out nproperties, 
                                CORBA::Environment &env)
{
  CosProperty_Hash_Entry_ptr entry_ptr = 0;
  if ((this->iterator_.next (entry_ptr) == 0) || (how_many == 0))
    return CORBA::B_FALSE;
  nproperties = new CosPropertyService::Properties;
  size_t size = this->iterator_.map ().current_size ();
  nproperties->length ((how_many <= size) ? how_many : size);
  for (size_t ni = 0;
       ni < nproperties->length ();
       ni++,
         this->iterator_.advance ())
    if (this->iterator_.next (entry_ptr) != 0)
      {
        nproperties [ni].property_name = entry_ptr->ext_id_.pname_;
        nproperties [ni].property_value =
          entry_ptr->int_id_.pvalue_.in ();
      }
    else
      // @@ Should be an exception.
      break;
  return CORBA::B_TRUE;
}  

void
TAO_PropertiesIterator::destroy (CORBA::Environment &env)
{
}