summaryrefslogtreecommitdiff
path: root/TAO/CIAO/DAnCE/DomainApplicationManager/Deployment_Configuration.cpp
blob: c42e892081da349595420bf277fb822daf6b2934 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// $Id$

#include "Deployment_Configuration.h"

#include "ace/OS_NS_stdio.h"

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

const int NAME_BUFSIZE = 1024;

CIAO::Deployment_Configuration::Deployment_Configuration (CORBA::ORB_ptr o)
  : orb_ (CORBA::ORB::_duplicate (o))
{
}

CIAO::Deployment_Configuration::~Deployment_Configuration (void)
{
  this->deployment_info_.unbind_all ();
}

int
CIAO::Deployment_Configuration::init (const char *filename)
{
  // @@ We should change to use ACE_Configuration here.

  if (filename == 0)
    return -1;

  FILE *inf = ACE_OS::fopen (filename, "r");

  if (inf == NULL)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Fail to open node manager map data file: %s.\n",
                       filename),
                      -1);

  char destination[NAME_BUFSIZE], ior[NAME_BUFSIZE];

  int first = 1;

  while (fscanf (inf, "%s %s", destination, ior ) != EOF)
    {
      this->deployment_info_.bind (destination, ior);

      if (first)
        {
          this->default_node_manager_.IOR_ = ior;
          first = 0;
        }
    }

  return 0;
}

const char *
CIAO::Deployment_Configuration::get_node_manager_ior (const char *name)
{
  if (name == 0)
    return get_default_node_manager_ior ();

  ACE_Hash_Map_Entry
    <ACE_CString,
    CIAO::Deployment_Configuration::Node_Manager_Info> *entry;

  if (this->deployment_info_.find (ACE_CString (name),
                                   entry) != 0)
    return 0;                   // no valid name found.

  return entry->int_id_.IOR_.c_str ();
}

const char *
CIAO::Deployment_Configuration::get_default_node_manager_ior (void)
{
  if (this->default_node_manager_.IOR_.length () == 0)
    return 0;
  return this->default_node_manager_.IOR_.c_str ();
}

::Deployment::NodeManager_ptr
CIAO::Deployment_Configuration::get_node_manager (const char *name
                                                  ACE_ENV_ARG_DECL)
{
  if (name == 0)
    return get_default_node_manager (ACE_ENV_SINGLE_ARG_PARAMETER);

  ACE_Hash_Map_Entry
    <ACE_CString,
    CIAO::Deployment_Configuration::Node_Manager_Info> *entry;

  if (this->deployment_info_.find (ACE_CString (name),
                                   entry) != 0)
    return 0;                   // no valid name found.

  if (CORBA::is_nil (entry->int_id_.node_manager_.in ()))
    {
      CORBA::Object_var temp = this->orb_->string_to_object
        (entry->int_id_.IOR_.c_str ()
         ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (0);

      entry->int_id_.node_manager_ =
        ::Deployment::NodeManager::_narrow (temp.in ()
                                            ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (0);
    }
  return ::Deployment::NodeManager::_duplicate 
    (entry->int_id_.node_manager_.in ());
}

::Deployment::NodeManager_ptr
CIAO::Deployment_Configuration::get_default_node_manager (ACE_ENV_SINGLE_ARG_DECL)
{
  if (CORBA::is_nil (this->default_node_manager_.node_manager_.in ()))
    {
      CORBA::Object_var temp = this->orb_->string_to_object
        (this->default_node_manager_.IOR_.c_str ()
         ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (0);

      this->default_node_manager_.node_manager_ =
        ::Deployment::NodeManager::_narrow (temp.in ()
                                            ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (0);
    }
  return ::Deployment::NodeManager::_duplicate
    (this->default_node_manager_.node_manager_.in ());
}