(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.47.12.1

version 1.37, 2003/11/07 19:18:46 version 1.47.12.1, 2006/06/30 22:37:52
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 25 
Line 31 
 // //
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By:  // Modified By: Amit K Arora, IBM (amita@in.ibm.com) for Bug#1090
   //              Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#2076
   //              David Dillard, VERITAS Software Corp.
   //                  (david.dillard@veritas.com)
   //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3475
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 34 
Line 44 
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include "MessageQueue.h" #include "MessageQueue.h"
 #include "MessageQueueService.h" #include "MessageQueueService.h"
   #include "IDFactory.h"
   
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
Line 46 
Line 58 
  
 void MessageQueue::remove_myself(Uint32 qid) void MessageQueue::remove_myself(Uint32 qid)
 { {
    q_table_mut.lock(pegasus_thread_self());      AutoMutex autoMut(q_table_mut);
   
    _queueTable.remove(qid);    _queueTable.remove(qid);
    q_table_mut.unlock();  
 } }
  
   static IDFactory _qidFactory(CIMOM_Q_ID + 1);
  
 Uint32 MessageQueue::getNextQueueId() throw(IPCException)  Uint32 MessageQueue::getNextQueueId()
 {  
    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  
    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)
    //          return _qidFactory.putID(queueId);
    // Unlock mutex:  
    //  
   
    _id_mut.unlock();  
   
    return queueId;  
 } }
  
   
   
 MessageQueue::MessageQueue( MessageQueue::MessageQueue(
     const char* name,     const char* name,
     Boolean async,     Boolean async,
Line 108 
Line 94 
     strcpy(_name, name);     strcpy(_name, name);
  
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,     Tracer::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()");
   
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
         "MessageQueue::~MessageQueue queueId = %i, name = %s", _queueId, _name);         "MessageQueue::~MessageQueue queueId = %i, name = %s", _queueId, _name);
  
     q_table_mut.lock(pegasus_thread_self());      {
           AutoMutex autoMut(q_table_mut);
     _queueTable.remove(_queueId);     _queueTable.remove(_queueId);
     q_table_mut.unlock();      } // mutex unlocks here
  
     // Free the name:     // Free the name:
  
     delete [] _name;     delete [] _name;
  
       while(_front)
       {
          Message* tmp = _front;
          _front = _front->_next;
          delete tmp;
       }
   
       // Return the queue id.
   
       putQueueId(_queueId);
   
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
  
Line 166 
Line 156 
                       MessageTypeToString(message->getType()),                       MessageTypeToString(message->getType()),
                       message->getKey() );                       message->getKey() );
  
     _mut.lock(pegasus_thread_self());      {
       AutoMutex autoMut(_mut);
     if (_back)     if (_back)
     {     {
        _back->_next = message;        _back->_next = message;
Line 187 
Line 178 
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,
                   "MessageQueue::enqueue _queueId = %d, _count = %d", _queueId, _count);                   "MessageQueue::enqueue _queueId = %d, _count = %d", _queueId, _count);
  
     _mut.unlock();      } // mutex unlocks here
  
     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());      AutoMutex autoMut(_mut);
     if (_front)     if (_front)
     {     {
         Message* message = _front;         Message* message = _front;
Line 213 
Line 204 
             "MessageQueue::dequeue _queueId = %d, _count = %d",             "MessageQueue::dequeue _queueId = %d, _count = %d",
             _queueId, _count);             _queueId, _count);
  
         _mut.unlock();  
         message->_next = 0;         message->_next = 0;
         message->_prev = 0;         message->_prev = 0;
         message->_owner = 0;         message->_owner = 0;
Line 221 
Line 211 
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return message;         return message;
     }     }
     _mut.unlock();  
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return 0;     return 0;
 } }
 ;  
  
  
 void MessageQueue::remove(Message* message) throw(IPCException)  
   void MessageQueue::remove(Message* message)
 { {
     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::remove()");     PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE,"MessageQueue::remove()");
  
Line 245 
Line 234 
         throw NoSuchMessageOnQueue();         throw NoSuchMessageOnQueue();
     }     }
  
     _mut.lock(pegasus_thread_self());      {
       AutoMutex autoMut(_mut);
  
     if (message->_next)     if (message->_next)
         message->_next->_prev = message->_prev;         message->_next->_prev = message->_prev;
Line 261 
Line 251 
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL4,
        "MessageQueue::remove _count = %d", _count);        "MessageQueue::remove _count = %d", _count);
  
     _mut.unlock();      } // mutex unlocks here
  
     message->_prev = 0;     message->_prev = 0;
     message->_next = 0;     message->_next = 0;
Line 270 
Line 260 
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
  
 Message* MessageQueue::findByType(Uint32 type) throw(IPCException)  Message* MessageQueue::findByType(Uint32 type)
 { {
    _mut.lock(pegasus_thread_self());      AutoMutex autoMut(_mut);
  
     for (Message* m = front(); m; m = m->getNext())     for (Message* m = front(); m; m = m->getNext())
     {     {
        if (m->getType() == type)        if (m->getType() == type)
        {        {
           _mut.unlock();  
           return m;           return m;
        }        }
     }     }
     _mut.unlock();  
     return 0;     return 0;
 } }
  
 Message* MessageQueue::findByKey(Uint32 key) throw(IPCException)  Message* MessageQueue::findByKey(Uint32 key)
 { {
    _mut.lock(pegasus_thread_self());      AutoMutex autoMut(_mut);
  
     for (Message* m = front(); m; m = m->getNext())     for (Message* m = front(); m; m = m->getNext())
     {     {
        if (m->getKey() == key)        if (m->getKey() == key)
        {        {
           _mut.unlock();  
           return m;           return m;
        }        }
  
     }     }
     _mut.unlock();  
     return 0;     return 0;
 } }
  
 void MessageQueue::print(ostream& os) const throw(IPCException)  #ifdef PEGASUS_DEBUG
   void MessageQueue::print(ostream& os) const
 { {
    const_cast<MessageQueue *>(this)->_mut.lock(pegasus_thread_self());      AutoMutex autoMut(const_cast<MessageQueue *>(this)->_mut);
  
    for (const Message* m = front(); m; m = m->getNext())    for (const Message* m = front(); m; m = m->getNext())
         m->print(os);         m->print(os);
    const_cast<MessageQueue *>(this)->_mut.unlock();  
 } }
   #endif
  
 Message* MessageQueue::find(Uint32 type, Uint32 key) throw(IPCException)  Message* MessageQueue::find(Uint32 type, Uint32 key)
 { {
    _mut.lock(pegasus_thread_self());      AutoMutex autoMut(_mut);
  
     for (Message* m = front(); m; m = m->getNext())     for (Message* m = front(); m; m = m->getNext())
     {     {
        if (m->getType() == type && m->getKey() == key)        if (m->getType() == type && m->getKey() == key)
        {        {
           _mut.unlock();  
           return m;           return m;
        }        }
     }     }
     _mut.unlock();  
  
     return 0;     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();  
   
     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,     Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
         "MessageQueue::lookup failure queueId = %i", queueId);          "MessageQueue::lookup failure queueId = %u", 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,    Tracer::trace(TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3,
         "MessageQueue::lookup failure - name = %s", name);         "MessageQueue::lookup failure - name = %s", name);


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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2