Go to the documentation of this file.00001
00002
00003 #include "orbsvcs/Notify/ETCL_FilterFactory.h"
00004
00005 ACE_RCSID(Notify, TAO_Notify_ETCL_FilterFactory, "$Id: ETCL_FilterFactory.cpp 85525 2009-06-05 16:33:57Z johnnyw $")
00006
00007 #include "orbsvcs/Notify/ETCL_Filter.h"
00008 #include "orbsvcs/Notify/Properties.h"
00009 #include "tao/debug.h"
00010
00011
00012 #ifndef DEBUG_LEVEL
00013 # define DEBUG_LEVEL TAO_debug_level
00014 #endif //DEBUG_LEVEL
00015
00016
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 TAO_Notify_ETCL_FilterFactory::TAO_Notify_ETCL_FilterFactory (void) :
00021 filter_poa_ (PortableServer::POA::_nil ())
00022 {
00023 }
00024
00025 TAO_Notify_ETCL_FilterFactory::~TAO_Notify_ETCL_FilterFactory ()
00026 {
00027 FILTERMAP::ITERATOR iterator (this->filters_);
00028
00029 for (FILTERMAP::ENTRY *entry = 0;
00030 iterator.next (entry) != 0;
00031 iterator.advance ())
00032 {
00033 delete entry->int_id_;
00034 entry->int_id_ = 0;
00035 }
00036
00037 this->filters_.unbind_all ();
00038
00039 }
00040
00041 CosNotifyFilter::FilterFactory_ptr
00042 TAO_Notify_ETCL_FilterFactory::create (PortableServer::POA_ptr filter_poa)
00043 {
00044 this->filter_poa_ = PortableServer::POA::_duplicate(filter_poa);
00045
00046 CORBA::Object_var object = CORBA::Object::_nil();
00047 try
00048 {
00049 PortableServer::ObjectId_var id = filter_poa->activate_object (this);
00050 object = filter_poa->id_to_reference (id.in());
00051 }
00052 catch (PortableServer::POA::ServantAlreadyActive&)
00053 {
00054 try
00055 {
00056 object = filter_poa->servant_to_reference (this);
00057 }
00058 catch (CORBA::Exception& )
00059 {
00060 return CosNotifyFilter::FilterFactory::_nil();
00061 }
00062 }
00063
00064 return CosNotifyFilter::FilterFactory::_narrow (object.in ());
00065 }
00066
00067 void
00068 TAO_Notify_ETCL_FilterFactory::destroy (void)
00069 {
00070 if (CORBA::is_nil(this->filter_poa_.in ()))
00071 return;
00072 PortableServer::ServantBase_var guard(this);
00073 try
00074 {
00075 PortableServer::ObjectId_var id =
00076 this->filter_poa_->servant_to_id (this);
00077 this->filter_poa_->deactivate_object (id.in());
00078 }
00079 catch (CORBA::Exception&)
00080 {
00081 }
00082
00083 }
00084
00085 CosNotifyFilter::Filter_ptr
00086 TAO_Notify_ETCL_FilterFactory::create_filter (const char *constraint_grammar)
00087 {
00088
00089 if (ACE_OS::strcmp (constraint_grammar, "TCL") != 0 &&
00090 ACE_OS::strcmp (constraint_grammar, "ETCL") != 0 &&
00091 ACE_OS::strcmp (constraint_grammar, "EXTENDED_TCL") != 0)
00092 throw CosNotifyFilter::InvalidGrammar ();
00093
00094 TAO_Notify_Object::ID id = filter_ids_.id ();
00095 TAO_Notify_ETCL_Filter* filter = 0;
00096 return this->create_filter (constraint_grammar, id, filter);
00097 }
00098
00099
00100 CosNotifyFilter::Filter_ptr
00101 TAO_Notify_ETCL_FilterFactory::create_filter (
00102 const char *constraint_grammar,
00103 const TAO_Notify_Object::ID& id,
00104 TAO_Notify_ETCL_Filter*& filter)
00105 {
00106
00107 filter = 0;
00108
00109 ACE_NEW_THROW_EX (filter,
00110 TAO_Notify_ETCL_Filter (this->filter_poa_.in (),
00111 constraint_grammar,
00112 id),
00113 CORBA::NO_MEMORY ());
00114
00115 if (filters_.bind (id, filter) == -1)
00116 {
00117 throw CORBA::INTERNAL ();
00118 return 0;
00119 }
00120
00121 PortableServer::ObjectId_var oid;
00122 try
00123 {
00124 oid = this->filter_poa_->activate_object (filter);
00125 }
00126 catch (PortableServer::POA::ServantAlreadyActive&)
00127 {
00128 try
00129 {
00130 oid = this->filter_poa_->servant_to_id (filter);
00131 }
00132 catch (CORBA::Exception& )
00133 {
00134 throw CORBA::INTERNAL ();
00135 return 0;
00136 }
00137 }
00138 CORBA::Object_var obj =
00139 this->filter_poa_->id_to_reference (oid.in ());
00140
00141 return CosNotifyFilter::Filter::_narrow (obj.in ());
00142 }
00143
00144 CosNotifyFilter::MappingFilter_ptr
00145 TAO_Notify_ETCL_FilterFactory::create_mapping_filter (const char * ,
00146 const CORBA::Any & )
00147 {
00148 throw CORBA::NO_IMPLEMENT ();
00149 }
00150
00151 TAO_END_VERSIONED_NAMESPACE_DECL
00152
00153
00154 void
00155 TAO_Notify_ETCL_FilterFactory::save_persistent (TAO_Notify::Topology_Saver& saver)
00156 {
00157 bool changed = true;
00158 TAO_Notify::NVPList attrs;
00159 saver.begin_object(0, "filter_factory", attrs, changed);
00160
00161 if (this->filters_.current_size () > 0)
00162 {
00163 int index = 0;
00164 FILTERMAP::ITERATOR iterator (this->filters_);
00165
00166 for (FILTERMAP::ENTRY *entry = 0;
00167 iterator.next (entry) != 0;
00168 iterator.advance (), ++index)
00169 {
00170 entry->int_id_->save_persistent (saver);
00171 }
00172 }
00173
00174 saver.end_object(0, "filter_factory");
00175 }
00176
00177
00178 TAO_Notify::Topology_Object*
00179 TAO_Notify_ETCL_FilterFactory::load_child (const ACE_CString &type,
00180 CORBA::Long id, const TAO_Notify::NVPList& attrs)
00181 {
00182 ACE_UNUSED_ARG (id);
00183
00184 TAO_Notify::Topology_Object* result = this;
00185 if (type == "filter")
00186 {
00187 const char* value = 0;
00188 if (attrs.find ("FilterId", value))
00189 {
00190 TAO_Notify_Object::ID const id = ACE_OS::atoi (value);
00191 if (DEBUG_LEVEL)
00192 ACE_DEBUG ((LM_DEBUG,
00193 ACE_TEXT ("(%P|%t) reload filter %d\n"),
00194 static_cast<int> (id)
00195 ));
00196
00197 filter_ids_.set_last_used (id);
00198
00199 TAO_Notify_ETCL_Filter* filter = 0;
00200 this->create_filter (0, id, filter);
00201 filter->load_attrs (attrs);
00202
00203 return filter;
00204 }
00205 }
00206 return result;
00207 }
00208
00209
00210 void
00211 TAO_Notify_ETCL_FilterFactory::release (void)
00212 {
00213 delete this;
00214
00215 }
00216
00217
00218 TAO_Notify_Object::ID
00219 TAO_Notify_ETCL_FilterFactory::get_filter_id (CosNotifyFilter::Filter_ptr filter)
00220 {
00221 ::PortableServer::Servant svt
00222 = this->filter_poa_->reference_to_servant (filter);
00223
00224 FILTERMAP::ITERATOR iterator (this->filters_);
00225
00226 for (FILTERMAP::ENTRY *entry = 0;
00227 iterator.next (entry) != 0;
00228 iterator.advance ())
00229 {
00230 if (svt == entry->int_id_)
00231 return entry->ext_id_;
00232 }
00233
00234 throw CORBA::INTERNAL ();
00235 return 0;
00236 }
00237
00238
00239 CosNotifyFilter::Filter_ptr
00240 TAO_Notify_ETCL_FilterFactory::get_filter (const TAO_Notify_Object::ID& id)
00241 {
00242 TAO_Notify_ETCL_Filter* filter = 0;
00243 if (filters_.find (id, filter) == -1)
00244 return CosNotifyFilter::Filter::_nil ();
00245 else
00246 {
00247 CORBA::Object_var obj =
00248 this->filter_poa_->servant_to_reference (filter);
00249
00250 CosNotifyFilter::Filter_var filter
00251 = CosNotifyFilter::Filter::_narrow (obj.in ());
00252
00253 return filter._retn ();
00254 }
00255 }
00256
00257
00258 ACE_FACTORY_DEFINE (TAO_Notify_Serv, TAO_Notify_ETCL_FilterFactory)