summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Log/Log_i.cpp
blob: dfd6e3c3b6c523331191b16eeb308c1cde135f91 (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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
// $Id$

#include "orbsvcs/Log/Log_i.h"
#include "orbsvcs/Log/Iterator_i.h"
#include "orbsvcs/Log/Log_Constraint_Interpreter.h"
#include "orbsvcs/Log/Log_Constraint_Visitors.h"

#include "tao/debug.h"

#define QUERY_LANG_SUPPORTED_BY_LOG "TCL"

Log_i::Log_i (DsLogAdmin::LogMgr_ptr factory,
              DsLogAdmin::LogId id,
              DsLogAdmin::LogFullAction log_full_action,
              CORBA::ULongLong max_size,
              ACE_Reactor *reactor)
  : factory_ (DsLogAdmin::LogMgr::_duplicate (factory)),
    log_full_action_ (log_full_action),
    logid_ (id),
    admin_state_ (DsLogAdmin::locked),
    forward_state_ (DsLogAdmin::off),
    op_state_ (DsLogAdmin::disabled),
    reactor_ (reactor),
    recordstore_ (max_size),
    max_rec_list_len_ (LOG_DEFAULT_MAX_REC_LIST_LEN)
{
  avail_status_.off_duty = 0;
  avail_status_.log_full = 0;
}

void
Log_i::init (CORBA::Environment &ACE_TRY_ENV)
{
  if (recordstore_.open () ==-1)
    ACE_THROW (CORBA::UNKNOWN ());

  // enable the log now.
  this->admin_state_ = DsLogAdmin::unlocked;
  this->forward_state_ = DsLogAdmin::on;
  this->op_state_ = DsLogAdmin::enabled;
}

Log_i::~Log_i (void)
{
  recordstore_.close ();
}

DsLogAdmin::LogMgr_ptr
Log_i::my_factory (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return DsLogAdmin::LogMgr::_duplicate (factory_.in ());
}

DsLogAdmin::LogId
Log_i::id (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return logid_;
}

DsLogAdmin::QoSList*
Log_i::get_qos (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  DsLogAdmin::QoSList* ret_val;
  ACE_NEW_THROW_EX (ret_val,
                    DsLogAdmin::QoSList (this->qoslist_),
                    CORBA::NO_MEMORY ());

  return ret_val;
}

void
Log_i::set_qos (const DsLogAdmin::QoSList &qos,
                CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::UnsupportedQoS))
{
  // validate supported properties..
  for (CORBA::ULong i = 0; i < qos.length (); i++)
    {
      DsLogAdmin::QoSType qostype = qos[i];
      if (qostype == DsLogAdmin::QoSFlush ||
          qostype == DsLogAdmin::QoSReliability)
        {
          DsLogAdmin::QoSList denied;
          denied._allocate_buffer (2);
          denied.length (0);

          denied[0] = DsLogAdmin::QoSFlush;
          denied[1] = DsLogAdmin::QoSReliability;

          ACE_THROW (DsLogAdmin::UnsupportedQoS (denied));
        }
    }

  // store this list.
  this->qoslist_ = qos;
}

CORBA::ULong
Log_i::get_max_record_life (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return max_record_life_;
}

void
Log_i::set_max_record_life (CORBA::ULong life,
                            CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // life is in seconds.
  // @@ TODO: Need to iterate over all records in storage to timeout all
  // those outside the lifetime....
  max_record_life_ = life;
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

CORBA::ULongLong
Log_i::get_max_size (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return recordstore_.get_max_size ();
}

void
Log_i::set_max_size (CORBA::ULongLong size,
                     CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidParam))
{
  // size == 0 => infinite size.
  if (size == 0)
    {
      this->recordstore_.set_max_size (size);
    }
  else
    if (size < this->recordstore_.get_current_size ())
      {
        ACE_THROW (DsLogAdmin::InvalidParam ());
      }
    else
      this->recordstore_.set_max_size (size);
}

CORBA::ULongLong
Log_i::get_current_size (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return this->recordstore_.get_current_size ();
}

CORBA::ULongLong
Log_i::get_n_records (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return this->recordstore_.get_n_records ();
}

