blob: 7c2cf1a213459ebca6d0223d8dc16e85367807de (
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
|
// -*- C++ -*-
#include "orbsvcs/Naming/FaultTolerant/FT_Random.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h"
#include "orbsvcs/PortableGroup/PG_conf.h"
#include "tao/debug.h"
#include "tao/ORB_Constants.h"
TAO_BEGIN_VERSIONED_NAMESPACE_DECL
TAO_FT_Random::TAO_FT_Random ()
{
}
TAO_FT_Random::~TAO_FT_Random ()
{
}
bool
TAO_FT_Random::next_location (
PortableGroup::ObjectGroup_ptr object_group,
TAO_FT_Naming_Manager *naming_manager,
PortableGroup::Location& location)
{
PortableGroup::Locations_var locations =
naming_manager->locations_of_members (object_group);
const CORBA::ULong len = locations->length ();
// No locations exist, so we can't get the next one
if (len == 0)
return false;
CORBA::ULong i = 0;
if (len > 1)
{
// Prevent integer arithmetic overflow.
double flen = static_cast<double> (len);
do
{
i = static_cast<CORBA::ULong> (flen * ACE_OS::rand () / (RAND_MAX + 1.0));
}
while (i == len);
}
location = locations[i];
return true;
}
TAO_END_VERSIONED_NAMESPACE_DECL
|