/***************************************************************************
                Synchronization
                -----------------------------------------
	begin      : 2012/05/14
	copyright  : (C) 2011 SolutionBox Inc.
	author     : Service 1 Team
	email      : svc1@solbox.com
	version    : 3.1.0

    CopyRight(C) 2011 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 __SYNCHRONIZATION_H__
#define __SYNCHRONIZATION_H__

class DataBase;
class CSynchronization
{
public:
	CSynchronization(JOB_TYPE::JOB_TYPE type, vector<string>& syncdata);
	~CSynchronization();

	// 실행 
	int Execute();


	void SetTragetHost(vector<string> &src);

	inline void	SetEnable(const char* szOn)	{ m_enable = szOn; }
	inline void SetNetworkMode(int mode)	{ m_networkmode = mode; }
	inline void SetFHSMount(vector<string> &mount)	{ m_fhsmount = mount; }

protected:
	//	TOP FHS 정보를 가져온다. (가져온후 random으로 1개를 추출하여 return 함)
	bool GetTargetFHS(string & targethost);

	// copy(move)에 source 정보 찾기
	bool GetSource(string & srchost, string & srchash);

	// 동일한 파일 가지고 있는 host 추출
	bool GetHostHasFile(string & srchosts);

	//	ftsd를 이용한 파일전송
	bool ReqFileTrans(string & strsrc, vector<string>& vecdest);
	
	// kind of sync
	int Deleted();
	int Syned();
	int NSyned();
	int Copy();
	int Move();
	int MoveTypeCopy();
	int MoveTypeMove();
	int Rechk();

	// change value
	string ChgFilenamehash();
	string MakeFilenameorg();

	// Database
	DataBase* GetDB(string & tblname, bool & usedisplay);
	void FreeDB(DataBase *db, bool success = true);

private:
	string			m_enable;
	int				m_networkmode;
	vector<string>	m_fhsmount;

	vector<string>	m_vecTargetFHS;	// target TOP FHS

	JOB_TYPE::JOB_TYPE		m_type;
	vector<string>			m_syncdata;

	bool			m_exit;
};

#endif // __SYNCHRONIZATION_H__
