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

📄 capiclnt.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
 * Copyright (C) Ericsson Mobile Communications AB, 2000.
 * Licensed to AU-System AB.
 * All rights reserved.
 *
 * This software is covered by the license agreement between
 * the end user and AU-System AB, and may be used and copied
 * only in accordance with the terms of the said agreement.
 *
 * Neither Ericsson Mobile Communications AB nor AU-System AB
 * assumes any responsibility or liability for any errors or inaccuracies in
 * this software, or any consequential, incidental or indirect damage arising
 * out of the use of the Generic WAP Client software.
 */
#include "capiclnt.h"
#include "wiptrgt.h"
#include "aapiclnt.h"
#include "cmmnrsrc.h"
#include "ml_typw.h"
#include "wap.ifc"
#include "trnscode.h"
#include "mk_queu.h"
#include "wipdb.h"
#include "dbfunct.h"
#include "waectype.h"


#ifdef USE_WIP_MALLOC
#include "wip_mem.h"
#endif

#if defined USE_CHARSET_PLUGIN
    #include "charset.h"
#endif

#ifdef NO_GLOBAL_VARS
    #include "userdata.h"
#endif

#ifndef NO_GLOBAL_VARS
    #ifdef HAS_SETJMP
        /* global variable for exception handling in CLNTc_run. */
        jmp_buf jmpbuf;
    #else
        /* global variable for alternative exception handling */
        BOOL    exception;
        char    *safetyblock;
        #define SIZE_OF_SAFETY_BLOCK 1000
    #endif
#endif


extern DB_ref globalRef; /* Equal to getRef(DB_root, "globl", &error). */
                         /* Internal variable in wipdb.c. Don't touch! */


EXPORT_C VOID    CLNTc_run (VOID)
{
    /* defined in cmmnrsrc.c */
    executingSDL = 1;

    #ifdef HAS_SETJMP
        if (setjmp(jmpbuf) == 0)
        {
            /*
                Process one signal and return.
                It is important that this value not exceeds 1. Otherwise, the
                function may be stucked in an internal loop in the function
                processSignal in mk_sche.c. Instead, processing power should
                be regulated for this function with the function CLNTc_wantsToRun.
            */
            xmk_RunSDL(1);
        }
        else
        {
            /*
                A longjmp from WIPAlloc. If we are here there is no more
                memory, and the situation could not be worse.
                Terminate and re-initialise again.
            */
            deleteAllTimers();
			authenticateTerminate();
			cookiesTerminate();
			dataChannelTerminate();
            db_dbTerminate();
            deleteAllMemory();
        }
    #else
        xmk_RunSDL(1);
        if (exception == TRUE)
        {
            /*
                If we are here there is no more
                memory, and the situation could not be worse.
                Terminate and re-initialise again.
            */
            exception = FALSE;
            deleteAllTimers();
			authenticateTerminate();
			cookiesTerminate();
			dataChannelTerminate();
            db_dbTerminate();
            deleteAllMemory();
        }
    #endif

    executingSDL = 0;
    SetMemoryGuard(TRUE);
}


EXPORT_C BOOL    CLNTc_wantsToRun (VOID)
{
    /*
        IF ((1 || 0) && 1) THEN RETURN 0
        If there is no signals in the cmicro queue and there is no messages in
        the connector call queue, we don't want to run.

        IF ((0 || 1) && 1) THEN RETURN 0
        If there is signals in the cmicro signal queue and all of them are saved
        for later pocessing, and there is nothing in the connector call queue,
        we don't want to run.

        IF ((1 || 0) && 0) THEN RETURN 1
        IF ((0 || 0) && 1) THEN RETURN 1
        IF ((0 || 1) && 1) THEN RETURN 1
        Otherwise we want to run as soon as possible.
    */
    if ( ((xmk_FirstSignal() == NULL) || xmk_SaveSignalsOnly()))
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}

#ifndef NO_GLOBAL_VARS

typedef struct xdormantProcessInstance
{
    char process;
    char instance;
} xdormantProcessInstance;

#define MAX_NO_OF_XDORMANT_STATES 128

#if defined USE_WIP_MALLOC && defined INITIALISE_WIP_MALLOC
char    wip_memory[WIP_MALLOC_MEM_SIZE];
#endif

#endif

EXPORT_C VOID    CLNTc_start (VOID)
{
    XMK_SEND_TMP_VARS

    #ifndef NO_GLOBAL_VARS
    extern XCONST XPDTBL xmk_ROM_ptr xPDTBL[MAX_SDL_PROCESS_TYPES+1];  /* <root-process-table> */
    static xdormantProcessInstance xdormantProcessInstances[MAX_NO_OF_XDORMANT_STATES];
    static char firstRun = 1;
    static char noOfXdormantProcessInstance = 0;
    #endif

    /* initialise the memory allocator */
    #if defined USE_WIP_MALLOC && defined INITIALISE_WIP_MALLOC
        if (firstRun)
        {
            wip_initmalloc(wip_memory, WIP_MALLOC_MEM_SIZE);
        }
    #endif

    #if defined USE_CHARSET_PLUGIN
        initialiseCharsetPlugin();
    #endif

    #ifndef HAS_SETJMP
        exception = FALSE;
        safetyblock = (char *)OSConnectorAlloc(sizeof(char) * SIZE_OF_SAFETY_BLOCK);
    #endif

    #if     defined LOG_EXTERNAL
    {
        CLNTa_log(0, 0, "CLNTc_start\nVOID\n");
    }
    #endif

    if (firstRun) /* prepare for a later restart */
    {
        XCONST    XPDTBL      xmk_ROM_ptr pProcessType;
        int Process = 0;
        /* this loop ensures that all processes are initialised correctly
           after a restart without a prior termination of the program.
           All processes that not is in state XSTARTUP is in state XDORMANT.
           Therefore must all XDORMANT state processes be remembered so that
           they can be restarted properly. */
        while ( (pProcessType = xPDTBL [Process]) != X_END_ROOT_TABLE )
        {
            int Instance = 0;
            while( Instance < pProcessType->MaxInstances )
            {
                if (pProcessType->ProcessStateTable[ Instance ] == XDORMANT)
                {
                    if (noOfXdormantProcessInstance >= MAX_NO_OF_XDORMANT_STATES)
                    {
                    	#if defined LOG_INTERNAL
                        CLNTa_log(0, 0, "Error: increase the number of MAX_NO_OF_XDORMANT_STATES in CLNTc_start!\nVOID\n");
                    	#endif
                    	break;
                    }
                    else
                    {
                    	xdormantProcessInstances[noOfXdormantProcessInstance].process = Process;
                    	xdormantProcessInstances[noOfXdormantProcessInstance].instance = Instance;
                    	noOfXdormantProcessInstance++;
                    }
                }
                Instance++;
            }
            Process++;
        }
        firstRun = 0;
    }
    else /* re-initialise process tables */
    {
        XCONST    XPDTBL      xmk_ROM_ptr pProcessType;
        int iXdormantProcessInstance = 0;
        int Process = 0;
        while ( (pProcessType = xPDTBL [Process]) != X_END_ROOT_TABLE )
        {
            int Instance = 0;
            while( Instance < pProcessType->MaxInstances )
            {
                pProcessType->ProcessStateTable[ Instance ] = XSTARTUP;
                Instance++;
            }
            Process++;
        }
        while ( iXdormantProcessInstance < noOfXdormantProcessInstance )
        {
            pProcessType = xPDTBL [xdormantProcessInstances[iXdormantProcessInstance].process];
            pProcessType->ProcessStateTable[xdormantProcessInstances[iXdormantProcessInstance].instance] = XDORMANT;
            iXdormantProcessInstance++;
        }
    }

    xmk_InitQueue();
    xmk_InitSDL();

	db_dbInit();
	dataChannelInit();
	authenticateInit();
	cookiesInit();

	XMK_SEND_ENV( ENV,
				  StartWAPStack,
				  xDefaultPrioSignal,
				  0,
				  NULL,
				  GLOBALPID(XPTID_StackCtrl,0));
}


EXPORT_C VOID    CLNTc_terminate (VOID)
{
	XMK_SEND_TMP_VARS

#if     defined LOG_EXTERNAL
    {
        CLNTa_log(0, 0, "CLNTc_terminate\nVOID\n");
    }
#endif

    XMK_SEND_ENV( ENV,
                  TerminateWAPStack,
                  xDefaultPrioSignal,
                  0,
                  NULL,
                  GLOBALPID(XPTID_StackCtrl,0));
}

