(file) Return to MessageQueue.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/MessageQueue.cpp between version 1.37 and 1.56.18.1

version 1.37, 2003/11/07 19:18:46 version 1.56.18.1, 2008/07/01 15:18:00
Line 1 
Line 1 
 //%2003////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
 // IBM Corp.; EMC Corporation, The Open Group. // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 23 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com)  
 //  
 // Modified By:  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/HashTable.h> #include <Pegasus/Common/HashTable.h>
 #include <Pegasus/Common/IPC.h>  
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
   #include <Pegasus/Common/CimomMessage.h>
 #include "MessageQueue.h" #include "MessageQueue.h"
 #include "MessageQueueService.h"  #include "IDFactory.h"
   
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
Line 44 
Line 47 
 static QueueTable _queueTable(256); static QueueTable _queueTable(256);
 static Mutex q_table_mut ; static Mutex q_table_mut ;
  
 void MessageQueue::remove_myself(Uint32 qid)  static IDFactory _qidFactory(CIMOM_Q_ID + 1);
 {  
    q_table_mut.lock(pegasus_thread_self());  
   
    _queueTable.remove(qid);  
    q_table_mut.unlock();  
 }  
   
   
 Uint32 MessageQueue::getNextQueueId() throw(IPCException)  
 {  
    static Uint32 _nextQueueId = 2;  
   
    //  
    // Lock mutex:  
    //  
   
    static Mutex _id_mut ;  
    _id_mut.lock(pegasus_thread_self());  
   
    Uint32 queueId;  
  
    // Assign the next queue ID that is not already in use  Uint32 MessageQueue::getNextQueueId()
    do  
    {    {
       // Handle wrap around and never assign zero or one as a queue id:      return _qidFactory.getID();
       if (_nextQueueId == 0)  
       {  
          _nextQueueId = 2;  
       }       }
  
       queueId = _nextQueueId++;  void MessageQueue::putQueueId(Uint32 queueId)
    } while (lookup(queueId) != 0);  {
       if (queueId != CIMOM_Q_ID)
    //          _qidFactory.putID(queueId);
    // Unlock mutex:  
    //  
   
    _id_mut.unlock();  
   
    return queueId;  
 } }
  
   
   
 MessageQueue::MessageQueue( MessageQueue::MessageQueue(
     const char* name,     const char* name,
     Boolean async,     Boolean async,
     Uint32 queueId)     Uint32 queueId)
    : _queueId(queueId), _capabilities(0), _count(0), _front(0), _back(0), _async(async)     : _queueId(queueId), _capabilities(0), _async(async)
 { {
     //     //
     // Copy the name:     // Copy the name:
Line 107 
Line 78 
     _name = new char[strlen(name) + 1];     _name = new char[strlen(name) + 1];
     strcpy(_name, name);     strcpy(_name, name);
  
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,      PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
         "MessageQueue::MessageQueue  name = %s, queueId = %i", name, queueId);          "MessageQueue::MessageQueue  name = %s, queueId = %u", name, queueId));
  
     //     //
     // Insert into queue table:     // Insert into queue table:
     //     //
       AutoMutex autoMut(q_table_mut);
     q_table_mut.lock(pegasus_thread_self());  
   
     while (!_queueTable.insert(_queueId, this))     while (!_queueTable.insert(_queueId, this))
        ;        ;
  
     q_table_mut.unlock();  
   
   
    PEG_METHOD_EXIT();    PEG_METHOD_EXIT();
 } }
  
 MessageQueue::~MessageQueue() MessageQueue::~MessageQueue()
 { {
     // ATTN-A: thread safety!     // ATTN-A: thread safety!
   
     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::~MessageQueue()");     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::~MessageQueue()");
       PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
           "MessageQueue::~MessageQueue queueId = %i, name = %s",
           _queueId,
           _name));
  
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,      {
         "MessageQueue::~MessageQueue queueId = %i, name = %s", _queueId, _name);          AutoMutex autoMut(q_table_mut);
   
     q_table_mut.lock(pegasus_thread_self());  
   
     _queueTable.remove(_queueId);     _queueTable.remove(_queueId);
     q_table_mut.unlock();      } // mutex unlocks here
  
     // Free the name:     // Free the name:
  
     delete [] _name;     delete [] _name;
  
       // Return the queue id.
   
       putQueueId(_queueId);
   
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
  
