/***************************************************************************
                HotContentInfo.h
                -----------------------------------------
    begin      : 2011/11/24
    copyright  : (C) 2005 SolutionBox Inc.
    author     : Service 1 Team
    email      : svc1@solbox.com
    version    : 1.0

    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.
***************************************************************************/
#ifndef	__HOT_CONTENT_INFO_MAP_H__
#define	__HOT_CONTENT_INFO_MAP_H__

#include <string>
#include <map>
#include <time.h>
#include <pthread.h>
#include <stdint.h>

class CHotContentData
{
// Attributes
private:
	std::string m_szFilename;   // 파일명
	time_t m_timeLastReq;         // 최종 Rep 요청 시간
	time_t m_timeLastUpdate;      // 정보 최종 갱신 시간
	int m_nFdCount;             // 이전 fd count

	uint32_t m_updateExpire;

	pthread_mutex_t m_mutex;
protected:

public:


// Operations
private:

protected:

public:
	CHotContentData( std::string filename, int nFdCount );
	~CHotContentData();
    
	void UpdateInfo(int nFdCount);
	void UpdateRequestTime();
	bool IsExipireTimeout();
	bool IsReqTimeOver();
	bool IsIncrease(int nFdCount);
	
	inline std::string GetFilename() { return m_szFilename; };
};

class CHotContentInfoMap
{
private:
// Attributes
	std::map<std::string, CHotContentData> m_mapHotContentInfo;
	int m_nMaxSize;

	pthread_mutex_t m_mutex;

// Operations
	bool IsOverflow();

protected:
    
public:    
	CHotContentInfoMap();
	virtual ~CHotContentInfoMap();

	CHotContentData* GetData( std::string filename );
	bool AddData( std::string szFileName, int nFdCount );
    // 지정시간 이상 변경이 없는 데이터 정리.
	void Arrangement();
    
	bool IsExist() { return (m_mapHotContentInfo.size() > 0) ? true : false; }
};
#endif //	__HOT_CONTENT_INFO_MAP_H__
