/***************************************************************************
                Parameter
                -----------------------------------------
	begin      : 2015/05/13
	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 __PARAMETER_H__
#define __PARAMETER_H__

class Config;

class parameter
{
public:
	enum DBINF0_TYPE {
		MASTER			=	0,
		SLAVE_FIRST		=	1,
		SLAVE_SECOND	=	2
	};

private:
	static parameter		*inst;
	string					m_confpath;
	
	// use common
	string					m_mode;
	string					m_synclistpath;
	string					m_targetlistpath;

	// use move mode
	int						m_networkmode;

	// use sync mode
	vector<string>			m_synctime;
	string					m_service;
	bool					m_includedel;
	
	// config
	string					m_logpath;
	int						m_loglevel;
	int						m_workpoolcnt;
	vector<int>				m_dbpoolcnt;
	vector<databaseinfo>	m_dbinfo;
	vector<string>			m_skipkey;
	vector<string>			m_fhsmount;

	string					m_logreport;
public:
	static parameter* getInstance();
	static void release();

	bool argvtoparam( int argc, char * const argv[] );
	bool loadconf();

	void print_loginfo();
	void print_dbinfo();
	
	
	databaseinfo	getdbinfo( int dbinfotype )		{ return m_dbinfo[dbinfotype]; }
	int				getdbpoolcnt( int dbinfotype )	{ return m_dbpoolcnt[dbinfotype]; }
	int				getskipkeycnt()					{ return m_skipkey.size(); }
	string			getskipkey(int i)				{ return m_skipkey[i]; }
	string			getlogpath()					{ return m_logpath; }
	string			getreportpath()					{ return m_logreport; }
	string			getsyncpath()					{ return m_synclistpath; }
	string			gettargetlistpath()				{ return m_targetlistpath; }
	int				getnetworkmode()				{ return m_networkmode; }
	int				getloglevel()					{ return m_loglevel; }	
	int				getworkpoolcnt()				{ return m_workpoolcnt; }
	string			getsyncmode()					{ return m_mode; }
	string			getsyncstart()					{ return m_synctime.empty() ? "" : m_synctime[0]; }
	string			getsyncend()					{ return m_synctime.empty() ? "" : m_synctime[1]; }
	string			getservice()					{ return m_service; }
	bool			includdel()						{ return m_includedel; }
	bool			issyncmode()					{ return (m_mode.compare(MODE_SYNC) == 0); }
	bool			ismovemode()					{ return (m_mode.compare(MODE_MOVE) == 0); }
	bool			iscopymode()					{ return (m_mode.compare(MODE_COPY) == 0); }
	vector<string>& getfhsmount()					{ return m_fhsmount;  }
private:
	parameter();
	~parameter();

	bool getconfdbinof(Config &conf,int dbinfotype, databaseinfo &data);
	bool getconfdata(Config &conf, const string& key, string& value, bool bcommon = false, bool returnerr = true);
	bool getconfdata(Config &conf, const string& key, vector< string >& value, bool bcommon = false, bool returnerr = true);

	void printusage();
};
#endif // __PARAMETER_H__
