Esempio n. 1
0
/**
 * Called to start a batch, you make sure you have enough memory 
 * to store all the geometry, then you clear out the memory and set the
 * number of primitives to 0
 */
void geometry_batcher::allocate_internal(int n_verts)
{

	if (n_verts > n_allocated) {
		if (vert != NULL) {
			vm_free(vert);
			vert = NULL;
		}

		if (radius_list != NULL) {
			vm_free(radius_list);
			radius_list = NULL;
		}

		vert = (vertex *) vm_malloc( sizeof(vertex) * n_verts );
		radius_list = (float *) vm_malloc( sizeof(float) * n_verts );

		Verify( (vert != NULL) );
		Verify( (radius_list != NULL) );

		memset( vert, 0, sizeof(vertex) * n_verts );
		memset( radius_list, 0, sizeof(float) * n_verts );

		n_allocated = n_verts;
	}

	n_to_render = 0;
	use_radius = true;
}
Esempio n. 2
0
void UI_WINDOW::destroy()
{
	UI_GADGET *cur;
	int idx;

	// free up any bitmaps
	release_bitmaps();

	// destroy all gadgets
	if (first_gadget) {
		cur = first_gadget;
		do {
			cur->destroy();
			cur = cur->next;

		} while (cur != first_gadget);
	}

	// free up all xstrs
	for(idx=0; idx<MAX_UI_XSTRS; idx++){
		// free up this struct
		if(xstrs[idx] != NULL){
			if(xstrs[idx]->xstr != NULL){
				// This const_cast is safe since the string was allocated by vm_strdup
				vm_free(const_cast<char*>(xstrs[idx]->xstr));
			}
			vm_free(xstrs[idx]);
			xstrs[idx] = NULL;
		}
	}
}
Esempio n. 3
0
void UI_INPUTBOX::destroy()
{
	if (text) {
		vm_free(text);
		text = NULL;
	}

	// free any valid chars
	if(valid_chars != NULL){
		vm_free(valid_chars);
		valid_chars = NULL;
	}

	// free any invalid chars
	if(invalid_chars != NULL){
		vm_free(invalid_chars);
		invalid_chars = NULL;
	}

	if ((flags & UI_INPUTBOX_FLAG_PASSWD) && passwd_text) {
		vm_free(passwd_text);
		passwd_text = NULL;
	}

	UI_GADGET::destroy();
}
Esempio n. 4
0
void UI_WINDOW::destroy()
{
	UI_GADGET* cur;
	int idx;

	// free up any bitmaps
	release_bitmaps();

	// destroy all gadgets
	if (first_gadget)
	{
		cur = first_gadget;
		do
		{
			cur->destroy();
			cur = cur->next;

		} while (cur != first_gadget);
	}

	// free up all xstrs
	for (idx = 0; idx < MAX_UI_XSTRS; idx++)
	{
		// free up this struct
		if (xstrs[idx] != NULL)
		{
			if (xstrs[idx]->xstr != NULL)
			{
				vm_free(xstrs[idx]->xstr);
			}
			vm_free(xstrs[idx]);
			xstrs[idx] = NULL;
		}
	}
}
/**
 * Call it to close the connection. It returns immediately
 */
void DisconnectFromChatServer()
{
	if(!Socket_connected) return;
	SendChatString(NOX("/QUIT"),1);
	shutdown(Chatsock,2);
	closesocket(Chatsock);
	Socket_connecting = 0;
	Socket_connected = 0;
	Input_chat_buffer[0] = '\0';
	if(User_list)
	{
		vm_free(User_list);
		User_list = NULL;
	}
	if(Chan_list)
	{
		vm_free(Chan_list);
		Chan_list = NULL;
	}
	
	Chat_server_connected = 0;
	Joining_channel = 0;
	Joined_channel = 0;
	RemoveAllChatUsers();
	FlushChatCommandQueue();
	return;
}
int main(int argc, char *argv[]) {
	VM *vm = vm_create(hello, sizeof(hello), 0);
	vm_exec(vm, 0, false);
	vm_free(vm);

//    int t1 = (clock() / (CLOCKS_PER_SEC / 1000));
	vm = vm_create(loop, sizeof(loop), 2);
	vm_exec(vm, 0, false);
	vm_print_data(vm->globals, vm->nglobals);
	vm_free(vm);

//    int t2 = (clock() / (CLOCKS_PER_SEC / 1000));

	vm = vm_create(factorial, sizeof(factorial), 0);
	vm_exec(vm, 23, false);
	vm_free(vm);

	vm = vm_create(f, sizeof(f), 0);
	vm_exec(vm, 0, false);
	vm_free(vm);

//    printf("duration = %d ms\n", (t2 - t1));

	return 0;
}
Esempio n. 7
0
static gboolean
ToolsCoreRpcSetOption(RpcInData *data)
{

   gboolean retVal = FALSE;
   char *option;
   char *value;
   unsigned int index = 0;
   ToolsServiceState *state = data->clientData;

   /* Parse the option & value string. */
   option = StrUtil_GetNextToken(&index, data->args, " ");
   /* Ignore leading space before value. */
   index++;
   value = StrUtil_GetNextToken(&index, data->args, "");

   if (option != NULL && value != NULL && strlen(value) != 0) {

      g_debug("Setting option '%s' to '%s'.\n", option, value);
      g_signal_emit_by_name(state->ctx.serviceObj,
                            TOOLS_CORE_SIG_SET_OPTION,
                            &state->ctx,
                            option,
                            value,
                            &retVal);
   }

   vm_free(option);
   vm_free(value);

   RPCIN_SETRETVALS(data, retVal ? "" : "Unknown or invalid option", retVal);

   return retVal;
}
Esempio n. 8
0
int test_vm_alloc() {
	int i;
	int *baz, *buf = vm_zalloc(tvm, sizeof(int) * 16);
	ASSERT_NOTNULL(buf);
	for (i = 0; i < 16; ++i)
		ASSERT_EQ(int, buf[i], 0);
	vm_free(tvm, buf);

	buf = vm_zalloc(tvm, sizeof(int) * 4096);
	ASSERT_NOTNULL(buf);
	for (i = 0; i < 4096; ++i)
		ASSERT_EQ(int, buf[i], 0);
	vm_free(tvm, buf);

	buf = vm_zalloc(tvm, sizeof(int) * 32);
	for (i = 0; i < 32; ++i)
		ASSERT_EQ(int, buf[i], 0);
	baz = vm_realloc(tvm, buf, sizeof(int) * 4096);
	ASSERT_TRUE(buf == baz);
	for (i = 0; i < 32; ++i)
		ASSERT_EQ(int, baz[i], 0);
	
	vm_free(tvm, vm_zalloc(tvm, 16));

	buf = vm_realloc(tvm, baz, sizeof(int) * 1024 * 4096);
	ASSERT_FALSE(buf == baz);
	return 0;
}
Esempio n. 9
0
/* check that multiple allocations create different maps */
void test_vm_alloc_multiple_arguments(void)
{
	vm_map_t map1, map2;
	const w_size_t num_pages = 10;
	const w_size_t num_frames = 4;
	w_ptr_t start1, start2;
	w_handle_t ram_handle1, ram_handle2;
	w_handle_t swap_handle1, swap_handle2;

	memset(&map1, 0, sizeof(vm_map_t));
	memset(&map2, 0, sizeof(vm_map_t));

	vmsim_init();
	w_set_exception_handler(vmsim_test_segv_handler);
	vm_alloc(num_pages, num_frames, &map1);
	vm_alloc(num_pages, num_frames, &map2);

	start1 = map1.start;
	start2 = map2.start;
	ram_handle1 = map1.ram_handle;
	ram_handle2 = map2.ram_handle;
	swap_handle1 = map1.swap_handle;
	swap_handle2 = map2.swap_handle;

	vm_free(map1.start);
	vm_free(map2.start);
	vmsim_cleanup();

	basic_test(start1 != start2 &&
			ram_handle1 != ram_handle2 &&
			swap_handle1 != swap_handle2);
}
Esempio n. 10
0
geometry_batcher::~geometry_batcher()
{
	if (vert != NULL) {
		vm_free(vert);
		vert = NULL;
	}

	if (radius_list != NULL) {
		vm_free(radius_list);
		radius_list = NULL;
	}
}
Esempio n. 11
0
static gboolean
RpcDebugDispatch(gpointer _chan)
{
   gboolean ret;
   RpcChannel *chan = _chan;
   DbgChannelData *cdata = chan->_private;
   RpcDebugPlugin *plugin = cdata->plugin;
   RpcInData data;
   RpcDebugMsgMapping rpcdata;

   memset(&data, 0, sizeof data);
   memset(&rpcdata, 0, sizeof rpcdata);

   if (plugin->sendFn == NULL || !plugin->sendFn(&rpcdata)) {
      RpcDebug_DecRef(cdata->ctx);
      cdata->hasLibRef = FALSE;
      return FALSE;
   } else if (rpcdata.message == NULL) {
      /*
       * Nothing to send. Maybe the debug plugin is waiting for something to
       * happen before sending another message.
       */
      return TRUE;
   }

   data.clientData = chan;
   data.appCtx = cdata->ctx;
   data.args = rpcdata.message;
   data.argsSize = rpcdata.messageLen;

   ret = RpcChannel_Dispatch(&data);
   if (rpcdata.validateFn != NULL) {
      ret = rpcdata.validateFn(&data, ret);
   } else if (!ret) {
      g_debug("RpcChannel_Dispatch returned error for RPC.\n");
   }

   if (data.freeResult) {
      vm_free(data.result);
   }

   if (rpcdata.freeMsg) {
      vm_free(rpcdata.message);
   }

   if (!ret) {
      VMTOOLSAPP_ERROR(cdata->ctx, 1);
      RpcDebug_DecRef(cdata->ctx);
      cdata->hasLibRef = FALSE;
      return FALSE;
   }
   return TRUE;
}
Esempio n. 12
0
VMUINT8 gsm_sms_get_unread(void* userdata)
{
	sms_unread_msg_struct *dest = (sms_unread_msg_struct*)userdata;
    VMINT16 message_id;
    vm_gsm_sms_read_message_data_t* message_data = NULL;
    VMWCHAR* content_buff;
    VMINT res;

    //message_id = vm_gsm_sms_get_message_id(VM_GSM_SMS_BOX_INBOX, 0);
	//dest -> id = message_id;
    message_id = dest->id;

    if(message_id >= 0)
    {
		// Allocates memory for the message data
		message_data = (vm_gsm_sms_read_message_data_t*)vm_calloc(sizeof(vm_gsm_sms_read_message_data_t));
		if(message_data == NULL)
		{
			vm_log_info("sms read malloc message data fail");
			return FALSE;
		}

		// Allocates memory for the content buffer of the message
		content_buff = (VMWCHAR*)vm_calloc((500+1)*sizeof(VMWCHAR));
		if(content_buff == NULL)
		{
			vm_free(message_data);
			vm_log_info("sms read malloc content fail");
			return FALSE;

		}
		message_data->content_buffer = content_buff;
		message_data->content_buffer_size = 500;

		// Reads the message
		res = vm_gsm_sms_read_message(message_id, VM_TRUE, message_data, sms_read_callback, NULL);
    	//vm_log_info("vm_gsm_sms_read_message message_id is %d", message_id);

		if(res != VM_GSM_SMS_RESULT_OK)
		{
			vm_free(content_buff);
			vm_free(message_data);

			vm_log_info("register read callback fail");
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
}
Esempio n. 13
0
ADC_HANDLE open_hx711(int scl_pin, int sda_pin)
{
	ADC_HANDLE handle = 0;
	handle_details* details;
	hx711_task* task;

	while (open_handles[handle] != NULL)
	{
		handle++;
		if (handle > MAX_HANDLE)
		{
			return ADC_HANDLE_INVALID;
		}
	}

	details = vm_calloc(sizeof(handle_details));
	if (details == NULL)
	{
		return ADC_HANDLE_INVALID;
	}

	task = &details->task;
	task->scl_handle = vm_dcl_open(VM_DCL_GPIO, scl_pin);
	if (task->scl_handle == VM_DCL_HANDLE_INVALID)
	{
		vm_free(details);
		return ADC_HANDLE_INVALID;
	}
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_OUT, NULL);
	vm_dcl_control(task->scl_handle, VM_DCL_GPIO_COMMAND_WRITE_HIGH, NULL);

	task->sda_handle = vm_dcl_open(VM_DCL_GPIO, sda_pin);
	if (task->sda_handle == VM_DCL_HANDLE_INVALID)
	{
		vm_dcl_close(task->scl_handle);
		vm_free(details);
		return ADC_HANDLE_INVALID;
	}
	vm_dcl_control(task->sda_handle, VM_DCL_GPIO_COMMAND_SET_MODE_0, NULL);
	vm_dcl_control(task->sda_handle, VM_DCL_GPIO_COMMAND_SET_DIRECTION_IN, NULL);

	vm_mutex_init(&details->mutex);
	task->op = WAIT;
	task->delay = 100;
	task->callback = dummy_callback;
	task->callback_env = NULL;
	open_handles[handle] = details;
	write_console("open\n");
	vm_thread_create(measurement, (void*) details, (VM_THREAD_PRIORITY) 0);
	return handle;
}
Esempio n. 14
0
static uint8_t *vm_restore_frame(vm_context_t *ctx)
{
	vm_callframe_t *frame;
	uint8_t *pc;

	vm_free(ctx->locals);
	frame = (vm_callframe_t *)vm_stack_pop(ctx->cstack);
	ctx->locals = frame->locals;
	pc = frame->return_pc;
	vm_free(frame);

	return pc;
}
Esempio n. 15
0
// Close down the audiostream system.  Must call audiostream_init() before any audiostream functions can
// be used.
void audiostream_close()
{
	int i;
	if (Audiostream_inited == 0)
		return;

	for (i = 0; i < MAX_AUDIO_STREAMS; i++)
	{
		if (Audio_streams[i].status == ASF_USED)
		{
			Audio_streams[i].status = ASF_FREE;
			Audio_streams[i].Destroy();
		}
	}

	// Destroy AudioStreamServices object
	if (m_pass)
	{
		vm_free(m_pass);
		m_pass = NULL;
	}

	// free global buffers
	if (Wavedata_load_buffer)
	{
		vm_free(Wavedata_load_buffer);
		Wavedata_load_buffer = NULL;
	}

	if (Wavedata_service_buffer)
	{
		vm_free(Wavedata_service_buffer);
		Wavedata_service_buffer = NULL;
	}

	if (Compressed_buffer)
	{
		vm_free(Compressed_buffer);
		Compressed_buffer = NULL;
	}

	if (Compressed_service_buffer)
	{
		vm_free(Compressed_service_buffer);
		Compressed_service_buffer = NULL;
	}

	DELETE_CRITICAL_SECTION(Global_service_lock);

	Audiostream_inited = 0;
}
// called at the end of a mission for cleanup
void mission_event_shutdown()
{
	int i;

	for (i=0; i<Num_mission_events; i++) {
		if (Mission_events[i].objective_text) {
			vm_free(Mission_events[i].objective_text);
			Mission_events[i].objective_text = NULL;
		}
		if (Mission_events[i].objective_key_text) {
			vm_free(Mission_events[i].objective_key_text);
			Mission_events[i].objective_key_text = NULL;
		}
	}
}
/**
 * @brief Free an animation that was loaded with anim_load().  
 * @details All instances referencing this animation must be free'ed or get an assert.
 */
int anim_free(anim *ptr)
{
	Assert ( ptr != NULL );
	anim *list, **prev_anim;

	list = first_anim;
	prev_anim = &first_anim;
	while (list && (list != ptr)) {
		prev_anim = &list->next;
		list = list->next;
	}

	if ( !list )
		return -2;

	// only free when ref_count is 0
	ptr->ref_count--;
	if ( ptr->ref_count > 0 ) 
		return -1;

	// only free if there are no playing instances
	if ( ptr->instance_count > 0 )
		return -1;

	if(ptr->keys != NULL){
		vm_free(ptr->keys);
		ptr->keys = NULL;
	}

	if ( ptr->flags & (ANF_MEM_MAPPED|ANF_STREAMED) ) {
		cfclose(ptr->cfile_ptr);
		if (ptr->cache != NULL) {
			vm_free(ptr->cache);
			ptr->cache = NULL;
		}
	}
	else {
		Assert(ptr->data);
		if (ptr->data != NULL) {
			vm_free(ptr->data);
			ptr->data = NULL;
		}
	}

	*prev_anim = ptr->next;
	vm_free(ptr);
	return 0;
}
Esempio n. 18
0
// evaluate a certain function for all docked objects
void dock_evaluate_all_docked_objects(object *objp, dock_function_info *infop, void (*function)(object *, dock_function_info *))
{
	Assert((objp != NULL) && (infop != NULL) && (function != NULL));

	// not docked?
	if (!object_is_docked(objp))
	{
		// call the function for just the one object
		function(objp, infop);
		return;
	}

	// we only have two objects docked
	if (dock_check_docked_one_on_one(objp))
	{
		// call the function for the first object, and return if instructed
		function(objp, infop);
		if (infop->early_return_condition) return;

		// call the function for the second object, and return if instructed
		function(objp->dock_list->docked_objp, infop);
		if (infop->early_return_condition) return;
	}

	// we have multiple objects docked and we're treating them as a hub
	else if (dock_check_assume_hub())
	{
		// get the hub
		object *hub_objp = dock_get_hub(objp);

		// call the function for the hub, and return if instructed
		function(hub_objp, infop);
		if (infop->early_return_condition) return;

		// iterate through all docked objects
		for (dock_instance *ptr = hub_objp->dock_list; ptr != NULL; ptr = ptr->next)
		{
			// call the function for this object, and return if instructed
			function(ptr->docked_objp, infop);
			if (infop->early_return_condition) return;
		}
	}

	// we have multiple objects docked and we must treat them as a tree
	else
	{
		// create a bit array to mark the objects we check
		ubyte *visited_bitstring = (ubyte *) vm_malloc(calculate_num_bytes(MAX_OBJECTS));

		// clear it
		memset(visited_bitstring, 0, calculate_num_bytes(MAX_OBJECTS));

		// start evaluating the tree
		dock_evaluate_tree(objp, infop, function, visited_bitstring);

		// destroy the bit array
		vm_free(visited_bitstring);
		visited_bitstring = NULL;
	}
}
Esempio n. 19
0
void io_libraryRelease(io_library_t *library)
{
	spinlock_lock(&library->lock);

	if((-- library->refCount) == 0)
	{
		struct io_dependency_s *dependency = list_first(library->dependencies);
		while(dependency)
		{
			io_libraryRelease(dependency->library);
			dependency = dependency->next;
		}

		io_storeRemoveLibrary(library);

		if(library->vmemory)
			vm_free(vm_getKernelDirectory(), library->vmemory, library->pages);

		if(library->pmemory)
			pm_free(library->pmemory, library->pages);

		hfree(NULL, library->path);
		list_destroy(library->dependencies);
		return;
	}

	spinlock_unlock(&library->lock);
}
void gr_opengl_set_gamma(float gamma)
{
	ushort *gamma_ramp = NULL;

	Gr_gamma = gamma;
	Gr_gamma_int = int (Gr_gamma*10);

	// new way - but not while running FRED
	if (!Fred_running && !Cmdline_no_set_gamma && os::getSDLMainWindow() != nullptr) {
		gamma_ramp = (ushort*) vm_malloc( 3 * 256 * sizeof(ushort), memory::quiet_alloc);

		if (gamma_ramp == NULL) {
			Int3();
			return;
		}

		memset( gamma_ramp, 0, 3 * 256 * sizeof(ushort) );

		// Create the Gamma lookup table
		opengl_make_gamma_ramp(gamma, gamma_ramp);

		SDL_SetWindowGammaRamp( os::getSDLMainWindow(), gamma_ramp, (gamma_ramp+256), (gamma_ramp+512) );

		vm_free(gamma_ramp);
	}
}
void gr_opengl_shutdown()
{
	graphics::paths::PathRenderer::shutdown();

	opengl_tcache_shutdown();
	opengl_tnl_shutdown();
	opengl_scene_texture_shutdown();
	opengl_post_process_shutdown();
	opengl_shader_shutdown();

	GL_initted = false;

	glDeleteVertexArrays(1, &GL_vao);
	GL_vao = 0;

	if (GL_original_gamma_ramp != NULL && os::getSDLMainWindow() != nullptr) {
		SDL_SetWindowGammaRamp( os::getSDLMainWindow(), GL_original_gamma_ramp, (GL_original_gamma_ramp+256), (GL_original_gamma_ramp+512) );
	}

	if (GL_original_gamma_ramp != NULL) {
		vm_free(GL_original_gamma_ramp);
		GL_original_gamma_ramp = NULL;
	}

	graphic_operations->makeOpenGLContextCurrent(nullptr, nullptr);
	GL_context = nullptr;
}
Esempio n. 22
0
int http_gethostbynameworker(void *parm)
#endif
{
#ifdef SCP_UNIX
//	df_pthread_detach(df_pthread_self());
#endif
	async_dns_lookup *lookup = (async_dns_lookup *)parm;
	HOSTENT *he = gethostbyname(lookup->host);
	if(he==NULL)
	{
		lookup->error = true;
#ifdef WIN32
		return;
#else
		return 0;
#endif
	}
	else if(!lookup->abort)
	{
		memcpy(&lookup->ip,he->h_addr_list[0],sizeof(unsigned int));
		lookup->done = true;
		memcpy(&httpaslu,lookup,sizeof(async_dns_lookup));
	}
	vm_free(lookup);

#ifdef SCP_UNIX
	return 0;
#endif
}
void opengl_light_shutdown()
{
	if (opengl_lights != NULL) {
		vm_free(opengl_lights);
		opengl_lights = NULL;
	}
}
Esempio n. 24
0
// hud_add_msg_to_scrollback() adds the new_msg to the scroll-back message list.  If there
// are no more free slots, the first slot is released to make room for the new message.
//
void hud_add_line_to_scrollback(char *text, int source, int t, int x, int y, int underline_width)
{
    line_node *new_line;

    Assert(HUD_msg_inited);
    if (!text || !strlen(text))
        return;

    if ( EMPTY(&Msg_scrollback_free_list) ) {
        new_line = GET_FIRST(&Msg_scrollback_used_list);
        list_remove(&Msg_scrollback_used_list, new_line);
        vm_free(new_line->text);

    } else {
        new_line = GET_FIRST(&Msg_scrollback_free_list);
        list_remove(&Msg_scrollback_free_list, new_line);
    }

    new_line->x = x;
    new_line->y = y;
    new_line->underline_width = underline_width;
    new_line->time = t;
    new_line->source = source;
    new_line->text = (char *) vm_malloc( strlen(text) + 1 );
    strcpy(new_line->text, text);
    list_append(&Msg_scrollback_used_list, new_line);
}
Esempio n. 25
0
// called when a popup goes away
void popup_close(popup_info *pi, int screen_id)
{
	int i;
	
	gamesnd_play_iface(SND_POPUP_DISAPPEAR); 	// play sound when popup disappears

	for (i=0; i<pi->nchoices; i++ )	{
		if ( pi->button_text[i] != NULL ) {
			vm_free(pi->button_text[i]);
			pi->button_text[i] = NULL;
		}
	}

	if(screen_id >= 0){
		gr_free_screen(screen_id);	
	}
	Popup_window.destroy();
	anim_ignore_next_frametime();					// to avoid skips in animation since next frametime is saturated
	game_flush();

	Popup_is_active = 0;
	Popup_running_state = 0;

	// anytime in single player, and multiplayer, not in mission, go ahead and stop time
	if ( (Game_mode & GM_NORMAL) || ((Game_mode & GM_MULTIPLAYER) && !(Game_mode & GM_IN_MISSION)) )
		game_start_time();
}
Esempio n. 26
0
//=========================
int https_get(lua_State* L)
{
	int ret = 0;
    vm_https_callbacks_t callbacks = { (vm_https_set_channel_response_callback)https_send_request_set_channel_rsp_cb,
    								   (vm_https_unset_channel_response_callback)https_unset_channel_rsp_cb,
									   (vm_https_release_all_request_response_callback)https_send_release_all_req_rsp_cb,
									   (vm_https_termination_callback)https_send_termination_ind_cb,
                                       (vm_https_send_response_callback)https_send_read_request_rsp_cb,
									   (vm_https_read_content_response_callback)https_send_read_read_content_rsp_cb,
                                       (vm_https_cancel_response_callback)https_send_cancel_rsp_cb,
									   (vm_https_status_query_response_callback)https_send_status_query_rsp_cb };

	size_t sl;
    const char* url = luaL_checklstring(L, 1, &sl);

    vm_free(g_https_url);
    g_https_url = vm_calloc(sl+1);
    strncpy(g_https_url, url, sl);

    vm_https_register_context_and_callback(gprs_bearer_type, &callbacks);
    if (ret != 0) {
        l_message(NULL, "register context & cb failed");
    }
    else {
    	ret = vm_https_set_channel(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    }
    lua_pushinteger(L, ret);

	return 1;
}
Esempio n. 27
0
// Init the playback portion of the real-time voice system
//	exit:	0	=>	success
//			!0	=>	failure, playback not possible
int rtvoice_init_playback()
{
	rtv_format	*rtvf=NULL;

	if ( !Rtv_playback_inited ) {

		rtvoice_reset_out_buffers();

		Rtv_playback_format=0;
		rtvf = &Rtv_formats[Rtv_playback_format];

		if ( Rtv_playback_uncompressed_buffer ) {
			vm_free(Rtv_playback_uncompressed_buffer);
			Rtv_playback_uncompressed_buffer=NULL;
		}

		Rtv_playback_uncompressed_buffer_size = rtvf->frequency * (RTV_BUFFER_TIME) * fl2i(rtvf->bits_per_sample/8.0f);
		Rtv_playback_uncompressed_buffer = (unsigned char*)vm_malloc(Rtv_playback_uncompressed_buffer_size);
		Assert(Rtv_playback_uncompressed_buffer);

		Rtv_playback_inited=1;
	}

	return 0;
}
Esempio n. 28
0
/* Free resources used by a router instance */
static int c3725_delete_instance(vm_instance_t *vm)
{
   c3725_t *router = VM_C3725(vm);
   int i;

   /* Stop all CPUs */
   if (vm->cpu_group != NULL) {
      vm_stop(vm);
      
      if (cpu_group_sync_state(vm->cpu_group) == -1) {
         vm_error(vm,"unable to sync with system CPUs.\n");
         return(FALSE);
      }
   }

   /* Remove NIO bindings */
   for(i=0;i<vm->nr_slots;i++)
      vm_slot_remove_all_nio_bindings(vm,i);

   /* Shutdown all Network Modules */
   vm_slot_shutdown_all(vm);

   /* Free mainboard EEPROM */
   cisco_eeprom_free(&router->mb_eeprom);

   /* Free all resources used by VM */
   vm_free(vm);

   /* Free the router structure */
   free(router);
   return(TRUE);
}
Esempio n. 29
0
/* Create an instance of the specified type */
vm_instance_t *vm_create_instance(char *name,int instance_id,char *type)
{
   vm_platform_t *platform;
   vm_instance_t *vm = NULL;

   if (!(platform = vm_platform_find(type))) {
      fprintf(stderr,"VM %s: unknown platform '%s'\n",name,type);
      goto error;
   }

   /* Create a generic VM instance */
   if (!(vm = vm_create(name,instance_id,platform)))
      goto error;

   /* Initialize specific parts */
   if (vm->platform->create_instance(vm) == -1)
      goto error;

   return vm;

 error:
   fprintf(stderr,"VM %s: unable to create instance!\n",name);
   vm_free(vm);
   return NULL;
}
Esempio n. 30
0
void batching_allocate_and_load_buffer(primitive_batch_buffer *draw_queue)
{
    Assert(draw_queue != NULL);

    if ( draw_queue->buffer_size < draw_queue->desired_buffer_size ) {
        if ( draw_queue->buffer_ptr != NULL ) {
            vm_free(draw_queue->buffer_ptr);
        }

        draw_queue->buffer_size = draw_queue->desired_buffer_size;
        draw_queue->buffer_ptr = vm_malloc(draw_queue->desired_buffer_size);
    }

    draw_queue->desired_buffer_size = 0;

    size_t offset = 0;
    size_t num_items = draw_queue->items.size();

    for ( size_t i = 0; i < num_items; ++i ) {
        primitive_batch_item *item = &draw_queue->items[i];

        item->offset = offset;
        item->n_verts = item->batch->load_buffer((batch_vertex*)draw_queue->buffer_ptr, offset);
        item->batch->clear();

        offset += item->n_verts;
    }

    if ( draw_queue->buffer_num >= 0 ) {
        gr_update_buffer_data(draw_queue->buffer_num, draw_queue->buffer_size, draw_queue->buffer_ptr);
    }
}