Exemplo n.º 1
0
void InitializeLimeEvents()
{
    static int initialized = 0;

    IsJavaRunning = 1;

    if (!initialized) {
        LimeFunction *f;
        initialized = TRUE;
        f = NewLimeFunction(LIME_PACKAGE,
                            LIME_GRAPHICS_CLASS,
                            "initialize");
        f->call(f, NULL);
        DeleteLimeFunction(f);

        /* initialize the event bridge */
        f = NewLimeFunction(LIME_PACKAGE,
                            LIME_EVENT_CLASS,
                            "initialize");
        f->call(f, NULL);
        DeleteLimeFunction(f);

    }

    CreateThread(NULL, 0, DispatcherThread, (void *)2000, 0, NULL);

}
void initializeWMASupport() {
    int vmArgc=0;
  //  char *vmArgv[3]; /* CLDC parameters */

    LimeFunction *initWMA = NULL;

    char* resultBytes = NULL;
    int resultLen = 0;

    initWMA = NewLimeFunction(WMA_CLIENT_PACKAGE,
    "WMAClientBridge",
    "initializeWMASupport");

    initWMA->call(initWMA, &resultBytes, &resultLen);
    if (resultLen < 3) {
        /* it's too small to be a valid response */
    }
    else {
        char* resultStr = NULL;
        char* clientTrafficPort = NULL;
        char* serverTrafficPort = NULL;
        char* phoneNum = NULL;

        char* newlinePtr = NULL;
        char* keyPtr = NULL;
        char* valuePtr = NULL;

        /* make the result null-terminated */
        resultStr = (char*)malloc(resultLen + 1);
        resultStr[resultLen] = '\0';
        memcpy(resultStr, resultBytes, resultLen);

        /* break up the result string into its 3 pieces */
        newlinePtr = strrchr(resultStr, '\n');
        phoneNum = newlinePtr + 1;
        *newlinePtr = '\0';
        newlinePtr = strrchr(resultStr, '\n');
        serverTrafficPort = newlinePtr + 1;
        *newlinePtr = '\0';
        clientTrafficPort = resultStr;

        smsInPortNumber = atoi(clientTrafficPort);
        smsOutPortNumber = atoi(serverTrafficPort);

        devicePhoneNumber = strdup(phoneNum);
        javacall_set_property("com.sun.midp.io.j2me.sms.PhoneNumber",
                                          devicePhoneNumber,
                                          JAVACALL_TRUE,
                                          JAVACALL_APPLICATION_PROPERTY);


        free(resultStr);
    }
    DeleteLimeFunction(initWMA);


}
void tearDownWMASupport() {
    LimeFunction *killWMA = NULL;

    int result = 0;

    killWMA = NewLimeFunction(WMA_CLIENT_PACKAGE,
    "WMAClientBridge",
    "cleanupWMASupport");

    /* result is only for synchronization so it doesn't run ansynchronously */
    killWMA->call(killWMA, &result);

    DeleteLimeFunction(killWMA);

	free(devicePhoneNumber);
}