DsLogAdmin::LogFullAction
Log_i::get_log_full_action (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return log_full_action_;
}

void
Log_i::set_log_full_action (DsLogAdmin::LogFullAction action,
                            CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  log_full_action_ = action;
}

DsLogAdmin::AdministrativeState
Log_i::get_administrative_state (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return admin_state_;
}

void
Log_i::set_administrative_state (DsLogAdmin::AdministrativeState state,
                                 CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->admin_state_ = state;
}

DsLogAdmin::ForwardingState
Log_i::get_forwarding_state (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return this->forward_state_;
}

void
Log_i::set_forwarding_state (DsLogAdmin::ForwardingState state,
                             CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  this->forward_state_ = state;
}

DsLogAdmin::OperationalState
Log_i::get_operational_state (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return this->op_state_;
}

DsLogAdmin::TimeInterval
Log_i::get_interval (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return this->interval_;
}

void
Log_i::set_interval (const DsLogAdmin::TimeInterval &interval,
                     CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidTime,
                   DsLogAdmin::InvalidTimeInterval))
{
  //@@ TODO: validate the time.
  //         modify the timer settings to the new values.
  this->interval_ = interval;
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

DsLogAdmin::AvailabilityStatus
Log_i::get_availability_status (CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // TODO:
  // "on duty" => "enabled" AND "unlocked" AND current time within log
  // duration time AND current time within log scheduling times.
  if (this->op_state_ == DsLogAdmin::enabled
      && this->admin_state_ == DsLogAdmin::unlocked
      && this->scheduled () == 1)
    {
      this->avail_status_.off_duty = 0; // "on duty"
    }
  // The log_full flag is set by the write operations.
  return this->avail_status_;
}

DsLogAdmin::CapacityAlarmThresholdList*
Log_i::get_capacity_alarm_thresholds (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  DsLogAdmin::CapacityAlarmThresholdList* ret_val;
  ACE_NEW_THROW_EX (ret_val,
                     DsLogAdmin::CapacityAlarmThresholdList (this->thresholds_),
                     CORBA::NO_MEMORY ());
  ACE_CHECK_RETURN (0);

  return ret_val;
}

void
Log_i::set_capacity_alarm_thresholds (const
                                      DsLogAdmin::CapacityAlarmThresholdList
                                      &threshs,
                                      CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidThreshold))
{
  // @@ TODO: validate thresholds
  //          How do we implement thresholds in DsLogAdmin !?
  //          According to the spec, the log must "notify" when threshold
  //          conditions are reached.we need to be an Event Channel to do that.  //          now what!?
  this->thresholds_ = threshs;
}

DsLogAdmin::WeekMask*
Log_i::get_week_mask (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  DsLogAdmin::WeekMask* ret_val;
  ACE_NEW_THROW_EX (ret_val,
                    DsLogAdmin::WeekMask (this->weekmask_),
                    CORBA::NO_MEMORY ());
  ACE_CHECK_RETURN (0);

  return ret_val;
}

void
Log_i::set_week_mask (const DsLogAdmin::WeekMask &masks,
                      CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidTime,
                   DsLogAdmin::InvalidTimeInterval,
                   DsLogAdmin::InvalidMask))
{
  // @@ TODO: validate masks.
  //           Activate various timers to trigger appropriate acition.
  this->weekmask_ = masks;
}

