summaryrefslogtreecommitdiff
path: root/TAO/tao/Object_Ref_Table.cpp
blob: f5f4554f1a952ff5422880ec455c015e30803f87 (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
// $Id$

#include "tao/Object_Ref_Table.h"
#include "tao/ORB.h"
#include "tao/Environment.h"
#include "tao/debug.h"
#include "tao/ORB_Constants.h"
#include "tao/SystemException.h"
#include "ace/OS_NS_string.h"
#include "ace/Log_Msg.h"


ACE_RCSID (tao,
           Object_Ref_Table,
           "$Id$")


#ifndef __ACE_INLINE__
# include "tao/Object_Ref_Table.inl"
#endif  /* __ACE_INLINE__ */


// ****************************************************************

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

int
TAO_Object_Ref_Table::bind (const char *id,
                            CORBA::Object_ptr obj)
{
  // Make sure that the supplied Object reference is valid,
  // i.e. not nil.
  if (id == 0
      || ACE_OS::strlen (id) == 0
      || CORBA::is_nil (obj))
    {
      errno = EINVAL;
      return -1;
    };

  Table::value_type const value =
    std::make_pair (CORBA::String_var (id),
                    CORBA::Object_var (CORBA::Object::_duplicate (obj)));

  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    guard,
                    this->lock_,
                    -1);

  std::pair<iterator, bool> const result = this->table_.insert (value);

  if (!result.second)
    {
      if (TAO_debug_level > 1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("(%P|%t) Object_Ref_Table::")
                      ACE_TEXT ("bind:")
                      ACE_TEXT ("  Could not register duplicate object <%s> ")
                      ACE_TEXT ("with the ORB\n"),
                      ACE_TEXT_CHAR_TO_TCHAR (id)));
        }

      return -1;
    }

  return 0;
}

CORBA::Object_ptr
TAO_Object_Ref_Table::find (const char *id)
{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                    guard,
                    this->lock_,
                    CORBA::Object::_nil ());

  iterator const found =
    this->table_.find (CORBA::String_var (id));

  if (found == this->table_.end ())
    return CORBA::Object::_nil ();

  return CORBA::Object::_duplicate ((*found).second.in ());
}

TAO_END_VERSIONED_NAMESPACE_DECL