EventTypeSeq.cpp

Go to the documentation of this file.
00001 // $Id: EventTypeSeq.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #include "orbsvcs/Notify/EventTypeSeq.h"
00004 #include "orbsvcs/Notify/Topology_Saver.h"
00005 
00006 #include "tao/debug.h"
00007 //#define DEBUG_LEVEL 9
00008 #ifndef DEBUG_LEVEL
00009 # define DEBUG_LEVEL TAO_debug_level
00010 #endif //DEBUG_LEVEL
00011 
00012 ACE_RCSID(Notify, TAO_Notify_EventTypeSeq, "$Id: EventTypeSeq.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00013 
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 TAO_Notify_EventTypeSeq::TAO_Notify_EventTypeSeq (void)
00017 {
00018 }
00019 
00020 TAO_Notify_EventTypeSeq::TAO_Notify_EventTypeSeq (const CosNotification::EventTypeSeq& event_type_seq)
00021 {
00022   this->insert_seq (event_type_seq);
00023 }
00024 
00025 TAO_Notify_EventTypeSeq &
00026 TAO_Notify_EventTypeSeq::operator = (const TAO_Notify_EventTypeSeq & rhs)
00027 {
00028   ACE_Unbounded_Set <TAO_Notify_EventType>::operator = (rhs);
00029   return *this;
00030 }
00031 
00032 TAO_Notify_EventTypeSeq::TAO_Notify_EventTypeSeq (const TAO_Notify_EventTypeSeq & rhs)
00033   : TAO_Notify_Object ()
00034   , TAO_Notify::Topology_Savable ()
00035   , ACE_Unbounded_Set <TAO_Notify_EventType> (rhs)
00036   , TAO_Notify::Topology_Object ()
00037 {
00038 }
00039 
00040 void
00041 TAO_Notify_EventTypeSeq::populate (CosNotification::EventTypeSeq& event_type_seq) const
00042 {
00043   event_type_seq.length (static_cast<CORBA::ULong> (this->size ()));
00044 
00045   inherited::CONST_ITERATOR iter (*this);
00046 
00047   TAO_Notify_EventType* event_type = 0;
00048 
00049   CORBA::ULong i = 0;
00050   for (iter.first (); iter.next (event_type); iter.advance (), ++i)
00051     event_type_seq[i] = event_type->native ();
00052 }
00053 
00054 void
00055 TAO_Notify_EventTypeSeq::populate_no_special (CosNotification::EventTypeSeq& event_type_seq) const
00056 {
00057   // If the special exists in us, don't include it.
00058   const TAO_Notify_EventType& special = TAO_Notify_EventType::special ();
00059 
00060   if (this->find (special) == 0)
00061     {
00062       event_type_seq.length (static_cast<CORBA::ULong> (this->size () - 1));
00063     }
00064   else
00065       event_type_seq.length (static_cast<CORBA::ULong> (this->size ()));
00066 
00067   inherited::CONST_ITERATOR iter (*this);
00068 
00069   TAO_Notify_EventType* event_type = 0;
00070 
00071   CORBA::ULong i = 0;
00072   for (iter.first (); iter.next (event_type); iter.advance (), ++i)
00073     {
00074       if (event_type->is_special () == 0) // if its not the special event type.
00075         event_type_seq[i] = event_type->native ();
00076     }
00077 }
00078 
00079 void
00080 TAO_Notify_EventTypeSeq::insert_seq (const CosNotification::EventTypeSeq& event_type_seq)
00081 {
00082   TAO_Notify_EventType event_type;
00083 
00084   for (CORBA::ULong i = 0; i < event_type_seq.length (); ++i)
00085     {
00086       event_type = event_type_seq[i];
00087       inherited::insert (event_type);
00088     }
00089 }
00090 
00091 void
00092 TAO_Notify_EventTypeSeq::remove_seq (const CosNotification::EventTypeSeq& event_type_seq)
00093 {
00094   TAO_Notify_EventType event_type;
00095 
00096   for (CORBA::ULong i = 0; i < event_type_seq.length (); ++i)
00097     {
00098       event_type = event_type_seq[i];
00099       inherited::remove (event_type);
00100     }
00101 }
00102 
00103 void
00104 TAO_Notify_EventTypeSeq::insert_seq (const TAO_Notify_EventTypeSeq& event_type_seq)
00105 {
00106   TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (event_type_seq);
00107 
00108   TAO_Notify_EventType* event_type;
00109 
00110   for (iter.first (); iter.next (event_type); iter.advance ())
00111     inherited::insert (*event_type);
00112 }
00113 
00114 void
00115 TAO_Notify_EventTypeSeq::remove_seq (const TAO_Notify_EventTypeSeq& event_type_seq)
00116 {
00117   TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (event_type_seq);
00118 
00119   TAO_Notify_EventType* event_type;
00120 
00121   for (iter.first (); iter.next (event_type); iter.advance ())
00122     inherited::remove (*event_type);
00123 }
00124 
00125 void
00126 TAO_Notify_EventTypeSeq::add_and_remove (TAO_Notify_EventTypeSeq& seq_added, TAO_Notify_EventTypeSeq& seq_remove)
00127 {
00128   const TAO_Notify_EventType& special = TAO_Notify_EventType::special ();
00129 
00130   if (this->find (special) == 0) // If this object has the special type.
00131     {
00132       if (seq_added.find (special) == 0) // if the seq. being added has the special type, you cannot be adding or removing anythings. * overrides.
00133         {
00134           seq_added.reset ();   // remove everything from the sequence bening added.
00135           seq_remove.reset (); // remove everything form whats being removed.
00136         }
00137       else // sequence being added does not have *
00138         {
00139           if (!seq_added.is_empty ()) // if sequence being added is non empty
00140             {
00141               this->reset ();   // take away the * from this object.
00142               this->insert_seq (seq_added); // insert the sequence being added as the new list of types.
00143 
00144               seq_remove.reset ();   // reset all that is being removed.
00145               seq_remove.insert (special); // remove *
00146             }
00147           else // nothing is being added
00148             {
00149               if (seq_remove.find (special) == 0) // we're removing everything
00150                 {
00151                   this->reset ();
00152                   seq_remove.reset ();   // reset all that is being removed.
00153                   seq_remove.insert (special); // remove *
00154                 }
00155               else if (!seq_remove.is_empty ())
00156                 {
00157                   // if we're currently subscribed for everything and did not added anything, we can't remove something.
00158                   seq_remove.reset ();
00159                 }
00160             }
00161         }
00162     }
00163   else // if this object does not have the special type.
00164     {
00165       if (seq_added.find (special) == 0) // but the seq. being added has the special type,
00166         {
00167           if (seq_remove.find (special) == 0) // and you're removing * as well
00168             {
00169               seq_added.reset ();      // ignore the request
00170               seq_remove.reset ();  // ignore the request
00171             }
00172           else // seq being removed does not have the special type
00173             {
00174               seq_remove.reset (); // everything that we're subscribed for is being removed.
00175               seq_remove.insert_seq (*this);
00176 
00177               this->reset (); // insert the special in this object.
00178               this->insert (special);
00179 
00180               seq_added.reset (); // also clear our set and add only *
00181               seq_added.insert (special);
00182             }
00183         }
00184       else // seq being added does not have special.
00185         {
00186           if (seq_remove.find (special) == 0) // but we're removing everything.
00187             {
00188               seq_remove.reset (); // move all that we have currently to removed.
00189               seq_remove.insert_seq (*this);
00190             }
00191 
00192           // so now there are no specials anywhere..
00193             {
00194               //= First remove the duplicates in the added and removes lists.
00195               // compute the intersection.
00196 
00197               TAO_Notify_EventTypeSeq common;
00198               common.intersection (seq_added, seq_remove);
00199 
00200               // remove the common elements from both the lists so Added {BCDK} and Removed {CDEA} will yield Added {BK} and Removed {EA}
00201               seq_added.remove_seq (common);
00202               seq_remove.remove_seq (common);
00203 
00204               // If we're already subscribed for an element we should not subscribe again (duplicate events).
00205               // so if we currently subscribe for ABC and we Added {BK} we should now get ABCK as current subscription and Added {K}
00206               common.reset ();
00207               common.intersection (*this, seq_added);
00208               // remove the common elements from the added list. i,e. doent ask to add what we're already added for.
00209               seq_added.remove_seq (common);
00210               // update the current subscription.
00211               this->insert_seq (seq_added);
00212 
00213 
00214               // Similarly for removed.. if we're removing EA and now our current list looks like ABC we should emd up with
00215               // current subscription BC and Removed {A}
00216               common.reset ();
00217               common.intersection (*this, seq_remove);
00218 
00219               seq_remove.reset ();
00220               seq_remove.insert_seq (common); // only remove what we currently have.
00221 
00222               this->remove_seq (seq_remove);
00223             }
00224         }
00225     }
00226 }
00227 
00228 void
00229 TAO_Notify_EventTypeSeq::intersection (const TAO_Notify_EventTypeSeq& rhs, const TAO_Notify_EventTypeSeq& lhs)
00230 {
00231   // linear search.
00232   TAO_Notify_EventTypeSeq::CONST_ITERATOR rhs_iter (rhs);
00233   TAO_Notify_EventType* rhs_event_type;
00234 
00235   TAO_Notify_EventTypeSeq::CONST_ITERATOR lhs_iter (lhs);
00236   TAO_Notify_EventType* lhs_event_type;
00237 
00238   for (rhs_iter.first (); rhs_iter.next (rhs_event_type); rhs_iter.advance ())
00239     {
00240       for (lhs_iter.first (); lhs_iter.next (lhs_event_type); lhs_iter.advance ())
00241         {
00242           if (*rhs_event_type == *lhs_event_type) // if both are same add to this object.
00243             this->insert (*rhs_event_type);
00244         }
00245     }
00246 }
00247 
00248 void
00249 TAO_Notify_EventTypeSeq::dump (void) const
00250 {
00251   TAO_Notify_EventTypeSeq::CONST_ITERATOR iter (*this);
00252 
00253   TAO_Notify_EventType* event_type;
00254 
00255   for (iter.first (); iter.next (event_type); iter.advance ())
00256     {
00257       event_type->dump ();
00258       ACE_DEBUG ((LM_DEBUG, ", "));
00259     }
00260 }
00261 
00262   // TAO_Notify::Topology_Object
00263 void
00264 TAO_Notify_EventTypeSeq::save_persistent (TAO_Notify::Topology_Saver& saver)
00265 {
00266   bool changed = this->self_changed_;
00267   this->self_changed_ = false;
00268   this->children_changed_ = false;
00269   TAO_Notify::NVPList attrs;
00270 
00271   TAO_Notify_EventTypeSeq::ITERATOR iter (*this);
00272   TAO_Notify_EventType* event_type;
00273 
00274   if (this->size() != 0)
00275   {
00276     saver.begin_object(0, "subscriptions", attrs, changed);
00277     for (iter.first (); iter.next (event_type) != 0; iter.advance ())
00278     {
00279       event_type->save_persistent(saver);
00280     }
00281 // todo:
00282 //    for all deleted children
00283 //    {
00284 //      saver.delete_child(child_type, child_id);
00285 //    }
00286     saver.end_object(0, "subscriptions");
00287   }
00288 }
00289 
00290 TAO_Notify::Topology_Object*
00291 TAO_Notify_EventTypeSeq::load_child (const ACE_CString &type, CORBA::Long id,
00292   const TAO_Notify::NVPList& attrs)
00293 {
00294   ACE_UNUSED_ARG (id);
00295   TAO_Notify::Topology_Object *result = this;
00296   TAO_Notify_EventType et;
00297 
00298   if ((type == "subscription") && et.init(attrs))
00299   {
00300     if (DEBUG_LEVEL) ACE_DEBUG ((LM_DEBUG,
00301       ACE_TEXT ("(%P|%t) Event_Type reload subscription\n")
00302       ));
00303     inherited::insert(et);
00304   }
00305   return result;
00306 }
00307 
00308 void
00309 TAO_Notify_EventTypeSeq::release (void)
00310 {
00311   delete this;
00312 }
00313 
00314 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:45:29 2010 for TAO_CosNotification by  doxygen 1.4.7