summaryrefslogtreecommitdiff
path: root/modules/CIAO/ciao/Deployment/Handlers/CIAO_State.cpp
blob: da27aae66af8572f715d71f329f631b03be30dd8 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// $Id$

#include "CIAO_State.h"
#include "ciao/Logger/Log_Macros.h"

namespace CIAO
{
  void 
  Deployment_State::add_container (const char *id,
                                   CIAO::Container_ptr container)
  {
    CIAO_TRACE ("Deployment_State::add_container");
    
    if (CIAO_debug_level && // Let's only perform this lookup if we have logging enabled.
        this->containers_.find (id) != this->containers_.end ())
      {
        CIAO_ERROR (1, (LM_WARNING, CLINFO
                        "Deployment_State::add_container - "
                        "Warning:  Attempting to add duplicate container reference\n"));
      }
    
    this->containers_[id] = CIAO::Container::_duplicate (container);
  }
  
  void
  Deployment_State::remove_container (const char *id)
  {
    CIAO_TRACE ("Deployment_State::remove_container");
    
    CONTAINERS::iterator pos = this->containers_.find (id);
    
    if (pos != this->containers_.end ())
      this->containers_.erase (pos);
  }
    
  CIAO::Container_ptr
  Deployment_State::fetch_container (const char *id)
  {
    CIAO_TRACE ("Deployment_State::fetch_container");
    
    CONTAINERS::iterator pos = this->containers_.find (id);
    
    if (pos == this->containers_.end ()) return 0;
    return CIAO::Container::_duplicate (pos->second.in ());
  }

  void 
  Deployment_State::add_home (const char *id,
                              const char *cont_id,
                              Components::CCMHome_ptr home)
  {
    CIAO_TRACE ("Deployment_State::add_home");
    
    if (CIAO_debug_level && // Let's only perform this lookup if we have logging enabled.
        this->homes_.find (id) != this->homes_.end ())
      {
        CIAO_ERROR (1, (LM_WARNING, CLINFO
                        "Deployment_State::add_home - "
                        "Warning:  Attempting to add duplicate home reference\n"));
      }
    
    this->instance_container_[id] = cont_id;
    this->homes_[id] = Components::CCMHome::_duplicate (home);
  }
  
  void
  Deployment_State::remove_home (const char *id)
  {
    CIAO_TRACE ("Deployment_State::remove_home");

    HOMES::iterator pos = this->homes_.find (id);
    
    if (pos != this->homes_.end ())
      this->homes_.erase (pos);
    
    INSTANCE_CONTAINER::iterator cont = 
      this->instance_container_.find (id);
    
    if (cont != this->instance_container_.end ())
      this->instance_container_.erase (cont);
  }
    
  Components::CCMHome_ptr
  Deployment_State::fetch_home (const char *id)
  {
    CIAO_TRACE ("Deployment_State::fetch_home");

    HOMES::iterator pos = this->homes_.find (id);
    
    if (pos == this->homes_.end ()) return 0;
    return Components::CCMHome::_duplicate (pos->second.in ());    
  }
  
  void 
  Deployment_State::add_component (const char *id,
                                   const char *cont_id,
                                   Components::CCMObject_ptr component)
  {
    CIAO_TRACE ("Deployment_State::add_component");
    
    if (CIAO_debug_level && // Let's only perform this lookup if we have logging enabled.
        this->components_.find (id) != this->components_.end ())
      {
        CIAO_ERROR (1, (LM_WARNING, CLINFO
                        "Deployment_State::add_component - "
                        "Warning:  Attempting to add duplicate component reference\n"));
      }
    
    this->instance_container_[id] = cont_id;
    this->components_[id] = Components::CCMObject::_duplicate (component);
  }
  
  void
  Deployment_State::remove_component (const char *id)
  {
    CIAO_TRACE ("Deployment_State::remove_component");

    COMPONENTS::iterator pos = this->components_.find (id);
    
    if (pos != this->components_.end ())
      this->components_.erase (pos);
    
    INSTANCE_CONTAINER::iterator cont = 
      this->instance_container_.find (id);
    
    if (cont != this->instance_container_.end ())
      this->instance_container_.erase (cont);
  }
    
  Components::CCMObject_ptr
  Deployment_State::fetch_component (const char *id)
  {
    CIAO_TRACE ("Deployment_State::fetch_component");

    COMPONENTS::iterator pos = this->components_.find (id);
    
    if (pos == this->components_.end ()) return 0;
    return Components::CCMObject::_duplicate (pos->second.in ());    
  }
  
  const char * 
  Deployment_State::instance_to_container (const char *id)
  {
    CIAO_TRACE ("Deployment_State::instance_to_container");
    
    INSTANCE_CONTAINER::const_iterator cont = 
      this->instance_container_.find (id);
    
    if (cont != this->instance_container_.end ())
      return cont->second.c_str ();
    
    CIAO_ERROR (1, (LM_ERROR, CLINFO
                    "Deployment_State::instance_to_container - "
                    "Error: Unknown instance ID <%C>\n",
                    id));
    return 0;
  }
}