//// This example is from the ACE Programmers Guide.
////  Chapter:  "The Message Queue"
//// For details please see the guide at
//// http://www.cs.wustl.edu/~schmidt/ACE.html
////  AUTHOR: Umar Syyid ([email protected])
//// and Ambreen Ilyas ([email protected])

//Example 1
#include "ace/Message_Queue.h"
#include "ace/Get_Opt.h"
#define SIZE_BLOCK 1
#define NO_MSGS 10

class QTest{
 //First create a message queue of default size.
 if(!(this->mq_=new ACE_Message_Queue<ACE_NULL_SYNCH> ()))
  ACE_DEBUG((LM_ERROR,"Error in message queue initialization \n"));
int start_test(){
  for(int i=0; i<no_msgs_;i++){
 //create a new message block of size 1
 ACE_Message_Block *mb= new ACE_Message_Block(SIZE_BLOCK);

 //Insert data into the message block using the rd_ptr

 //Be careful to advance the wr_ptr

 //Enqueue the message block onto the message queue
  ACE_DEBUG((LM_ERROR,"\nCould not enqueue on to mq!!\n"));
  return -1;
 ACE_DEBUG((LM_INFO,"EQd data: %d\n",*mb->rd_ptr()));
   } //end for

//Now dequeue all the messages
return 0;

void dequeue_all(){
 ACE_DEBUG((LM_INFO,"\n\nBeginning DQ \n"));
 ACE_DEBUG((LM_INFO,"No. of Messages on Q:%d Bytes on Q:%d \n",mq_->message_count(), mq_->message_bytes()));
 ACE_Message_Block *mb;

 //dequeue the head of the message queue until no more messages are left
 for(int i=0;i<no_msgs_;i++){
  ACE_DEBUG((LM_INFO,"DQd data %d\n",*mb->rd_ptr()));
 ACE_Message_Queue<ACE_NULL_SYNCH> *mq_;
 int no_msgs_;

int main(int argc, char* argv[]){
 QTest test;
  ACE_DEBUG((LM_ERROR,"Program failure \n"));

 Next Example