Пример #1
0
/**
 * java call:
 *   private native String findHandler0(String callerId, int searchBy, 
 *                                      String value);
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_content_RegistryStore_findHandler0(void) {
    pcsl_string callerId = PCSL_STRING_NULL_INITIALIZER;
    jsr211_field searchBy;
    pcsl_string value = PCSL_STRING_NULL_INITIALIZER;
    JSR211_RESULT_CHARRAY result = _JSR211_RESULT_INITIALIZER_;

    KNI_StartHandles(2);
    KNI_DeclareHandle(callerObj);
    KNI_DeclareHandle(valueObj);

    do {
        KNI_GetParameterAsObject(1, callerObj);
        KNI_GetParameterAsObject(3, valueObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(callerObj, &callerId) ||
            PCSL_STRING_OK != midp_jstring_to_pcsl_string(valueObj, &value)) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                   "RegistryStore_register0 no memory for string arguments");
            break;
        }

        searchBy = (jsr211_field) KNI_GetParameterAsInt(2);
        jsr211_find_handler(&callerId, searchBy, &value, &result);

    } while (0);

    pcsl_string_free(&value);
    pcsl_string_free(&callerId);
    result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&result, valueObj);

    KNI_EndHandlesAndReturnObject(valueObj);
}
Пример #2
0
 /**
  * java call:
  * private native String getHandler0(String callerId, String id, int mode);
  */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_content_RegistryStore_getHandler0(void) {
    int mode;
    pcsl_string callerId = PCSL_STRING_NULL_INITIALIZER;
    pcsl_string id = PCSL_STRING_NULL_INITIALIZER;
    JSR211_RESULT_CH handler = _JSR211_RESULT_INITIALIZER_;
    
    KNI_StartHandles(2);
    KNI_DeclareHandle(callerObj);
    KNI_DeclareHandle(handlerObj);

    do {
        KNI_GetParameterAsObject(1, callerObj);
        KNI_GetParameterAsObject(2, handlerObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(callerObj, &callerId) ||
            PCSL_STRING_OK != midp_jstring_to_pcsl_string(handlerObj, &id)) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                   "RegistryStore_getHandler0 no memory for string arguments");
            break;
        }
        mode = KNI_GetParameterAsInt(3);

        jsr211_get_handler(&callerId, &id, mode, &handler);
    } while (0);

    pcsl_string_free(&callerId);
    pcsl_string_free(&id);
    result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&handler, handlerObj);

    KNI_EndHandlesAndReturnObject(handlerObj);
}
Пример #3
0
/**
 * java call:
 *  private native String getByURL0(String callerId, String url, String action);
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_content_RegistryStore_getByURL0(void) {
    pcsl_string callerId = PCSL_STRING_NULL_INITIALIZER;
    pcsl_string url = PCSL_STRING_NULL_INITIALIZER;
    pcsl_string action = PCSL_STRING_NULL_INITIALIZER;
    JSR211_RESULT_CH result = _JSR211_RESULT_INITIALIZER_;

    KNI_StartHandles(4);
    KNI_DeclareHandle(callerObj);
    KNI_DeclareHandle(urlObj);
    KNI_DeclareHandle(actionObj);
    KNI_DeclareHandle(resultObj);

    do {
        KNI_GetParameterAsObject(1, callerObj);
        KNI_GetParameterAsObject(2, urlObj);
        KNI_GetParameterAsObject(3, actionObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(callerObj, &callerId) ||
            PCSL_STRING_OK != midp_jstring_to_pcsl_string(urlObj, &url) ||
            PCSL_STRING_OK != midp_jstring_to_pcsl_string(actionObj, &action)) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                   "RegistryStore_getByURL0 no memory for string arguments");
            break;
        }

        jsr211_handler_by_URL(&callerId, &url, &action, &result);
    } while (0);

    pcsl_string_free(&action);
    pcsl_string_free(&url);
    pcsl_string_free(&callerId);
    result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&result, resultObj);

    KNI_EndHandlesAndReturnObject(resultObj);
}
/**
 * KNI function that creates new native resource for the current ImageItem.
 *
 * Class: javax.microedition.lcdui.ImageItemLFImpl
 * Java prototype:
 * private native int createNativeResource0(int ownerId, String label,
 *                                          int layout,
 *                                          Image img, String altText,
 *                                          int appearanceMode)
 *
 * INTERFACE (operand stack manipulation):
 *   parameters:  ownerId            pointer to the owner's native resource
 *                label              ImageItem's label
 *                layout             ImageItem's layout
 *                img                ImageItem's image
 *                altText            ImageItem's attText
 *                appearanceMode     the appearanceMode of ImageItem
 *   return pointer to the created native resource
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_ImageItemLFImpl_createNativeResource0() {
  MidpError err = KNI_OK;
  MidpDisplayable  *ownerPtr;
  MidpItem *itemPtr = NULL;
  pcsl_string label, altText;
  pcsl_string_status rc1,rc2;
  unsigned char* imgPtr = NULL;
  int appearanceMode, layout;

  KNI_StartHandles(3);
  
  KNI_DeclareHandle(labelJString);
  KNI_DeclareHandle(image);
  KNI_DeclareHandle(altTextJString);

  ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
  KNI_GetParameterAsObject(2, labelJString);
  layout = KNI_GetParameterAsInt(3);
  KNI_GetParameterAsObject(4, image);
  KNI_GetParameterAsObject(5, altTextJString);

  if (KNI_IsNullHandle(image) != KNI_TRUE) {
    imgPtr = gxp_get_imagedata(image);
  }

  appearanceMode = KNI_GetParameterAsInt(6);

  rc1 = midp_jstring_to_pcsl_string(labelJString, &label);
  rc2 = midp_jstring_to_pcsl_string(altTextJString, &altText);

  KNI_EndHandles();

  /* NULL and empty strings are acceptable. */
  if (PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2 ) {
    err = KNI_ENOMEM;
    goto cleanup;
  }

  itemPtr = MidpNewItem(ownerPtr, MIDP_PLAIN_IMAGE_ITEM_TYPE+appearanceMode);
  if (itemPtr == NULL) {
    err = KNI_ENOMEM;
    goto cleanup;
  }

  err = lfpport_imageitem_create(itemPtr, ownerPtr, &label, layout,
				 imgPtr, &altText, appearanceMode);

cleanup:
  pcsl_string_free(&altText);
  pcsl_string_free(&label);

  if (err != KNI_OK) {
    MidpDeleteItem(itemPtr);
    KNI_ThrowNew(midpOutOfMemoryError, NULL);
  }

  KNI_ReturnInt(itemPtr);
}
Пример #5
0
/**
 * Fills <code>MidpString</code> arrays for locales and action_maps from 
 * <code>ActionMap</code> objects.
 * <BR>Length of <code>actionnames</code> array must be the same as in
 * <code>act_num</code> parameter for each element of <code>ActionMap</code>
 * array.
 *
 * @param o <code>ActionMap[]</code> object 
 * @param handler pointer on <code>JSR211_content_handler</code> structure
 * being filled up
 * @return KNI_OK - if successfully get all fields, 
 * KNI_ERR or KNI_ENOMEM - otherwise
 */
static int fillActionMap(jobject o, JSR211_content_handler* handler) {
    int ret = KNI_OK;   // returned result
    int len;            // number of locales

    len = KNI_IsNullHandle(o)? 0: (int)KNI_GetArrayLength(o);
    if (len > 0) {
        int i, j;
        int n = handler->act_num;   // number of actions
        pcsl_string *locs = NULL;   // fetched locales
        pcsl_string *nams = NULL;   // fetched action names

        KNI_StartHandles(3);
        KNI_DeclareHandle(map);   // current ANMap object
        KNI_DeclareHandle(str);   // the ANMap's locale|name String object
        KNI_DeclareHandle(arr);   // the ANMap's array of names object

        do {
            // allocate buffers
            handler->locales = alloc_pcsl_string_list(len);
            if (handler->locales == NULL) {
                ret = KNI_ENOMEM;
                break;
            }
            handler->locale_num = len;
            handler->action_map = alloc_pcsl_string_list(len * n);
            if (handler->action_map == NULL) {
                ret = KNI_ENOMEM;
                break;
            }

            // iterate array elements
            locs = handler->locales;
            nams = handler->action_map;
            for (i = 0; i < len && ret == KNI_OK; i++) {
                KNI_GetObjectArrayElement(o, i, map);
                KNI_GetObjectField(map, anMapLocale, str);
                if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, locs++)) {
                    ret = KNI_ENOMEM;
                    break;
                }
                KNI_GetObjectField(map, anMapActionnames, arr);
                for (j = 0; j < n; j++) {
                    KNI_GetObjectArrayElement(arr, j, str);
                    if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, nams++)) {
                        ret = KNI_ENOMEM;
                        break;
                    }
                }
            }
        } while (0);
        
        KNI_EndHandles();
    }
    
    return ret;
}
Пример #6
0
/**
 * Fetch a KNI String array object into the string array.
 *
 * @param arrObj KNI Java String object handle
 * @param arrPtr the String array pointer for values storing
 * @return number of retrieved strings
 * <BR>KNI_ENOMEM - indicates memory allocation error
 */
static int getStringArray(jobjectArray arrObj, pcsl_string** arrPtr) {
    int i, n = 0;
    pcsl_string* arr;

    KNI_StartHandles(1);
    KNI_DeclareHandle(strObj);

    n = KNI_IsNullHandle(arrObj)? 0: (int)KNI_GetArrayLength(arrObj);
    while (n > 0) {
        arr = alloc_pcsl_string_list(n);
        if (arr == NULL) {
            n = KNI_ENOMEM;
            break;
        }

        *arrPtr = arr;
        for (i = 0; i < n; i++, arr++) {
            KNI_GetObjectArrayElement(arrObj, i, strObj);
            if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(strObj, arr)) {
                free_pcsl_string_list(*arrPtr, n);
                *arrPtr = NULL;
                n = KNI_ENOMEM;
                break;
            }
        }
        break;
    }

    KNI_EndHandles();
    return n;
}
Пример #7
0
/**
 * java call:
 *   private native String getValues0(String callerId, int searchBy);
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_content_RegistryStore_getValues0(void) {
    jsr211_field searchBy;
    pcsl_string callerId = PCSL_STRING_NULL_INITIALIZER;
    JSR211_RESULT_STRARRAY result = _JSR211_RESULT_INITIALIZER_;

    KNI_StartHandles(1);
    KNI_DeclareHandle(strObj);   // String object

    do {
        KNI_GetParameterAsObject(1, strObj);   // callerId
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(strObj, &callerId)) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                   "RegistryStore_getValues0 no memory for string arguments");
            break;
        }

        searchBy = (jsr211_field) KNI_GetParameterAsInt(2);
        jsr211_get_all(&callerId, searchBy, &result);
    } while (0);

    pcsl_string_free(&callerId);
    result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&result, strObj);

    KNI_EndHandlesAndReturnObject(strObj);
}
Пример #8
0
/**
 * java call:
 *  private native boolean unregister(String handlerId);
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_midp_content_RegistryStore_unregister0(void) {
    int ret = KNI_FALSE;
    pcsl_string id = PCSL_STRING_NULL_INITIALIZER;

    KNI_StartHandles(1);
    KNI_DeclareHandle(idStr);   // content handler ID
    KNI_GetParameterAsObject(1, idStr);

    do {
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(idStr, &id)) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                            "RegistryStore_unregister0 no memory for ID");
            break;
        }
        
        if (JSR211_OK != jsr211_unregister_handler(&id)) {
            break;
        }
        
        ret = KNI_TRUE;
    } while (0);

    pcsl_string_free(&id);
    KNI_EndHandles();

    KNI_ReturnBoolean(ret);
}
Пример #9
0
/**
 * Mark of the existing Invocations for a content handler
 * by suiteId and classname so they can be cleaned up on
 * exit.
 *
 * @param suiteId to match a pending invocation
 * @param classname to match a pending invocation
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_setCleanup0(void) {
    StoredLink* link;
    StoredInvoc* invoc;
    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;
    jboolean cleanup;

    KNI_StartHandles(1);
    KNI_DeclareHandle(classname); /* Arg2: non-null classname */

    /* Argument indices must match Java native method declaration */
#define markSuiteIdArg 1
#define markClassnameArg 2
#define markCleanup 3

    do {/* Block to break out of on exceptions */

    if (!isEmpty()) {
        /* Queue is not empty
         * Need a string copy of the desired classname
         * to use for comparisons
         */
        desiredSuiteId = KNI_GetParameterAsInt(markSuiteIdArg);

        KNI_GetParameterAsObject(markClassnameArg, classname);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, 
                           &desiredClassname)) {
            KNI_ThrowNew(midpOutOfMemoryError, 
          "InvocationStore_setListenCleanup0 no memory for [desiredClassname]");
            break;
        }

        cleanup = KNI_GetParameterAsInt(markCleanup);

        /* Inspect the queue of Invocations and pick one that
         * matches the suiteId and classname.
         */
        for (link = invocQueue; link != NULL; link = link->flink) {
            invoc = link->invoc;
            /*
             * If the suite matches and the classname matches
             * set cleanup to the next tid;
             */
            if (desiredSuiteId == invoc->suiteId &&
                pcsl_string_equals(&desiredClassname, &invoc->classname)) {
                /* Found an entry for the Invocation */
                invoc->cleanup = cleanup;
                invoc->notified = KNI_FALSE;
            }
        }
    }
    } while (0);
    
    pcsl_string_free(&desiredClassname);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Пример #10
0
/**
 * Get a String from a field of an object and converts it to pcsl_string.
 *
 * @param obj a handle to Java object whose field will be set
 * @param classObj handle of the object's class
 * @param pszFieldName field name
 * @param fieldHandle handle where to put the resulting jstring
 * @param newValue a handle to the new Java value of the field
 * @param result pointer to the location where the result must be saved
 *
 * @return status of the operation
 */
pcsl_string_status midp_get_string_field(KNIDECLARGS jobject obj, jclass classObj,
                                  char* pszFieldName, jobject fieldHandle,
                                  pcsl_string* result) {
    KNI_GetObjectField(obj, midp_get_field_id(KNIPASSARGS classObj, pszFieldName,
        "Ljava/lang/String;"), fieldHandle);

    return midp_jstring_to_pcsl_string(fieldHandle, result);
}
Пример #11
0
/**
 * KNI function that creates new native resource for the current CustomItem.
 *
 * The native widget created by this function must take into account
 * label and body locations, using Item methods.
 * Also it must be able to grab key/pointer events directed to this 
 * item in order to pass them to java through the event queue.
 * The implementation should create a native offline buffer to be used
 * as the target for draw operation os the CustomItem, and as a source for
 * screen refresh in case a repaint is requested from the operating system.
 *
 * Class: javax.microedition.lcdui.CustomItemLFImpl
 * Java prototype:
 * private native int createNativeResource0(int ownerId, String label, 
 *                                          int layout)
 *
 * INTERFACE (operand stack manipulation):
 *   parameters:  ownerId            pointer to the owner's native resource
 *                label              CustomItem's label
 *                layout             CustomItem's layout
 *   return pointer to the created native resource
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_CustomItemLFImpl_createNativeResource0() {
    MidpError err = KNI_OK;
    MidpItem *ciPtr = NULL;
    pcsl_string label;
    pcsl_string_status rc;
    MidpDisplayable *ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
    int layout = KNI_GetParameterAsInt(3);

    KNI_StartHandles(1);
    KNI_DeclareHandle(labelHandle);

    KNI_GetParameterAsObject(2, labelHandle);

    rc = midp_jstring_to_pcsl_string(labelHandle, &label);

    KNI_EndHandles();

    if (PCSL_STRING_OK != rc) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    ciPtr = MidpNewItem(ownerPtr, MIDP_CUSTOM_ITEM_TYPE);
    if (ciPtr == NULL) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    err = lfpport_customitem_create(ciPtr, ownerPtr, &label, layout);

cleanup:
    pcsl_string_free(&label);

    if (err != KNI_OK) {
        MidpDeleteItem(ciPtr);
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_ReturnInt(ciPtr);
}
/**
 * KNI function that sets new content on the native resource corresponding to
 * the current ImageItem.
 *
 * Class: javax.microedition.lcdui.ImageItemLFImpl
 * Java prototype:
 * private native int setContent0(int nativeId, Image image, altText, 
 *                                appearanceMode)
 *
 * INTERFACE (operand stack manipulation):
 *   parameters:  nativeId   pointer to a native resource of this ImageItem
 *                image     the new image set in the ImageItem
 *                altText   the new altText set in the ImageItem
 *                appearanceMode the actual appearance mode to be used
 *   returns:     <nothing>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ImageItemLFImpl_setContent0() {
  MidpError err = KNI_OK;
  unsigned char* imgPtr = NULL;
  pcsl_string altText;
  pcsl_string_status rc;
  MidpItem *itemPtr = (MidpItem *)KNI_GetParameterAsInt(1);
  int appearanceMode = KNI_GetParameterAsInt(4);

  KNI_StartHandles(2);
  KNI_DeclareHandle(image);
  KNI_DeclareHandle(altTextJString);

  KNI_GetParameterAsObject(2, image);
  
  if (KNI_IsNullHandle(image) != KNI_TRUE) {
    imgPtr = gxp_get_imagedata(image);
  }
  
  KNI_GetParameterAsObject(3, altTextJString);

  rc = midp_jstring_to_pcsl_string(altTextJString, &altText);

  KNI_EndHandles();

  /* NULL and empty strings are acceptable. */
  if (PCSL_STRING_OK != rc) {
    err = KNI_ENOMEM;
  } else {
    err = lfpport_imageitem_set_content(itemPtr, imgPtr, &altText,
				        appearanceMode);
  }

  pcsl_string_free(&altText);
  
  if (err == KNI_ENOMEM) {
    KNI_ThrowNew(midpOutOfMemoryError, NULL);
  }

  KNI_ReturnVoid();
}
Пример #13
0
/**
 * java call:
 * private native int launch0(String handlerId);
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_content_RegistryStore_launch0(void) {
    pcsl_string id = PCSL_STRING_NULL_INITIALIZER;
    jsr211_launch_result result;

    KNI_StartHandles(1);
    KNI_DeclareHandle(idStr);           /* handlerId */

    KNI_GetParameterAsObject(1, idStr); /* handlerId */
    if (PCSL_STRING_OK == midp_jstring_to_pcsl_string(idStr, &id)) {
        result = jsr211_execute_handler(&id);
    } else {
        KNI_ThrowNew(midpOutOfMemoryError, 
                   "RegistryStore_launch0 no memory for handler ID");
        result = JSR211_LAUNCH_ERROR;
    }

    pcsl_string_free(&id);
    KNI_EndHandles();    
    KNI_ReturnInt(result);
}
Пример #14
0
/**
 * KNI function that inserts new element with passed in string and image 
 *  into the native resource corresponding to the current ChoiceGroup.
 *
 * Java declaration:
 * <pre>
 *     insert0(IISOB)V
 * </pre>
 * @param nativeId - id of the native resource corresponding to the current
 *                   ChoiceGroup
 * @param elementNum - location at which new element should be inserted
 * @param stringPart - string part of the element to be inserted
 * @param imagePart - image part of the element to be inserted
 * @param selected  - current selection state of the inserted element
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_lcdui_ChoiceGroupLFImpl_insert0() {
  MidpError err = KNI_OK;
  MidpItem *cgPtr = (MidpItem *)KNI_GetParameterAsInt(1);
  MidpChoiceGroupElement cgElement;
  pcsl_string_status perr;
  int elementNum = KNI_GetParameterAsInt(2);
  

  KNI_StartHandles(2);
  KNI_DeclareHandle(stringPartJString);
  KNI_DeclareHandle(imgPartJImage);
  
  KNI_GetParameterAsObject(3, stringPartJString);
  KNI_GetParameterAsObject(4, imgPartJImage);

  if (KNI_IsNullHandle(imgPartJImage) == KNI_TRUE) {
    cgElement.image = NULL;
  } else {
    cgElement.image = gxp_get_imagedata(imgPartJImage);
  }

  perr = midp_jstring_to_pcsl_string(stringPartJString, &cgElement.string);
  cgElement.selected = KNI_GetParameterAsBoolean(5);
  cgElement.font = NULL;

  KNI_EndHandles();

  if (PCSL_STRING_OK == perr) {
    err = lfpport_choicegroup_insert(cgPtr, elementNum, cgElement);
  }
  
  pcsl_string_free(&cgElement.string);
  
  if (err == KNI_ENOMEM) {
    KNI_ThrowNew(midpOutOfMemoryError, NULL);
  }
  
  KNI_ReturnVoid();
}
Пример #15
0
/**
 * java call:
 *     private native String loadFieldValues0(String handlerId, int fieldId);
 */
