⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genericresource.h

📁 Brew程序设计框架
💻 H
字号:
#ifndef _gresource_h_
#define _gresource_h_



#include "BrewString.h"
#include "AEEStdlib.h"
#include "AEEAppGen.h"
#include "AEEFile.h"
#include "CbkDispatcher.h"

//A few utility macros; We shall eventually move this into the AEE Services.
#define ISDIGIT(c)  ( (unsigned) ((c) - '0') < 10)
#define ISALPHA(c)  ( (unsigned) ( ((c)|32) - 'a') < 26 )
#define ISALNUM(c)  ( ISDIGIT(c) || ISALPHA(c) )



struct GDS: public IRelease
{
	virtual void releaseResource( ) 
	{
		delete this;
	}

	virtual int getUID( ) 
	{
		return 555;
	}

	
	static int getID()
	{
		return 555;
	}
	template <class R>
	static GDS* initDataStruct(R* rr, char* address, const String& params )
	{
		GDS* ds=static_cast<GDS*>(rr->getRegistered(GDS::getID()));
		GDS::createGDS(ds);
		ds->address = address;
		ds->parameters = params;
		if (!ds->data.isEmpty())
			ds->data="";
		rr->registerResource(ds);
		return ds;
	}

	char* address;
	String parameters;
	String data;
	int error;
	UINT bufSize;

private:
	GDS() :  bufSize(7)
	{}
	static void createGDS(GDS*& ds)
	{
		if (ds==0)
			ds = new GDS();
	}
	GDS( const GDS &Value );
	const GDS &operator = ( const GDS &Rhs );
};

template <class Y, class F>
struct pkCBK;



class GResource 
{
public:
	
	GResource(IShell* shell,  IExecute* pp, GDS* ds) :	
							shell_(shell),
							processPolicy_(pp), 
							resource_("Address "),
							ds_(ds), 
							idx_(0)
	{
	}
	
	~GResource();

	int	init();
	int	initConnection();
	void reset();

private:
	void write();
	void read();
	void onError( int errorCode) ;
	void onData( ) ;
	void releaseResources();
	void releaseResource();
private:
	IShell* shell_;
	String resource_;
	IExecute* processPolicy_; 
	int idx_;
	typedef pkAEECBK<GResource> A;
	A a_;
	GDS* ds_;
private:	
	GResource( const GResource &Value );
	const GResource &operator = ( const GResource &Rhs );

	

};



GResource::~GResource()
{
	releaseResources();
}

void GResource::releaseResource()
{
	idx_ = 0;
	resource_ =("Address ");
}

void GResource::reset()
{
	releaseResource();
}


void GResource::releaseResources()
{
	releaseResource();
}




int GResource::init()
{ 
	int err;
	resource_ += ds_->address;
	//do specific creation if any
	return SUCCESS;
}


int GResource::initConnection()
{
	resource_ += " Param: ";
	resource_ += ds_->parameters;
	a_.setCallback(this, read, shell_);
	a_();
	return SUCCESS;
}


void GResource::read ()
{
	int end = idx_ + ds_->bufSize;
	end = end>resource_.length()? resource_.length(): end;
	String s = resource_.substring(idx_, end);
	if (s.length() > 0) 
	{
		ds_->data += s;
		a_.setCallback(this, read, shell_);
		a_();
		idx_ = end;
		return;
	}
	else 
	{	
		onData();
		return;
	}
}





void GResource::onError( int errorCode) {
	ds_->error = errorCode;
	ds_->data = "";
	processPolicy_->onCbk() ;
}

void GResource::onData( ) {
	ds_->error = SUCCESS;
	processPolicy_->onCbk() ;
}




#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -