Example #1
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;
}
Example #2
0
/**
 * private static native void getLinks0(Link[] linkarray);
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_links_LinkPortal_getLinks0(void)
{
    int targetIsolate;
    jsize len;
    int i;
    KNI_StartHandles(2);
    KNI_DeclareHandle(linkArray);
    KNI_DeclareHandle(linkObj);

    targetIsolate = JVM_CurrentIsolateID();
    KNI_GetParameterAsObject(1, linkArray);
    len = KNI_GetArrayLength(linkArray);

    if (portals != NULL) {
        if (portals[targetIsolate].count > 0) {
            rendezvous **rpp = portals[targetIsolate].rppa;
            for (i = 0; i < len; i++) {
                KNI_GetObjectArrayElement(linkArray, i, linkObj);
                setNativePointer(linkObj, rpp[i]);
                rp_incref(rpp[i]);
            }
        }
        portal_free(&portals[targetIsolate]);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Example #3
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;
}
Example #4
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;
}
Example #5
0
/**
 * private static native void setLinks0(int isolateid, Link[] linkarray);
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_links_LinkPortal_setLinks0(void)
{
    int targetIsolate;
    int len;
    int i;
    int ok = 1;
    rendezvous *rp;
    rendezvous **newrppa = NULL;

    KNI_StartHandles(2);
    KNI_DeclareHandle(linkArray);
    KNI_DeclareHandle(linkObj);

    targetIsolate = KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, linkArray);

    if (KNI_IsNullHandle(linkArray)) {
        len = 0;
    } else {
        len = KNI_GetArrayLength(linkArray);
    }

    for (i = 0; i < len; i++) {
        KNI_GetObjectArrayElement(linkArray, i, linkObj);
        rp = getNativePointer(linkObj);
        if (rp == NULL || rp->state == CLOSED) {
            ok = 0;
            KNI_ThrowNew(midpIllegalArgumentException, NULL);
            break;
        }
    }

    if (ok && portals == NULL) {
        portals =
            (portal *)pcsl_mem_malloc(JVM_MaxIsolates() * sizeof(portal));
        if (portals == NULL) {
            ok = 0;
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
        } else {
            int i;
            for (i = 0; i < JVM_MaxIsolates(); i++) {
                portals[i].count = -1;
                portals[i].rppa = NULL;
            }
        }
    }

    if (ok && len > 0) {
        newrppa = (rendezvous **)pcsl_mem_malloc(len * sizeof(rendezvous *));
        if (newrppa == NULL) {
            KNI_ThrowNew(midpOutOfMemoryError, NULL);
            ok = 0;
        }
    }

    if (ok) {
        portal *pp = &portals[targetIsolate];

        portal_free(pp);

        /* at this point the portal's count is zero and rppa is null */

        if (len > 0) {
            for (i = 0; i < len; i++) {
                KNI_GetObjectArrayElement(linkArray, i, linkObj);
                rp = getNativePointer(linkObj);
                /* rp not null, checked above */
                newrppa[i] = rp;
                rp_incref(rp);
            }
            pp->count = len;
            pp->rppa = newrppa;
        } else if (KNI_IsNullHandle(linkArray)) {
            pp->count = -1;
            pp->rppa = NULL;
        } else {
            /* len == 0 */
            pp->count = 0;
            pp->rppa = NULL;
        }

        midp_thread_signal(LINK_PORTAL_SIGNAL, targetIsolate, 0);
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Example #6
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);
}
/**
 * Reads information about the installed midlet suite's components
 * from the storage.
 *
 * @param suiteId unique ID of the suite
 * @param ci array of ComponentInfo objects to fill with the information
 *           about the installed midlet suite's components
 *
 * @exception IOException if an the information cannot be read
 * @exception IllegalArgumentException if suiteId is invalid or ci is null
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_midletsuite_DynamicComponentStorage_getSuiteComponentsList) {
    SuiteIdType suiteId;
    int numberOfComponents = 0, arraySize;
    MidletSuiteData *pData = g_pSuitesData;

    KNI_StartHandles(4);
    KNI_DeclareHandle(components);
    KNI_DeclareHandle(componentObj);
    KNI_DeclareHandle(componentObjClass);
    KNI_DeclareHandle(tmpHandle);

    suiteId = KNI_GetParameterAsInt(1);
    KNI_GetParameterAsObject(2, components);

    arraySize = (int)KNI_GetArrayLength(components);

    do {
        if (arraySize <= 0) {
            break;
        }

        while (pData) {
            if (pData->suiteId == suiteId && pData->type == COMPONENT_DYNAMIC) {
                KNI_GetObjectArrayElement(components, (jint)numberOfComponents,
                                          componentObj);
                KNI_GetObjectClass(componentObj, componentObjClass);

                KNI_RESTORE_INT_FIELD(componentObj, componentObjClass,
                                      "componentId",
                                      (jint)pData->componentId);
                KNI_RESTORE_INT_FIELD(componentObj, componentObjClass,
                                      "suiteId",
                                      (jint)suiteId);
                KNI_RESTORE_BOOLEAN_FIELD(componentObj,
                                      componentObjClass,
                                      "trusted",
                                      pData->isTrusted);
                KNI_RESTORE_PCSL_STRING_FIELD(componentObj,
                                      componentObjClass,
                                      "displayName",
                                      &(pData->varSuiteData.displayName),
                                      tmpHandle);
                KNI_RESTORE_PCSL_STRING_FIELD(componentObj,
                                      componentObjClass,
                                      "version",
                                      &(pData->varSuiteData.suiteVersion),
                                      tmpHandle);

                numberOfComponents++;
                if (numberOfComponents == arraySize) {
                    /* IMPL_NOTE: log an error! */
                    break;
                }
            }

            pData = pData->nextEntry;
        }
    } while (0);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
/**
 * 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;
}