Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Activation_Queue.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 #include "ace/Activation_Queue.h"
00003 
00004 #if !defined (__ACE_INLINE__)
00005 #include "ace/Activation_Queue.i"
00006 #endif /* __ACE_INLINE__ */
00007 
00008 #include "ace/Log_Msg.h"
00009 #include "ace/Malloc_Base.h"
00010 
00011 ACE_RCSID (ace,
00012            Activation_Queue,
00013            "$Id: Activation_Queue.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:20 chad Exp $")
00014 
00015 
00016 void
00017 ACE_Activation_Queue::dump (void) const
00018 {
00019   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00020   ACE_DEBUG ((LM_DEBUG,
00021               ACE_LIB_TEXT ("delete_queue_ = %d\n"),
00022               this->delete_queue_));
00023   ACE_DEBUG ((LM_INFO, ACE_LIB_TEXT ("queue_: \n")));
00024   if (this->queue_)
00025     this->queue_->dump();
00026   else
00027     ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("(NULL)\n")));
00028   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00029 }
00030 
00031 ACE_Activation_Queue::ACE_Activation_Queue (ACE_Message_Queue<ACE_SYNCH> *new_queue,
00032                                             ACE_Allocator *alloc,
00033                                             ACE_Allocator *db_alloc)
00034   : delete_queue_ (0)
00035   , allocator_(alloc)
00036   , data_block_allocator_(db_alloc)
00037 {
00038   if (this->allocator_ == 0)
00039     this->allocator_ = ACE_Allocator::instance ();
00040 
00041   if (new_queue)
00042     this->queue_ = new_queue;
00043   else
00044     {
00045       ACE_NEW (this->queue_,
00046                ACE_Message_Queue<ACE_SYNCH>);
00047       this->delete_queue_ = 1;
00048     }
00049 }
00050 
00051 ACE_Activation_Queue::~ACE_Activation_Queue (void)
00052 {
00053   if (this->delete_queue_ != 0)
00054     delete this->queue_;
00055 }
00056 
00057 ACE_Method_Request *
00058 ACE_Activation_Queue::dequeue (ACE_Time_Value *tv)
00059 {
00060   ACE_Message_Block *mb;
00061 
00062   // Dequeue the message.
00063   if (this->queue_->dequeue_head (mb, tv) != -1)
00064     {
00065       // Get the next <Method_Request>.
00066       ACE_Method_Request *mr =
00067         ACE_reinterpret_cast (ACE_Method_Request *,
00068                               mb->base ());
00069       // Delete the message block.
00070       mb->release ();
00071       return mr;
00072     }
00073   else
00074     return 0;
00075 }
00076 
00077 int
00078 ACE_Activation_Queue::enqueue (ACE_Method_Request *mr,
00079                                ACE_Time_Value *tv)
00080 {
00081   ACE_Message_Block *mb;
00082 
00083   // We pass sizeof (*mr) here so that flow control will work
00084   // correctly.  Since we also pass <mr> note that no unnecessary
00085   // memory is actually allocated -- just the size field is set.
00086   ACE_NEW_MALLOC_RETURN (mb,
00087                          ACE_static_cast(ACE_Message_Block *,
00088                                          this->allocator_->malloc (sizeof (ACE_Message_Block))),
00089                          ACE_Message_Block (sizeof (*mr),    // size
00090                                             ACE_Message_Block::MB_DATA, // type
00091                                             0,       // cont
00092                                             (char *) mr,    // data
00093                                             0,       // allocator
00094                                             0,       // locking strategy
00095                                             mr->priority (), // priority
00096                                             ACE_Time_Value::zero,     // execution time
00097                                             ACE_Time_Value::max_time, // absolute time of deadline
00098                                             this->data_block_allocator_,  // data_block allocator
00099                                             this->allocator_), // message_block allocator
00100                          -1);
00101 
00102   // Enqueue in priority order.
00103   int result = this->queue_->enqueue_prio (mb, tv);
00104 
00105   // Free ACE_Message_Block if enqueue_prio failed.
00106   if (result == -1)
00107       ACE_DES_FREE (mb, this->allocator_->free, ACE_Message_Block);
00108 
00109   return result;
00110 }

Generated on Mon Jun 16 11:19:02 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002