da_result_t check_enough_storage(stage_info *stage)
{
	da_result_t ret = DA_RESULT_OK;
	unsigned long cont_size = 0;
	da_storage_size_t avail_memory = {0, };
	da_storage_type_t type = DA_STORAGE_PHONE;

	DA_LOG_FUNC_START(Default);

	/* check enough storage here because of multiple download */
	ret = get_storage_type(&type);
	if (DA_RESULT_OK != ret)
		return ret;

	cont_size
		= GET_CONTENT_STORE_CURRENT_FILE_SIZE(GET_STAGE_CONTENT_STORE_INFO(stage));

	DA_LOG(Default,"cont_size [%d]", cont_size);
	if (cont_size) {
		ret = get_available_memory(DA_STORAGE_PHONE, &avail_memory);
		if (DA_RESULT_OK == ret && (avail_memory.b_available
		        < ((cont_size + SAVE_FILE_BUFFERING_SIZE_5MB)
		                / avail_memory.b_size))) /* 5MB buffering */
		{
			DA_LOG_ERR(Default,"There is no space for content in Phone memory");
			return DA_ERR_DISK_FULL;
		} else if (DA_RESULT_OK != ret) {
			return ret;
		}
		/* If default memeory type is mmc,
		 * it need to check phone memroy for temproary folder
		 * and mmc memory for actual install folder */
		if (type == DA_STORAGE_MMC) {
			DA_LOG(Default,"Storage type == DA_STORAGE_MMC\n");
			ret = get_available_memory(type, &avail_memory);
			if (DA_RESULT_OK == ret && (avail_memory.b_available
			        < ((cont_size + SAVE_FILE_BUFFERING_SIZE_50KB)
			                / avail_memory.b_size))) /* 50KB buffering */
			{
				DA_LOG_ERR(Default,"There is no space for content in MMC memory");
				return DA_ERR_DISK_FULL;
			} else if (DA_RESULT_OK != ret) {
				return ret;
			}
		}
	}

	return ret;
}
示例#2
0
size_t builder::calculate_memory_limit() const {
     // compute memory parameters
    const size_t memory_budget = get_total_memory() * desc_.memory_ratio;
    const size_t occupied = get_total_memory() - get_available_memory();

    if (occupied >= memory_budget) {
        LOGGER_ERROR("Memory ratio is too small");
        return false;
    }
    size_t memory_limit = memory_budget - occupied; 
    LOGGER_INFO("Total physical memory: " << get_total_memory() / 1024 / 1024 << " MiB");
    LOGGER_INFO("Memory limit: " << memory_limit / 1024 / 1024 << " MiB");
    LOGGER_INFO("Precision for storing coordinates and radii: " << std::string((sizeof(real) == 8) ? "double" : "single"));   
    return memory_limit;
}