⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpush_timealarm.c

📁 java 1.1 gemini 08_16
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2001
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *   jam_push.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *
 * Author:
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/*************************************************************************
 * Include Statements
 *************************************************************************/
#include <stdlib.h>     /* for atoll */
#include <stdio.h>
#include "jal.h"
#include "jvm_internal.h"
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h" /* Task message communiction */
#include "tst_ltlcom.h"
#include "syscomp_config.h"
#include "task_config.h"        /* Task creation */
#include "stacklib.h"   /* Basic type for dll, evshed, stacktimer */
#include "event_shed.h" /* Event scheduler */
#include "app_buff_alloc.h"
#include "jpush_interface.h"
#include "jam_interface.h"
#include "jam_msg_handler.h"

/*************************************************************************
 * Global Definition
 *************************************************************************/
alarmentry_struct *g_jpush_alarmlist_ptr = NULL;
static char _alarm_path[MAX_WCHAR_FILENAME_LEN];
kal_int32 g_timealarm_count = 0;

/*************************************************************************
 * Global Declaration
 *************************************************************************/
extern event_scheduler *j2me_alarm_es_ptr;
extern kal_int32 g_push_length;
extern mmi_java_timealarm_push_ind_struct timealarm_push_ind_msg[];
extern kal_bool timealarm_push_ind_msg_used[];
extern void j2me_alarm_timeout_handler(void *msg_ptr);
extern kal_uint64 CurrentTime_md(void);

extern void java_mmi_timealarm_push_ind_handler(
                game_type_enum game_type,
                kal_uint32 type,
                void *callback_entry,
                kal_char *mid_name,
                kal_char *mid_storagename);

/*************************************************************************
 * Function Definition
 *************************************************************************/


/*****************************************************************************
 * FUNCTION
 *  jpush_alarm_open
 * DESCRIPTION
 *  Open the Alram Registry file, if it exists and populate
 *  an in memory cache of the file contents.
 * PARAMETERS
 *  alarm_path      [?]    
 * RETURNS
 *  void
 *****************************************************************************/
kal_int32 jpush_alarm_open(char *alarm_path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 pushfd;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, JPUSH_ALARM_OPEN);

    memcpy(_alarm_path, alarm_path, strlen(alarm_path) + 1);

#if !PERSISTENT_ALARMPUSH
    /* Force to clean all timealarm after re-boot */
    if ((pushfd = jvm_file_open((const char*)alarm_path, O_CREAT | O_TRUNC)) == -1)
    {
        return (-1);
    }
    else
    {
        jvm_file_close(pushfd);
        return (0);
    }
#else /* !PERSISTENT_ALARMPUSH */ 
    /* Now read the registered connections. */
    kal_trace(TRACE_FUNC, JPUSH_ALARM_OPEN_PERSISTENT);

    if ((pushfd = jvm_file_open((const char*)alarm_path, O_RDONLY)) != -1)
    {
        kal_int32 ret;

        /* Read through the file one line at a time */
        if ((ret = jpush_alarm_parse(pushfd)) == -2)
        {
            return (-1);
        }

        /* Close the storage handle */
        jvm_file_close(pushfd);

        if (ret == -1)
        {
            return (-1);
        }

        return (-1);
    }
    else if ((pushfd = jvm_file_open((const char*)alarm_path, O_CREAT | O_RDWR)) == -1)
    {
        return (-1);
    }
    return (0);
#endif /* !PERSISTENT_ALARMPUSH */ /* !PERSISTENT_PUSH */
}


/*****************************************************************************
 * FUNCTION
 *  jpush_alarm_save
 * DESCRIPTION
 *  Save the in memory cache of alarm registrations to a persistent
 *  file for use in subsequent runs.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void jpush_alarm_save()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    alarmentry_struct *alarmp;
    int pushfd;
    int counter = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, JPUSH_ALARM_SAVE);

    if ((pushfd = jvm_file_open(_alarm_path, O_CREAT | O_TRUNC | FS_COMMITTED)) != -1)
    {

        /* Write a new list of push registrations to the persistent file */
        for (alarmp = g_jpush_alarmlist_ptr; alarmp; alarmp = alarmp->next)
        {
            char buffer[250] = "";     /* one push record length */
            kal_trace(TRACE_FUNC, JPUSH_ALARM_SAVE_ENTRY,counter);       
            
            /* for fix the issue : the performace is low due to committed FS_write()*/
            if(alarmp->executed)
            {
                sprintf(buffer, "1,%s,%lld,%s,%u\n", 
                    alarmp->midlet,
                    alarmp->wakeup,
                    alarmp->storagename,
                    alarmp->alarm_game_type);
                jvm_file_write(pushfd, buffer, strlen(buffer));            
            }
            else
            {
                sprintf(buffer, "0,%s,%lld,%s,%u\n", 
                    alarmp->midlet,
                    alarmp->wakeup,
                    alarmp->storagename,
                    alarmp->alarm_game_type);
                jvm_file_write(pushfd, buffer, strlen(buffer));                        
            }
            Kputs(alarmp->midlet);         
            sprintf(buffer, "%lld", alarmp->wakeup);
            Kputs(buffer);               

            /* old version suffer performance issue on SAPPHIRE28(write little data much times)
            sprintf(buffer, "%d", alarmp->executed);
            jvm_file_write(pushfd, buffer, strlen(buffer));
            jvm_file_write(pushfd, ",", 1);
            jvm_file_write(pushfd, alarmp->midlet, strlen(alarmp->midlet));
            Kputs(alarmp->midlet);            
            jvm_file_write(pushfd, ",", 1);
            sprintf(buffer, "%lld", alarmp->wakeup);
            jvm_file_write(pushfd, buffer, strlen(buffer));
            Kputs(buffer);            
            jvm_file_write(pushfd, ",", 1);
            jvm_file_write(pushfd, alarmp->storagename, strlen(alarmp->storagename));
            jvm_file_write(pushfd, ",", 1);
            sprintf(buffer, "%u", alarmp->alarm_game_type);
            jvm_file_write(pushfd, buffer, strlen(buffer));
            jvm_file_write(pushfd, "\n", 1);
            */
            counter++;
        }       
        jvm_file_close(pushfd);
    }
}


/*****************************************************************************
 * FUNCTION
 *  jpush_alarm_add
 * DESCRIPTION
 *  Add one entry to the alarm registry.
 *  If the entry already exists return previous alarm time.
 *  On succesful registration, write a new copy of the file to disk.
 * PARAMETERS
 *  str             [?]     
 *  alarm           [IN]        
 *  lastalarm       [?]      
 * RETURNS
 *  
 *****************************************************************************/
int jpush_alarm_add(char *str, kal_int64 alarm, kal_int64 *lastalarm)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -