/** * The platform should invoke this function in platform context to start * Java. */ void javanotify_start(void) { int argc = 0; char *argv[MIDP_RUNMIDLET_MAXIMUM_ARGS]; javacall_result res; REPORT_INFO(LC_CORE, "javanotify_start() >>\n"); JVM_Initialize(); if (initialize_memory_slavemode() != JAVACALL_OK) { return; } argv[argc++] = "runMidlet"; argv[argc++] = "-1"; argv[argc++] = #if ENABLE_MULTIPLE_ISOLATES "com.sun.midp.appmanager.MVMManager"; #else "com.sun.midp.appmanager.Manager"; #endif /* if ENABLE_MULTIPLE_ISOLATES */ javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
/** * A notification function for telling Java to perform installation of * a MIDlet from filesystem, * * The installation will be performed in the background without launching * the graphic installer application. * * The given path is the full path to MIDlet's jad file or jad. * In case the MIDlet's jad file is specified, then * the MIDlet's jar file muts reside in the same directory as the jad * file. * * @param jadFilePath full path the jad (or jar) file which is of the form: * file://a/b/c/d.jad * @param jadFilePathLen length of the file path * @param userWasAsked a flag indicating whether the platform already asked * the user for permission to download and install the application * so there's no need to ask again and we can immediately install. */ void javanotify_install_midlet_from_filesystem(const javacall_utf16* jadFilePath, int jadFilePathLen, int userWasAsked) { int argc = 0; char *argv[MIDP_RUNMIDLET_MAXIMUM_ARGS]; javacall_result res; REPORT_INFO(LC_CORE, "javanotify_install_midlet_from_filesystem() >>\n"); JVM_Initialize(); if (initialize_memory_slavemode() != JAVACALL_OK) { return; } argv[argc++] = "runMidlet"; argv[argc++] = "-1"; argv[argc++] = "com.sun.midp.scriptutil.CommandLineInstaller"; argv[argc++] = "I"; if (jadFilePathLen >= BINARY_BUFFER_MAX_LEN){ REPORT_ERROR(LC_AMS, "javanotify_install_midlet_from_filesystem(): jadFilePathLen is too long"); return; } memset(urlAddress, 0, BINARY_BUFFER_MAX_LEN); unicodeToNative(jadFilePath, jadFilePathLen, (unsigned char *)urlAddress, BINARY_BUFFER_MAX_LEN); argv[argc++] = urlAddress; javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
/** * The platform should invoke this function in platform context to start * a specified MIDlet suite. * * @param suiteId the ID of the suite to start */ void javanotify_start_suite(char* suiteId) { int length; int argc = 0; char *argv[MIDP_RUNMIDLET_MAXIMUM_ARGS]; javacall_result res; REPORT_INFO(LC_CORE, "javanotify_start_suite() >>\n"); JVM_Initialize(); if (initialize_memory_slavemode() != JAVACALL_OK) { return; } length = strlen(suiteId); if (length >= BINARY_BUFFER_MAX_LEN) { REPORT_ERROR(LC_AMS, "javanotify_start_suite(): Incorrect suiteId parameter\n"); return; } memset(urlAddress, 0, BINARY_BUFFER_MAX_LEN); memcpy(urlAddress, suiteId, length); argv[argc++] = "runMidlet"; argv[argc++] = "-1"; argv[argc++] = "com.sun.midp.appmanager.MIDletSuiteLauncher"; argv[argc++] = urlAddress; javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
/** * The platform should invoke this function in platform context to start * the Java VM and run i3test framework. * * @param arg1 optional argument 1 * @param arg2 optional argument 2 * * @note allowed argument description can be obtained by '-help' value as arg1. */ void javanotify_start_i3test(char* arg1, char* arg2) { int argc = 0; char *argv[MIDP_RUNMIDLET_MAXIMUM_ARGS]; javacall_result res; REPORT_INFO2(LC_CORE,"javanotify_start_i3test() >> %s %s\n",arg1,arg2); JVM_Initialize(); if (initialize_memory_slavemode() != JAVACALL_OK) { return; } argv[argc++] = "runMidlet"; argv[argc++] = "-1"; argv[argc++] = "com.sun.midp.i3test.Framework"; if (NULL != arg1) { argv[argc++] = arg1; if (NULL != arg2) argv[argc++] = arg2; } javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
int main(int argc, char **argv) { #if ENABLE_PCSL pcsl_mem_initialize(NULL, 0); #endif // Call this before any other Jvm_ functions. JVM_Initialize(); // Ignore arg[0] -- the name of the program. argc --; argv ++; while (true) { int n = JVM_ParseOneArg(argc, argv); if (n < 0) { JVMSPI_DisplayUsage(NULL); return -1; } else if (n == 0) { break; } argc -= n; argv += n; } int rv; if (JVM_GetConfig(JVM_CONFIG_SLAVE_MODE) == KNI_FALSE) { // Run the VM in regular mode -- JVM_Start won't return until // the VM completes execution. rv = JVM_Start(NULL, NULL, argc, argv); } else { JVM_Start(NULL, NULL, argc, argv); for (;;) { jlong timeout = JVM_TimeSlice(); if (timeout <= ((jlong)-2)) { break; } else { int blocked_threads_count; JVMSPI_BlockedThreadInfo * blocked_threads; blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count); JVMSPI_CheckEvents(blocked_threads, blocked_threads_count, timeout); } } rv = JVM_CleanUp(); } printf("ADSEXITCODE=%d\n", rv); #if ENABLE_PCSL pcsl_mem_finalize(); #endif return rv; }
/* * We can't run the VM in the main thread (because it has to handle events). * So we run the VM in this thread. */ static DWORD WINAPI vm_thread_routine(LPVOID lpvParam) { // Print arguments that we are using JVMSPI_PrintRaw("Running VM"); JVMSPI_PrintRaw("\n"); for (int i = 1; i < _argc; i++) { JVMSPI_PrintRaw(" "); JVMSPI_PrintRaw(_argv[i]); JVMSPI_PrintRaw("\n"); } // Call this before any other Jvm_ functions. JVM_Initialize(); int argc = _argc; char ** argv = _argv; // Ignore arg[0] -- the name of the program. argc --; argv ++; while (true) { int n = JVM_ParseOneArg(argc, argv); if (n < 0) { JVMSPI_DisplayUsage(NULL); return -1; } else if (n == 0) { break; } argc -= n; argv += n; } if (LogConsole) { write_console("Console output logged at \n"); write_console(logfilename); write_console("\n"); for (int index=0; index<_argc; index++) { log_console(_argv[index]); log_console(" "); } log_console("\n"); } if (!WriteConsole) { write_console("On-screen console output disabled.\n"); } int code = JVM_Start(NULL, NULL, argc, argv); JVMSPI_Exit(code); SHOULD_NOT_REACH_HERE(); return 0; }
/** * A notification function for telling Java to perform installation of * a MIDlet with parameters * * If the given url is of the form http://www.sun.com/a/b/c/d.jad then * java will start a graphical installer will download the MIDlet * fom the internet. * If the given url is a file url (see below, file:///a/b/c/d.jar or * file:///a/b/c/d/jad) installation will be performed * in the backgroudn without launching the graphic installer application * * * @param url of MIDlet to install, can be either one of the following * 1. A full path to the jar file, of the following form file:///a/b/c/d.jar * 2. A full path to the JAD file, of the following form file:///a/b/c/d.jad * 3. An http url of jad file, of the following form, * http://www.sun.com/a/b/c/d.jad * @param silentInstall install the MIDlet without user interaction * @param forceUpdate install the MIDlet even if it already exist regardless * of version */ void javanotify_install_midlet_wparams(const char* httpUrl, int silentInstall, int forceUpdate) { int argc = 0; char *argv[MIDP_RUNMIDLET_MAXIMUM_ARGS]; javacall_result res; int length; REPORT_INFO2(LC_CORE,"javanotify_install_midlet_wparams() >> " "httpUrl = %s, silentInstall = %d\n", httpUrl, silentInstall); JVM_Initialize(); if (initialize_memory_slavemode() != JAVACALL_OK) { return; } argv[argc++] = "runMidlet"; argv[argc++] = "-1"; argv[argc++] = "com.sun.midp.installer.GraphicalInstaller"; if (silentInstall == 1) { if (forceUpdate == 1) { argv[argc++] = "FU"; } else { argv[argc++] = "FI"; } } else { argv[argc++] = "I"; } length = strlen(httpUrl); if (length >= BINARY_BUFFER_MAX_LEN) { REPORT_ERROR(LC_AMS, "javanotify_install_midlet_wparams(): httpUrl is too long"); return; } memset(urlAddress, 0, BINARY_BUFFER_MAX_LEN); memcpy(urlAddress, httpUrl, length); argv[argc++] = urlAddress; javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
/** * The platform should invoke this function in platform context to start * Java in local context (not OTA). */ void javanotify_start_local(char* classname, char* descriptor, char* classpath, javacall_bool debug) { int argc = 0; char *argv[MIDP_RUNMIDLET_MAXIMUM_ARGS]; javacall_result res; REPORT_INFO2(LC_CORE,"javanotify_start_local() >> classname=%s, descriptor=%d \n", classname, descriptor); JVM_Initialize(); if (initialize_memory_slavemode() != JAVACALL_OK) { return; } argv[argc++] = "runMidlet"; argv[argc++] = "-1"; if (classname == NULL) { argv[argc++] = "internal"; } else { argv[argc++] = classname; } if (descriptor != NULL) { argv[argc++] = descriptor; } else { argv[argc++] = classpath; } if (classpath != NULL) { argv[argc++] = "-classpathext"; argv[argc++] = classpath; } javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
/** * Runs a MIDlet from an installed MIDlet suite. This is an example of * how to use the public MIDP API. * * @param argc The total number of arguments * @param argv An array of 'C' strings containing the arguments * * @return <tt>0</tt> for success, otherwise <tt>-1</tt> * * IMPL_NOTE:determine if it is desirable for user targeted output * messages to be sent via the log/trace service, or if * they should remain as printf calls */ int runMidlet(int argc, char** commandlineArgs) { int status = -1; SuiteIdType suiteId = UNUSED_SUITE_ID; pcsl_string classname = PCSL_STRING_NULL; pcsl_string arg0 = PCSL_STRING_NULL; pcsl_string arg1 = PCSL_STRING_NULL; pcsl_string arg2 = PCSL_STRING_NULL; int repeatMidlet = 0; char* argv[RUNMIDLET_MAX_ARGS]; int i, used; int debugOption = MIDP_NO_DEBUG; char *progName = commandlineArgs[0]; char* appDir = NULL; char* confDir = NULL; char* additionalPath; SuiteIdType* pSuites = NULL; int numberOfSuites = 0; int ordinalSuiteNumber = -1; char* chSuiteNum = NULL; MIDPError errCode; char** ppParamsFromPlatform; char** ppSavedParams = NULL; int savedNumberOfParams = 0, numberOfParams = 0; JVM_Initialize(); /* It's OK to call this more than once */ /* get midp application directory, set it */ appDir = getApplicationDir(argv[0]); if (appDir == NULL) { REPORT_ERROR(LC_AMS, "Failed to recieve midp application directory"); return -1; } midpSetAppDir(appDir); /* get midp configuration directory, set it */ confDir = getConfigurationDir(argv[0]); if (confDir == NULL) { REPORT_ERROR(LC_AMS, "Failed to recieve midp configuration directory"); return -1; } midpSetConfigDir(confDir); if (midpInitialize() != 0) { REPORT_ERROR(LC_AMS, "Not enough memory"); return -1; } /* Set Java heap parameters now so they can been overridden from command line */ setHeapParameters(); /* * Check if there are some parameters passed to us from the platform * (i.e., in the current implementation, they are read from a file). */ errCode = ams_get_startup_params(&ppParamsFromPlatform, &numberOfParams); if (errCode == ALL_OK && numberOfParams > 0) { savedNumberOfParams = numberOfParams; ppSavedParams = ppParamsFromPlatform; while ((used = JVM_ParseOneArg(numberOfParams, ppParamsFromPlatform)) > 0) { numberOfParams -= used; ppParamsFromPlatform += used; } if (numberOfParams + 1 > RUNMIDLET_MAX_ARGS) { REPORT_ERROR(LC_AMS, "(1) Number of arguments exceeds supported limit"); ams_free_startup_params(ppSavedParams, savedNumberOfParams); return -1; } argv[0] = progName; for (i = 0; i < numberOfParams; i++) { /* argv[0] is the program name */ argv[i + 1] = ppParamsFromPlatform[i]; } } /* if savedNumberOfParams > 0, ignore the command-line parameters */ if (savedNumberOfParams <= 0) { /* * Debugger port: command-line argument overrides * configuration settings. */ { char* debuggerPortString = midpRemoveCommandOption("-port", commandlineArgs, &argc); if (debuggerPortString != NULL) { int debuggerPort; if (sscanf(debuggerPortString, "%d", &debuggerPort) != 1) { REPORT_ERROR(LC_AMS, "Invalid debugger port format"); return -1; } setInternalProperty("VmDebuggerPort", debuggerPortString); } } /* * Parse options for the VM. This is desirable on a 'development' platform * such as linux_qte. For actual device ports, copy this block of code only * if your device can handle command-line arguments. */ /* * JVM_ParseOneArg expects commandlineArgs[0] to contain the first actual * parameter */ argc --; commandlineArgs ++; while ((used = JVM_ParseOneArg(argc, commandlineArgs)) > 0) { argc -= used; commandlineArgs += used; } /* Restore commandlineArgs[0] to contain the program name. */ argc ++; commandlineArgs --; commandlineArgs[0] = progName; } /* * Not all platforms allow rewriting the command line arg array, * make a copy */ if ((numberOfParams <= 0 && argc > RUNMIDLET_MAX_ARGS) || (numberOfParams > RUNMIDLET_MAX_ARGS)) { REPORT_ERROR(LC_AMS, "Number of arguments exceeds supported limit"); ams_free_startup_params(ppSavedParams, savedNumberOfParams); return -1; } if (savedNumberOfParams <= 0) { for (i = 0; i < argc; i++) { argv[i] = commandlineArgs[i]; } } else { /* * if savedNumberOfParams is greater than zero, command-line parameters * are ignored */ argc = numberOfParams + 1; /* +1 because argv[0] is the program name */ } /* * IMPL_NOTE: corresponding VM option is called "-debugger" */ if (midpRemoveOptionFlag("-debug", argv, &argc) != NULL) { debugOption = MIDP_DEBUG_SUSPEND; } if (midpRemoveOptionFlag("-loop", argv, &argc) != NULL) { repeatMidlet = 1; } /* run the midlet suite by its ordinal number */ if ((chSuiteNum = midpRemoveCommandOption("-ordinal", argv, &argc)) != NULL) { /* the format of the string is "number:" */ if (sscanf(chSuiteNum, "%d", &ordinalSuiteNumber) != 1) { REPORT_ERROR(LC_AMS, "Invalid suite number format"); ams_free_startup_params(ppSavedParams, savedNumberOfParams); return -1; } } /* additionalPath gets appended to the classpath */ additionalPath = midpRemoveCommandOption("-classpathext", argv, &argc); if (argc == 1 && ordinalSuiteNumber == -1) { REPORT_ERROR(LC_AMS, "Too few arguments given."); ams_free_startup_params(ppSavedParams, savedNumberOfParams); return -1; } if (argc > 6) { REPORT_ERROR(LC_AMS, "Too many arguments given\n"); ams_free_startup_params(ppSavedParams, savedNumberOfParams); return -1; } do { int onlyDigits; int len; int i; if (argc > 5) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[5], &arg2)) { REPORT_ERROR(LC_AMS, "Out of Memory"); break; } } if (argc > 4) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[4], &arg1)) { REPORT_ERROR(LC_AMS, "Out of Memory"); break; } } if (argc > 3) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[3], &arg0)) { REPORT_ERROR(LC_AMS, "Out of Memory"); break; } } if (argc > 2) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[2], &classname)) { REPORT_ERROR(LC_AMS, "Out of Memory"); break; } } /* if the storage name only digits, convert it */ onlyDigits = 1; len = strlen(argv[1]); for (i = 0; i < len; i++) { if (!isdigit((argv[1])[i])) { onlyDigits = 0; break; } } if (ordinalSuiteNumber != -1 || onlyDigits) { /* load IDs of the installed suites */ MIDPError err = midp_get_suite_ids(&pSuites, &numberOfSuites); if (err != ALL_OK) { REPORT_ERROR1(LC_AMS, "Error in midp_get_suite_ids(), code %d", err); break; } } if (ordinalSuiteNumber != -1) { /* run the midlet suite by its ordinal number */ if (ordinalSuiteNumber > numberOfSuites || ordinalSuiteNumber < 1) { REPORT_ERROR(LC_AMS, "Suite number out of range"); midp_free_suite_ids(pSuites, numberOfSuites); break; } suiteId = pSuites[ordinalSuiteNumber - 1]; } else if (onlyDigits) { /* run the midlet suite by its ID */ int i; /* the format of the string is "number:" */ if (sscanf(argv[1], "%d", &suiteId) != 1) { REPORT_ERROR(LC_AMS, "Invalid suite ID format"); break; } for (i = 0; i < numberOfSuites; i++) { if (suiteId == pSuites[i]) { break; } } if (i == numberOfSuites) { REPORT_ERROR(LC_AMS, "Suite with the given ID was not found"); break; } } else { /* Run by ID */ suiteId = INTERNAL_SUITE_ID; if (strcmp(argv[1], "internal") && strcmp(argv[1], "-1") && additionalPath == NULL) { /* * If the argument is not a suite ID, it might be a full * path to the midlet suite's jar file. * In this case this path is added to the classpath and * the suite is run without installation (it is useful * for internal test and development purposes). */ additionalPath = argv[1]; } } if (pcsl_string_is_null(&classname)) { int res = find_midlet_class(suiteId, 1, &classname); if (OUT_OF_MEM_LEN == res) { REPORT_ERROR(LC_AMS, "Out of Memory"); break; } if (NULL_LEN == res) { REPORT_ERROR(LC_AMS, "Could not find the first MIDlet"); break; } } do { status = midp_run_midlet_with_args_cp(suiteId, &classname, &arg0, &arg1, &arg2, debugOption, additionalPath); } while (repeatMidlet && status != MIDP_SHUTDOWN_STATUS); if (pSuites != NULL) { midp_free_suite_ids(pSuites, numberOfSuites); suiteId = UNUSED_SUITE_ID; } } while (0); pcsl_string_free(&arg0); pcsl_string_free(&arg1); pcsl_string_free(&arg2); pcsl_string_free(&classname); switch (status) { case MIDP_SHUTDOWN_STATUS: break; case MIDP_ERROR_STATUS: REPORT_ERROR(LC_AMS, "The MIDlet suite could not be run."); break; case SUITE_NOT_FOUND_STATUS: REPORT_ERROR(LC_AMS, "The MIDlet suite was not found."); break; default: break; } if (JVM_GetConfig(JVM_CONFIG_SLAVE_MODE) == KNI_FALSE) { midpFinalize(); } ams_free_startup_params(ppSavedParams, savedNumberOfParams); return status; }
/** * Runs a MIDlet from an installed MIDlet suite. This is an example of * how to use the public MIDP API. * * @param argc The total number of arguments * @param argv An array of 'C' strings containing the arguments * * @return <tt>0</tt> for success, otherwise <tt>-1</tt> * * IMPL_NOTE:determine if it is desirable for user targeted output * messages to be sent via the log/trace service, or if * they should remain as printf calls */ int runMidlet(int argc, char** commandlineArgs) { int status = -1; SuiteIdType suiteId = UNUSED_SUITE_ID; pcsl_string classname = PCSL_STRING_NULL; pcsl_string arg0 = PCSL_STRING_NULL; pcsl_string arg1 = PCSL_STRING_NULL; pcsl_string arg2 = PCSL_STRING_NULL; int repeatMidlet = 0; char* argv[RUNMIDLET_MAX_ARGS]; int i, used; int debugOption = MIDP_NO_DEBUG; char *progName = commandlineArgs[0]; char* midpHome = NULL; char* additionalPath; SuiteIdType* pSuites = NULL; int numberOfSuites = 0; JVM_Initialize(); /* It's OK to call this more than once */ /* * Set Java heap capacity now so it can been overridden from command line. */ JVM_SetConfig(JVM_CONFIG_HEAP_CAPACITY, MIDP_HEAP_REQUIREMENT); /* * Parse options for the VM. This is desirable on a 'development' platform * such as linux_qte. For actual device ports, copy this block of code only * if your device can handle command-line arguments. */ /* JVM_ParseOneArg expects commandlineArgs[0] to contain the first actual * parameter */ argc --; commandlineArgs ++; while ((used = JVM_ParseOneArg(argc, commandlineArgs)) > 0) { argc -= used; commandlineArgs += used; } /* Restore commandlineArgs[0] to contain the program name. */ argc ++; commandlineArgs --; commandlineArgs[0] = progName; /* * Not all platforms allow rewriting the command line arg array, * make a copy */ if (argc > RUNMIDLET_MAX_ARGS) { REPORT_ERROR(LC_AMS, "Number of arguments exceeds supported limit"); fprintf(stderr, "Number of arguments exceeds supported limit\n"); return -1; } for (i = 0; i < argc; i++) { argv[i] = commandlineArgs[i]; } if (midpRemoveOptionFlag("-debug", argv, &argc) != NULL) { debugOption = MIDP_DEBUG_SUSPEND; } if (midpRemoveOptionFlag("-loop", argv, &argc) != NULL) { repeatMidlet = 1; } /* additionalPath gets appended to the classpath */ additionalPath = midpRemoveCommandOption("-classpathext", argv, &argc); if (argc == 1) { REPORT_ERROR(LC_AMS, "Too few arguments given."); fprintf(stderr, runUsageText); return -1; } if (argc > 6) { REPORT_ERROR(LC_AMS, "Too many arguments given\n"); fprintf(stderr, "Too many arguments given\n%s", runUsageText); return -1; } /* get midp home directory, set it */ midpHome = midpFixMidpHome(argv[0]); if (midpHome == NULL) { return -1; } /* set up midpHome before calling initialize */ midpSetHomeDir(midpHome); if (midpInitialize() != 0) { REPORT_ERROR(LC_AMS, "Not enough memory"); fprintf(stderr, "Not enough memory\n"); return -1; } do { int onlyDigits; int len; int i; if (argc > 5) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[5], &arg2)) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } if (argc > 4) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[4], &arg1)) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } if (argc > 3) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[3], &arg0)) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } if (argc > 2) { if (PCSL_STRING_OK != pcsl_string_from_chars(argv[2], &classname)) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } } /* if the storage name only digits, convert it */ onlyDigits = 1; len = strlen(argv[1]); for (i = 0; i < len; i++) { if (!isdigit((argv[1])[i])) { onlyDigits = 0; break; } } if (onlyDigits) { /* Run by number */ int suiteNumber; MIDPError err; /* the format of the string is "number:" */ if (sscanf(argv[1], "%d", &suiteNumber) != 1) { REPORT_ERROR(LC_AMS, "Invalid suite number format"); fprintf(stderr, "Invalid suite number format\n"); break; } err = midp_get_suite_ids(&pSuites, &numberOfSuites); if (err != ALL_OK) { REPORT_ERROR1(LC_AMS, "Error in midp_get_suite_ids(), code %d", err); fprintf(stderr, "Error in midp_get_suite_ids(), code %d.\n", err); break; } if (suiteNumber > numberOfSuites || suiteNumber < 1) { REPORT_ERROR(LC_AMS, "Suite number out of range"); fprintf(stderr, "Suite number out of range\n"); midp_free_suite_ids(pSuites, numberOfSuites); break; } suiteId = pSuites[suiteNumber - 1]; } else { /* Run by ID */ suiteId = INTERNAL_SUITE_ID; /* IMPL_NOTE: consider handling of other IDs. */ if (strcmp(argv[1], "internal") && additionalPath == NULL) { /* * If the argument is not a suite ID, it might be a full * path to the midlet suite's jar file. * In this case this path is added to the classpath and * the suite is run without installation (it is useful * for internal test and development purposes). */ additionalPath = argv[1]; } } if (pcsl_string_is_null(&classname)) { int res = find_midlet_class(suiteId, 1, &classname); if (OUT_OF_MEM_LEN == res) { REPORT_ERROR(LC_AMS, "Out of Memory"); fprintf(stderr, "Out Of Memory\n"); break; } if (NULL_LEN == res) { REPORT_ERROR(LC_AMS, "Could not find the first MIDlet"); fprintf(stderr, "Could not find the first MIDlet\n"); break; } } do { status = midp_run_midlet_with_args_cp(suiteId, &classname, &arg0, &arg1, &arg2, debugOption, additionalPath); } while (repeatMidlet && status != MIDP_SHUTDOWN_STATUS); if (pSuites != NULL) { midp_free_suite_ids(pSuites, numberOfSuites); suiteId = UNUSED_SUITE_ID; } } while (0); pcsl_string_free(&arg0); pcsl_string_free(&arg1); pcsl_string_free(&arg2); pcsl_string_free(&classname); switch (status) { case MIDP_SHUTDOWN_STATUS: break; case MIDP_ERROR_STATUS: REPORT_ERROR(LC_AMS, "The MIDlet suite could not be run."); fprintf(stderr, "The MIDlet suite could not be run.\n"); break; case SUITE_NOT_FOUND_STATUS: REPORT_ERROR(LC_AMS, "The MIDlet suite was not found."); fprintf(stderr, "The MIDlet suite was not found.\n"); break; default: break; } midpFinalize(); return status; }
/** * The platform should invoke this function in platform context to start * the Java VM and run TCK. * * @param url the http location of the TCK server * the url should be of the form: "http://host:port" * @param domain the TCK execution domain */ void javanotify_start_tck(char *tckUrl, javacall_lifecycle_tck_domain domain_type) { int length; int argc = 0; char *argv[MIDP_RUNMIDLET_MAXIMUM_ARGS]; javacall_result res; REPORT_INFO2(LC_CORE,"javanotify_start_tck() >> tckUrl=%s, domain_type=%d \n",tckUrl,domain_type); midp_thread_set_timeslice_proc(midp_slavemode_schedule_vm_timeslice); JVM_Initialize(); if (initialize_memory_slavemode() != JAVACALL_OK) { return; } argv[argc++] = "runMidlet"; argv[argc++] = "-1"; argv[argc++] = "com.sun.midp.installer.AutoTester"; length = strlen(tckUrl); if (length >= BINARY_BUFFER_MAX_LEN) { REPORT_ERROR(LC_AMS, "javanotify_start_tck(): tckUrl is too long"); return; } memset(urlAddress, 0, BINARY_BUFFER_MAX_LEN); memcpy(urlAddress, tckUrl, length); if (strcmp(urlAddress, "none") != 0) { argv[argc++] = urlAddress; } switch (domain_type) { case JAVACALL_LIFECYCLE_TCK_DOMAIN_UNTRUSTED: argv[argc] = "untrusted"; break; case JAVACALL_LIFECYCLE_TCK_DOMAIN_TRUSTED: argv[argc] = "trusted"; break; case JAVACALL_LIFECYCLE_TCK_DOMAIN_UNTRUSTED_MIN: argv[argc] = "minimum"; break; case JAVACALL_LIFECYCLE_TCK_DOMAIN_UNTRUSTED_MAX: argv[argc] = "maximum"; break; case JAVACALL_LIFECYCLE_TCK_DOMAIN_MANUFACTURER: argv[argc] = "manufacturer"; break; case JAVACALL_LIFECYCLE_TCK_DOMAIN_OPERATOR: argv[argc] = "operator"; break; case JAVACALL_LIFECYCLE_TCK_DOMAIN_IDENTIFIED: argv[argc] = "identified_third_party"; break; case JAVACALL_LIFECYCLE_TCK_DOMAIN_UNIDENTIFIED: argv[argc] = "unidentified_third_party"; break; default: REPORT_ERROR(LC_CORE, "javanotify_start_tck() [slave mode] Can not recognize TCK domain\n"); REPORT_ERROR1(LC_CORE, "TCK domain type is %d. System will now exit\n", domain_type); return; } argc++; javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED, JAVACALL_OK); res = runMidlet(argc, argv); }
int main(int argc, char **argv) { int code = 0; #if ENABLE_PCSL pcsl_mem_initialize(NULL, 0); #endif // Call this before any other Jvm_ functions. JVM_Initialize(); // Ignore arg[0] -- the name of the program. argc --; argv ++; while (true) { int n = JVM_ParseOneArg(argc, argv); if (n < 0) { printf("Unknown argument: %s\n", argv[0]); JVMSPI_DisplayUsage(NULL); code = -1; goto end; } else if (n == 0) { break; } argc -= n; argv += n; } if (JVM_GetConfig(JVM_CONFIG_SLAVE_MODE) == KNI_FALSE) { // Run the VM in regular mode -- JVM_Start won't return until // the VM completes execution. code = JVM_Start(NULL, NULL, argc, argv); } else { // Run the VM in slave mode -- we keep calling JVM_TimeSlice(), // which executes bytecodes for a small amount and returns. This // mode is necessary for platforms that need to keep the main // control loop outside of of the VM. // // Note that this mode is not necessary on Win32. We do it here // just as a demo. JVM_Start(NULL, NULL, argc, argv); for (;;) { jlong timeout = JVM_TimeSlice(); if (timeout <= -2) { break; } else { int blocked_threads_count; JVMSPI_BlockedThreadInfo * blocked_threads; blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count); JVMSPI_CheckEvents(blocked_threads, blocked_threads_count, timeout); } } code = JVM_CleanUp(); } end: #if ENABLE_PCSL pcsl_mem_finalize(); #endif return code; }