KNIEXPORT KNI_RETURNTYPE_OBJECT
Java_com_sun_midp_content_RegistryStore_loadFieldValues0(void) {
    int fieldId;
    pcsl_string id = PCSL_STRING_NULL_INITIALIZER;
    JSR211_RESULT_STRARRAY result = _JSR211_RESULT_INITIALIZER_;

    KNI_StartHandles(1);
    KNI_DeclareHandle(strObj);       /* string object */

    KNI_GetParameterAsObject(1, strObj); /* handlerId */
    if (PCSL_STRING_OK == midp_jstring_to_pcsl_string(strObj, &id)) {
        fieldId = KNI_GetParameterAsInt(2);
        jsr211_get_handler_field(&id, fieldId, &result);
        pcsl_string_free(&id);
        result2string((_JSR211_INTERNAL_RESULT_BUFFER_*)&result, strObj);
    } else {
        KNI_ThrowNew(midpOutOfMemoryError, 
                   "RegistryStore_loadFieldValues0 no memory for handler ID");
        KNI_ReleaseHandle(strObj);
    }

    KNI_EndHandlesAndReturnObject(strObj);
}
Пример #16
0
/**
 * 
 * Listens for  an InvocationImpl from the store using a MIDlet suiteId
 * and optional, and status. Each Invocation must be returned only
 * once.  When an Invocation is returned; it is marked as being
 * notified.
 *
 * @param suiteId to match a pending invocation
 * @param classname to match a pending invocation
 * @param mode one of {@link #MODE_REQUEST}, {@link #MODE_RESPONSE},
 *    or {@link #MODE_CLEANUP}
 * @param blocking true to block until a matching invocation is available
 * @return true if an Invocation is found with 
 *  the same MIDlet suiteId and classname; false is returne dotherwise
 */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
Java_com_sun_midp_content_InvocationStore_listen0(void) {
    StoredLink* match = NULL;
    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;

    KNI_StartHandles(1);
    KNI_DeclareHandle(classname); /* Arg2: non-null classname */
    int mode;                  /* Arg3: requested invocation mode */
    jboolean blocking = KNI_FALSE; /* Arg4: true if should block */

    /* Argument indices must match Java native method declaration */
#define listenSuiteIdArg 1
#define listenClassnameArg 2
#define listenModeArg 3
#define listenBlockingArg 4

    do {/* Block to break out of on exceptions */
        /* Check if blocked invocation was cancelled. */
        if (isThreadCancelled()) {
            /* blocking is always false to cleanup and exit immediately */
            break;
        }
    
        /* Get the desired blocking mode. */
        blocking = KNI_GetParameterAsBoolean(listenBlockingArg);
    
        if (!isEmpty()) {
            /* Queue is not empty
             * Need a string copy of the desired suiteID and classname
             * to use for comparisons
             */
            desiredSuiteId = KNI_GetParameterAsInt(listenSuiteIdArg);
    
                KNI_GetParameterAsObject(listenClassnameArg, classname);
            if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, 
                               &desiredClassname)) {
                KNI_ThrowNew(midpOutOfMemoryError, 
                    "InvocationStore_listen0 no memory for [desiredClassname]");
                break;
            }

            /* Get the desired request mode. */
            mode = KNI_GetParameterAsInt(listenModeArg);
            match = invocFind(desiredSuiteId, &desiredClassname, mode);
        }
    } while (KNI_FALSE);

    /* Always free strings allocated */
    pcsl_string_free(&desiredClassname);

    if (match != NULL) {
        match->invoc->notified = KNI_TRUE;
    } else {
        if (blocking) {
            /* No found; block the thread in the VM */
            blockThread();
            /* Fall into the return to manage handles correctly */
        }
    }

    KNI_EndHandles();
    KNI_ReturnBoolean(match != NULL);
}
Пример #17
0
/**
 * 
 * Gets an InvocationImpl from the store using a MIDlet suiteId
 * and optional classname.
 * Getting an Invocation from the store removes it from the store.
 * If an OutOfMemory exception is thrown the matched Invocation
 * is NOT removed from the queue. If the heap memory can be
 * replenished then the operation can be retried.
 *
 * @param invoc an Invocation Object to fill in
 * @param suiteId to match a pending invocation
 * @param classname to match a pending invocation
 * @param mode one of {@link #MODE_REQUEST}, {@link #MODE_RESPONSE},
 *    or {@link #MODE_CLEANUP}
 * @param blocking true to block until a matching invocation is available
 * @return 1 if a matching invocation was found and returned 
 *    in its entirety; zero if there was no matching invocation;
 *    -1 if the sizes of the arguments or parameter array were wrong
 * @see StoredInvoc
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_content_InvocationStore_get0(void) {
    int ret = 0;          /* return value = nothing matched */
    KNI_StartHandles(4);
    KNI_DeclareHandle(obj);      /* multipurpose handle */
    KNI_DeclareHandle(argsObj);      /* handle for argument array */
    KNI_DeclareHandle(invocObj);  /* Arg1: Invocation object; non-null */
    KNI_DeclareHandle(classname); /* Arg3: non-null classname */
    int mode = MODE_REQUEST;      /* Arg4: mode for get */
    jboolean blocking = KNI_FALSE; /* Arg5: true if should block */

    /* Argument indices must match Java native method declaration */
