import util.metaProperty;
import aaz.libhpsocket.listener;
import aaz.libhpsocket.component.httpAgent;

var _dll = aaz.libhpsocket._dll;

namespace aaz.libhpsocket.listener;
class httpAgent{
	ctor(){
		this = ..aaz.libhpsocket.listener("httpAgent");
		this.pListener = _dll.Create_HP_HttpAgentListenerP();  
	}
	
	createComponent = function(){
		return ..aaz.libhpsocket.component.httpAgent( null, this.pListener ); 	
	}
	
	destroy = function(){
		if(this.pListener){
			_dll.Destroy_HP_HttpAgentListener(this.pListener);
			this.pListener = null;
		}
	}
	
	@_metaProperty;
}
namespace httpAgent{
	_properties = {
		_topointer = function(){
			return owner.pListener;
		}
		
		_serialize = function(kernelCall){
			return 
				..string.format(
					"global.import('aaz.hpsocket.%s') : aaz.hpsocket.%s( topointer(0x%x))",
					owner.className,
					owner.className,
					tonumber(owner.pSocket) 
				);
		}
		
		onPrepareConnect = {
			_set = function(callback){
				owner.OnPrepareConnectCallback = owner.createThreadCallback(callback, "int(ptr pSender,ADDR connId,addr soListen)");
				_dll.HP_Set_FN_HttpAgent_OnPrepareConnect(owner.pListener, owner.OnPrepareConnectCallback);
			} 	
		}
		
		onConnect = {
			_set = function(callback){
				owner.OnConnectCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId)");
				_dll.HP_Set_FN_HttpAgent_OnConnect(owner.pListener, owner.OnConnectCallback);
			} 	
		}
		
		onHandShake = {
			_set = function(callback){
				owner.OnHandShakeCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId)");
				_dll.HP_Set_FN_HttpAgent_OnHandShake(owner.pListener, owner.OnHandShakeCallback);
			} 	
		}
		
		onSend = {
			_set = function(callback){
				owner.OnSendCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,pointer pData, int length)");
				_dll.HP_Set_FN_HttpAgent_OnSend(owner.pListener, owner.OnSendCallback);
			} 	
		}
		
		onReceive = {
			_set = function(callback){
				owner.OnReceiveCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,pointer pData, int length)");
				_dll.HP_Set_FN_HttpAgent_OnReceive(owner.pListener, owner.OnReceiveCallback );
			} 	
		}
		
		onClose = {
			_set = function( callback ){
				owner.OnCloseCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId, int enOperation, int iErrorCode)");
				_dll.HP_Set_FN_HttpAgent_OnClose(owner.pListener, owner.OnCloseCallback);
			} 	
		}
		
		onShutdown = {
			_set = function(callback){
				owner.OnShutdownCallback = owner.createThreadCallback(callback,"int(ptr pSender)");
				_dll.HP_Set_FN_HttpAgent_OnShutdown(owner.pListener, owner.OnShutdownCallback);
			} 	
		};
		onMessageBegin = {
			_set = function(callback){
				owner.OnMessageBeginCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId)");
				_dll.HP_Set_FN_HttpAgent_OnMessageBegin(owner.pListener, owner.OnMessageBeginCallback); 
			} 	
		}
		
		onStatusLine = {
			_set = function(callback){
				owner.OnStatusLineCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,WORD statusCode,ustring Desc)");
				_dll.HP_Set_FN_HttpAgent_OnStatusLine(owner.pListener, owner.OnStatusLineCallback);
			} 	
		};
		onHeader = {
			_set = function(callback){
				owner.OnHeaderCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,string name,string value)");
				_dll.HP_Set_FN_HttpAgent_OnHeader(owner.pListener, owner.OnHeaderCallback); 
			} 	
		}
		
		onHeadersComplete = {
			_set = function(callback){
				owner.OnHeadersCompleteCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId)");
				_dll.HP_Set_FN_HttpAgent_OnHeadersComplete(owner.pListener, owner.OnHeadersCompleteCallback); 
			} 	
		};
		onBody = {
			_set = function(callback){
				owner.OnBodyCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,ptr pData, int len)");
				_dll.HP_Set_FN_HttpAgent_OnBody(owner.pListener, owner.OnBodyCallback); 
			} 	
		}
		
		onChunkHeader = {
			_set = function(callback){
				owner.OnChunkHeaderCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,int len)");
				_dll.HP_Set_FN_HttpAgent_OnChunkHeader(owner.pListener, owner.OnChunkHeaderCallback); 
			} 	
		}
		
		onChunkComplete = {
			_set = function(callback){
				owner.OnChunkCompleteCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId)");
				_dll.HP_Set_FN_HttpAgent_OnChunkComplete(owner.pListener, owner.OnChunkCompleteCallback); 
			} 	
		}
		
		onMessageComplete = {
			_set = function(callback){
				owner.OnMessageCompleteCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId)");
				_dll.HP_Set_FN_HttpAgent_OnMessageComplete(owner.pListener, owner.OnMessageCompleteCallback); 
			} 	
		}
		
		onUpgrade = {
			_set = function(callback){
				owner.OnUpgradeCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,int upgradeType)");
				_dll.HP_Set_FN_HttpAgent_OnUpgrade(owner.pListener, owner.OnUpgradeCallback); 
			} 	
		}
		
		onParseError = {
			_set = function(callback){
				owner.OnParseErrorCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId, int errorCode,ustring errorDesc)");
				_dll.HP_Set_FN_HttpAgent_OnParseError(owner.pListener, owner.OnParseErrorCallback); 
			} 	
		}
		
		onWsMessageHeader = {
			_set = function(callback){
				owner.OnWsMessageHeaderCallback = owner.createThreadCallback(callback,"int(ptr pSender,ADDR connId,bool final,BYTE reserved,BYTE operationCode,INT mask,long bodyLen)");
				_dll.HP_Set_FN_HttpAgent_OnWSMessageHeader(owner.pListener, owner.OnWsMessageHeaderCallback); 
			} 	
		}
		
		onWsMessageBody = {
			_set = function(callback){
				owner.OnWsMessageBodyCallback = owner.createThreadCallback(callback, "int(ptr pSender,ADDR connId,ptr pData,int len)");
				_dll.HP_Set_FN_HttpAgent_OnWSMessageBody(owner.pListener, owner.OnWsMessageBodyCallback); 
			} 	
		}
		
		onWsMessageComplete = {
			_set = function(callback){
				owner.OnWsMessageCompleteCallback = owner.createThreadCallback(callback, "int(ptr pSender,ADDR connId)");
				_dll.HP_Set_FN_HttpAgent_OnWSMessageComplete(owner.pListener, owner.OnWsMessageCompleteCallback); 
			} 	
		}
	}
	
	_metaProperty = ..util.metaProperty(_properties);	
}

