summaryrefslogtreecommitdiff
path: root/trunk/CIAO/DAnCE/ExecutionManager/DAM_Map.cpp
blob: 5d50cc682d053b52a96cf14e9f25c00ac9a5cb19 (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
#include "DAM_Map.h"
#include "ciao/CIAO_Config.h"
#include "ciao/CIAO_common.h"

ACE_RCSID (ExecutionManager,
           DAM_Map,
           "$Id$")

namespace CIAO
{
  namespace Execution_Manager
  {
    DAM_Map::DAM_Map (void)
      : map_ (CIAO_DEFAULT_MAP_SIZE)
    {
    }

    size_t
    DAM_Map::size (void) const
    {
      return this->map_.current_size ();
    }

    bool
    DAM_Map::is_plan_available (const ACE_CString &str) const
    {
      CIAO_TRACE("Execution_Manager::DAM_Map::is_plan_available");
      if (this->map_.find (str) == 0)
        return true;

      return false;
    }

    ::Deployment::DomainApplicationManager_ptr
    DAM_Map::fetch_dam_reference (const ACE_CString &str)
    {
      CIAO_TRACE("Execution_Manager::DAM_Map::fetch_dam_reference");
      if (!this->is_plan_available (str))
        return ::Deployment::DomainApplicationManager::_nil ();

      ::Deployment::DomainApplicationManager_var tmp;

      /// There should be duplicate when assigning a _var to an _var.
      int const retval =  this->map_.find (str, tmp);

      if (CIAO::debug_level () > 9)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "(%P|%t) CIAO_ExecutionManager: fetch_dam_reference, "
                      "result from find is [%d] \n",
                      retval));
        }

      return tmp._retn ();
    }


    bool
    DAM_Map::bind_dam_reference (
      const ACE_CString &str,
      ::Deployment::DomainApplicationManager_ptr dam)
    {
      CIAO_TRACE("Execution_Manager::DAM_Map::bind_dam_reference");

      if (this->map_.rebind (str, dam) != 0)
        return false;

      return true;
    }


    Deployment::DomainApplicationManagers *
    DAM_Map::get_dams ()
    {
      CIAO_TRACE("Execution_Manager::DAM_Map::get_dams");
      CORBA::ULong const sz = this->map_.current_size ();

      // Initialize the list of DomainApplication Managers
      Deployment::DomainApplicationManagers_var list;
      ACE_NEW_THROW_EX (list,
                        Deployment::DomainApplicationManagers (sz),
                        CORBA::NO_MEMORY());

      // Add the manager to the list
      list->length (sz);

      Iterator end = this->map_.end ();

      CORBA::ULong i = 0;

      for (Iterator b = this->map_.begin (); b != end; ++b)
        {
          list [i] =
            Deployment::DomainApplicationManager::_duplicate ((*b).int_id_.in ());

          ++i;
        }

      return list._retn ();
    }

    bool
    DAM_Map::unbind_dam (const ACE_CString &str)
    {
      CIAO_TRACE("Execution_Manager::DAM_Map::unbind_dam");

      if (this->map_.unbind (str) != 0)
        return false;

      return true;
    }
  }
}