summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Log/Iterator_i.cpp
blob: 1a241795c865bef9be1b256633d4d9a7814b81a1 (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
// $Id$

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

Iterator_i::Iterator_i (LogRecordStore::LOG_RECORD_STORE &store,
                        CORBA::ULong start,
                        const char *constraint,
                        CORBA::ULong max_store_size,
                        CORBA::ULong max_rec_list_len
                        )
  :iter_ (store),
   constraint_ (constraint),
   max_store_size_ (max_store_size),
   max_rec_list_len_ (max_rec_list_len)
{
  // Advance the iterator to the starting point.
  for (CORBA::ULong i = 0;
       i < start && iter_.advance () != -1;
       ++i)
    {
      ;
    }
}

Iterator_i::~Iterator_i (void)
{
  // Do nothing
}

void
Iterator_i::destroy (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  PortableServer::POA_ptr poa = this->_default_POA (ACE_TRY_ENV);
  ACE_CHECK;

  PortableServer::ObjectId_var oid =
    poa->servant_to_id (this,
                        ACE_TRY_ENV);
  ACE_CHECK;

  // Goodbye cruel world...
  // deactivate from the poa.
  poa->deactivate_object (oid.in (),
                          ACE_TRY_ENV);
  ACE_CHECK;
  return;
}

DsLogAdmin::RecordList*
Iterator_i::get (CORBA::ULong position,
                 CORBA::ULong how_many,
                 CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   DsLogAdmin::InvalidParam))
{
  how_many = how_many ? 0 : 1;

  if (how_many > this->max_rec_list_len_ - position)
    ACE_THROW_RETURN (DsLogAdmin::InvalidParam (), 0);

  CORBA::ULong i = 0;
  // move the iterator to "position"
  for (;
       i < position && iter_.advance () != -1;
       ++i)
    {
      ;
    }

  // 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.

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

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

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

  CORBA::ULong count = 0;

  CORBA::Boolean done = 0;

  for ( i = 0;
        i < how_many && count < this->max_rec_list_len_;
        ++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)
      {
        (*rec_list)[count] = hash_entry->int_id_;
        // copy the log record.
        count++;
      }
    }

  rec_list->length (count);

  if (done == 1)
    {
      // destroy this object..
      this->destroy (ACE_TRY_ENV);
      ACE_CHECK_RETURN (rec_list);
    }

  return rec_list;
}