text: /*
   * packetfactory.cpp
   *
   *  Description: The abstract base class of all packet factorys.
   *
   *  Created on: Jul 22, 2010
   *      Author: Thomas Henry
   */
  // Copyright (c) 2010 Agilent Technologies.  All rights reserved.
  // $Log: packetfactory.cpp $
  // Revision 4 2012/07/18 05:41:26 +0800 hen55467 deleted(id=30957)
  // Run astyler
  // 
  // Revision 3 2012/07/17 14:19:06 -0600 hen55467 /MassTransit/MT1.10.100_Tip/Integration/Thomas
  // Ran with Astyler
  //
  // Revision 2 2012/06/15 13:52:25 -0600 hen55467 /MassTransit/MT1.10.100_Tip/Integration/Thomas
  // Fix compile bugs
  //
  // Revision 1 2012/06/14 17:20:57 -0600 hen55467 /MassTransit/MT1.10.100_Tip/Integration/Thomas
  // Add new packet factory class with SpecificPacketFactory template class
  //
  
  #include "logger.h"
  #include "packet.h"
  #include "packetfactory.h"
  
  /*
  template<class PacketTypeT>
  SpecificPacketFactory<PacketTypeT>::SpecificPacketFactory<PacketTypeT>(uint32_t allocPacketCount)
  : m_nPacketCount(allocPacketCount)
  {
    pthread_mutex_init(&m_FactoryLock, NULL);
    m_nPackets = new PacketTypeT[m_nPacketCount];
    for(uint32_t i = 0; i < m_nPacketCount; i++)
      {
        m_nFreeQ.push_back(m_nPackets[i]);
      }
  }
  
  template<class PacketTypeT>
  SpecificPacketFactory<PacketTypeT>::~SpecificPacketFactory<PacketTypeT>()
  {
    while(m_nFreeQ.size() < m_nPacketCount)
      {
        LOG_ERROR(LOG_ID("classifyinfo"), "Error destroying packet factory!  %u out of %u packets returned to free Q!", m_nFreeQ.size(), m_nPacketCount);
      }
    m_nFreeQ.clear();
    delete [] m_nPackets;
  }
  */
  
  template<class PacketTypeT>
  Packet *SpecificPacketFactory<PacketTypeT>::CreatePacket(Packet *previous)
  {
      pthread_mutex_lock(&m_FactoryLock);
      while(m_nFreeQ.empty())
      {
          LOG_ERROR(LOG_ID("classifyinfo"), "Error Creating Packet! Free Q is empty!");
      }
      Packet *newPacket = m_nFreeQ.front();
      m_nFreeQ.pop_front();
      pthread_mutex_unlock(&m_FactoryLock);
      newPacket->setPrevious(previous);
      return newPacket;
  }
  
  template<class PacketTypeT>
  void SpecificPacketFactory<PacketTypeT>::FreePacket(Packet *toFree)
  {
      pthread_mutex_lock(&m_FactoryLock);
      m_nFreeQ.push_back(toFree);
      pthread_mutex_unlock(&m_FactoryLock);
  }
  