#define getInvokeObjArg 1
#define getSuiteIdArg 2
#define getClassnameArg 3
#define getModeArg 4
#define getBlockingArg 5

    StoredLink* match = NULL;

    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;

    do {/* Block to break out of on exceptions */
        /* Check if blocked invocation was cancelled. */
        if (isThreadCancelled()) {
            /* blocking is always false to cleanup and exit immediately */
            break;
        }
    
        /* Get the desired blocking mode. */
        blocking = KNI_GetParameterAsBoolean(getBlockingArg);
    
        if (!isEmpty()) {
            /* Queue is not empty, get InvocationImpl obj and init. */
            KNI_GetParameterAsObject(getInvokeObjArg, invocObj);
            init(invocObj, obj);
    
            /* Get the desired type of invocation. */
            mode = KNI_GetParameterAsInt(getModeArg);
            if (mode == MODE_TID || 
                mode == MODE_TID_NEXT ||
                mode == MODE_TID_PREV) {
                int tid = KNI_GetIntField(invocObj, tidFid);
                if (tid != 0) {
                    match = invocFindTid(tid);
                } else {
                    /* start with the root */
                    match = invocQueue;
                }
                if (match != NULL) {
                    /* Link to the next or previous depending on the mode. */
                    if (mode == MODE_TID_NEXT) {
                        match = match->flink;
                    } else if (mode == MODE_TID_PREV) {
                        match = match->blink;
                    }
                }
            } else {
                desiredSuiteId = KNI_GetParameterAsInt(getSuiteIdArg);
                KNI_GetParameterAsObject(getClassnameArg, classname);
                if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, 
                                        &desiredClassname)) {
                    KNI_ThrowNew(midpOutOfMemoryError, 
                       "InvocationStore_get0 no memory for [desiredClassname]");
                    break;
                }
                match = invocFind(desiredSuiteId, &desiredClassname, mode);
            }
        }
    } while (KNI_FALSE);

    /* Always free strings allocated */
    pcsl_string_free(&desiredClassname);

    if (match != NULL) {
        StoredInvoc *invoc = match->invoc;
        int st = copyOut(invoc, mode, invocObj, argsObj, obj);
        switch (st) {
        case 1:
            /* If a match was found and successfully copied;
             * do final set of actions on the Invocation selected.
             */
            switch (mode) {
            case MODE_REQUEST:
                if (invoc->status == STATUS_INIT) {
                    /* 
                     * Returning new request, change status to ACTIVE
                     * Keep this entry in the queue.
                     */
                    invoc->status = STATUS_ACTIVE;
                    KNI_SetIntField(invocObj, statusFid, invoc->status);
                }
                break;
            case MODE_RESPONSE:
                if (invoc->status >= STATUS_OK &&
                    invoc->status <= STATUS_INITIATED) {
                    /*
                     * Remove responses from the list and free.
                     */
                    removeEntry(match);
                    invocFree(invoc);
                }
                break;
            case MODE_LREQUEST:
            case MODE_LRESPONSE:
            case MODE_CLEANUP:
            case MODE_TID:
            case MODE_TID_NEXT:
            case MODE_TID_PREV:
            default:
                /* No additional action */
                break;
            }
            /* Returning an Invocation */
            ret = 1;
            break;
        case 0:
            /* Insufficient memory for strings. */
            KNI_ThrowNew(midpOutOfMemoryError, "invocStore returning strings");
            KNI_ReleaseHandle(invocObj);
            ret = 0;
            break;
        case -1:
            /* Either args array or data array is incorrect size. */
            ret = -1;
        }
    } else {
        /* No match found. */
        /* If blocking, setup to block. */
        if (blocking) {
            blockThread();
            /* Fall into the return to manage handles correctly */
        }
        ret = 0;
    }
    KNI_EndHandles();
    KNI_ReturnInt(ret);
}
Пример #18
0
/**
 * Extract the parameters ID, Type, URL, arguments and data
 * and update/copy their values to the InvocStore instance.
 * @param invoc the StoreInvoc to update
 * @param invocObj the Java invoc instance
 * @param tmp1 a temporary object
 * @param tmp2 a 2nd temporary object 
 * @return TRUE if all the allocations and modifications worked
 */
static jboolean setParamsFromObj(StoredInvoc* invoc,
                     jobject invocObj,
                     jobject tmp1, jobject tmp2) {
    jboolean ret = KNI_ENOMEM;    /* Assume failure */
    do {
        /* On any error break out of this block */
        int len;
    
        KNI_GetObjectField(invocObj, urlFid, tmp1);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->url))
            break;
    
        KNI_GetObjectField(invocObj, typeFid, tmp1);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->type ))
            break;
    
        KNI_GetObjectField(invocObj, actionFid, tmp1);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->action ))
            break;
    
        KNI_GetObjectField(invocObj, IDFid, tmp1);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, &invoc->ID))
            break;
    
        /*
         * Copy the arguments if non-empty.
         * Always keep the pointers safe so invocFree()
         * can function correctly.
         */
        KNI_GetObjectField(invocObj, argumentsFid, tmp2);
        len = (KNI_IsNullHandle(tmp2)? 0: KNI_GetArrayLength(tmp2));
        if (len <= 0) {
            invoc->argsLen = 0;
            invoc->args = NULL;
        } else {
            pcsl_string* args;
            args = (pcsl_string*)pcsl_mem_malloc(len * sizeof(pcsl_string));
            if (args == NULL)
                break;
            invoc->argsLen = len;
            invoc->args = args;
            args += len;
            while (len-- > 0) {
                KNI_GetObjectArrayElement(tmp2, len, tmp1);
                if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(tmp1, --args))
                    break;
            }
        }
    
        /* Copy any data from the Invocation to malloc's memory. */
        KNI_GetObjectField(invocObj, dataFid, tmp2);
        len = (KNI_IsNullHandle(tmp2)? 0: KNI_GetArrayLength(tmp2));
        if (len <= 0) {
            invoc->data = NULL;
            invoc->dataLen = 0;
        } else {
            invoc->data = pcsl_mem_malloc(len);
            if (invoc->data == NULL)
                break;
    
            KNI_GetRawArrayRegion(tmp2, 0, len, invoc->data);
            invoc->dataLen = len;
        }
    
        /* Clear to indicate everything worked. */
        ret = KNI_TRUE;
    } while (0);

    return ret;
}
Пример #19
0
/**
 * KNI function that create native resource for current DateField.
 *
 * The native widget created by this function must take into account
 * label and body locations, using Item methods.
 * The implementation must create a native date/time widget that can be
 * displayed as date only, time only, or date/time modes.
 *
 * The displayMode is a two bit mask in which the MSB is the date, and the
 * LSB (ie. binary 10 is date only, 01 is time only, 11 is both).
 *
 * As the datetime parameter coming from java is in milliseconds since the
 * epoch 00:00 1/1/1970, it is needed to translate this value to the native
 * date/time representation. (for example, QT uses the same epoch, but in
 * resolution of seconds rather than milliseconds).
 *
 *
 * Class: javax.microedition.lcdui.DateFieldLFImpl
 * Java prototype:
 * 	private native int createNativeResource0 ( int ownerId , 
 * 	String label , int layout, long datetime , int displayMode,
 *	String timeZone);
 * @param datetime in milliseconds since 00:00 1/1/1970
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_DateFieldLFImpl_createNativeResource0() {

    MidpDisplayable *ownerPtr;
    pcsl_string label;
    pcsl_string timezone;
    pcsl_string_status rc1, rc2;
    jint layout;
    jint displayMode;
    jlong datetime;

    long qtime = 0;

    MidpError err = KNI_OK;
    MidpItem *dfPtr = NULL;

    KNI_StartHandles(2);
    KNI_DeclareHandle(labelHandle);
    KNI_DeclareHandle(timezoneHandle);

    ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, labelHandle);
    layout = KNI_GetParameterAsInt(3);
    datetime = KNI_GetParameterAsLong(4); /* Long occupies two parameters */
    displayMode = KNI_GetParameterAsInt(6);
    KNI_GetParameterAsObject(7, timezoneHandle);

    rc1 = midp_jstring_to_pcsl_string(labelHandle, &label);
    rc2 = midp_jstring_to_pcsl_string(timezoneHandle, &timezone);
    
    KNI_EndHandles();

    /* NULL and empty strings are acceptable */
    if (PCSL_STRING_OK != rc1 || PCSL_STRING_OK != rc2) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    dfPtr = MidpNewItem(ownerPtr, MIDP_DATE_FIELD_TYPE);
    if (dfPtr == NULL) {
        err = KNI_ENOMEM;
        goto cleanup;
    }

    qtime = (long)(datetime/1000); /* qt date works in seconds */

    err = lfpport_datefield_create(dfPtr, ownerPtr, &label, layout,
				   displayMode, qtime, &timezone);

cleanup:

    pcsl_string_free(&label);
    pcsl_string_free(&timezone);

    if (err != KNI_OK) {
        MidpDeleteItem(dfPtr);
        KNI_ThrowNew(midpOutOfMemoryError, NULL);
    }

    KNI_ReturnInt(dfPtr);

}
Пример #20
0
/**
 * 
 * Resets the request or response flags for listener notification.
 * Each request or response is marked as not having been notified.
 *
 * @param suiteId to match a pending invocation
 * @param classname to match a pending invocation
 * @param mode one of {@link #MODE_LREQUEST}, {@link #MODE_LRESPONSE}
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_setListenNotify0(void) {
    StoredLink* link;
    StoredInvoc* invoc;
    SuiteIdType desiredSuiteId;
    pcsl_string desiredClassname = PCSL_STRING_NULL_INITIALIZER;

    KNI_StartHandles(2);
    KNI_DeclareHandle(classname); /* Arg2: non-null classname */
    int mode;                  /* Arg3: requested invocation mode */

    /* Argument indices must match Java native method declaration */
#define listenSuiteIdArg 1
#define listenClassnameArg 2
#define listenModeArg 3

    do {/* Block to break out of on exceptions */
        if (!isEmpty()) {
            /* Queue is not empty
             * Need a string copy of the desired suiteId and classname
             * to use for comparisons
             */
            desiredSuiteId = KNI_GetParameterAsInt(listenSuiteIdArg);
    
            KNI_GetParameterAsObject(listenClassnameArg, classname);
            if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(classname, 
                               &desiredClassname)) {
                KNI_ThrowNew(midpOutOfMemoryError, 
                "InvocationStore_setListenNotify0 no memory for [desiredClassname]");
                break;
            }
    
            /* Get the desired request mode. */
            mode = KNI_GetParameterAsInt(listenModeArg);
    
            /* Inspect the queue of Invocations and pick one that
             * matches the suiteId and classname
             */
            for (link = invocQueue; link != NULL; link = link->flink) {
                invoc = link->invoc;
                /*
                 * If the status matches the request
                 * and the suite matches and the classname matches.
                 */
                if (mode == MODE_LREQUEST &&
                    invoc->status == STATUS_INIT) {
                       /* This invocation is a match; check classname and suite below */
                } else if (mode == MODE_LRESPONSE &&
                       (invoc->status >= STATUS_OK &&
                        invoc->status <= STATUS_INITIATED)) {
                    /* A pending response; check classname and suite below */
                } else {
                    /* Not this invocation; on to the next */
                    continue;
                }
                /* Check if this is the right class and suite */
                if (desiredSuiteId == invoc->suiteId &&
                    pcsl_string_equals(&desiredClassname, &invoc->classname)) {
                    /* Reset the flag so this Invocation will notify. */
                    invoc->notified = KNI_FALSE;
                }
            }
        }
    } while (KNI_FALSE);

    /* TBD: MidpMalloc failure not reported; not found is returned */

    /* Always free strings allocated */
    pcsl_string_free(&desiredClassname);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Пример #21