/* Is called when the Generic WAP Client is done with its cleanup */
VOID   TerminationDone(VOID)
{
    deleteAllTimers();
	authenticateTerminate();
	cookiesTerminate();
	dataChannelTerminate();
    db_dbTerminate();
    deleteAllMemory();
    CLNTa_terminated();
}


EXPORT_C VOID    CLNTc_timerExpired (VOID)
{

#if     defined LOG_EXTERNAL
    {
        CLNTa_log(0, 0, "CLNTc_timerExpired\nVOID\n");
    }
#endif

    timerExpired();
}



EXPORT_C VOID  CLNTc_setIntConfig (UINT8 objectId, ConfigInt kind, UINT32 value)
{
    DB_ref ref;

#ifdef LOG_EXTERNAL
    char        szFormat[256];
    size_t      strlength, end = 0;
    const char  *csz;
    const char  *cszParam  = NULL;

    strlength = strlen(csz = "CLNTc_setIntConfig: \t");
    strncpy(&szFormat[end], csz, strlength);
    end += strlength;

    switch (kind) {
    case configHISTORY_SIZE:        /*  How many URLs should be held in the history.    */
        csz = "configHISTORY_SIZE";
        break;
    case configCACHE_AGE:           /*  The time in seconds a cached item shall be in the cache, if no "expires date" is given with the downloaded item.    */
        csz = "configCACHE_AGE";
        break;
    case configCACHE_MODE:          /*  Supported cache modes are:
                                        0: Always check if a newer version of the item is available on server
                                        1: After the Generic WAP Client has been started, check the first time a cached item is accessed  if a newer version is available on server
                                        2: Never check if newer version is available on server. (Always use cached version) */
        csz = "configCACHE_MODE";
        switch (value) {
        case 0:
            cszParam = ":  Always check if a newer version of the item is available on server.";
            break;
        case 1:
            cszParam = ":  After the Generic WAP Client has been started, check the first time a cached item is accessed if a newer version is available on server.";
            break;
        case 2:
            cszParam = ":  Never check if newer version is available on server. (Always use cached version)";
            break;
        default:
            cszParam = ":  (Currently not a supported cache mode.)";
            break;
        }
       break;
    case configDISPLAY_IMAGES:      /*  1 if images can be displayed, 0 otherwise.  */
        csz = "configDISPLAY_IMAGES";
        break;
    case configUPDATE_IMAGES:       /*  1 if images can be displayed after the card has been displayed, 0 otherwise.    */
        csz = "configUPDATE_IMAGES";
        break;
    case configPUSH_SECURITY_LEVEL:
        csz = "configPUSH_SECURITY_LEVEL";
        break;
    case configDEFAULT_CHANNEL:
        csz = "configDEFAULT_CHANNEL";
        break;
    case configCOOKIES_ENABLED:
        csz = "configCOOKIES_ENABLED";
        break;
    case configBA_PERSISTENT_ENABLED:
        csz = "configBA_PERSISTENT_ENABLED";
        break;
    default:
        csz = "INVALID ConfigInt";
        break;
    }
    
    strlength = strlen(csz);
    strncpy(&szFormat[end], csz, strlength);
    end += strlength;

    strlength = strlen(csz = "\nUINT32 \t\tvalue \t%u");
    strncpy(&szFormat[end], csz, strlength);
    end += strlength;

    if (cszParam != NULL) {
        strlength = strlen(cszParam);
        strncpy(&szFormat[end], cszParam, strlength);
        end += strlength;
    }

    szFormat[end++] = '\n';
    szFormat[end++] = '\n';
    szFormat[end] = '\0';
    CLNTa_log(objectId, 0, szFormat, (int)value);
#endif

    switch (kind) {
    case configHISTORY_SIZE:
        if ((ref = getObjectRef(objectId)) == DB_null)
            ref = addObject(objectId);
        db_setInt(ref, (BYTE*) HISTORY_SIZE, value);
        break;
    case configCACHE_AGE:
        db_setInt(globalRef, (BYTE*) CACHE_AGE, value);

⌨️ 快捷键说明

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