cdc_natives.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 686 行 · 第 1/2 页
C
686 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */#include <jvmconfig.h>#include <kni.h>#include <midp_logging.h>#include <midpMalloc.h>#include <midpAMS.h>#include <midpInit.h>#include <midp_mastermode_port.h>#include <midp_foreground_id.h>#include <keymap_input.h>#include <windows.h>#include <Msgqueue.h>static HANDLE controlPipe[2]; // [0] for read, [1] for writestatic MidpReentryData newSignal;static MidpEvent newMidpEvent;static void initCDCEvents();KNIEXPORT KNI_RETURNTYPE_LONGJVM_JavaMilliSeconds() { return CVMtimeMillis();}/** * Get the current Isolate ID. * * @return ID of the current Isolate */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_main_MIDletSuiteLoader_getIsolateId) { (void)_p_mb; KNI_ReturnInt(0);}/** * Get the Isolate ID of the AMS Isolate. * * @return Isolate ID of AMS Isolate */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(com_sun_midp_main_MIDletSuiteLoader_getAmsIsolateId) { (void) _p_mb; KNI_ReturnInt(0);}/** * Register the Isolate ID of the AMS Isolate by making a native * method call that will call JVM_CurrentIsolateId and set * it in the proper native variable. */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_main_MIDletSuiteLoader_registerAmsIsolateId) { (void) _arguments; (void) _p_mb; KNI_ReturnVoid();}/** * Send hint to VM about the begin of MIDlet startup phase * to allow the VM to fine tune its internal parameters to * achieve optimal peformance * * @param midletIsolateId ID of the started MIDlet isolate */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_main_MIDletSuiteLoader_vmBeginStartUp) { (void) _arguments; (void) _p_mb; KNI_ReturnVoid();}/** * Send hint to VM about the end of MIDlet startup phase * to allow the VM to restore its internal parameters * changed on startup time for better performance * * @param midletIsolateId ID of the started MIDlet isolate */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_main_MIDletSuiteLoader_vmEndStartUp) { (void) _arguments; (void) _p_mb; KNI_ReturnVoid();}/** * Initializes the UI. * * @return <tt>0</tt> upon successful initialization, otherwise * <tt>-1</tt> */static intmidpInitializeUI(void) { /*if (InitializeEvents() != 0) {*/ /* return -1;*/ /*}*/ /* * Porting consideration: * Here is a good place to put I18N init. * function. e.g. initLocaleMethod(); */#if ENABLE_JAVA_DEBUGGER { char* argv[2]; /* Get the VM debugger port property. */ argv[1] = (char *)getInternalProperty("VmDebuggerPort"); if (argv[1] != NULL) { argv[0] = "-port"; (void)JVM_ParseOneArg(2, argv); } }#endif /* IMPL_NOTE if (pushopen() != 0) {*/ /* return -1;*/ /*}*/ lcdlf_ui_init(); return 0;}/** * Finalizes the UI. */static voidmidpFinalizeUI(void) { lcdlf_ui_finalize(); /*IMPL_NOTE: pushclose();*/ /*finalizeCommandState();*/ /*FinalizeEvents();*/ /* Porting consideration:*/ /* Here is a good place to put I18N finalization*/ /*function. e.g. finalizeLocaleMethod();*/ /* * Note: the AMS isolate will have been registered by a native method * call, so there is no corresponding midpRegisterAmsIsolateId in the * midpInitializeUI() function. */ /*midpUnregisterAmsIsolateId();*/ CloseMsgQueue(controlPipe[0]); CloseMsgQueue(controlPipe[1]);}KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(com_sun_midp_main_CDCInit_initMidpNativeStates) { jchar jbuff[1024]; static char conf_buff[1024], store_buff[1024]; int max = sizeof(conf_buff) - 1; int len, i; KNI_StartHandles(2); KNI_DeclareHandle(config); KNI_DeclareHandle(storage); KNI_GetParameterAsObject(1, config); KNI_GetParameterAsObject(2, storage); len = KNI_GetStringLength(config); if (len > max) { len = max; } KNI_GetStringRegion(config, 0, len, jbuff); jbuff[len]=0; convertWtoU8(conf_buff, jbuff); len = KNI_GetStringLength(storage); if (len > max) { len = max; } KNI_GetStringRegion(storage, 0, len, jbuff); jbuff[len]=0; convertWtoU8(store_buff, jbuff); initCDCEvents(); midpSetAppDir(store_buff); midpSetConfigDir(conf_buff); if (midpInitialize() != 0) { printf("midpInitialize() failed\n"); } if (midpInitCallback(VM_LEVEL, midpInitializeUI, midpFinalizeUI) != 0) { printf("midpInitCallback(VM_LEVEL, ...) failed\n"); } KNI_EndHandles(); KNI_ReturnVoid();}static MSGQUEUEOPTIONS readEventQueueOptions;static MSGQUEUEOPTIONS writeEventQueueOptions;/* * Event handling */static void initCDCEvents() { DWORD err; enum { MAX_MESSAGE_SIZE = 1024 }; readEventQueueOptions.dwSize = sizeof(MSGQUEUEOPTIONS); readEventQueueOptions.dwFlags = MSGQUEUE_NOPRECOMMIT; readEventQueueOptions.dwMaxMessages = 0; readEventQueueOptions.cbMaxMessage = MAX_MESSAGE_SIZE; readEventQueueOptions.bReadAccess = TRUE; /* Read*/ controlPipe[0] = CreateMsgQueue(TEXT("EventQueue"), &readEventQueueOptions); err = GetLastError(); if (err != ERROR_SUCCESS) { NKDbgPrintfW(TEXT("Creating Read Queue Failed\n")); return; } writeEventQueueOptions.dwSize = sizeof(MSGQUEUEOPTIONS); writeEventQueueOptions.dwFlags = MSGQUEUE_NOPRECOMMIT; writeEventQueueOptions.dwMaxMessages = 0; writeEventQueueOptions.cbMaxMessage = MAX_MESSAGE_SIZE; writeEventQueueOptions.bReadAccess = FALSE; /* Write*/ controlPipe[1] = OpenMsgQueue(GetCurrentProcess(), controlPipe[0], &writeEventQueueOptions); err = GetLastError(); if (err != ERROR_SUCCESS) { NKDbgPrintfW(TEXT("Creating Write Queue Failed\n")); return; }}/* * Looking up field IDs takes some time, but does not change during a VM * session so the field IDs can be cached to save time. These IDs are only * access by native methods running in the VM thread. */static int eventFieldIDsObtained = 0;static jfieldID typeFieldID;static jfieldID intParam1FieldID;static jfieldID intParam2FieldID;static jfieldID intParam3FieldID;static jfieldID intParam4FieldID;static jfieldID intParam5FieldID;static jfieldID stringParam1FieldID;static jfieldID stringParam2FieldID;static jfieldID stringParam3FieldID;static jfieldID stringParam4FieldID;static jfieldID stringParam5FieldID;static jfieldID stringParam6FieldID;/** * Gets the field ids of a Java event object and cache them * in local static storage. * * @param eventObj handle to an NativeEvent Java object * @param classObj handle to the NativeEvent class */static voidcacheEventFieldIDs(KNIDECLARGS jobject eventObj, jclass classObj) { (void) _arguments; (void) _p_mb; if (eventFieldIDsObtained) { return; } KNI_GetObjectClass(eventObj, classObj); typeFieldID = KNI_GetFieldID(classObj, "type", "I"); intParam1FieldID = KNI_GetFieldID(classObj, "intParam1", "I"); intParam2FieldID = KNI_GetFieldID(classObj, "intParam2", "I"); intParam3FieldID = KNI_GetFieldID(classObj, "intParam3", "I"); intParam4FieldID = KNI_GetFieldID(classObj, "intParam4", "I"); intParam5FieldID = KNI_GetFieldID(classObj, "intParam5", "I"); stringParam1FieldID = KNI_GetFieldID(classObj, "stringParam1", "Ljava/lang/String;"); stringParam2FieldID = KNI_GetFieldID(classObj, "stringParam2", "Ljava/lang/String;"); stringParam3FieldID = KNI_GetFieldID(classObj, "stringParam3", "Ljava/lang/String;"); stringParam4FieldID = KNI_GetFieldID(classObj, "stringParam4", "Ljava/lang/String;"); stringParam5FieldID = KNI_GetFieldID(classObj, "stringParam5", "Ljava/lang/String;"); stringParam6FieldID = KNI_GetFieldID(classObj, "stringParam6", "Ljava/lang/String;"); eventFieldIDsObtained = 1;}static void getControlStringField(KNIDECLARGS jobject objectHandle, jfieldID fieldID, pcsl_string *str) { KNI_StartHandles(1); KNI_DeclareHandle(stringObj); if (str->length > 0) { KNI_NewString(str->data, str->length, stringObj); KNI_SetObjectField(objectHandle, fieldID, stringObj); } KNI_EndHandles();}static void setControlStringField(KNIDECLARGS jobject objectHandle,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?