DsLogAdmin::RecordList*
Log_i::query_i (const char *constraint,
                DsLogAdmin::Iterator_out &iter_out,
                CORBA::ULong how_many,
                CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidConstraint))
{
  // Use an Interpreter to build an expression tree.
  TAO_Log_Constraint_Interpreter interpreter (constraint,
                                              ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  // Sequentially iterate over all the records and pick the ones that
  // meet the constraints.

  // get the underlying storage.
  LogRecordStore::LOG_RECORD_STORE &store =
    this->recordstore_.get_storage ();

  // Create an iterator
  LogRecordStore::LOG_RECORD_HASH_MAP_ITER iter (store);

  CORBA::ULong len = store.current_size ();
  // How many entries?

  // Iterate over and populate the list.
  LogRecordStore::LOG_RECORD_HASH_MAP_ENTRY *hash_entry;

  DsLogAdmin::RecordList* rec_list;
  // Figure out the length of the list.

  // Allocate the list of <how_many> length.
  ACE_NEW_THROW_EX (rec_list,
                    DsLogAdmin::RecordList (how_many),
                    CORBA::NO_MEMORY ());
  ACE_CHECK_RETURN (0);

  CORBA::ULong count = 0; // count of matches found.
  CORBA::Boolean done = 0; // flag to end "for" operation.
  CORBA::ULong i = 0;
  for (;
       i < len && count < how_many;
       ++i)
    {
      if (iter.next (hash_entry) == -1 || iter.advance () == -1)
        {
          done = 1;
          break;
        }

      // Use an evaluator.
      TAO_Log_Constraint_Evaluator evaluator (hash_entry->int_id_);

      // Does it match the constraint?
      if (interpreter.evaluate (evaluator) == 1)
      {
        if (TAO_debug_level > 0)
          #if defined (ACE_LACKS_LONGLONG_T)
               ACE_DEBUG ((LM_DEBUG,"Matched constraint! d = %Q, Time = %Q\n",
                      ACE_U64_TO_U32 (hash_entry->int_id_.id),
                      ACE_U64_TO_U32 (hash_entry->int_id_.time)));

          #else
               ACE_DEBUG ((LM_DEBUG,"Matched constraint! d = %Q, Time = %Q\n",
                      hash_entry->int_id_.id,
                      hash_entry->int_id_.time));
          #endif

        (*rec_list)[count] = hash_entry->int_id_;
        // copy the log record.
        count++;
      }
    }

  rec_list->length (count);

  if (i < len && done == 0) // There are more records to process.
    {
      // Create an iterator to pass out.
      Iterator_i *iter_query = 0;
      ACE_NEW_THROW_EX (iter_query,
                        Iterator_i (store,
                                    i,
                                    constraint,
                                    len,
                                    how_many),
                        CORBA::NO_MEMORY ());
      ACE_CHECK_RETURN (rec_list);

      // Activate it.
      iter_out = iter_query->_this (ACE_TRY_ENV);
      ACE_CHECK_RETURN (rec_list);

      // Give ownership to the POA.
      this->_remove_ref (ACE_TRY_ENV);
      ACE_CHECK_RETURN (rec_list);
    }

  return rec_list;
}

DsLogAdmin::RecordList*
Log_i::query (const char *grammar,
              const char *constraint,
              DsLogAdmin::Iterator_out iter_out,
              CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidGrammar,
                   DsLogAdmin::InvalidConstraint))
{
  this->check_grammar (grammar, ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  DsLogAdmin::RecordList* rec_list =
    this->query_i (constraint,
                   iter_out,
                   this->max_rec_list_len_,
                   ACE_TRY_ENV);
  ACE_CHECK_RETURN (rec_list);

  return rec_list;
}

DsLogAdmin::RecordList*
Log_i::retrieve (DsLogAdmin::TimeT from_time,
                 CORBA::Long how_many,
                 DsLogAdmin::Iterator_out iter_out,
                 CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // Decide between forward vs backward retrieval.
  char constraint[32];
  char uint64_formating[32];

  #if defined (ACE_LACKS_LONGLONG_T)
         ACE_OS::sprintf (uint64_formating,
                   ACE_UINT64_FORMAT_SPECIFIER, ACE_U64_TO_U32 (from_time));
  #else
         ACE_OS::sprintf (uint64_formating,
                   ACE_UINT64_FORMAT_SPECIFIER, from_time);
  #endif

  if (how_many >= 0)
    ACE_OS::sprintf (constraint, "time >= %s", uint64_formating);
  else
    ACE_OS::sprintf (constraint, "time < %s", uint64_formating);

  DsLogAdmin::RecordList* rec_list =
    this->query_i (constraint,
                   iter_out,
                   how_many,
                   ACE_TRY_ENV);
  ACE_CHECK_RETURN (rec_list);

  return rec_list;
}

CORBA::ULong
Log_i::match_i (const char *constraint,
                CORBA::Boolean delete_rec,
                CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidConstraint))
{
  // Use an Interpreter to build an expression tree.
  TAO_Log_Constraint_Interpreter interpreter (constraint,
                                              ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  // Get the underlying storage.
  LogRecordStore::LOG_RECORD_STORE &store =
    this->recordstore_.get_storage ();

  // Create an iterator
  LogRecordStore::LOG_RECORD_STORE_ITER iter (store);

  CORBA::ULong len = store.current_size ();
  // How many entries?

  // Iterate over and populate the list.
  LogRecordStore::LOG_RECORD_HASH_MAP_ENTRY *hash_entry;

  CORBA::ULong count = 0; // count of matches found.

  for (CORBA::ULong i = 0; i < len; ++i)
    {
      if (iter.next (hash_entry) == -1 || iter.advance () == -1)
        {
          break;
        }
      // Use an evaluator.
      TAO_Log_Constraint_Evaluator evaluator (hash_entry->int_id_);

      // Does it match the constraint?
      if (interpreter.evaluate (evaluator) == 1)
      {
        if (delete_rec == 1)
          {
            if (this->recordstore_.remove (hash_entry->int_id_.id) == 0)
              count++;
          }
        else
          count++;
      }
    }

  return count;
}

CORBA::ULong
Log_i::match (const char* grammar,
              const char *constraint,
              CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidGrammar,
                   DsLogAdmin::InvalidConstraint))
{
  this->check_grammar (grammar, ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  CORBA::ULong count =
    this->match_i (constraint, 0, ACE_TRY_ENV);
  ACE_CHECK_RETURN (count);

  return count;
}

CORBA::ULong
Log_i::delete_records (const char *grammar,
                       const char *constraint,
                       CORBA::Environment &ACE_TRY_ENV)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     DsLogAdmin::InvalidGrammar,
                     DsLogAdmin::InvalidConstraint))
{
  this->check_grammar (grammar, ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  CORBA::ULong count =
    this->match_i (constraint, 1, ACE_TRY_ENV);
  ACE_CHECK_RETURN (count);

  return count;
}

CORBA::ULong
Log_i::delete_records_by_id (const
                             DsLogAdmin::RecordIdList &ids,
                             CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  CORBA::ULong numdone (0);

  for (CORBA::ULong i = 0; i < ids.length (); i++)
    {
      if (this->recordstore_.remove (ids [i]) == 0)
        {
          numdone++;
        }
    }

  return numdone;
}

void
Log_i::write_records (const DsLogAdmin::Anys &records,
                      CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::LogFull,
                   DsLogAdmin::LogLocked))
{
  // create a record list..
  DsLogAdmin::RecordList reclist (records.length ());
  reclist.length (records.length ());

  for (CORBA::ULong i = 0; i < records.length (); i++)
    {
      reclist [i].info = records[i];
    }

  this->write_recordlist (reclist, ACE_TRY_ENV);
  ACE_CHECK;
}

