ToDoListDB.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:20k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * ToDoListDB.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for providing phonebook interface for java package
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  *------------------------------------------------------------------------------
  116.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  117.  *============================================================================
  118.  ****************************************************************************/
  119. #ifndef __PIMEVTDB_C__
  120. #define __PIMEVTDB_C__
  121. /*  Include: MMI header file */
  122. #include "MMI_features.h"
  123. #include "stdC.h"
  124. #include "L4Dr1.h"
  125. #include "PixtelDataTypes.h"
  126. #include "GlobalDefs.h"
  127. #include "CommonScreens.h"
  128. #include "ToDoListEnum.h"
  129. #include "ToDoListDef.h"
  130. #include "SettingProfile.h"
  131. #include "NVRAMEnum.h"
  132. #include "NVRAMType.h"
  133. #include "NVRAMProt.h"
  134. #include "AlarmFrameWorkProt.h"
  135. #include "AlarmDef.h"
  136. #include "DateTimeGprot.h"
  137. #ifdef __J2ME__
  138. #include "j2me_custom_option.h"
  139. #ifdef __SYNCML_SUPPORT__
  140. #include "SyncMLDef.h"
  141. #include "SyncMLGProt.h"
  142. #endif
  143. #if defined(SUPPORT_JSR_75_PIM)
  144. #include "ToDoListDB.h"
  145. /*
  146. ** Typedef
  147. */
  148. /*
  149. ** Define
  150. */
  151. /*
  152. ** Local Variable
  153. */
  154. /*
  155. ** Local Function
  156. */
  157. /*
  158. ** Global Variable
  159. */
  160. extern tdl_context_struct g_tdl_cntx;
  161. /*
  162. ** Global Function
  163. */
  164. /*****************************************************************************
  165. * FUNCTION
  166. *  mmi_phb_handler_init
  167. * DESCRIPTION
  168. *   This function initializes phonebook handler app.
  169. *
  170. * PARAMETERS
  171. *  void
  172. * RETURNS
  173. *  void
  174. * GLOBALS AFFECTED
  175. *   none
  176. *****************************************************************************/
  177. void mmi_tdl_evtdb_handler_init(void)
  178. {
  179.    /*----------------------------------------------------------------*/
  180.    /* Local Variables                                                */
  181.    /*----------------------------------------------------------------*/
  182.    /*----------------------------------------------------------------*/
  183.    /* Code Body                                                      */
  184.    /*----------------------------------------------------------------*/
  185.    SetProtocolEventHandler(mmi_tdl_pim_evtdb_wirte_req ,MSG_ID_MMI_EVTDB_JAVA_SET_ENTRY_REQ);
  186.    SetProtocolEventHandler(mmi_tdl_pim_evtdb_read_req ,MSG_ID_MMI_EVTDB_JAVA_GET_ENTRY_REQ);
  187. }
  188. /*****************************************************************************
  189. * FUNCTION
  190. *  mmi_tdl_pim_evtdb_wirte_req
  191. * DESCRIPTION
  192. *   This function write a todolist entry from pim request
  193. *
  194. * PARAMETERS
  195. *  void
  196. * RETURNS
  197. *  void
  198. * GLOBALS AFFECTED
  199. *   none
  200. *****************************************************************************/
  201. void mmi_tdl_pim_evtdb_wirte_req(void* info)
  202. {
  203.    /*----------------------------------------------------------------*/
  204.    /* Local Variables                                                */
  205.    /*----------------------------------------------------------------*/
  206.    mmi_evtdb_java_set_entry_req_struct* LocalPtr;
  207.    mmi_evtdb_java_entry_struct evtdbEntry;
  208.    mmi_evtdb_java_error_enum errorCode = MMI_EVTDB_JAVA_SUCCESS;
  209.    U8  deleteResult, recordindex = 0;
  210.    /*----------------------------------------------------------------*/
  211.    /* Code Body                                                      */
  212.    /*----------------------------------------------------------------*/
  213.     LocalPtr = (mmi_evtdb_java_set_entry_req_struct*)info;
  214.     /* Init check */
  215.     if ((&g_tdl_cntx == NULL)
  216. #ifdef __SYNCML_SUPPORT__        
  217.         || mmi_syncml_is_tdl_sync_now()
  218. #endif        
  219.         )
  220.     {
  221.         errorCode = MMI_EVTDB_JAVA_TDL_NOT_READY;
  222.     }
  223.     else if(LocalPtr->sort_type != MMI_EVTDB_SORT_BY_TIME)
  224.     {
  225.         errorCode = MMI_EVTDB_JAVA_NOT_SUPPORT;
  226.     }
  227.     else if (LocalPtr->entry_ptr == NULL)
  228.     {
  229.         /* delete record */
  230.         recordindex = LocalPtr->index;
  231.         if (recordindex < NUM_OF_TDL)
  232.         {
  233.             deleteResult = mmi_tdl_delete_record(recordindex);
  234.             if (!deleteResult)
  235.             {
  236.                 errorCode = MMI_EVTDB_JAVA_DELETE_FAIL;
  237.             }
  238.         }
  239.         else
  240.         {
  241.             errorCode = MMI_EVTDB_JAVA_OUT_OF_INDEX;
  242.         }
  243.     }
  244.     else /* Add and updaet new record */
  245.     {
  246.         memcpy(&evtdbEntry,LocalPtr->entry_ptr,sizeof(mmi_evtdb_java_entry_struct));
  247.         if (LocalPtr->index == 0xFFFF) /* Add */
  248.         {
  249.             recordindex = mmi_tdl_pim_util_get_new_index();
  250.         }
  251.         else /* Update */
  252.         {
  253.             recordindex = LocalPtr->index;
  254.         }
  255. if (recordindex < NUM_OF_TDL)
  256.         {
  257. errorCode = mmi_tdl_pim_update_record(recordindex, &evtdbEntry);
  258. if (errorCode == MMI_EVTDB_JAVA_SUCCESS)
  259. {
  260. #ifdef __SYNCML_SUPPORT__
  261.                 /* send notification to SyncML */
  262.                 if (LocalPtr->index == 0xFFFF)
  263.                 {
  264.                     mmi_syncml_tdl_data_changed_notification(SYNCML_RECORD_ADD, recordindex);
  265.                 }
  266.                 else
  267.                 {
  268.                     mmi_syncml_tdl_data_changed_notification(SYNCML_RECORD_MODIFY, recordindex);
  269.                 }
  270.             #endif
  271. TDLWriteToNvram(recordindex);
  272. /* alarm is canceled */
  273. if(evtdbEntry.alarm== TODO_LIST_ALARM_OFF)
  274. AlmCancelAlarm((U8)(recordindex+ALM_TDL_START));
  275. else if(evtdbEntry.alarm== TODO_LIST_ALARM_ON)
  276. AlmSetAlarm((U8)(recordindex+ALM_TDL_START));
  277. }
  278. }
  279. else
  280. {
  281. errorCode = MMI_EVTDB_JAVA_OUT_OF_INDEX;
  282. }
  283.     }
  284.     mmi_tdl_pim_write_rsp((U16) errorCode,recordindex);
  285. }
  286. /*****************************************************************************
  287. * FUNCTION
  288. *  mmi_phb_java_write_rsp
  289. * DESCRIPTION
  290. *   This function return write result to JAVA
  291. *
  292. * PARAMETERS
  293. *  void
  294. * RETURNS
  295. *  void
  296. * GLOBALS AFFECTED
  297. *   none
  298. *****************************************************************************/
  299. void mmi_tdl_pim_write_rsp(U16 result, U16 store_index)
  300. {
  301.    /*----------------------------------------------------------------*/
  302.    /* Local Variables                                                */
  303.    /*----------------------------------------------------------------*/
  304.    mmi_evtdb_java_set_entry_rsp_struct *MsgPtr;
  305.    MYQUEUE Message;
  306.    /*----------------------------------------------------------------*/
  307.    /* Code Body                                                      */
  308.    /*----------------------------------------------------------------*/
  309.    MsgPtr = (mmi_evtdb_java_set_entry_rsp_struct*) OslConstructDataPtr(sizeof(mmi_evtdb_java_set_entry_rsp_struct));
  310.    MsgPtr->index = MsgPtr->handle = store_index;
  311.    MsgPtr->result = result;
  312.    Message.oslSrcId=MOD_MMI;
  313.    Message.oslDestId=MOD_JASYN;
  314.    Message.oslMsgId = MSG_ID_MMI_EVTDB_JAVA_SET_ENTRY_RSP;
  315.    Message.oslDataPtr = (oslParaType *)MsgPtr;
  316.    Message.oslPeerBuffPtr= NULL;
  317.    OslMsgSendExtQueue(&Message);
  318. }
  319. /*****************************************************************************
  320. * FUNCTION
  321. *  mmi_tdl_pim_evtdb_read_req
  322. * DESCRIPTION
  323. *   This function read a todolist entry from pim.
  324. *
  325. * PARAMETERS
  326. *  void
  327. * RETURNS
  328. *  void
  329. * GLOBALS AFFECTED
  330. *   none
  331. *****************************************************************************/
  332. void mmi_tdl_pim_evtdb_read_req(void* info)
  333. {
  334.    /*----------------------------------------------------------------*/
  335.    /* Local Variables                                                */
  336.    /*----------------------------------------------------------------*/
  337.    mmi_evtdb_java_get_entry_req_struct* LocalPtr;
  338.    mmi_evtdb_java_error_enum errorCode = MMI_EVTDB_JAVA_SUCCESS;
  339.    U16 count = 0;
  340. //   ToDoListNode tdlItem;
  341.    /*----------------------------------------------------------------*/
  342.    /* Code Body                                                      */
  343.    /*----------------------------------------------------------------*/
  344.    LocalPtr = (mmi_evtdb_java_get_entry_req_struct*)info;
  345.     /* Init check */
  346.     if ((&g_tdl_cntx == NULL)
  347. #ifdef __SYNCML_SUPPORT__        
  348.                 || mmi_syncml_is_tdl_sync_now()
  349. #endif        
  350.         
  351.         )
  352.     {
  353.         errorCode = MMI_EVTDB_JAVA_TDL_NOT_READY;
  354.     }
  355.     else if(LocalPtr->sort_type != MMI_EVTDB_SORT_BY_TIME)
  356.     {
  357.         errorCode = MMI_EVTDB_JAVA_NOT_SUPPORT;
  358.     }
  359.     /* tdl does not init yet */
  360.     if (errorCode > MMI_EVTDB_JAVA_SUCCESS)
  361.     {
  362.         mmi_tdl_pim_read_rsp((U16) errorCode,count);
  363.         return;
  364.     }
  365.     /* init tdl list, sort by date */
  366.     if(LocalPtr->index == 0)
  367.     {
  368.         TDLMakeListOfAllTask();
  369.     }
  370.     if (LocalPtr->count == 0)
  371.     {
  372.         /* get total event amount*/
  373.         count = g_tdl_cntx.TotalListedTask;
  374.     }
  375.     else if (LocalPtr->count != 0)
  376.     {
  377.         /* get a record */
  378.         if (LocalPtr->index < NUM_OF_TDL)
  379.         {
  380.             count = mmi_tdl_pim_get_tdl_field(LocalPtr->index, LocalPtr->entry_ptr);
  381.             if (count == 0)
  382.             {
  383.                 errorCode = MMI_EVTDB_JAVA_NOT_FOUND;
  384.             }            
  385.         }
  386.         else
  387.         {
  388.             errorCode = MMI_EVTDB_JAVA_OUT_OF_INDEX;
  389.         }
  390.     }
  391.    mmi_tdl_pim_read_rsp((U16) errorCode,count);
  392. }
  393. /*****************************************************************************
  394. * FUNCTION
  395. *  mmi_tdl_pim_read_rsp
  396. * DESCRIPTION
  397. *   This function return read result to JAVA
  398. *
  399. * PARAMETERS
  400. *  void
  401. * RETURNS
  402. *  void
  403. * GLOBALS AFFECTED
  404. *   none
  405. *****************************************************************************/
  406. void mmi_tdl_pim_read_rsp(U16 result, U16 count)
  407. {
  408.    /*----------------------------------------------------------------*/
  409.    /* Local Variables                                                */
  410.    /*----------------------------------------------------------------*/
  411.    mmi_evtdb_java_get_entry_rsp_struct *MsgPtr;
  412.    MYQUEUE Message;
  413.    /*----------------------------------------------------------------*/
  414.    /* Code Body                                                      */
  415.    /*----------------------------------------------------------------*/
  416.    MsgPtr = (mmi_evtdb_java_get_entry_rsp_struct*) OslConstructDataPtr(sizeof(mmi_evtdb_java_get_entry_rsp_struct));
  417.    MsgPtr->result = result;
  418.    MsgPtr->count = count;
  419.    Message.oslSrcId=MOD_MMI;
  420.    Message.oslDestId=MOD_JASYN;
  421.    Message.oslMsgId = MSG_ID_MMI_EVTDB_JAVA_GET_ENTRY_RSP;
  422.    Message.oslDataPtr = (oslParaType *)MsgPtr;
  423.    Message.oslPeerBuffPtr= NULL;
  424.    OslMsgSendExtQueue(&Message);
  425. }
  426. /*****************************************************************************
  427. * FUNCTION
  428. *  mmi_tdl_pim_update_record
  429. * DESCRIPTION
  430. *   This function update tdl record
  431. *
  432. * PARAMETERS
  433. *  void
  434. * RETURNS
  435. *  void
  436. * GLOBALS AFFECTED
  437. *   none
  438. *****************************************************************************/
  439. U16 mmi_tdl_pim_update_record(U16 index, mmi_evtdb_java_entry_struct* evtdbEntry)
  440. {
  441.    U16 result;
  442.    ToDoListNode tdlItem;
  443.    mmi_evtdb_java_error_enum errorCode;
  444.     if (evtdbEntry->startTime.nYear != evtdbEntry->endTime.nYear ||
  445.                 evtdbEntry->startTime.nMonth != evtdbEntry->endTime.nMonth ||
  446.                 evtdbEntry->startTime.nDay!= evtdbEntry->endTime.nDay
  447.               )
  448.     {
  449.         return MMI_EVTDB_JAVA_INVALID_DATE;
  450.     }
  451.     else
  452.     {
  453.         /* Check date/time */
  454.         if (!mmi_dt_is_valid((MYTIME*)&evtdbEntry->startTime))
  455.         {
  456.             return MMI_TDL_INVALID_START_TIME;
  457.         }
  458.         else if (!mmi_dt_is_valid((MYTIME*)&evtdbEntry->endTime))
  459.         {
  460.             return MMI_TDL_INVALID_END_TIME;
  461.         }
  462.         memcpy(&tdlItem.StartTime, &evtdbEntry->startTime, sizeof(MYTIME));
  463.     #ifdef __MMI_ADVANCED_TODO__
  464.         memcpy(&tdlItem.EndTime, &evtdbEntry->endTime, sizeof(MYTIME));
  465.         if (g_tdl_cntx.TaskList[index].Present == 1)    /* modify */
  466.         {
  467.             tdlItem.Type = g_tdl_cntx.TaskList[index].Type;
  468.             tdlItem.Priority = g_tdl_cntx.TaskList[index].Priority;
  469.             memcpy(tdlItem.Location, g_tdl_cntx.TaskList[index].Location, MAX_TODO_LIST_NOTE);
  470.         }
  471.         else    /* add */
  472.         {
  473.             tdlItem.Type = TDL_TASK_REMINDER;
  474.             tdlItem.Priority = TDL_TASK_PRIORITY_MEDIUM;
  475.             memset(tdlItem.Location, 0, MAX_TODO_LIST_NOTE);
  476.         }
  477.     #else /* __MMI_ADVANCED_TODO__ */ 
  478.         tdlItem.EndHour = evtdbEntry->endTime.nHour;
  479.         tdlItem.EndMin= evtdbEntry->endTime.nMin;
  480.     #endif /* __MMI_ADVANCED_TODO__ */ 
  481.         memcpy(&tdlItem.Note,&evtdbEntry->note,MAX_TODO_LIST_NOTE);
  482.         tdlItem.Alarm = evtdbEntry->alarm;
  483.         //tdlItem.Repeat = evtdbEntry->repeat;
  484. tdlItem.Repeat = mmi_alm_get_freq_order(TODO_FREQ_NUM, g_tdl_freq_set, evtdbEntry->repeat);
  485.         tdlItem.Days = evtdbEntry->days;
  486.         tdlItem.Present = 1;
  487.         result = mmi_tdl_is_valid_fields(&tdlItem);
  488.         if (result == MMI_TDL_SUCCESS)
  489.         {
  490.             memcpy(&g_tdl_cntx.TaskList[index],&tdlItem,sizeof(ToDoListNode));
  491.             errorCode = MMI_EVTDB_JAVA_SUCCESS;
  492.         }
  493.         else if(result == MMI_TDL_EXPIRED_ALARM)
  494.         {
  495.          g_tdl_cntx.TaskList[index].Alarm = 0;
  496.          errorCode = MMI_EVTDB_JAVA_TDL_EXPIRED_ALARM;
  497.         }
  498.         else
  499.         {
  500.             errorCode = (result-MMI_TDL_SUCCESS) + MMI_EVTDB_JAVA_INVALID_DATE;
  501.         }
  502.     }
  503.     return errorCode;
  504. }
  505. /*****************************************************************************
  506. * FUNCTION
  507. *  mmi_tdl_pim_get_tdl_field
  508. * DESCRIPTION
  509. *   This function get tdl info by index
  510. *
  511. * PARAMETERS
  512. *  void
  513. * RETURNS
  514. *  void
  515. * GLOBALS AFFECTED
  516. *   none
  517. *****************************************************************************/
  518. U8 mmi_tdl_pim_get_tdl_field(U16 index, mmi_evtdb_java_entry_struct *entry)
  519. {
  520.     ToDoListNode tdlItem;
  521.     memcpy(&tdlItem, &(g_tdl_cntx.TaskList[g_tdl_cntx.SortedList[index]]), sizeof(ToDoListNode));
  522.     if (tdlItem.Present == 1)
  523.     {
  524.     #ifdef __MMI_ADVANCED_TODO__
  525.         memcpy(&entry->startTime, &tdlItem.StartTime, sizeof(MYTIME));
  526.         memcpy(&entry->endTime, &tdlItem.EndTime, sizeof(MYTIME));
  527.         entry->Type = tdlItem.Type;
  528.         entry->Priority = tdlItem.Priority;
  529.         memcpy(&entry->Location, &tdlItem.Location, MAX_TODO_LIST_NOTE);
  530.     #else /* __MMI_ADVANCED_TODO__ */ 
  531.         memcpy(&entry->startTime, &tdlItem.StartTime, sizeof(MYTIME));
  532.         entry->endTime.nYear = tdlItem.StartTime.nYear;
  533.         entry->endTime.nMonth = tdlItem.StartTime.nMonth;
  534.         entry->endTime.nDay = tdlItem.StartTime.nDay;
  535.         entry->endTime.nHour= tdlItem.EndHour;
  536.         entry->endTime.nMin= tdlItem.EndMin;
  537.         entry->endTime.nSec = 0;
  538.     #endif /* __MMI_ADVANCED_TODO__ */ 
  539.         memcpy(&entry->note,&tdlItem.Note,MAX_TODO_LIST_NOTE);
  540.         entry->alarm= tdlItem.Alarm;
  541.         entry->repeat= g_tdl_freq_set[tdlItem.Repeat];
  542.         entry->days= tdlItem.Days;
  543.         entry->index= index;
  544.         entry->handle= g_tdl_cntx.SortedList[index];
  545.         return MMI_TRUE;
  546.     }
  547.     else
  548.     {
  549.         return MMI_FALSE;
  550.     }
  551. }
  552. /*****************************************************************************
  553. * FUNCTION
  554. *  mmi_tdl_pim_get_handle
  555. * DESCRIPTION
  556. *   This function gets handle by sorted index.
  557. *
  558. * PARAMETERS
  559. *  void
  560. * RETURNS
  561. *  handle index, -1 means no matched record
  562. * GLOBALS AFFECTED
  563. *   none
  564. *****************************************************************************/
  565. S16 mmi_tdl_pim_get_handle(U16 index, U8 sort_type)
  566. {
  567.     switch (sort_type)
  568.     {
  569.         case MMI_EVTDB_SORT_BY_TIME:
  570.             /* sort the tdl by date */
  571.          TDLMakeListOfAllTask();
  572.          /* if the index is not exist */
  573.             if (g_tdl_cntx.SortedList[index] == 0xFF)
  574.                 return -1;
  575.             else
  576.                 return (S16)g_tdl_cntx.SortedList[index];
  577.         default:
  578.                 return -1;
  579.     }
  580. }
  581. /*****************************************************************************
  582. * FUNCTION
  583. *  mmi_tdl_pim_get_tdl_field
  584. * DESCRIPTION
  585. *   This function get tdl info by index
  586. *
  587. * PARAMETERS
  588. *  void
  589. * RETURNS
  590. *  handle index, -1 means no matched record
  591. * GLOBALS AFFECTED
  592. *   none
  593. *****************************************************************************/
  594. S16 mmi_tdl_pim_get_sorted_index(U16 handle, U8 sort_type)
  595. {
  596.     U8 i = 0;
  597.     switch (sort_type)
  598.     {
  599.         case MMI_EVTDB_SORT_BY_TIME:
  600.             /* If the handle point to invalid data */
  601.             if (g_tdl_cntx.TaskList[handle].Present == 0)
  602.                 return -1;
  603.             /* sort the tdl by date */
  604.             TDLMakeListOfAllTask();
  605.             for (i=0; i < NUM_OF_TDL ; i++)
  606.             {
  607.                 if (g_tdl_cntx.SortedList[i] == handle)
  608.                     break;
  609.             }
  610.             if(i >= NUM_OF_TDL)
  611.             {
  612.                 return -1;
  613.             }
  614.             else
  615.             {
  616.                 return (S16)i;
  617.             }
  618.         default:
  619.             return -1;
  620.     }
  621. }
  622. #endif /* SUPPORT_JSR_75_PIM */
  623. #endif /*ifdef __J2ME__*/
  624. #endif /*__PIMEVTDB_C__*/