Esempio n. 1
0
/** Update input keys state from OMAP730 keypad device */
jboolean read_omap730_key_event() {
    if (!keyState.hasPendingKeySignal) {
        // Platform structure to read key event to
        struct FbKeyEvent {
            struct timeval time;
            unsigned short type;
            unsigned short code;
            unsigned value;
        } fbKeyEvent;
        size_t fbKeyEventSize =
            sizeof(fbKeyEvent);

        int readBytes = read(
            fbapp_get_keyboard_fd(), &fbKeyEvent, fbKeyEventSize);

        if (readBytes < (int)fbKeyEventSize) {
            REPORT_ERROR2(LC_CORE,
                "Invalid key input event, received %d bytes instead of %d",
                readBytes, (int)fbKeyEventSize);
                    return KNI_FALSE;
        }
        keyState.km = mapping;
        keyState.changedBits = fbKeyEvent.value ^ keyState.key;
        keyState.key = fbKeyEvent.value;
    }
    keyState.down = -1;
    return KNI_TRUE;
}
Esempio n. 2
0
/**
 * Deletes 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 removeMidlet(int argc, char* argv[]) {
    int   status = -1;
    char* appDir = NULL;

    if (argc == 1) {
        fprintf(stderr, removeUsageText);
        return -1;
    }

    if (argc > 2) {
        REPORT_ERROR1(LC_AMS, "Too many arguments given\n%s", removeUsageText);
        fprintf(stderr, "Too many arguments given\n%s", removeUsageText);
        return -1;
    }

    /* get midp home directory, set it */
    appDir = getApplicationDir(argv[0]);
    if (appDir == NULL) {
        return -1;
    }
    /* set up appDir before calling initialize */
    midpSetAppDir(appDir);

    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;
        SuiteIdType* pSuites = NULL;
        int numberOfSuites = 0;
        MIDPError err;

        /* 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) {
            /* Remove by number */
            int suiteNumber;

            /* 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;
            }

            /* The suite number for the first suite is 1. */
            midp_remove_suite(pSuites[suiteNumber - 1]);

            midp_free_suite_ids(pSuites, numberOfSuites);
        } else if (strcmp(argv[1], "all") == 0) {
            /* Remove all */
            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;
            }

            for (i = 0; i < numberOfSuites; i++) {
                midp_remove_suite(pSuites[i]);
            }

            midp_free_suite_ids(pSuites, numberOfSuites);
        } else {
            REPORT_ERROR2(LC_AMS, "Invalid argument: '%s'.\n%s",
                          argv[1], removeUsageText);
            fprintf(stderr, "Invalid argument: '%s'.\n%s",
                    argv[1], removeUsageText);
        }

        status = 0;
    } while (0);

    midpFinalize();

    return status;
}