void
Log_i::write_recordlist (const DsLogAdmin::RecordList &reclist,
                         CORBA::Environment &ACE_TRY_ENV)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     DsLogAdmin::LogFull,
                     DsLogAdmin::LogLocked))
{
  // Check the operational status.
  if (this->op_state_ == DsLogAdmin::disabled)
    return; // return without a squeak.

  // Check if the log is on duty
  // @@ Wait for Comittee ruling on the proper behavior
  DsLogAdmin::AvailabilityStatus avail_stat =
    this->get_availability_status (ACE_TRY_ENV);
  ACE_CHECK;

  if (avail_stat.off_duty == 1)
    {
      // why are we off duty? investigate ...
      // Check if the log is full.
      if (avail_stat.log_full == 1)
        ACE_THROW (DsLogAdmin::LogFull (0));
      else   // Check the administrative state.
        if (this->admin_state_ == DsLogAdmin::locked)
          ACE_THROW (DsLogAdmin::LogLocked ());
        else
          return; // we are not scheduled at this time.
    }

  CORBA::Short num_written (0);
  DsLogAdmin::LogRecord record;

  for (CORBA::ULong i = 0; i < reclist.length (); i++)
    {
      // Check if the log is full.
      if (avail_status_.log_full == 1)
        {
          ACE_THROW (DsLogAdmin::LogFull (num_written));
        }
      else
        {
          // retval == 1 => log store reached max size.
          record = reclist[i]; // can't avoid this copy, reclist is const.
          int retval = this->recordstore_.log (record);
          if (retval == 1)
            {
              // The Log is full . check what the policy is
              // and take appropriate action.
              if (this->log_full_action_ == DsLogAdmin::halt)
                avail_status_.log_full = 1;
              else // the policy is to wrap. for this we need to delete
                // a few records. let the record store decide how many.
                if (this->recordstore_.purge_old_records () == -1)
                  ACE_THROW (CORBA::PERSIST_STORE ());

              // Now, we want to attempt to write the same record again
              // so decrement the index to balance the inc. in the for loop.
              --i;
            }
          else
            if (retval == 0)
              num_written++;
            else
              ACE_THROW (CORBA::PERSIST_STORE ());
        } // else

      this->check_threshold_list ();
    } // for
}

