#pragma once

//////////////////////////////////////////////////////////////////////////

// ࣬ʵָеĴӿ
class rpc_callback
{
public:
	rpc_callback() {}
	virtual ~rpc_callback() {}

	//  HTTP ͷ麯
	virtual void SetRequestHdr(const char* hdr) = 0;
	//  HTTP Ӧͷ麯
	virtual void SetResponseHdr(const char* hdr) = 0;
	// عеĻص麯
	virtual void OnDownloading(long long int content_length,
		long long int total_read) = 0;
	// ʱĻص麯
	virtual void OnDownloadOver(long long int total_read,
		double spent) = 0;
};

//////////////////////////////////////////////////////////////////////////

/**
 * http ࣬߳зԶ HTTP ̣
 * ظ߳
 */
class http_download : public acl::rpc_request
{
public:
	/**
	 * 캯
	 * @param addr {const char*} HTTP ַʽdomain:port
	 * @param url {const char*} http url ַ
	 * @param callback {rpc_callback*} http ͨ
	 *  ֪̹ͨ߳
	 */
	http_download(const char* addr, const char* url,
		rpc_callback* callback);
protected:
	~http_download() {}

	// 麯̴߳
	virtual void rpc_run();

	// 麯̴̣߳յ߳ɵϢ
	virtual void rpc_onover();

	// 麯̴̣߳յ̵֪߳ͨϢ
	virtual void rpc_wakeup(void* ctx);
private:
	acl::string addr_;
	acl::string url_;
	acl::string req_hdr_;
	acl::string res_hdr_;
	bool  error_;
	long long int total_read_;
	long long int content_length_;
	double total_spent_;

	rpc_callback* callback_;
};
