/***************************************************************************
                ContentList.cpp
                -----------------------------------------
    begin      : 2015/05/29
    copyright  : (C) 2005 SolutionBox Inc.
    author     : Service 1 Team
    email      : svc1@solbox.com

    CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
    Redistribution and use in source and binary forms, with or with out
    modification, are not permitted in outside of SolutionBox Inc.
***************************************************************************/
#include "CacheRequestList.h"
#include "MutexLock.hpp"

////////////////////////////////////////////////////////////////////////////
//
// CCacheRequestList Class
//
////////////////////////////////////////////////////////////////////////////
CCacheRequestList::CCacheRequestList()
{
	pthread_mutex_init(&m_mutex, NULL);
}

CCacheRequestList::~CCacheRequestList()
{
	ProtectedMutex mutex(m_mutex);
	pthread_mutex_destroy(&m_mutex);
}

void CCacheRequestList::Push( std::string szFileName_hash, uint32_t nServiceID, int szFDCount)
{ 
	ProtectedMutex mutex(m_mutex);
	replication_info objReplicationInfo;
	objReplicationInfo.szFileName_hash = szFileName_hash;
	objReplicationInfo.nServiceID = nServiceID;
	objReplicationInfo.szFDCount = szFDCount;

	m_ReplicationInfoQueue.push( objReplicationInfo );
}

struct replication_info CCacheRequestList::Pop()
{
	ProtectedMutex mutex(m_mutex);
	struct replication_info data;
	// 큐가 비었으면 빈 데이터 반환.
	if( m_ReplicationInfoQueue.empty() == true )
	{
		LOG( LDBG, "no element in the queue of TransferStatDataList." );
		return data;
	}
	data = m_ReplicationInfoQueue.front();
	m_ReplicationInfoQueue.pop();

	return data;
}

unsigned int CCacheRequestList::GetSize()
{
	ProtectedMutex mutex(m_mutex);
	return (unsigned int)m_ReplicationInfoQueue.size();
}

void CCacheRequestList::Clear()
{
	ProtectedMutex mutex(m_mutex);
	while( m_ReplicationInfoQueue.size() > 0 )
	{
		m_ReplicationInfoQueue.pop();
	}
}
