#ifndef __CALLFDK_H__
#define __CALLFDK_H__

#include "cstring.h"
#include "cstream.h"
#include "msgbase.h"
#include "msg.h"

class CCallFdkError;

class V2_DLL_API CCallFdk
{
public:
	static int Initialize(const char *p_szCfgFile, CCallFdkError *p_pError);
	static int Initialize(const char *p_szKeyFile, const char *p_szMsgDicFile,
			const char *p_szServer, int p_iPort, int p_iTimeOut, CCallFdkError *p_pError);
	static int CallService(int p_iSvcNum, CMsgBase *p_pIn, CMsgBase *p_pOut, CCallFdkError *p_pError);
	static int CallServiceByMsg(int p_iSvcNum, CMsg *p_pInMsg, CMsg *p_pOutMsg, CCallFdkError *p_pError);

private:
	static int CallServiceCore(int p_iSvcNum, CMsg *p_pInMsg, CMsg *p_pOutMsg, int p_iSeqNum, CString &p_sError);
	static int GetUserKey(const char *p_szKeyFile, CString &p_sUserKey, CString &p_sError);
	static int ReadFileToStream(const char *p_szFileName, CStream &p_aStream, CString &p_sError);

};

class V2_DLL_API CCallFdkError
{
public:
	CCallFdkError();
	~CCallFdkError();

	int GetCode();
	CString GetText();
	int GetRefSvcNum();
	void SetError(int p_iCode, const char *p_szText, int p_iRefSvcNum=0);
	void SetError(const char *p_szText);
	void Clear();
	CString Repr();

private:
	int m_iCode;
	CString m_sErrorText;
	int m_iRefSvcNum;
};

#endif /* __CALLFDK_H__ */
