#pragma once
#ifndef _BASEMODULE_
#define _BASEMODULE_

#ifndef BASEMODULE
#define BASEMODULE extern "C" _declspec(dllexport)
#else
#undef BASEMODULE
#define BASEMODULE extern "C" _declspec(dllimport)
#endif

#define CLSID_BASEMODULE L"{DA90D68D-99EB-45D5-A969-BC3D0D12D92A}"

#pragma pack(push,1)


typedef struct  USERINFO
{
	int id;
	char username[64];
	char expiretime[64];
	char password[64];
	char uuid[64];
	char level[10];
	char unusedTraffic[128];
	char access_token[64];
	int port;

}USERINFO,*PUSERINFO;


class IBaseCurl;
class IServerList;
class IUserinfo;
//获取其他类的指针
class IBaseGloablModule
{
public:
	virtual ~IBaseGloablModule(void) {}

	////获取错误的消息
	//virtual LPCSTR  GetLastErrorA() = 0;
	//virtual LPCWSTR GetLastErrorW() = 0;

	virtual IBaseCurl* GetBaseCurlInstance() = 0;
 

	virtual INT AddRef() = 0;
	virtual INT Release() = 0;
};

template<typename T>
class IInstanceList
{
public:
	IInstanceList(void)
	{
		m_pNext = NULL;
		m_pPrev = NULL;
	}
	virtual ~IInstanceList(void)
	{
		Detach();
	}

	virtual void AddInstance(T* pInstance)
	{
		if (m_pNext && (m_pNext != pInstance))
			m_pNext->AddInstance(pInstance);
		else
		{
			pInstance->m_pPrev = (T*)this;
			m_pNext = pInstance;
		}
	}

	virtual void Detach()
	{
		if (m_pNext)
			m_pNext->m_pPrev = m_pPrev;
		if (m_pPrev)
			m_pPrev->m_pNext = m_pNext;

		m_pPrev = m_pNext = NULL;
	}

	T* m_pPrev;
	T* m_pNext;
};
 
class IServerListCallback
{
public:
	virtual ~IServerListCallback(void) {};

	virtual void ServerListCallback() = 0;
};

class IServerList
	: public IInstanceList<IServerList>
{
public:
	virtual ~IServerList(void) {};
};

class IUserinfo
	: public IInstanceList<IUserinfo>
{
public:
	virtual ~IUserinfo(void) {};
};

enum HTTPRET
{
	http_no = 0,
	http_f,
	http_yes,
	http_start,
	http_end,
};

//请求网络接口
class IBaseCurl
	: public IInstanceList<IBaseCurl>
{
public:
	virtual ~IBaseCurl(void) {};

	virtual void SetUrl(LPCSTR url) = 0;

	//登录
	virtual HTTPRET PostLogin(LPCSTR username,LPCSTR password,LPCSTR& data) = 0;


	virtual HTTPRET GetHttpConnectstatus() = 0;

	virtual LPCSTR  GetLastErrorA() = 0;
	virtual LPCWSTR  GetLastErrorW() = 0;
};

BASEMODULE IBaseGloablModule* WINAPI GetBaseGlobalInstance();
BASEMODULE BOOL WINAPI ReleaseBaseGlobalInstance();

#pragma pack(pop)

#endif