EC_Conjunction_Filter.cpp

Go to the documentation of this file.
00001 // $Id: EC_Conjunction_Filter.cpp 76589 2007-01-25 18:04:11Z elliott_c $
00002 
00003 #include "orbsvcs/Event/EC_Conjunction_Filter.h"
00004 
00005 ACE_RCSID(Event, EC_Conjunction_Filter, "$Id: EC_Conjunction_Filter.cpp 76589 2007-01-25 18:04:11Z elliott_c $")
00006 
00007 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00008 
00009 const int bits_per_word = sizeof(TAO_EC_Conjunction_Filter::Word) * CHAR_BIT;
00010 
00011 TAO_EC_Conjunction_Filter::
00012     TAO_EC_Conjunction_Filter (TAO_EC_Filter* children[],
00013                                size_t n)
00014   :  children_ (children),
00015      n_ (n)
00016 {
00017   ChildrenIterator end = this->end ();
00018   for (ChildrenIterator i = this->begin ();
00019        i != end;
00020        ++i)
00021     {
00022       this->adopt_child (*i);
00023     }
00024 
00025   this->nwords_ = this->n_ / bits_per_word + 1;
00026   ACE_NEW (this->bitvec_, Word[this->nwords_]);
00027 
00028   this->clear ();
00029 }
00030 
00031 TAO_EC_Conjunction_Filter::~TAO_EC_Conjunction_Filter (void)
00032 {
00033   TAO_EC_Filter** end = this->children_ + this->n_;
00034   for (TAO_EC_Filter** i = this->children_;
00035        i != end;
00036        ++i)
00037     {
00038       delete *i;
00039       *i = 0;
00040     }
00041   delete[] this->children_;
00042   this->children_ = 0;
00043   this->n_ = 0;
00044 
00045   delete[] this->bitvec_;
00046   this->bitvec_ = 0;
00047 }
00048 
00049 int
00050 TAO_EC_Conjunction_Filter::all_received (void) const
00051 {
00052   Word* i = this->bitvec_;
00053   for (;
00054        i != this->bitvec_ + this->nwords_;
00055        ++i)
00056     {
00057       if (*i != static_cast<Word> (~0))
00058         return 0;
00059     }
00060   return 1;
00061 }
00062 
00063 TAO_EC_Filter::ChildrenIterator
00064 TAO_EC_Conjunction_Filter::begin (void) const
00065 {
00066   return this->children_;
00067 }
00068 
00069 TAO_EC_Filter::ChildrenIterator
00070 TAO_EC_Conjunction_Filter::end (void) const
00071 {
00072   return this->children_ + this->n_;
00073 }
00074 
00075 int
00076 TAO_EC_Conjunction_Filter::size (void) const
00077 {
00078   return static_cast<int> (this->n_);
00079 }
00080 
00081 int
00082 TAO_EC_Conjunction_Filter::filter (const RtecEventComm::EventSet& event,
00083                                    TAO_EC_QOS_Info& qos_info)
00084 {
00085   ChildrenIterator end = this->end ();
00086   for (this->current_child_ = this->begin ();
00087        this->current_child_ != end;
00088        ++this->current_child_)
00089     {
00090       int n = (*this->current_child_)->filter (event, qos_info);
00091       if (n != 0)
00092         return n;
00093     }
00094   return 0;
00095 }
00096 
00097 int
00098 TAO_EC_Conjunction_Filter::filter_nocopy (RtecEventComm::EventSet& event,
00099                                           TAO_EC_QOS_Info& qos_info)
00100 {
00101   ChildrenIterator end = this->end ();
00102   for (ChildrenIterator i = this->begin ();
00103        i != end;
00104        ++i)
00105     {
00106       int n = (*i)->filter_nocopy (event, qos_info);
00107       if (n != 0)
00108         return n;
00109     }
00110   return 0;
00111 }
00112 
00113 void
00114 TAO_EC_Conjunction_Filter::push (const RtecEventComm::EventSet& event,
00115                                  TAO_EC_QOS_Info& qos_info)
00116 {
00117   CORBA::Long pos = this->current_child_ - this->begin ();
00118   int w = pos / bits_per_word;
00119   int b = pos % bits_per_word;
00120   if (ACE_BIT_ENABLED (this->bitvec_[w], 1<<b))
00121     return;
00122   ACE_SET_BITS (this->bitvec_[w], 1<<b);
00123   CORBA::ULong n = event.length ();
00124   CORBA::ULong l = this->event_.length ();
00125   this->event_.length (l + n);
00126   for (CORBA::ULong i = 0; i != n; ++i)
00127     {
00128       this->event_[l + i] = event[i];
00129     }
00130   if (this->all_received () && this->parent () != 0)
00131     this->parent ()->push_nocopy (this->event_, qos_info);
00132 }
00133 
00134 void
00135 TAO_EC_Conjunction_Filter::push_nocopy (RtecEventComm::EventSet& event,
00136                                         TAO_EC_QOS_Info& qos_info)
00137 {
00138   this->push (event, qos_info);
00139 }
00140 
00141 void
00142 TAO_EC_Conjunction_Filter::clear (void)
00143 {
00144   ChildrenIterator end = this->end ();
00145   for (ChildrenIterator i = this->begin ();
00146        i != end;
00147        ++i)
00148     {
00149       (*i)->clear ();
00150     }
00151   Word* j = this->bitvec_;
00152   for (;
00153        j != this->bitvec_ + this->nwords_ - 1;
00154        ++j)
00155     {
00156       *j = 0;
00157     }
00158   int b = static_cast<int> (this->n_ % bits_per_word);
00159   Word last = ~0 << b;
00160   *j = last;
00161 
00162   this->event_.length (0);
00163 }
00164 
00165 CORBA::ULong
00166 TAO_EC_Conjunction_Filter::max_event_size (void) const
00167 {
00168   CORBA::ULong n = 0;
00169   ChildrenIterator end = this->end ();
00170   for (ChildrenIterator i = this->begin ();
00171        i != end;
00172        ++i)
00173     {
00174       n += (*i)->max_event_size ();
00175     }
00176   return n;
00177 }
00178 
00179 int
00180 TAO_EC_Conjunction_Filter::can_match (
00181       const RtecEventComm::EventHeader& header) const
00182 {
00183   ChildrenIterator end = this->end ();
00184   for (ChildrenIterator i = this->begin ();
00185        i != end;
00186        ++i)
00187     {
00188       if ((*i)->can_match (header) != 0)
00189         return 1;
00190     }
00191   return 0;
00192 }
00193 
00194 int
00195 TAO_EC_Conjunction_Filter::add_dependencies (
00196       const RtecEventComm::EventHeader&,
00197       const TAO_EC_QOS_Info&)
00198 {
00199   return 0;
00200 }
00201 
00202 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:44:05 2010 for TAO_RTEvent by  doxygen 1.4.7