summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Iterator.cpp
blob: abe512064a6e0431ddd64ce0ad9038ea92dab3b5 (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
//=============================================================================
/**
 *  @file   Iterator.cpp
 *
 *  $Id$
 *
 *  @brief  This file declares ImR's iterator.
 *
 *  @author Darrell Brunsch <brunsch@cs.wustl.edu>
 */
//=============================================================================

#include "Iterator.h"


ImR_AsyncIterator::ImR_AsyncIterator (CORBA::ULong start,
                                      AsyncListManager *lister)
  :count_ (start),
   lister_ (lister->_add_ref ())
{
}

void
ImR_AsyncIterator::next_n
  (ImplementationRepository::AMH_ServerInformationIteratorResponseHandler_ptr _tao_rh,
   CORBA::ULong how_many)
{
  this->count_ = this->lister_->list (_tao_rh, this->count_, how_many);
}

void
ImR_AsyncIterator::destroy
  (ImplementationRepository::AMH_ServerInformationIteratorResponseHandler_ptr _tao_rh)
{
  PortableServer::POA_var poa = this->lister_->poa ();
  PortableServer::ObjectId_var oid = poa->servant_to_id (this);
  poa->deactivate_object (oid.in());
  _tao_rh->destroy ();
}

//----------------------------------------------------------------------------
ImR_Iterator::ImR_Iterator (CORBA::ULong n,
                            Locator_Repository& repo,
                            PortableServer::POA_ptr poa)
  : repo_(repo)
  , count_(n)
  , poa_(poa)
{
}


CORBA::Boolean
ImR_Iterator::next_n (CORBA::ULong how_many,
                      ImplementationRepository::ServerInformationList_out server_list)
{
  ACE_NEW_THROW_EX (server_list,
    ImplementationRepository::ServerInformationList(0), CORBA::NO_MEMORY());

  Locator_Repository::SIMap::ENTRY* entry = 0;
  Locator_Repository::SIMap::ITERATOR it (this->repo_.servers ());

  // Number of servers that will go into the server_list.
  CORBA::ULong n = this->repo_.servers().current_size();
  if (n <= this->count_)
    {
      return 0; // We already finished.
    }
  else
    {
      n -= this->count_;
    }

  if (how_many > 0 && n > how_many)
    {
      n = how_many;
  }

  server_list->length (n);

  CORBA::ULong i = 0;
  for (; i < this->count_; ++i)
    {
      it.advance ();
    }

  for (i = 0; i < n; ++i)
    {
      it.next (entry);
      it.advance ();
      ACE_ASSERT(entry != 0);

      Server_Info_Ptr info = entry->int_id_;

      server_list[i].server = info->name.c_str ();
      server_list[i].startup.command_line = info->cmdline.c_str ();
      server_list[i].startup.environment = info->env_vars;
      server_list[i].startup.working_directory = info->dir.c_str ();
      server_list[i].startup.activation = info->activation_mode;
      server_list[i].startup.activator = info->activator.c_str ();
      server_list[i].startup.start_limit = info->start_limit;
      server_list[i].partial_ior = info->partial_ior.c_str ();
    }

  this->count_ += n;

  return 1;
}


void
ImR_Iterator::destroy (void)
{
  PortableServer::ObjectId_var oid = poa_->servant_to_id (this);
  poa_->deactivate_object (oid.in());
}