summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/LoadBalancing/GenericFactory/Infrastructure_Controlled/Factory.cpp
blob: 1c0798efa7e8a11590b32b60d30a4bb425c07b78 (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
#include "Factory.h"
#include "Simple.h"

#include "TestC.h"

ACE_RCSID (Infrastructure_Controlled,
           Factory,
           "$Id$")

Factory::Factory (void)
{
   this->fcid_ = 0;
}

CORBA::Object_ptr
Factory::create_object (
    const char * /*type_id*/,
    const PortableGroup::Criteria & /*the_criteria*/,
    PortableGroup::GenericFactory::FactoryCreationId_out fcid
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableGroup::NoFactory,
                   PortableGroup::ObjectNotCreated,
                   PortableGroup::InvalidCriteria,
                   PortableGroup::InvalidProperty,
                   PortableGroup::CannotMeetCriteria))
{
  Simple *servant;

  ACE_NEW_THROW_EX (servant,
		    Simple,
		    CORBA::NO_MEMORY ());

  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  PortableServer::ServantBase_var safe_servant = servant;

  CORBA::ULong tmp_fcid = 0;
  tmp_fcid = this->fcid_;

  while (this->factory_map_.find (this->fcid_) == 0)
    {
      this->fcid_++;
      if (this->fcid_ == tmp_fcid)
        ACE_THROW_RETURN (PortableGroup::ObjectNotCreated (),
			  CORBA::Object::_nil ());
    }

  tmp_fcid = this->fcid_;

  PortableGroup::GenericFactory::FactoryCreationId *my_fcid = 0;

  ACE_NEW_THROW_EX (my_fcid,
		    PortableGroup::GenericFactory::FactoryCreationId,
		    CORBA::NO_MEMORY ());
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  fcid = my_fcid;

  *my_fcid <<= tmp_fcid;

  this->poa_ =
    servant->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  this->oid_ = this->poa_->servant_to_id (servant
                                          ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  return servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER);

}

void
Factory::delete_object (
    const PortableGroup::GenericFactory::FactoryCreationId &
      fcid
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
		   PortableGroup::ObjectNotFound))
{
  CORBA::ULong my_fcid = 0;

  if (fcid >>= my_fcid)
    {
      ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);
      Factory_Map::ENTRY *entry = 0;
      if (this->factory_map_.find (my_fcid, entry) == 0)
        {
	  if (this->factory_map_.unbind (my_fcid) != 0)
	    ACE_THROW (CORBA::INTERNAL ());
	}
    }
  else
    ACE_THROW (PortableGroup::ObjectNotFound ());

  if (my_fcid == this->fcid_)
    {
      this->poa_->deactivate_object (this->oid_.in ()
		                     ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;
    }
  else
    {
      ACE_THROW (PortableGroup::ObjectNotFound ());
    }
}