Example #1
0
/*
	associate a buffer with a guid and a key
	the old buffer will be freeed automatically.
*/
F8RES_API __bool set_res_buf_ex(
	const f8_uuid * id,
	const void * buffer,
	int length,
	const char * key,
	__bool bForce
	)
{
	F8_RESOURCE * res;
	F8_RESITEM * item;

	res = _get_res(id);
	if(!res && bForce){
		create_resource(id);		
		res = _get_res(id);
	}
	if(!res){
		assert(0);
		return __false;
	}
	item = _get_item(res, key);
	if(!item){
		item = _new_item(res, key);
	}

	if(!item){
		return __false;
	}
	
	if(length == -1){
		length = strlen((const char*)buffer) + 1;
	}

	if(item->buffer == buffer){
		item->length = length;
		return __true;
	}

	if(item->buffer){
		__free__(item->buffer);
	}

	if(length){
		item->buffer = __malloc__(length);
		item->length = length;
		if(!item->buffer){
			return __false;
		}
		memcpy(item->buffer, buffer, length);
	}else{
		item->buffer = 0;
		item->length = 0;
	}

	return __true;
}
Example #2
0
KPROXY_API f8_bool kproxy_init(int leakDetect)
{
	ITcpAdapter *a;	

	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetBreakAlloc(leakDetect);
	
	/* initialize and start kernel */
	ex_init();
	
	/* KERN_F_ENABLE_INPUT */

	x_buffer = (char *)__malloc__(LARGE_BUF_SIZE);
	x_buf_len = LARGE_BUF_SIZE;
	b_ShellExit = __false;	

	__new__(ITcpAdapter, a);
	proxy_adapter = __ucast__(ITcpAdapter, IKAdapter, a);

	sections = ke_get_blk(proxy_adapter->kernel, 0);
	assert(sections->uuid == BLK_ID_ROOT);

	create_resource(&sections->uuid);
	create_f8_uuid(&sections->h.uuid);
	create_resource(&sections->h.uuid);

	memset(fileName, 0 , sizeof(fileName));

	g_shell = shell_create(commands);
	
	reset_reg_map();
	init_blklib();
	init_clipboard();

	g_bDirty = __false;


	init_network(RTK_INIT_AS_SERVER, 0);
	vbus = connect_vbus(0xf8, VBUS_CONNECT_AS_SERVER, sr, 0);
	
	return __true;
}
Example #3
0
/*
	construct a resource object in memory from a stream
	the stream is composed of:
	1) a magic
	2) uuid
	3) item count
	4) array of items

	NOTE!! 
	1) On success, the resource item is not reference counted. 
	If the client won't addref on the loaded resource, then the 
	item is exposed to the garbage collector.
	More exactly, this proc won't addref on the resource when
	the resource already exists.
*/
static F8_RESOURCE * _load_res_stream(IF8Stream * str)
{
	__u16	magic;
	RESMAP::iterator it;
	__u32 itemcount;
	c_bstr_t cbstr;
	f8_uuid id;
	__int	length;
	void	* buffer;
	F8_RESOURCE * res;
	__bool ret;

	// DEBUG_PRINTF(("stream %08x\n", __vcall__(str, tell, (str))));
	
	if(!__vcall__(str, get, (str, &magic, sizeof(magic)))){
		return 0;
	}

	if(magic != F8_RES_MAGIC && magic != F8_RES_MAGIC_2){
		__vcall__(str, seek, (str, -sizeof(magic), SEEK_CUR));
		return 0;
	}

	if(!__vcall__(str, get, (str, &id, sizeof(id)))){
		return 0;
	}

	res = create_resource_bibibobo(&id, __false);
	if(!res){
		return 0;
	}
	
	/* the resource has not been loaded yet */
	if(!__vcall__(str, get, (str, &itemcount, sizeof(itemcount)))){
		return 0;
	}

	if(res->refcount){
		/* note if the resource is already present we silently
		eat the stream without modifing the in-memory version
		*/
		for(; itemcount; itemcount--){
			if(!__vcall__(str, get, (str, &cbstr.count, sizeof(cbstr.count)))){
				goto __failed;
			}
			__vcall__(str, seek, (str, cbstr.count, SEEK_CUR));
			if(!__vcall__(str, get, (str, &length, sizeof(length)))){
				goto __failed;
			}
			__vcall__(str, seek, (str, length, SEEK_CUR));
		}	
	}else{
		for(; itemcount; itemcount--){	
			if(!bstr_from_stream(&cbstr, str)){
				goto __failed;
			}

			if(!__vcall__(str, get, (str, &length, sizeof(length)))){
				goto __failed;
			}
			if(length){
				buffer = __malloc__(length);
				if(!buffer){
					goto __failed;
				}
				if(!__vcall__(str, get, (str, buffer, length))){
					goto __failed;
				}
			}else{
				buffer = 0;
			}
			
			ret = set_res_buf(&id, buffer, length, cbstr.buffer);
			__free__(buffer);
			c_free_bstr(&cbstr);
			if(!ret){
				goto __failed;
			}
		}
	}
	return res;	

__failed:
	/* the unload_resource will decrease the refcount */
	res->refcount++;
	unload_resource(&id);
	
	return 0;
}
Example #4
0
LIBCOBJ_API char * c_alloc_str(int size)
{
	return __malloc__(size + 1);
}