summaryrefslogtreecommitdiff
path: root/TAO/tao/Parser_Registry.cpp
blob: eed0f04a2cd1383e5298cea44413545d2831ff67 (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
// -*- C++ -*-
#include "tao/Parser_Registry.h"
#include "tao/IOR_Parser.h"
#include "tao/ORB_Core.h"

#include "ace/Dynamic_Service.h"

#if !defined(__ACE_INLINE__)
#include "tao/Parser_Registry.inl"
#endif /* __ACE_INLINE__ */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_Parser_Registry::TAO_Parser_Registry ()
  : parsers_ (nullptr),
    size_ (0)
{
}

TAO_Parser_Registry::~TAO_Parser_Registry ()
{
  delete [] this->parsers_;
}

int
TAO_Parser_Registry::open (TAO_ORB_Core *orb_core)
{
  char **names = nullptr;
  int number_of_names = 0;

  if (orb_core->resource_factory () == nullptr)
    {
      return -1;
    }

  orb_core->resource_factory ()->get_parser_names (names, number_of_names);

  if (number_of_names == 0)
    {
      return -1;
    }

  this->size_ = number_of_names;
  ACE_NEW_RETURN (this->parsers_,
                  TAO_IOR_Parser*[this->size_],
                  -1);

  for (size_t i = 0, index = 0; i != this->size_; ++i)
    {
      this->parsers_[index] =
        ACE_Dynamic_Service<TAO_IOR_Parser>::instance (orb_core->configuration (),
                                                       names [i]);

      if (this->parsers_[index] == nullptr)
        {
          --number_of_names;
          if (TAO_debug_level >= 1)
            {
              TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) Failed to find Service Object"
                          " for %C.\n", names[i]));
            }
        }
      else
        {
          ++index;
        }
    }

  this->size_ = number_of_names;
  return 0;
}

TAO_IOR_Parser *
TAO_Parser_Registry::match_parser (const char *ior_string)
{
  for (Parser_Iterator i = this->begin (); i != this->end (); ++i)
    {
      if ((*i)->match_prefix (ior_string))
        {
          return *i;
        }
    }

  return nullptr;
}

TAO_END_VERSIONED_NAMESPACE_DECL