summaryrefslogtreecommitdiff
path: root/CIAO/tools/Config_Handlers/CIAO_Events/CIAOEvents_Handler.cpp
blob: 6c265bea2a507724b7b7499d5ddc2e6fe2e29943 (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
// $Id$
#include "Utils/XML_Helper.h"
#include "CIAOEvents_Handler.h"
#include "CIAOEvents.hpp"
#include "ciao/Deployment_EventsC.h"

namespace CIAO
{
  namespace Config_Handlers
  {
    CIAOEvents_Handler::CIAOEvents_Handler (const ACE_TCHAR *file) :
      idl_esd_(0),
      esd_(0),
      retval_ (false)
    {
      XML_Helper helper;

      XERCES_CPP_NAMESPACE::DOMDocument *dom =
        helper.create_dom (file);

      if (!dom)
        throw CIAOEvents_Handler::NoESD ();

      this->esd_.reset (new CIAOEventsDef
        (CIAOEvents (dom)));

      if (!this->build_esd ())
        throw NoESD ();
    }

    CIAOEvents_Handler::CIAOEvents_Handler (CIAOEventsDef *esd):
      idl_esd_(0),
      esd_(esd),
      retval_(false)
    {
      if(!this->build_esd())
        throw NoESD ();
    }


    CIAOEvents_Handler::~CIAOEvents_Handler (void)
    {
    }

    bool
    CIAOEvents_Handler::build_esd ()
    {
      this->idl_esd_.reset ( new ::CIAO::DAnCE::EventServiceDeploymentDescriptions );


      this->idl_esd_->length (this->esd_->count_eventServiceConfiguration ());
      CORBA::ULong pos_i = 0;
      for (CIAOEventsDef::eventServiceConfiguration_const_iterator i = this->esd_->begin_eventServiceConfiguration ();
           i != this->esd_->end_eventServiceConfiguration ();
           i++)
      {
           CIAO::DAnCE::EventServiceDeploymentDescription a_esd;

           a_esd.name = CORBA::string_dup (i->name ().c_str ());
           a_esd.node = CORBA::string_dup (i->node ().c_str ());

           switch (i->type ().integral ())
           {
             case ::CIAO::Config_Handlers::EventServiceType::EC_l:
               a_esd.type = CIAO::DAnCE::EC;
               break;
             case ::CIAO::Config_Handlers::EventServiceType::NOTIFY_l:
               a_esd.type = CIAO::DAnCE::NOTIFY;
               break;
             case ::CIAO::Config_Handlers::EventServiceType::RTEC_l:
               a_esd.type = CIAO::DAnCE::RTEC;
               break;
             case ::CIAO::Config_Handlers::EventServiceType::RTNOTIFY_l:
               a_esd.type = CIAO::DAnCE::RTNOTIFY;
               break;
             default:
             ACE_ERROR ((LM_ERROR,
                        "Invalid event service type\n"));
             return false;
           }

           a_esd.svc_cfg_file = CORBA::string_dup  (i->svc_cfg_file ().c_str ());


           a_esd.filters.length (i->count_filter ());
           CORBA::ULong pos_j = 0;
           for (EventServiceDescription::filter_const_iterator j = i->begin_filter ();
                j != i->end_filter ();
                j++)
           {
              a_esd.filters[pos_j].name = CORBA::string_dup (j->name ().c_str ());
              switch (j->type ().integral ())
              {
                  case ::CIAO::Config_Handlers::FilterType::CONJUNCTION_l:
                    a_esd.filters[pos_j].type = CIAO::DAnCE::CONJUNCTION;
                    break;
                  case ::CIAO::Config_Handlers::FilterType::DISJUNCTION_l:
                    a_esd.filters[pos_j].type = CIAO::DAnCE::DISJUNCTION;
                    break;
                  case ::CIAO::Config_Handlers::FilterType::LOGICAL_AND_l:
                    a_esd.filters[pos_j].type = CIAO::DAnCE::LOGICAL_AND;
                    break;
                  case ::CIAO::Config_Handlers::FilterType::NEGATE_l:
                    a_esd.filters[pos_j].type = CIAO::DAnCE::NEGATE;
                    break;
                    default:
                    ACE_ERROR ((LM_ERROR,
                              "Invalid filter type\n"));
                  return false;
               }

               a_esd.filters[pos_j].sources.length (j->count_source ());
               CORBA::ULong pos_k = 0;
               for (Filter::source_const_iterator k = j->begin_source ();
                    k != j->end_source ();
                    k++)
               {
                 a_esd.filters[pos_j].sources[pos_k] = CORBA::string_dup (k->c_str ());
                 pos_k++;

               }
               pos_j++;
            }

           (*this->idl_esd_)[pos_i] = a_esd;
           pos_i++;
      }
      return true;
    }


    ::CIAO::DAnCE::EventServiceDeploymentDescriptions const *
        CIAOEvents_Handler::esd_idl () const
      throw (CIAOEvents_Handler::NoESD)
      {
        if(!this->idl_esd_.get())
          throw NoESD ();

         //else
        return this->idl_esd_.get();
      }

    ::CIAO::DAnCE::EventServiceDeploymentDescriptions *
        CIAOEvents_Handler::esd_idl ()
      throw (CIAOEvents_Handler::NoESD)
      {
        if(!this->idl_esd_.get())
          throw NoESD();

        //else
        return this->idl_esd_.release();
      }
   }
}