Line 150 
Line 120 
 { {
     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::enqueue()");     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::enqueue()");
  
     if (!message)      PEGASUS_ASSERT(message != 0);
     {  
        Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,  
         "MessageQueue::enqueue failure");  
        PEG_METHOD_EXIT();  
        throw NullPointer();  
     }  
  
     PEG_TRACE_STRING( TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,      PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
                       String("Queue name: ") + getQueueName() ) ;          "Queue name: [%s], Message: [%s]",
     Tracer::trace   ( TRC_MESSAGEQUEUESERVICE,          getQueueName(),
                       Tracer::LEVEL3,          MessageTypeToString(message->getType())));
                       "Message: [%s, %d]",  
                       MessageTypeToString(message->getType()),  
                       message->getKey() );  
   
     _mut.lock(pegasus_thread_self());  
     if (_back)  
     {  
        _back->_next = message;  
        message->_prev = _back;  
        message->_next = 0;  
        _back = message;  
     }  
     else  
     {  
        _front = message;  
        _back = message;  
        message->_prev = 0;  
        message->_next = 0;  
     }  
     message->_owner = this;  
   
     _count++;  
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,  
                   "MessageQueue::enqueue _queueId = %d, _count = %d", _queueId, _count);  
  
     _mut.unlock();      _messageList.insert_back(message);
  
     handleEnqueue();     handleEnqueue();
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
  
 Message* MessageQueue::dequeue() throw(IPCException)  Message* MessageQueue::dequeue()
 { {
     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::dequeue()");     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::dequeue()");
  
    _mut.lock(pegasus_thread_self());      Message* message = _messageList.remove_front();
     if (_front)  
     {  
         Message* message = _front;  
         _front = _front->_next;  
         if (_front)  
             _front->_prev = 0;  
   
         if (_back == message)  
             _back = 0;  
   
         _count--;  
         Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,  
             "MessageQueue::dequeue _queueId = %d, _count = %d",  
             _queueId, _count);  
   
         _mut.unlock();  
         message->_next = 0;  
         message->_prev = 0;  
         message->_owner = 0;  
  
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return message;         return message;
     }     }
     _mut.unlock();  
   
     PEG_METHOD_EXIT();  
     return 0;  
 }  
 ;  
   
   
 void MessageQueue::remove(Message* message) throw(IPCException)  
 {  
     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::remove()");  
   
     if (!message)  
     {  
         PEG_METHOD_EXIT();  
         throw NullPointer();  
     }  
   
     if (message->_owner != this)  
     {  
         PEG_METHOD_EXIT();  
         throw NoSuchMessageOnQueue();  
     }  
   
     _mut.lock(pegasus_thread_self());  
   
     if (message->_next)  
         message->_next->_prev = message->_prev;  
     else  
         _back = message->_prev;  
   
     if (message->_prev)  
         message->_prev->_next = message->_next;  
     else  
         _front = message->_next;  
   
     _count--;  
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,  
        "MessageQueue::remove _count = %d", _count);  
   
     _mut.unlock();  
   
     message->_prev = 0;  
     message->_next = 0;  
     message->_owner = 0;  
   
     PEG_METHOD_EXIT();  
 }  
   
 Message* MessageQueue::findByType(Uint32 type) throw(IPCException)  
 {  
    _mut.lock(pegasus_thread_self());  
   
     for (Message* m = front(); m; m = m->getNext())  
     {  
        if (m->getType() == type)  
        {  
           _mut.unlock();  
           return m;  
        }  
     }  
     _mut.unlock();  
     return 0;  
 }  
   
 Message* MessageQueue::findByKey(Uint32 key) throw(IPCException)  
 {  
    _mut.lock(pegasus_thread_self());  
   
     for (Message* m = front(); m; m = m->getNext())  
     {  
        if (m->getKey() == key)  
        {  
           _mut.unlock();  
           return m;  
        }  
   
     }  
     _mut.unlock();  
     return 0;  
 }  
   
 void MessageQueue::print(ostream& os) const throw(IPCException)  
 {  
    const_cast<MessageQueue *>(this)->_mut.lock(pegasus_thread_self());  
   
    for (const Message* m = front(); m; m = m->getNext())  
         m->print(os);  
    const_cast<MessageQueue *>(this)->_mut.unlock();  
 }  
   
 Message* MessageQueue::find(Uint32 type, Uint32 key) throw(IPCException)  
 {  
    _mut.lock(pegasus_thread_self());  
   
     for (Message* m = front(); m; m = m->getNext())  
     {  
        if (m->getType() == type && m->getKey() == key)  
        {  
           _mut.unlock();  
           return m;  
        }  
     }  
     _mut.unlock();  
   
     return 0;  
 }  
   
 void MessageQueue::lock() throw(IPCException)  
 {  
    _mut.lock(pegasus_thread_self());  
 }  
   
 void MessageQueue::unlock()  
 {  
    _mut.unlock();  
 }  
  
 const char* MessageQueue::getQueueName() const const char* MessageQueue::getQueueName() const
 { {
    return _name;    return _name;
 } }
  
 MessageQueue* MessageQueue::lookup(Uint32 queueId) throw(IPCException)  MessageQueue* MessageQueue::lookup(Uint32 queueId)
 { {
  
     MessageQueue* queue = 0;     MessageQueue* queue = 0;
     q_table_mut.lock(pegasus_thread_self());      AutoMutex autoMut(q_table_mut);
  
     if (_queueTable.lookup(queueId, queue))     if (_queueTable.lookup(queueId, queue))
     {     {
        q_table_mut.unlock();  
        return queue;        return queue;
     }     }
  
     // Not found!     // Not found!
  
     q_table_mut.unlock();      PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL1,
           "MessageQueue::lookup failure queueId = %u", queueId));
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,  
         "MessageQueue::lookup failure queueId = %i", queueId);  
  
     return 0;     return 0;
 } }
  
  
 MessageQueue* MessageQueue::lookup(const char *name) throw(IPCException)  MessageQueue* MessageQueue::lookup(const char *name)
 { {
  
    if(name == NULL)    if(name == NULL)
       throw NullPointer();       throw NullPointer();
    q_table_mut.lock(pegasus_thread_self());  
  
       AutoMutex autoMut(q_table_mut);
    for(QueueTable::Iterator i = _queueTable.start(); i; i++)    for(QueueTable::Iterator i = _queueTable.start(); i; i++)
    {    {
         // ATTN: Need to decide how many characters to compare in queue names         // ATTN: Need to decide how many characters to compare in queue names
       if(! strcmp( ((MessageQueue *)i.value())->getQueueName(), name) )       if(! strcmp( ((MessageQueue *)i.value())->getQueueName(), name) )
       {       {
          q_table_mut.unlock();              return (MessageQueue *)i.value();
          return( (MessageQueue *)i.value());  
       }       }
   
    }    }
    q_table_mut.unlock();  
  
    Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,      PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL1,
         "MessageQueue::lookup failure - name = %s", name);          "MessageQueue::lookup failure - name = %s", name));
  
    return 0;    return 0;
 } }


Legend:
Removed from v.1.37  
changed lines
  Added in v.1.56.18.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2