void
Log_i::set_record_attribute (DsLogAdmin::RecordId id,
                             const DsLogAdmin::NVList &attr_list,
                             CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidRecordId,
                   DsLogAdmin::InvalidAttribute))
{
  // TODO: validate attributes here.

  DsLogAdmin::LogRecord rec;
  if (this->recordstore_.retrieve (id, rec) == -1)
    {
      ACE_THROW (DsLogAdmin::InvalidRecordId ());
    }

  rec.attr_list = attr_list;

  if (this->recordstore_.update (rec) == -1)
    {
      ACE_THROW (CORBA::PERSIST_STORE ());
    }
}

CORBA::ULong
Log_i::set_records_attribute (const char *grammar,
                              const char *constraint,
                              const DsLogAdmin::NVList
                              &attr_list, CORBA::Environment &ACE_TRY_ENV)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     DsLogAdmin::InvalidGrammar,
                     DsLogAdmin::InvalidConstraint,
                     DsLogAdmin::InvalidAttribute))
{
  ACE_UNUSED_ARG (grammar);
  ACE_UNUSED_ARG (constraint);
  ACE_UNUSED_ARG (attr_list);

  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
}

DsLogAdmin::NVList*
Log_i::get_record_attribute (DsLogAdmin::RecordId id,
                             CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidRecordId))
{
  DsLogAdmin::LogRecord rec;
  if (this->recordstore_.retrieve (id, rec) == -1)
    {
      ACE_THROW_RETURN(DsLogAdmin::InvalidRecordId (),
                       0);
    }

  DsLogAdmin::NVList* nvlist;
  ACE_NEW_THROW_EX (nvlist,
                    DsLogAdmin::NVList (rec.attr_list),
                    CORBA::NO_MEMORY ());
  ACE_CHECK_RETURN (0);

  return nvlist;
}

// @@ These two methods are non-trivial. Let's hold off on them for a while
DsLogAdmin::Log_ptr
Log_i::copy (DsLogAdmin::LogId_out id,
             CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_UNUSED_ARG (id);
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
}

DsLogAdmin::Log_ptr
Log_i::copy_with_id (DsLogAdmin::LogId id,
                     CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::LogIdAlreadyExists))
{
  ACE_UNUSED_ARG (id);
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
}

// @@ Should I just raise the exception?
void
Log_i::flush (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                     DsLogAdmin::UnsupportedQoS))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
  // @@ Perhaps later use a MMAP_Memory_Pool as the backing store, and
  // just have this map to its sync method
}

void
Log_i::check_threshold_list (void)
{
  // TBD: Anyways we can't notify from DsLogAdmin.
  //      Finish this when we use the CosEC.
  return;
}

CORBA::Boolean
Log_i::scheduled (void)
{
  // TBD: lie for now.
  return 1;
}

void
Log_i::check_grammar (const char* grammar,
                      CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidGrammar))
{
  // Verify that the grammar is "TCL".
  // The spec. asks for "extended TCL"
  if (ACE_OS::strcmp (grammar, QUERY_LANG_SUPPORTED_BY_LOG) != 0)
    ACE_THROW (DsLogAdmin::InvalidGrammar ());
}