0
/**
 * KNI function that creates native resource for the current StringItem.
 * <p>
 * Java declaration:
 * <pre>
 *     createNativeResource0(ISIII[OII)I
 * </pre>
 *
 * @param ownerId Owner screen's native resource id (MidpDisplayable *)
 * @param label - label to be used for this ChoiceGroup
 * @param layout layout directive associated with this ChoiceGroup
 * @param choiceType - should be EXCLUSIVE, MULTIPLE, IMPLICIT, POPUP
 * @param fitPolicy  - to be used to display created ChoiceGroup
 * @param cgElements - elements array with string, image, font, selected state
 *                     information per element
 * @param numChoices - number of elements in the ChoiceGroup
 * @param selectedIndex - currently selected index (for EXCLUSIVE, IMPLICIT, and
 *                        POPUP)
 * @return native resource id (MidpItem *) of this StringItem
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_lcdui_ChoiceGroupLFImpl_createNativeResource0() {
  MidpError err = KNI_OK;
  MidpDisplayable  *ownerPtr = NULL;
  MidpItem *cgPtr = NULL;
  pcsl_string label_str;
  MidpChoiceGroupElement *cgChoices = NULL;
  int choiceType, layout;
  int fitPolicy;
  int numChoices = 0;
  int selectedIndex;
  int i = 0;
  pcsl_string_status perr;

  ownerPtr = (MidpDisplayable *)KNI_GetParameterAsInt(1);
  layout = KNI_GetParameterAsInt(3);
  choiceType = KNI_GetParameterAsInt(4);
  fitPolicy  = KNI_GetParameterAsInt(5);
  numChoices = KNI_GetParameterAsInt(7);
  selectedIndex  = KNI_GetParameterAsInt(8);

  KNI_StartHandles(8);
  
  KNI_DeclareHandle(labelJString);
  KNI_DeclareHandle(cgElementsJObject);
  KNI_DeclareHandle(cgElement);
  KNI_DeclareHandle(strJString);
  KNI_DeclareHandle(imgJImage);
  KNI_DeclareHandle(fontJFont);
  KNI_DeclareHandle(cgElementHandle);
  KNI_DeclareHandle(fontHandle);

  KNI_GetParameterAsObject(2, labelJString);
  KNI_GetParameterAsObject(6, cgElementsJObject);
 
  if (numChoices > 0) {
    jobjectArray cgElementsArray;
    KNI_FindClass("javax/microedition/lcdui/ChoiceGroup$CGElement", 
		  cgElementHandle);

    KNI_FindClass("javax/microedition/lcdui/Font", fontHandle);
	  
    cgElementsArray = (jobjectArray)cgElementsJObject;

    cgChoices = (MidpChoiceGroupElement *)
		midpMalloc(sizeof(MidpChoiceGroupElement) * numChoices);
    if (cgChoices == NULL) {
      err = KNI_ENOMEM;
    }

    for (i = 0; err == KNI_OK && i < numChoices; i++) {

      KNI_GetObjectArrayElement(cgElementsArray, i, cgElement);

      KNI_GetObjectField(cgElement, 
			 _CACHE_FIELDID(cgElementHandle, "stringEl", 
					"Ljava/lang/String;", 
					_cgEl_stringEl_cache), strJString);

      perr = midp_jstring_to_pcsl_string(strJString, &cgChoices[i].string);
      if (PCSL_STRING_OK != perr) {
        err = KNI_ENOMEM;
      } else {

	KNI_GetObjectField(cgElement, 
			   _CACHE_FIELDID(cgElementHandle, "imageDataEl", 
					  "Ljavax/microedition/lcdui/ImageData;", 
					  _cgEl_imageDataEl_cache), imgJImage);

	if (KNI_IsNullHandle(imgJImage) == KNI_TRUE) {
	  cgChoices[i].image = NULL;
	} else {
	  cgChoices[i].image = gxp_get_imagedata(imgJImage);
	}

	cgChoices[i].selected = 
	  KNI_GetBooleanField(cgElement, _CACHE_FIELDID(cgElementHandle, 
							"selected", "Z",
							_cgEl_selected_cache));
	
	KNI_GetObjectField(cgElement,
			   _CACHE_FIELDID(cgElementHandle, "fontEl",
					  "Ljavax/microedition/lcdui/Font;", 
					  _cgEl_font_cache), fontJFont); 
	
	if (KNI_IsNullHandle(fontJFont) == KNI_TRUE) {
	  cgChoices[i].font = NULL;
	} else {
	  
	  int face, style, size; /* usually only few fonts are set */

	  face = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "face", 
                             "I", _f_face_cache));
	  style = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, 
                             "style",
                             "I", _f_style_cache));
      size = KNI_GetIntField(fontJFont, _CACHE_FIELDID(fontHandle, "size",
                             "I", _f_size_cache));

            if ((err = lfpport_get_font(&(cgChoices[i].font), face, style, size))
                != KNI_OK) {
                  err = KNI_ENOMEM;
                  i++;
                  break;
            }
        }
      }
    }
  }
 
  if (err == KNI_OK) {
    if(PCSL_STRING_OK
        != midp_jstring_to_pcsl_string(labelJString, &label_str)) {
      err = KNI_ENOMEM;
    }
  }

  KNI_EndHandles();

  if (err == KNI_OK) {
    cgPtr = MidpNewItem(ownerPtr, 
			MIDP_EXCLUSIVE_CHOICE_GROUP_TYPE + choiceType - 1);
    
    if (cgPtr == NULL) {
      err = KNI_ENOMEM;
    } else {
      err = lfpport_choicegroup_create(cgPtr, ownerPtr, &label_str, layout,
				    choiceType, cgChoices, numChoices,
				    selectedIndex, fitPolicy);
    }
  }

  // do clean up
  pcsl_string_free(&label_str);
  for (i--; i >= 0; i--) {
    pcsl_string_free(&cgChoices[i].string);
  }
  midpFree(cgChoices);
  
  if (err != KNI_OK) {
    MidpDeleteItem(cgPtr);
    KNI_ThrowNew(midpOutOfMemoryError, NULL);
  }

  KNI_ReturnInt(cgPtr);
}
Пример #22
0
/**
 * Fills <code>JSR211_content_handler</code> structure with data from 
 * <code>ContentHandlerImpl</code> object.
 * <BR>Fields <code>ID, storageId</code> and <code>classname</code>
 * are mandatory. They must have not 0 length.
 *
 * @param o <code>ContentHandlerImpl</code> object
 * @param handler pointer on <code>JSR211_content_handler</code> structure
 * to be filled up
 * @return KNI_OK - if successfully get all fields, 
 * KNI_ERR or KNI_ENOMEM - otherwise
 */
