Activation_Queue.cpp

Go to the documentation of this file.
00001 #include "ace/Activation_Queue.h"
00002 
00003 #if !defined (__ACE_INLINE__)
00004 #include "ace/Activation_Queue.inl"
00005 #endif /* __ACE_INLINE__ */
00006 
00007 #include "ace/Log_Msg.h"
00008 #include "ace/Method_Request.h"
00009 #include "ace/Malloc_Base.h"
00010 #include "ace/Time_Value.h"
00011 
00012 ACE_RCSID (ace,
00013            Activation_Queue,
00014            "Activation_Queue.cpp,v 4.30 2006/05/24 16:01:04 schmidt Exp")
00015 
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 void
00019 ACE_Activation_Queue::dump (void) const
00020 {
00021 #if defined (ACE_HAS_DUMP)
00022   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00023   ACE_DEBUG ((LM_DEBUG,
00024               ACE_LIB_TEXT ("delete_queue_ = %d\n"),
00025               this->delete_queue_));
00026   ACE_DEBUG ((LM_INFO, ACE_LIB_TEXT ("queue_: \n")));
00027   if (this->queue_)
00028     this->queue_->dump();
00029   else
00030     ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("(NULL)\n")));
00031   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00032 #endif /* ACE_HAS_DUMP */
00033 }
00034 
00035 ACE_Activation_Queue::ACE_Activation_Queue (ACE_Message_Queue<ACE_SYNCH> *new_queue,
00036                                             ACE_Allocator *alloc,
00037                                             ACE_Allocator *db_alloc)
00038   : delete_queue_ (0)
00039   , allocator_(alloc)
00040   , data_block_allocator_(db_alloc)
00041 {
00042   if (this->allocator_ == 0)
00043     this->allocator_ = ACE_Allocator::instance ();
00044 
00045   if (new_queue)
00046     this->queue_ = new_queue;
00047   else
00048     {
00049       ACE_NEW (this->queue_,
00050                ACE_Message_Queue<ACE_SYNCH>);
00051       this->delete_queue_ = 1;
00052     }
00053 }
00054 
00055 void
00056 ACE_Activation_Queue::queue (ACE_Message_Queue<ACE_SYNCH> *q)
00057 {
00058   // Destroy the internal queue if one exist.
00059   if (this->delete_queue_ != 0)
00060     {
00061       // Destroy the current queue.
00062       delete this->queue_;
00063  
00064       // Set the flag to false.  NOTE that the delete_queue_ flag is a
00065       // flag used to only indicate whether or not if an internal
00066       // ACE_Message_Queue has been created, therefore, it will not
00067       // affect the user if the user decided to replace the queue with
00068       // their own queue no matter how many time they call on this
00069       // function.
00070       this->delete_queue_ = 0;
00071     }
00072  
00073   queue_ = q;
00074 }
00075 
00076 ACE_Activation_Queue::~ACE_Activation_Queue (void)
00077 {
00078   if (this->delete_queue_ != 0)
00079     delete this->queue_;
00080 }
00081 
00082 ACE_Method_Request *
00083 ACE_Activation_Queue::dequeue (ACE_Time_Value *tv)
00084 {
00085   ACE_Message_Block *mb = 0;
00086 
00087   // Dequeue the message.
00088   if (this->queue_->dequeue_head (mb, tv) != -1)
00089     {
00090       // Get the next <Method_Request>.
00091       ACE_Method_Request *mr =
00092         reinterpret_cast<ACE_Method_Request *> (mb->base ());
00093       // Delete the message block.
00094       mb->release ();
00095       return mr;
00096     }
00097   else
00098     return 0;
00099 }
00100 
00101 int
00102 ACE_Activation_Queue::enqueue (ACE_Method_Request *mr,
00103                                ACE_Time_Value *tv)
00104 {
00105   ACE_Message_Block *mb = 0;
00106 
00107   // We pass sizeof (*mr) here so that flow control will work
00108   // correctly.  Since we also pass <mr> note that no unnecessary
00109   // memory is actually allocated -- just the size field is set.
00110   ACE_NEW_MALLOC_RETURN (mb,
00111                          static_cast<ACE_Message_Block *> (this->allocator_->malloc (sizeof (ACE_Message_Block))),
00112                          ACE_Message_Block (sizeof (*mr),    // size
00113                                             ACE_Message_Block::MB_DATA, // type
00114                                             0,       // cont
00115                                             (char *) mr,    // data
00116                                             0,       // allocator
00117                                             0,       // locking strategy
00118                                             mr->priority (), // priority
00119                                             ACE_Time_Value::zero,     // execution time
00120                                             ACE_Time_Value::max_time, // absolute time of deadline
00121                                             this->data_block_allocator_,  // data_block allocator
00122                                             this->allocator_), // message_block allocator
00123                          -1);
00124 
00125   // Enqueue in priority order.
00126   int const result = this->queue_->enqueue_prio (mb, tv);
00127 
00128   // Free ACE_Message_Block if enqueue_prio failed.
00129   if (result == -1)
00130       ACE_DES_FREE (mb, this->allocator_->free, ACE_Message_Block);
00131 
00132   return result;
00133 }
00134 
00135 ACE_END_VERSIONED_NAMESPACE_DECL

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