📄 mmidc_storage.c
字号:
overlapped.offset = 0;
overlapped.complete_route = DCSaveFS_AsyReadCallBack;
overlapped.param = (FFS_PARAM)param_save_ptr; //free it in call back function
ffs_error = FFS_Read(
e_file_dev,
cur_hfs,
buf_ptr,
read_size,
&transmit,
&overlapped
);
if (FFS_ERROR_NONE == ffs_error)
{
SCI_TRACE_LOW("mmidc_storage.c: DCSaveFS_AsyRead() Read success");
FFS_Close(e_file_dev, cur_hfs);
read_result = DCFFS_READ_SUCCEED;
}
else if (FFS_ERROR_IO_PENDING == ffs_error)
{
SCI_TRACE_LOW("mmidc_storage.c: DCSaveFS_AsyRead() Read start");
read_result = DCFFS_READ_PANDING;
}
else
{
SCI_TRACE_LOW("mmidc_storage.c: DCSaveFS_AsyRead() read file failed");
FFS_Close(e_file_dev, cur_hfs);
read_result = DCFFS_READ_FAIL;
}
}
else
{
SCI_TRACE_LOW("mmidc_storage.c: DCSaveFS_AsyRead() open file failed");
read_result = DCFFS_READ_FAIL;
}
}
else
{
uint32 i;
SCI_TRACE_LOW("mmidc_storage:DCSaveFS_AsyRead:file is not exist");
for (i = 0; i<name_len;i++)
{
SCI_TRACE_LOW("file_name[%d]=0x%04x", i, file_name[i]);
}
read_result = DCFFS_READ_FAIL;
}
}
else
{
SCI_TRACE_LOW("LoadPhoto: can't enter the DC dir!");
read_result = DCFFS_READ_FAIL;
}
return (read_result);
}
/*****************************************************************************/
// Description : call back of DCSaveFS_AsyRead
// Global resource dependence :
// Author: bruce.chi
// Note: standard interface
/*****************************************************************************/
LOCAL void DCSaveFS_AsyReadCallBack(
FFS_ERROR_E ffs_error,
FFS_RESULT result,
FFS_PARAM param
)
{
MMIDC_FFS_SAVE_PARAM_T *ffs_param_in_ptr = PNULL;
MMIDC_FFS_ASY_READ_RESULT_T st_read_result = {0};
SCI_TRACE_LOW("mmidc_storage:DCSaveFS_AsyReadCallBack, efs_error=%d, result=%d, param=%d", ffs_error, result, param);
//init
SCI_MEMSET(&st_read_result, 0, sizeof(st_read_result));
//get in param
SCI_ASSERT(param != 0);
ffs_param_in_ptr = (MMIDC_FFS_SAVE_PARAM_T *)param;
//judge write status
if(FFS_ERROR_NONE == ffs_error && result == ffs_param_in_ptr->buf_size)
{
st_read_result.e_read_result = DCFFS_READ_SUCCEED;
}
else
{
st_read_result.e_read_result = DCFFS_READ_FAIL;
}
//post message
st_read_result.e_file_dev = ffs_param_in_ptr->e_file_dev;
st_read_result.hfs = ffs_param_in_ptr->hfs;
st_read_result.photo_detail = ffs_param_in_ptr->photo_detail;
st_read_result.buf_ptr = ffs_param_in_ptr->buf_ptr;
st_read_result.read_size = result;
st_read_result.win_id = ffs_param_in_ptr->win_id;
MMK_PostMsg(
VIRTUAL_WIN_ID,
MSG_DC_FILE_READ_DONE,
&st_read_result,
sizeof(st_read_result)
); //note: MMK_PostMsg will save one copy of this message, and it will free it
MMI_TriggerMMITask();
//free in param
SCI_FREE(ffs_param_in_ptr);
}
/*****************************************************************************/
// Description : read a photo file
// Global resource dependence :
// Author: bruce.chi
// Note: make sure it is ucs2 name
/*****************************************************************************/
MMIDC_FFS_READ_RESULT_E DCSaveInfo_AsyRead(
MMI_WIN_ID_T win_id, //the window that will receive the ffs callback message
uint32 photo_index,
uint8 *buf_ptr,
uint32 buf_len
)
{
MMIDC_PHOTO_DETAIL_T photo_detail = {0};
uint32 file_size = 0;
uint16 read_times = 0;
MMIDC_FFS_READ_RESULT_E read_result = 0;
FILE_DEV_E_T e_file_dev = 0;
SCI_ASSERT(photo_index < MMIDC_MAX_PHOTO_NUM);
//get file name
photo_detail = s_mmidc_photo_info.photo_detail[photo_index];
//get file size
file_size = buf_len;
//alloc memory
if (buf_ptr == PNULL)
{
return DC_FFS_READ_TOOBIG;
}
//save read times
read_times = (file_size / MMIDC_MAX_PHOTO_SIZE) + 1;
//storage device
e_file_dev = DCSaveInfo_GetPhotoStorageDev(photo_index);
//begin to read
read_result = DCSaveFS_AsyRead(win_id, e_file_dev, read_times, buf_ptr, &photo_detail, photo_index);
return read_result;
}
/*****************************************************************************/
// Description : asynchronize save photo step 2
// Global resource dependence :
// Author: bruce.chi
// Note:
/*****************************************************************************/
PUBLIC MMIDC_FFS_READ_RESULT_E DCSaveInfo_AsyReadStep2(MMIDC_FFS_ASY_READ_RESULT_T *save_result_ptr)
{
static uint32 s_read_total_size = 0;
DC_ASSERT_LOW(save_result_ptr != PNULL);
if (save_result_ptr->e_read_result == DCFFS_READ_SUCCEED)
{
s_read_total_size += save_result_ptr->read_size;
//judge whether all memory has been read
if (s_read_total_size >= save_result_ptr->photo_detail.memory_size)
{
s_read_total_size = 0;
FFS_Close(save_result_ptr->e_file_dev, save_result_ptr->hfs);
}
}
else
{
s_read_total_size = 0;
FFS_Close(save_result_ptr->e_file_dev, save_result_ptr->hfs);
}
return save_result_ptr->e_read_result;
}
/*****************************************************************************/
// Description : get photo name according to photo_index
// Global resource dependence :
// Author: Bruce.Chi
// Note:
///*****************************************************************************/
PUBLIC MMI_STRING_T DCSaveInfo_GetPotoName(uint32 photo_index)
{
MMI_STRING_T mmi_str = {0};
SCI_ASSERT(photo_index < s_mmidc_photo_info.total_num);
mmi_str.str_ptr = (uint8 *)s_mmidc_photo_info.photo_detail[photo_index].name_ptr;
mmi_str.length = s_mmidc_photo_info.photo_detail[photo_index].name_len;
mmi_str.is_ucs2 = TRUE;
return mmi_str;
}
/*****************************************************************************/
// Description : get total photo total number
// Global resource dependence :
// Author: Bruce.Chi
// Note:
///*****************************************************************************/
PUBLIC uint32 DCSaveInfo_GetPotoTotalNum(void)
{
return s_mmidc_photo_info.total_num;
}
/*****************************************************************************/
// Description : get total photo total memory
// Global resource dependence :
// Author: Bruce.Chi
// Note:
/*****************************************************************************/
PUBLIC uint32 DCSaveInfo_GetPhotoTotalSize(void)
{
return s_mmidc_photo_info.total_memory;
}
/*****************************************************************************/
// Description : get photo detail according to photo index
// Global resource dependence :
// Author: Bruce.Chi
// Note:
/*****************************************************************************/
PUBLIC const MMIDC_PHOTO_DETAIL_T *DCSaveInfo_GetPhotoDetail(uint32 photo_index)
{
DC_ASSERT_LOW(photo_index < s_mmidc_photo_info.total_num);
return &s_mmidc_photo_info.photo_detail[photo_index];
}
/*****************************************************************************/
// Description : get photo saved location
// Global resource dependence :
// Author: Bruce.Chi
// Note:
/*****************************************************************************/
PUBLIC FILE_DEV_E_T DCSaveInfo_GetPhotoStorageDev(uint32 photo_index)
{
DC_ASSERT_LOW(photo_index < s_mmidc_photo_info.total_num);
return s_mmidc_photo_info.photo_detail[photo_index].location;
}
/*****************************************************************************/
// Description : get photo size
// Global resource dependence :
// Author: Bruce.Chi
// Note:
/*****************************************************************************/
PUBLIC int32 DCSaveInfo_GetPhotoSize(uint32 photo_index)
{
DC_ASSERT_LOW(photo_index < s_mmidc_photo_info.total_num);
return s_mmidc_photo_info.photo_detail[photo_index].memory_size;
}
/*****************************************************************************/
// Description : set photo size after the size info got
// Global resource dependence :
// Author: Bruce.Chi
// Note:
///*****************************************************************************/
PUBLIC BOOLEAN DCSaveInfo_SetPhotoSize(uint32 photo_index, uint32 width, uint32 height)
{
DC_ASSERT_LOW(photo_index < s_mmidc_photo_info.total_num);
s_mmidc_photo_info.photo_detail[photo_index].width = width;
s_mmidc_photo_info.photo_detail[photo_index].height = height;
return TRUE;
}
/*****************************************************************************/
// Description : adapter for FILE SYSTEM
// Global resource dependence :
// Author: Bruce.Chi
// Note:
///*****************************************************************************/
LOCAL FFS_ERROR_E FILE_CdRootPath(FILE_DEV_E_T file_dev)
{
uint16 ucs2_name_arr[8] = {0};
int ucs2_name_len = 0;
ucs2_name_len = GUI_GB2UCS(ucs2_name_arr, (uint8 *)MMIDC_ROOT_DIR, strlen(MMIDC_ROOT_DIR));
return FFS_CD(file_dev, (const wchar*)ucs2_name_arr);
}
/*****************************************************************************/
// Description : adapter for FILE SYSTEM
// Global resource dependence :
// Author: Bruce.Chi
// Note: it's FFS now
///*****************************************************************************/
LOCAL FFS_ERROR_E FILE_CdDCPath(FILE_DEV_E_T file_dev)
{
uint16 ucs2_name_arr[32] = {0};
int ucs2_name_len = 0;
if (FILE_CdRootPath(file_dev) != FFS_NO_ERROR)
{
return FFS_ERROR_DEVICE;
}
ucs2_name_len = GUI_GB2UCS(ucs2_name_arr, (uint8 *)MMIDC_DEFAULT_DIR, strlen(MMIDC_DEFAULT_DIR));
return FFS_CD(file_dev, (const wchar*)ucs2_name_arr);
}
/*****************************************************************************/
// Description : 进入DC子目录
// Global resource dependence :
// Author: Great.Tian
// Note:
/*****************************************************************************/
PUBLIC BOOLEAN DC_EnterDCSubDir(FILE_DEV_E_T file_dev)
{
if (FFS_NO_ERROR == FILE_CdDCPath(file_dev))
{
return TRUE;
}
else
{
return FALSE;
}
}
/*****************************************************************************/
// Description : assign a photo name, length is (MMIDC_MAX_PHOTO_NAME_LEN + 2)
// Global resource dependence :
// Author: bruce.chi
// Return: length of this string
// Note:
/*****************************************************************************/
uint16 MMIDC_AssignPhotoDefaultName(
uint8 *photo_name_ptr//OUT:照片名指针
)
{
uint16 random = 0;//随机数
int i_protect = 0;
SCI_ASSERT(PNULL != photo_name_ptr);
srand(SCI_GetTickCount());
random = rand();
if(random > 9999)
{
random = random & 0x1fff;
}
sprintf((char *)photo_name_ptr, "PIC_%04d", random);
DC_ASSERT_LOW(strlen((char*) photo_name_ptr) <= MMIDC_MAX_PHOTO_NAME_LEN );
i_protect = 0;
while(!MMIDC_IsFileNameValid(photo_name_ptr, strlen((char *)photo_name_ptr), FALSE))
{
srand(SCI_GetTickCount());
random = rand();
sprintf((char *)photo_name_ptr, "PIC_%04d", random);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -