00001 #include "ace/Activation_Queue.h"
00002
00003 #if !defined (__ACE_INLINE__)
00004 #include "ace/Activation_Queue.inl"
00005 #endif
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
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
00059 if (this->delete_queue_ != 0)
00060 {
00061
00062 delete this->queue_;
00063
00064
00065
00066
00067
00068
00069
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
00088 if (this->queue_->dequeue_head (mb, tv) != -1)
00089 {
00090
00091 ACE_Method_Request *mr =
00092 reinterpret_cast<ACE_Method_Request *> (mb->base ());
00093
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
00108
00109
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),
00113 ACE_Message_Block::MB_DATA,
00114 0,
00115 (char *) mr,
00116 0,
00117 0,
00118 mr->priority (),
00119 ACE_Time_Value::zero,
00120 ACE_Time_Value::max_time,
00121 this->data_block_allocator_,
00122 this->allocator_),
00123 -1);
00124
00125
00126 int const result = this->queue_->enqueue_prio (mb, tv);
00127
00128
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