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 "$Id: Activation_Queue.cpp 80826 2008-03-04 14:51:23Z wotte $")
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_TEXT ("delete_queue_ = %d\n"),
00025 this->delete_queue_));
00026 ACE_DEBUG ((LM_INFO, ACE_TEXT ("queue_: \n")));
00027 if (this->queue_)
00028 this->queue_->dump();
00029 else
00030
00031 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(NULL)\n")));
00032
00033
00034 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00035 #endif
00036 }
00037
00038 ACE_Activation_Queue::ACE_Activation_Queue (ACE_Message_Queue<ACE_SYNCH> *new_queue,
00039 ACE_Allocator *alloc,
00040 ACE_Allocator *db_alloc)
00041 : delete_queue_ (false)
00042 , allocator_(alloc)
00043 , data_block_allocator_(db_alloc)
00044 {
00045 if (this->allocator_ == 0)
00046 this->allocator_ = ACE_Allocator::instance ();
00047
00048 if (new_queue)
00049 this->queue_ = new_queue;
00050 else
00051 {
00052 ACE_NEW (this->queue_,
00053 ACE_Message_Queue<ACE_SYNCH>);
00054 this->delete_queue_ = true;
00055 }
00056 }
00057
00058 void
00059 ACE_Activation_Queue::queue (ACE_Message_Queue<ACE_SYNCH> *q)
00060 {
00061
00062 if (this->delete_queue_)
00063 {
00064
00065 delete this->queue_;
00066
00067
00068
00069
00070
00071
00072
00073 this->delete_queue_ = false;
00074 }
00075
00076 queue_ = q;
00077 }
00078
00079 ACE_Activation_Queue::~ACE_Activation_Queue (void)
00080 {
00081 if (this->delete_queue_)
00082 delete this->queue_;
00083 }
00084
00085 ACE_Method_Request *
00086 ACE_Activation_Queue::dequeue (ACE_Time_Value *tv)
00087 {
00088 ACE_Message_Block *mb = 0;
00089
00090
00091 if (this->queue_->dequeue_head (mb, tv) != -1)
00092 {
00093
00094 ACE_Method_Request *mr =
00095 reinterpret_cast<ACE_Method_Request *> (mb->base ());
00096
00097 mb->release ();
00098 return mr;
00099 }
00100 else
00101 return 0;
00102 }
00103
00104 int
00105 ACE_Activation_Queue::enqueue (ACE_Method_Request *mr,
00106 ACE_Time_Value *tv)
00107 {
00108 ACE_Message_Block *mb = 0;
00109
00110
00111
00112
00113 ACE_NEW_MALLOC_RETURN (mb,
00114 static_cast<ACE_Message_Block *> (this->allocator_->malloc (sizeof (ACE_Message_Block))),
00115 ACE_Message_Block (sizeof (*mr),
00116 ACE_Message_Block::MB_DATA,
00117 0,
00118 (char *) mr,
00119 0,
00120 0,
00121 mr->priority (),
00122 ACE_Time_Value::zero,
00123 ACE_Time_Value::max_time,
00124 this->data_block_allocator_,
00125 this->allocator_),
00126 -1);
00127
00128
00129 int const result = this->queue_->enqueue_prio (mb, tv);
00130
00131
00132 if (result == -1)
00133 ACE_DES_FREE (mb, this->allocator_->free, ACE_Message_Block);
00134
00135 return result;
00136 }
00137
00138 ACE_END_VERSIONED_NAMESPACE_DECL