00001
00002
00003 #include "orbsvcs/Event/EC_Type_Filter.h"
00004
00005 ACE_RCSID(Event, EC_Type_Filter, "$Id: EC_Type_Filter.cpp 76589 2007-01-25 18:04:11Z elliott_c $")
00006
00007 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00008
00009 TAO_EC_Type_Filter::TAO_EC_Type_Filter (const RtecEventComm::EventHeader& header)
00010 : header_ (header)
00011 {
00012 }
00013
00014 int
00015 TAO_EC_Type_Filter::filter (const RtecEventComm::EventSet& event,
00016 TAO_EC_QOS_Info& qos_info)
00017 {
00018 if (event.length () != 1)
00019 return this->filter_set (event, qos_info);
00020
00021 if (this->can_match (event[0].header))
00022 {
00023 this->push (event, qos_info);
00024 return 1;
00025 }
00026 return 0;
00027 }
00028
00029 int
00030 TAO_EC_Type_Filter::filter_nocopy (RtecEventComm::EventSet& event,
00031 TAO_EC_QOS_Info& qos_info)
00032 {
00033 if (event.length () != 1)
00034 return this->filter_set (event, qos_info);
00035
00036 if (this->can_match (event[0].header))
00037 {
00038 this->push_nocopy (event, qos_info);
00039 return 1;
00040 }
00041 return 0;
00042 }
00043
00044 void
00045 TAO_EC_Type_Filter::push (const RtecEventComm::EventSet& event,
00046 TAO_EC_QOS_Info& qos_info)
00047 {
00048 if (this->parent () != 0)
00049 this->parent ()->push (event, qos_info);
00050 }
00051
00052 void
00053 TAO_EC_Type_Filter::push_nocopy (RtecEventComm::EventSet& event,
00054 TAO_EC_QOS_Info& qos_info)
00055 {
00056 if (this->parent () != 0)
00057 this->parent ()->push_nocopy (event, qos_info);
00058 }
00059
00060 void
00061 TAO_EC_Type_Filter::clear (void)
00062 {
00063 }
00064
00065 CORBA::ULong
00066 TAO_EC_Type_Filter::max_event_size (void) const
00067 {
00068 return 1;
00069 }
00070
00071 int
00072 TAO_EC_Type_Filter::can_match (
00073 const RtecEventComm::EventHeader& header) const
00074 {
00075 if (this->header_.source == 0)
00076 {
00077 if (this->header_.type == 0 || header.type == 0)
00078 return 1;
00079 else
00080 return this->header_.type == header.type;
00081 }
00082
00083 if (this->header_.type == 0)
00084 {
00085 if (header.source == 0)
00086 return 1;
00087 else
00088 return this->header_.source == header.source;
00089 }
00090
00091 if (header.source == 0)
00092 {
00093 if (header.type != 0)
00094 return this->header_.type == header.type;
00095 return 1;
00096 }
00097
00098 if (header.type == 0)
00099 {
00100 return this->header_.source == header.source;
00101 }
00102
00103 return (this->header_.type == header.type
00104 && this->header_.source == header.source);
00105 }
00106
00107 int
00108 TAO_EC_Type_Filter::add_dependencies (
00109 const RtecEventComm::EventHeader& header,
00110 const TAO_EC_QOS_Info &)
00111 {
00112 return this->can_match (header);
00113 }
00114
00115 int
00116 TAO_EC_Type_Filter::filter_set (const RtecEventComm::EventSet& event,
00117 TAO_EC_QOS_Info& qos_info)
00118 {
00119 CORBA::ULong maximum = event.length ();
00120 if (event.maximum () == 0)
00121 return 0;
00122
00123 RtecEventComm::EventSet matched (maximum);
00124 CORBA::ULong next_slot = 0;
00125 for (CORBA::ULong i = 0; i != maximum; ++i)
00126 {
00127 if (!this->can_match (event[i].header))
00128 continue;
00129 matched.length (next_slot + 1);
00130 matched[next_slot] = event[i];
00131 next_slot++;
00132 }
00133 if (matched.length () == 0)
00134 return 0;
00135
00136 this->push (matched, qos_info);
00137
00138 return 1;
00139 }
00140
00141 TAO_END_VERSIONED_NAMESPACE_DECL