Message_Block.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Message_Block.inl,v 4.4 2005/10/28 16:14:53 ossama Exp
00004 
00005 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00006 
00007 ACE_INLINE ACE_Data_Block *
00008 ACE_Message_Block::data_block (void) const
00009 {
00010   ACE_TRACE ("ACE_Message_Block::data_block");
00011   return this->data_block_;
00012 }
00013 
00014 ACE_INLINE ACE_Message_Block::Message_Flags
00015 ACE_Message_Block::set_self_flags (ACE_Message_Block::Message_Flags more_flags)
00016 {
00017   ACE_TRACE ("ACE_Message_Block::set_self_flags");
00018   // Later we might mask more_glags so that user can't change internal
00019   // ones: more_flags &= ~(USER_FLAGS -1).
00020   return ACE_SET_BITS (this->flags_, more_flags);
00021 }
00022 
00023 ACE_INLINE ACE_Message_Block::Message_Flags
00024 ACE_Message_Block::clr_self_flags (ACE_Message_Block::Message_Flags less_flags)
00025 {
00026   ACE_TRACE ("ACE_Message_Block::clr_self_flags");
00027   // Later we might mask more_flags so that user can't change internal
00028   // ones: less_flags &= ~(USER_FLAGS -1).
00029   return ACE_CLR_BITS (this->flags_, less_flags);
00030 }
00031 
00032 ACE_INLINE ACE_Message_Block::Message_Flags
00033 ACE_Message_Block::self_flags (void) const
00034 {
00035   ACE_TRACE ("ACE_Message_Block::self_flags");
00036   return this->flags_;
00037 }
00038 
00039 ACE_INLINE int
00040 ACE_Data_Block::reference_count_i (void) const
00041 {
00042   return reference_count_;
00043 }
00044 
00045 ACE_INLINE int
00046 ACE_Message_Block::reference_count (void) const
00047 {
00048   return data_block () ? data_block ()->reference_count () : 0;
00049 }
00050 
00051 ACE_INLINE char *
00052 ACE_Data_Block::base (void) const
00053 {
00054   ACE_TRACE ("ACE_Data_Block::base");
00055   return this->base_;
00056 }
00057 
00058 ACE_INLINE size_t
00059 ACE_Data_Block::size (void) const
00060 {
00061   ACE_TRACE ("ACE_Data_Block::size");
00062   return this->cur_size_;
00063 }
00064 
00065 ACE_INLINE size_t
00066 ACE_Data_Block::capacity (void) const
00067 {
00068   ACE_TRACE ("ACE_Data_Block::capacity");
00069   return this->max_size_;
00070 }
00071 
00072 ACE_INLINE ACE_Message_Block::Message_Flags
00073 ACE_Data_Block::set_flags (ACE_Message_Block::Message_Flags more_flags)
00074 {
00075   ACE_TRACE ("ACE_Data_Block::set_flags");
00076   // Later we might mask more_glags so that user can't change internal
00077   // ones: more_flags &= ~(USER_FLAGS -1).
00078   return ACE_SET_BITS (this->flags_, more_flags);
00079 }
00080 
00081 ACE_INLINE ACE_Message_Block::Message_Flags
00082 ACE_Data_Block::clr_flags (ACE_Message_Block::Message_Flags less_flags)
00083 {
00084   ACE_TRACE ("ACE_Data_Block::clr_flags");
00085   // Later we might mask more_flags so that user can't change internal
00086   // ones: less_flags &= ~(USER_FLAGS -1).
00087   return ACE_CLR_BITS (this->flags_, less_flags);
00088 }
00089 
00090 ACE_INLINE ACE_Message_Block::Message_Flags
00091 ACE_Data_Block::flags (void) const
00092 {
00093   ACE_TRACE ("ACE_Data_Block::flags");
00094    return this->flags_;
00095 }
00096 
00097 ACE_INLINE ACE_Allocator*
00098 ACE_Data_Block::data_block_allocator (void) const
00099 {
00100   ACE_TRACE ("ACE_Data_Block::data_block_allocator");
00101   return this->data_block_allocator_;
00102 }
00103 
00104 ACE_INLINE ACE_Message_Block::Message_Flags
00105 ACE_Message_Block::set_flags (ACE_Message_Block::Message_Flags more_flags)
00106 {
00107   ACE_TRACE ("ACE_Message_Block::set_flags");
00108   return this->data_block ()->set_flags (more_flags);
00109 }
00110 
00111 ACE_INLINE ACE_Message_Block::Message_Flags
00112 ACE_Message_Block::clr_flags (ACE_Message_Block::Message_Flags less_flags)
00113 {
00114   ACE_TRACE ("ACE_Message_Block::clr_flags");
00115   return this->data_block ()->clr_flags (less_flags);
00116 }
00117 
00118 ACE_INLINE ACE_Message_Block::Message_Flags
00119 ACE_Message_Block::flags (void) const
00120 {
00121   ACE_TRACE ("ACE_Message_Block::flags");
00122    return this->data_block ()->flags ();
00123 }
00124 
00125 // Return the length of the "active" portion of the message.
00126 
00127 ACE_INLINE size_t
00128 ACE_Message_Block::length (void) const
00129 {
00130   ACE_TRACE ("ACE_Message_Block::length");
00131   return this->wr_ptr_ - this->rd_ptr_;
00132 }
00133 
00134 // Sets the length of the "active" portion of the message.  This is
00135 // defined as the offset from RD_PTR to WR_PTR.
00136 
00137 ACE_INLINE void
00138 ACE_Message_Block::length (size_t len)
00139 {
00140   ACE_TRACE ("ACE_Message_Block::length");
00141   this->wr_ptr_ = this->rd_ptr_ + len;
00142 }
00143 
00144 // Return the length of the potential size of the message.
00145 
00146 ACE_INLINE size_t
00147 ACE_Message_Block::size (void) const
00148 {
00149   ACE_TRACE ("ACE_Message_Block::size");
00150   return this->data_block ()->size ();
00151 }
00152 
00153 ACE_INLINE size_t
00154 ACE_Message_Block::capacity (void) const
00155 {
00156   ACE_TRACE ("ACE_Message_Block::capacity");
00157   return this->data_block ()->capacity ();
00158 }
00159 
00160 ACE_INLINE ACE_Message_Block::ACE_Message_Type
00161 ACE_Data_Block::msg_type (void) const
00162 {
00163   ACE_TRACE ("ACE_Data_Block::msg_type");
00164   return this->type_;
00165 }
00166 
00167 ACE_INLINE void
00168 ACE_Data_Block::msg_type (ACE_Message_Block::ACE_Message_Type t)
00169 {
00170   ACE_TRACE ("ACE_Data_Block::msg_type");
00171   this->type_ = t;
00172 }
00173 
00174 ACE_INLINE ACE_Message_Block::ACE_Message_Type
00175 ACE_Message_Block::msg_type (void) const
00176 {
00177   ACE_TRACE ("ACE_Message_Block::msg_type");
00178   return this->data_block ()->msg_type ();
00179 }
00180 
00181 ACE_INLINE void
00182 ACE_Message_Block::msg_type (ACE_Message_Block::ACE_Message_Type t)
00183 {
00184   ACE_TRACE ("ACE_Message_Block::msg_type");
00185   this->data_block ()->msg_type (t);
00186 }
00187 
00188 ACE_INLINE ACE_Message_Block::ACE_Message_Type
00189 ACE_Message_Block::msg_class (void) const
00190 {
00191   ACE_TRACE ("ACE_Message_Block::msg_class");
00192 
00193   if (this->msg_type () < ACE_Message_Block::MB_PRIORITY)
00194     return ACE_Message_Block::MB_NORMAL;
00195   else if (this->msg_type () < ACE_Message_Block::MB_USER)
00196     return ACE_Message_Block::MB_PRIORITY;
00197   else
00198     return ACE_Message_Block::MB_USER;
00199 }
00200 
00201 ACE_INLINE int
00202 ACE_Message_Block::is_data_msg (void) const
00203 {
00204   ACE_TRACE ("ACE_Message_Block::is_data_msg");
00205   ACE_Message_Type mt = this->msg_type ();
00206   return
00207     mt == ACE_Message_Block::MB_DATA
00208     || mt == ACE_Message_Block::MB_PROTO
00209     || mt == ACE_Message_Block::MB_PCPROTO;
00210 }
00211 
00212 ACE_INLINE unsigned long
00213 ACE_Message_Block::msg_priority (void) const
00214 {
00215   ACE_TRACE ("ACE_Message_Block::msg_priority");
00216   return this->priority_;
00217 }
00218 
00219 ACE_INLINE void
00220 ACE_Message_Block::msg_priority (unsigned long pri)
00221 {
00222   ACE_TRACE ("ACE_Message_Block::msg_priority");
00223   this->priority_ = pri;
00224 }
00225 
00226 ACE_INLINE const ACE_Time_Value &
00227 ACE_Message_Block::msg_execution_time (void) const
00228 {
00229   ACE_TRACE ("ACE_Message_Block::msg_execution_time (void)");
00230 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00231   return this->execution_time_;
00232 #else
00233   return ACE_Time_Value::zero;
00234 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00235 }
00236 
00237 ACE_INLINE void
00238 ACE_Message_Block::msg_execution_time (const ACE_Time_Value &et)
00239 {
00240   ACE_TRACE ("ACE_Message_Block::msg_execution_time (const ACE_Time_Value & et)");
00241 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00242   this->execution_time_ = et;
00243 #else
00244   ACE_UNUSED_ARG (et);
00245 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00246 }
00247 
00248 ACE_INLINE const ACE_Time_Value &
00249 ACE_Message_Block::msg_deadline_time (void) const
00250 {
00251   ACE_TRACE ("ACE_Message_Block::msg_deadline_time (void)");
00252 
00253 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00254   return this->deadline_time_;
00255 #else
00256   return ACE_Time_Value::max_time; // absolute time of deadline
00257 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00258 }
00259 
00260 ACE_INLINE void
00261 ACE_Message_Block::msg_deadline_time (const ACE_Time_Value &dt)
00262 {
00263   ACE_TRACE ("ACE_Message_Block::msg_deadline_time (const ACE_Time_Value & et)");
00264 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00265   this->deadline_time_ = dt;
00266 #else
00267   ACE_UNUSED_ARG (dt);
00268 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00269 }
00270 
00271 ACE_INLINE void
00272 ACE_Message_Block::access_allocators (ACE_Allocator *& allocator_strategy,
00273                                       ACE_Allocator *& data_block_allocator,
00274                                       ACE_Allocator *& message_block_allocator)
00275 {
00276   allocator_strategy =
00277     this->data_block_->allocator_strategy_;
00278   data_block_allocator =
00279     this->data_block_->data_block_allocator_;
00280   message_block_allocator =
00281     this->message_block_allocator_;
00282 }
00283 
00284 ACE_INLINE char *
00285 ACE_Message_Block::base (void) const
00286 {
00287   ACE_TRACE ("ACE_Message_Block::base");
00288   return this->data_block ()->base ();
00289 }
00290 
00291 ACE_INLINE void
00292 ACE_Message_Block::base (char *msg_data,
00293                          size_t msg_length,
00294                          Message_Flags msg_flags)
00295 {
00296   ACE_TRACE ("ACE_Message_Block::base");
00297   this->rd_ptr_ = 0;
00298   this->wr_ptr_ = 0;
00299   this->data_block ()->base (msg_data, msg_length, msg_flags);
00300 }
00301 
00302 ACE_INLINE char *
00303 ACE_Message_Block::rd_ptr (void) const
00304 {
00305   ACE_TRACE ("ACE_Message_Block::rd_ptr");
00306   return this->base () + this->rd_ptr_;
00307 }
00308 
00309 ACE_INLINE void
00310 ACE_Message_Block::wr_ptr (char *new_ptr)
00311 {
00312   ACE_TRACE ("ACE_Message_Block::wr_ptr");
00313   this->wr_ptr_ = new_ptr - this->base ();
00314 }
00315 
00316 // Return a pointer to 1 past the end of the data buffer.
00317 
00318 ACE_INLINE char *
00319 ACE_Data_Block::mark (void) const
00320 {
00321   ACE_TRACE ("ACE_Data_Block::mark");
00322   return this->base_ + this->cur_size_;
00323 }
00324 
00325 ACE_INLINE char *
00326 ACE_Message_Block::mark (void) const
00327 {
00328   ACE_TRACE ("ACE_Message_Block::mark");
00329   return this->data_block ()->mark ();
00330 }
00331 
00332 ACE_INLINE char *
00333 ACE_Data_Block::end (void) const
00334 {
00335   ACE_TRACE ("ACE_Data_Block::end");
00336   return this->base_ + this->max_size_;
00337 }
00338 
00339 ACE_INLINE char *
00340 ACE_Message_Block::end (void) const
00341 {
00342   ACE_TRACE ("ACE_Message_Block::end");
00343   return this->data_block ()->end ();
00344 }
00345 
00346 
00347 ACE_INLINE void
00348 ACE_Message_Block::rd_ptr (char *new_ptr)
00349 {
00350   ACE_TRACE ("ACE_Message_Block::rd_ptr");
00351   this->rd_ptr_ = new_ptr - this->base ();
00352 }
00353 
00354 ACE_INLINE void
00355 ACE_Message_Block::rd_ptr (size_t n)
00356 {
00357   ACE_TRACE ("ACE_Message_Block::rd_ptr");
00358   this->rd_ptr_ += n;
00359 }
00360 
00361 ACE_INLINE char *
00362 ACE_Message_Block::wr_ptr (void) const
00363 {
00364   ACE_TRACE ("ACE_Message_Block::wr_ptr");
00365   return this->base () + this->wr_ptr_;
00366 }
00367 
00368 ACE_INLINE void
00369 ACE_Message_Block::wr_ptr (size_t n)
00370 {
00371   ACE_TRACE ("ACE_Message_Block::wr_ptr");
00372   this->wr_ptr_ += n;
00373 }
00374 
00375 ACE_INLINE void
00376 ACE_Message_Block::reset (void)
00377 {
00378   ACE_TRACE ("ACE_Message_Block::reset");
00379   this->rd_ptr_ = 0;
00380   this->wr_ptr_ = 0;
00381 }
00382 
00383 ACE_INLINE size_t
00384 ACE_Message_Block::space (void) const
00385 {
00386   ACE_TRACE ("ACE_Message_Block::space");
00387   return this->mark () - this->wr_ptr ();
00388 }
00389 
00390 ACE_INLINE ACE_Data_Block *
00391 ACE_Message_Block::replace_data_block (ACE_Data_Block *db)
00392 {
00393   ACE_TRACE ("ACE_Message_Block::replace_data_block");
00394   ACE_Data_Block *old = this->data_block_;
00395   this->data_block_ = db;
00396 
00397   if (db != 0)
00398     {
00399       // Set the read and write pointers in the <Message_Block> to point
00400       // to the buffer in the <ACE_Data_Block>.
00401       this->rd_ptr (this->data_block ()->base ());
00402       this->wr_ptr (this->data_block ()->base ());
00403     }
00404 
00405   return old;
00406 }
00407 
00408 ACE_INLINE void
00409 ACE_Message_Block::cont (ACE_Message_Block *cont_msg)
00410 {
00411   ACE_TRACE ("ACE_Message_Block::cont");
00412   this->cont_ = cont_msg;
00413 }
00414 
00415 ACE_INLINE ACE_Message_Block *
00416 ACE_Message_Block::cont (void) const
00417 {
00418   ACE_TRACE ("ACE_Message_Block::cont");
00419   return this->cont_;
00420 }
00421 
00422 ACE_INLINE void
00423 ACE_Message_Block::reset_allocators (ACE_Allocator *allocator_strategy,
00424                                      ACE_Allocator *data_block_allocator,
00425                                      ACE_Allocator *message_block_allocator)
00426 {
00427   this->data_block_->allocator_strategy_ =
00428     allocator_strategy;
00429   this->data_block_->data_block_allocator_ =
00430     data_block_allocator;
00431   this->message_block_allocator_ =
00432     message_block_allocator;
00433 
00434   if (this->cont () != 0)
00435     this->cont ()->reset_allocators (allocator_strategy,
00436                                      data_block_allocator,
00437                                      message_block_allocator);
00438 }
00439 
00440 ACE_INLINE void
00441 ACE_Message_Block::next (ACE_Message_Block *next_msg)
00442 {
00443   ACE_TRACE ("ACE_Message_Block::next");
00444   this->next_ = next_msg;
00445 }
00446 
00447 ACE_INLINE ACE_Message_Block *
00448 ACE_Message_Block::next (void) const
00449 {
00450   ACE_TRACE ("ACE_Message_Block::next");
00451   return this->next_;
00452 }
00453 
00454 ACE_INLINE void
00455 ACE_Message_Block::prev (ACE_Message_Block *next_msg)
00456 {
00457   ACE_TRACE ("ACE_Message_Block::prev");
00458   this->prev_ = next_msg;
00459 }
00460 
00461 ACE_INLINE ACE_Message_Block *
00462 ACE_Message_Block::prev (void) const
00463 {
00464   ACE_TRACE ("ACE_Message_Block::prev");
00465   return this->prev_;
00466 }
00467 
00468 ACE_INLINE ACE_Allocator *
00469 ACE_Data_Block::allocator_strategy (void) const
00470 {
00471   ACE_TRACE ("ACE_Data_Block::allocator_strategy");
00472   return this->allocator_strategy_;
00473 }
00474 
00475 ACE_INLINE ACE_Lock *
00476 ACE_Data_Block::locking_strategy (void)
00477 {
00478   ACE_TRACE ("ACE_Data_Block::locking_strategy");
00479   return this->locking_strategy_;
00480 }
00481 
00482 ACE_INLINE ACE_Lock *
00483 ACE_Data_Block::locking_strategy (ACE_Lock *nls)
00484 {
00485   ACE_TRACE ("ACE_Data_Block::locking_strategy");
00486   ACE_Lock *ols = this->locking_strategy_;
00487 
00488   this->locking_strategy_ = nls;
00489   return ols;
00490 }
00491 
00492 ACE_INLINE ACE_Lock *
00493 ACE_Message_Block::locking_strategy (void)
00494 {
00495   ACE_TRACE ("ACE_Message_Block::locking_strategy");
00496   return this->data_block ()->locking_strategy ();
00497 }
00498 
00499 ACE_INLINE ACE_Lock *
00500 ACE_Message_Block::locking_strategy (ACE_Lock *nls)
00501 {
00502   ACE_TRACE ("ACE_Message_Block::locking_strategy");
00503   ACE_Lock *ols = this->data_block ()->locking_strategy ();
00504   this->data_block ()->locking_strategy (nls);
00505   return ols;
00506 }
00507 
00508 
00509 ////////////////////////////////////////
00510 // class ACE_Dynamic_Message_Strategy //
00511 ////////////////////////////////////////
00512 
00513 ACE_INLINE unsigned long
00514 ACE_Dynamic_Message_Strategy::static_bit_field_mask (void) const
00515 {
00516   return static_bit_field_mask_;
00517 }
00518   // get static bit field mask
00519 
00520 ACE_INLINE void
00521 ACE_Dynamic_Message_Strategy::static_bit_field_mask (unsigned long ul)
00522 {
00523   static_bit_field_mask_ = ul;
00524 }
00525   // set static bit field mask
00526 
00527 ACE_INLINE unsigned long
00528 ACE_Dynamic_Message_Strategy::static_bit_field_shift (void) const
00529 {
00530   return static_bit_field_shift_;
00531 }
00532   // get left shift value to make room for static bit field
00533 
00534 ACE_INLINE void
00535 ACE_Dynamic_Message_Strategy::static_bit_field_shift (unsigned long ul)
00536 {
00537   static_bit_field_shift_ = ul;
00538 }
00539   // set left shift value to make room for static bit field
00540 
00541 ACE_INLINE unsigned long
00542 ACE_Dynamic_Message_Strategy::dynamic_priority_max (void) const
00543 {
00544   return dynamic_priority_max_;
00545 }
00546   // get maximum supported priority value
00547 
00548 ACE_INLINE void
00549 ACE_Dynamic_Message_Strategy::dynamic_priority_max (unsigned long ul)
00550 {
00551   // pending_shift_ depends on dynamic_priority_max_: for performance
00552   // reasons, the value in pending_shift_ is (re)calculated only when
00553   // dynamic_priority_max_ is initialized or changes, and is stored
00554   // as a class member rather than being a derived value.
00555   dynamic_priority_max_ = ul;
00556   pending_shift_ = ACE_Time_Value (0, ul);
00557 }
00558   // set maximum supported priority value
00559 
00560 ACE_INLINE unsigned long
00561 ACE_Dynamic_Message_Strategy::dynamic_priority_offset (void) const
00562 {
00563   return dynamic_priority_offset_;
00564 }
00565   // get offset for boundary between signed range and unsigned range
00566 
00567 ACE_INLINE void
00568 ACE_Dynamic_Message_Strategy::dynamic_priority_offset (unsigned long ul)
00569 {
00570   // max_late_ and min_pending_ depend on dynamic_priority_offset_:
00571   // for performance reasons, the values in max_late_ and min_pending_
00572   // are (re)calculated only when dynamic_priority_offset_ is
00573   // initialized or changes, and are stored as a class member rather
00574   // than being derived each time one of their values is needed.
00575   dynamic_priority_offset_ = ul;
00576   max_late_ = ACE_Time_Value (0, ul - 1);
00577   min_pending_ = ACE_Time_Value (0, ul);
00578 }
00579   // set offset for boundary between signed range and unsigned range
00580 
00581 
00582 ACE_INLINE ACE_Dynamic_Message_Strategy::Priority_Status
00583 ACE_Dynamic_Message_Strategy::priority_status (ACE_Message_Block & mb,
00584                                                const ACE_Time_Value & tv)
00585 {
00586   // default the message to have pending priority status
00587   Priority_Status status = ACE_Dynamic_Message_Strategy::PENDING;
00588 
00589   // start with the passed absolute time as the message's priority, then
00590   // call the polymorphic hook method to (at least partially) convert
00591   // the absolute time and message attributes into the message's priority
00592   ACE_Time_Value priority (tv);
00593   convert_priority (priority, mb);
00594 
00595   // if the priority is negative, the message is pending
00596   if (priority < ACE_Time_Value::zero)
00597     {
00598       // priority for pending messages must be shifted
00599       // upward above the late priority range
00600       priority += pending_shift_;
00601       if (priority < min_pending_)
00602         priority = min_pending_;
00603     }
00604   // otherwise, if the priority is greater than the maximum late
00605   // priority value that can be represented, it is beyond late
00606   else if (priority > max_late_)
00607     {
00608       // all messages that are beyond late are assigned lowest priority (zero)
00609       mb.msg_priority (0);
00610       return ACE_Dynamic_Message_Strategy::BEYOND_LATE;
00611     }
00612   // otherwise, the message is late, but its priority is correct
00613   else
00614     status = ACE_Dynamic_Message_Strategy::LATE;
00615 
00616   // use (fast) bitwise operators to isolate and replace
00617   // the dynamic portion of the message's priority
00618   mb.msg_priority((mb.msg_priority() & static_bit_field_mask_) |
00619                   ((priority.usec () + ACE_ONE_SECOND_IN_USECS * priority.sec ()) <<
00620                    static_bit_field_shift_));
00621 
00622   return status;
00623 }
00624   // returns the priority status of the message
00625 
00626 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:56 2006 for ACE by doxygen 1.3.6