static int fillHandlerData(jobject o, JSR211_content_handler* handler) {
    int ret;    // returned result code
    KNI_StartHandles(1);
    KNI_DeclareHandle(fldObj);   // field object

    do {
        // ID
        KNI_GetObjectField(o, chImplId, fldObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(fldObj, &(handler->id))) {
            ret = KNI_ENOMEM;
            break;
        }
        // check mandatory field
        if (pcsl_string_length(&(handler->id)) <= 0) {
            ret = KNI_ERR;
            break;
        }

        // suiteId
        handler->suite_id = KNI_GetIntField(o, chImplSuiteId);

        // classname
        KNI_GetObjectField(o, chImplClassname, fldObj);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(fldObj, &(handler->class_name))) {
            ret = KNI_ENOMEM;
            break;
        }

        // flag
        handler->flag = KNI_GetIntField(o, chImplregMethod);

        // types
        KNI_GetObjectField(o, chImplTypes, fldObj);
        handler->type_num = getStringArray(fldObj, &(handler->types));
        if (handler->type_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // suffixes        
        KNI_GetObjectField(o, chImplSuffixes, fldObj);
        handler->suff_num = getStringArray(fldObj, &(handler->suffixes));
        if (handler->suff_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // actions
        KNI_GetObjectField(o, chImplActions, fldObj);
        handler->act_num = getStringArray(fldObj, &(handler->actions));
        if (handler->act_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        // action names
        if (handler->act_num > 0) {
            KNI_GetObjectField(o, chImplActionnames, fldObj);
            ret = fillActionMap(fldObj, handler);
            if (KNI_OK != ret) {
                break;
            }
        }

        // accesses
        KNI_GetObjectField(o, chImplAccesses, fldObj);
        handler->access_num = getStringArray(fldObj, &(handler->accesses));
        if (handler->access_num < 0) {
            ret = KNI_ENOMEM;
            break;
        }

        ret = KNI_OK;
    } while (0);

    KNI_EndHandles();
    return ret;
}
Пример #23
0
/**
 * Implementation of native method to queue a new Invocation.
 * The state of the InvocationImpl is copied to the heap
 * and inserted in the head of the invocation queue.
 * An StoredInvoc struct is allocated on the native heap and 
 * the non-null strings for each field of the InvocationImpl class
 * are copied to the heap.
 * A new transaction ID is assigned to this Invocation
 * and returned in the tid field of the InvocationImpl.
 * @param invoc the InvocationImpl to store
 * @throws OutOfMemoryError if the memory allocation fails
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_put0(void) {
    StoredInvoc* invoc = NULL;

    KNI_StartHandles(4);
    KNI_DeclareHandle(invocObj);
    KNI_DeclareHandle(classObj);
    KNI_DeclareHandle(argsObj);
    KNI_DeclareHandle(str);

    KNI_GetParameterAsObject(1, invocObj);
    init(invocObj, classObj);

    do {
        /* On any error break out of this block */
        /* Allocate a new zero'ed struct to save the values in */
        invoc = (StoredInvoc*) pcsl_mem_calloc(1, sizeof (StoredInvoc));
        if (invoc == NULL) {
            KNI_ThrowNew(midpOutOfMemoryError, 
                                "InvocationStore_put0 no memory for [invoc]");
            break;
        }
    
        /* Assign a new transaction id and set it */
        invoc->tid = invocNextTid();
        KNI_SetIntField(invocObj, tidFid, invoc->tid);
    
        /*
         * Copy all the parameters to native
         * Includes ID, type,url, action, args, data
         */
        if (KNI_TRUE != setParamsFromObj(invoc, invocObj, str, argsObj))
            break;
    
        invoc->previousTid = KNI_GetIntField(invocObj, previousTidFid);
    
        invoc->status = KNI_GetIntField(invocObj, statusFid);
        invoc->responseRequired =
            KNI_GetBooleanField(invocObj, responseRequiredFid);
    
        invoc->suiteId = KNI_GetIntField(invocObj, suiteIdFid);
    
        KNI_GetObjectField(invocObj, classnameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->classname))
            break;
    
        KNI_GetObjectField(invocObj, invokingAuthorityFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingAuthority))
            break;
    
        KNI_GetObjectField(invocObj, invokingAppNameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingAppName))
            break;
    
        invoc->invokingSuiteId = KNI_GetIntField(invocObj, invokingSuiteIdFid);
    
        KNI_GetObjectField(invocObj, invokingClassnameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, 
                                                    &invoc->invokingClassname))
            break;
    
        KNI_GetObjectField(invocObj, invokingIDFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->invokingID))
            break;
    
        KNI_GetObjectField(invocObj, usernameFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->username))
            break;
    
        KNI_GetObjectField(invocObj, passwordFid, str);
        if (PCSL_STRING_OK != midp_jstring_to_pcsl_string(str, &invoc->password))
            break;
    
        /* Insert the new Invocation at the end of the queue */
        if (!invocPut(invoc))
            break;
    
        unblockWaitingThreads(STATUS_OK);
    
        /* Clear to skip cleanup and throwing exception */
        invoc = NULL;
    } while (0);

    if (invoc != NULL) {
        /* An allocation error occurred; free any remaining */
        invocFree(invoc);
        KNI_ThrowNew(midpOutOfMemoryError, "invocStore.c allocation failed");
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Пример #24
0
/**
 * Sort the given commands based upon the definition of 
 * COMMAND_SORT_ALL_TABLE.
 *
 * This is NOT a platform dependent function and do NOT need to be ported.
 * Override the definition of COMMAND_SORT_ALL_TABLE to control sorting order.
 *
 * @param  ItemCmdArray The Item Command Java array
 * @param  numItemCmds  The number of Item Commands
 * @param  DispCmdArray The Displayable Command Java array
 * @param  numDispCmds  The number of the Displayable Commands 
 *
 * @returns A sorted command array. Caller is responsible to 
 * 	    free the array after use. NULL if out of memory.
 */
MidpCommand* MidpCommandSortAll(jobject ItemCmdArray, int numItemCmds,
				jobject DispCmdArray, int numDispCmds) {
    int nc = numItemCmds + numDispCmds;
    /* Need to allocate an extra command for qsort. */
    MidpCommand *c = (MidpCommand*)midpMalloc((nc+1)*sizeof(MidpCommand));

    jobjectArray  itemCmds = (jobjectArray)ItemCmdArray;
    jobjectArray  cmds = (jobjectArray)DispCmdArray;

    int      j;

    if (c == NULL) {
        return NULL;
    }

    KNI_StartHandles(2);
    KNI_DeclareHandle(i);
    KNI_DeclareHandle(str);

    /*
     * We need to copy the string data (not just keep a
     * pointer to it) because if the garbage collector is allowed
     * to move the contents of the heap, the pointers will become
     * invalid.
     */
    for (j = 0; j < nc; ++j) {
        /* First fill c array with Item commands from ItemCmdArray;
         * then fill it with Displayable commands from DispCmdArray;
         * Later all these commands will be sorted together.
         */
        if (j < numItemCmds) {
            KNI_GetObjectArrayElement(itemCmds, j, i);
        } else {
            KNI_GetObjectArrayElement(cmds, j - numItemCmds, i);
        }

        str = hand((getMidpCommandPtr(i)->shortLabel));
        if(PCSL_STRING_OK
                != midp_jstring_to_pcsl_string(str, &c[j].shortLabel_str)) {
            break;
        }

        str = hand(getMidpCommandPtr(i)->longLabel);
        if(PCSL_STRING_OK
                != midp_jstring_to_pcsl_string(str, &c[j].longLabel_str)) {
            pcsl_string_free(&c[j].shortLabel_str);
            break;
        }
        c[j].priority  = (int)(getMidpCommandPtr(i)->priority);
        c[j].type  = (int)(getMidpCommandPtr(i)->commandType);
        c[j].id  = (int)(getMidpCommandPtr(i)->id);

    } /* end for (j=0; j<nc; ++j); */

    if (j < nc) {
        /* Whoops! We need to undo all previous allocs */
        for (j--; j >= 0; j--) {
            pcsl_string_free(&c[j].longLabel_str);
            pcsl_string_free(&c[j].shortLabel_str);
        }
        midpFree(c);
        c = NULL;
    } else if (nc > 1) {
	qsort(c, nc, sizeof(MidpCommand), compareForAll);
    }

    KNI_EndHandles();
    return c;
}