Beispiel #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;
}
Beispiel #2
0
static void sendControlStringField(KNIDECLARGS kjobject objectHandle,
                                   kjobject stringObj, jfieldID fieldID) {
    int len;
    jchar *data = NULL;
    (void) _arguments;
    (void) _p_mb;
    (void) _ee;

    KNI_GetObjectField(objectHandle, fieldID, stringObj);
    len = KNI_GetStringLength(stringObj);
    if (len > 0) {
        data = (jchar*)midpMalloc(len * sizeof(jchar));
        if (data == NULL) {
            len = 0; /* IMPL_NOTE: throw out of memory */
        } else {
            KNI_GetStringRegion(stringObj, 0, len, data);
        }
    }

    write(controlPipe[1], &len, sizeof(int));
    if (len > 0) {
        write(controlPipe[1], data, len * sizeof(jchar));
        midpFree(data);
    }
}
/**
 * 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);
}
/**
 * (Internal) Fill addressInfo Field.
 */
static jboolean fill_adressInfoField(jobject landmarkObj, jfieldID fieldID, 
                jobject stringObj,  javacall_location_addressinfo_fieldinfo *fieldInfo, 
                javacall_location_addressinfo_field addressInfoFieldId) {
    KNI_GetObjectField(landmarkObj, fieldID, stringObj);
    if (!KNI_IsNullHandle(stringObj)) {
        fieldInfo->fieldId = addressInfoFieldId;
        return jsr179_jstring_to_utf16(stringObj, fieldInfo->data, JAVACALL_LOCATION_MAX_ADDRESSINFO_FIELD);
    }
    return KNI_FALSE;
}
/**
 * Restore the state of the MIDlet suite loader.
 * <p>
 * Java declaration:
 * <pre>
 *   restoreCommandState(Lcom/sun/midp/CommandState;)V
 * </pre>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_main_CommandState_restoreCommandState) {
    KNI_StartHandles(5);
    KNI_DeclareHandle(runtimeInfo);
    KNI_DeclareHandle(commandState);
    KNI_DeclareHandle(clazz);
    KNI_DeclareHandle(rtiClazz);
    KNI_DeclareHandle(string);

    KNI_GetParameterAsObject(1, commandState);
    KNI_GetObjectClass(commandState, clazz);

    KNI_GetObjectField(commandState, midp_get_field_id(KNIPASSARGS clazz,
        "runtimeInfo", "Lcom/sun/midp/main/RuntimeInfo;"), runtimeInfo);
    KNI_GetObjectClass(runtimeInfo, rtiClazz);

    KNI_RESTORE_INT_FIELD(commandState, clazz, "status",
                          MidpCommandState.status);
    KNI_RESTORE_BOOLEAN_FIELD(commandState, clazz, "logoDisplayed",
                              MidpCommandState.logoDisplayed);
    KNI_RESTORE_PCSL_STRING_FIELD(commandState, clazz, "midletClassName",
                                  &MidpCommandState.midletClassName, string);
    KNI_RESTORE_INT_FIELD(commandState, clazz, "suiteId",
                          MidpCommandState.suiteId);
    KNI_RESTORE_INT_FIELD(commandState, clazz, "lastSuiteId",
                          MidpCommandState.lastSuiteId);
    KNI_RESTORE_INT_FIELD(commandState, clazz, "debugMode",
                          MidpCommandState.debugMode);

    KNI_RESTORE_INT_FIELD(runtimeInfo, rtiClazz, "memoryReserved",
                          MidpCommandState.runtimeInfo.memoryReserved);
    KNI_RESTORE_INT_FIELD(runtimeInfo, rtiClazz, "memoryTotal",
                          MidpCommandState.runtimeInfo.memoryTotal);
    KNI_RESTORE_INT_FIELD(runtimeInfo, rtiClazz, "priority",
                          MidpCommandState.runtimeInfo.priority);

    KNI_RESTORE_PCSL_STRING_FIELD(commandState, clazz, "lastMidletClassName",
                                  &MidpCommandState.lastMidletClassName,
                                  string);
    KNI_RESTORE_PCSL_STRING_FIELD(commandState, clazz, "lastArg0",
                                  &MidpCommandState.lastArg0, string);
    KNI_RESTORE_PCSL_STRING_FIELD(commandState, clazz, "lastArg1",
                                  &MidpCommandState.lastArg1, string);
    KNI_RESTORE_PCSL_STRING_FIELD(commandState, clazz, "arg0",
                                  &MidpCommandState.arg0, string);
    KNI_RESTORE_PCSL_STRING_FIELD(commandState, clazz, "arg1",
                                  &MidpCommandState.arg1, string);
    KNI_RESTORE_PCSL_STRING_FIELD(commandState, clazz, "arg2",
                                  &MidpCommandState.arg2, string);
    KNI_RESTORE_PCSL_STRING_FIELD(runtimeInfo, rtiClazz, "profileName",
                                  &MidpCommandState.profileName, string);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_pisces_NativeFinalizer_00024SurfaceNativeFinalizer_finalize() {
    KNI_StartHandles(2);
    KNI_DeclareHandle(objectHandle);
    KNI_DeclareHandle(guardedHandle);

    KNI_GetThisPointer(objectHandle);
    KNI_GetObjectField(objectHandle, fieldIds[FINALIZER_GUARDED_OBJ],
                       guardedHandle);

    surface_finalize(guardedHandle);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #7
0
static void
getContents(jobject linkMessageObj, jobject contentsObj)
{
    jfieldID contentsField;

    KNI_StartHandles(1);
    KNI_DeclareHandle(linkMessageClass);

    KNI_GetObjectClass(linkMessageObj, linkMessageClass);
    contentsField = KNI_GetFieldID(linkMessageClass, "contents",
        "Ljava/lang/Object;");
    KNI_GetObjectField(linkMessageObj, contentsField, contentsObj);

    KNI_EndHandles();
}
Beispiel #8
0
static void
surface_acquire(AbstractSurface* surface, jobject surfaceHandle) {
    KNI_StartHandles(1);
    KNI_DeclareHandle(dataHandle);

    KNI_GetObjectField(surfaceHandle, ((JavaSurface *) surface)->javaArrayFieldID, dataHandle);
    switch(((JavaSurface*)surface)->javaArrayFieldSize) {
        case sizeof(jint):
            surface->super.data = JavaIntArray(dataHandle)->elements;
            break;
        case sizeof(jshort):
            surface->super.data = JavaShortArray(dataHandle)->elements;
            break;
        case sizeof(jbyte):
            surface->super.data = JavaByteArray(dataHandle)->elements;
            break;
        default:
            //shouldn't happen        
            break;
    }
    KNI_EndHandles();
}
Beispiel #9
0
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_jsr82emul_EmulationPolling_getRequest() {
    static jfieldID bufID = 0;
    static jfieldID lengthID = 0;
    int len = emul_data.req_offset > 512? 512 : emul_data.req_offset;
    
    KNI_StartHandles(3);
    KNI_DeclareHandle(thisHandle);     
    KNI_DeclareHandle(classHandle);     
    KNI_DeclareHandle(bufHandle);     
    
    if (bufID == 0) {
        KNI_GetClassPointer(classHandle);
        bufID = KNI_GetFieldID(classHandle, "requestBuf", "[B");
        lengthID = KNI_GetFieldID(classHandle, "length", "I");
    }
    
    KNI_GetThisPointer(thisHandle);
    KNI_SetIntField(thisHandle, lengthID, (jint)len);
    
    if (emul_data.req_offset > 0) {
        LOG1("EmulationPolling_getRequest(): getting %d request bytes", 
            emul_data.req_offset);
        
        KNI_GetObjectField(thisHandle, bufID, bufHandle);          
        memcpy(JavaByteArray(bufHandle), emul_data.request, len);
        if (len < emul_data.req_offset) {
            emul_data.req_offset -= len;
            memmove(emul_data.request, &emul_data.request[len], 
                emul_data.req_offset);
        } else {
            emul_data.req_offset = 0;
        }
    }
    
    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #10
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;
}
Beispiel #11
0
/**
 * Copy a native Invocation to the supplied Invocation instance.
 * @param invoc the native InvocStore 
 * @param mode the mode of copyout
 * @param invocObj the Invocation object to copy to
 * @param argsObj an object to use to refer to the arguments array
 * @param obj a temporary object handle
 * @return 0 if there were problems allocating Java Strings;
 *    1 if all the copies succeeded;
 *    -1 if the Java Arrays allocated for args or data were insufficient
 */
static int copyOut(StoredInvoc *invoc, int mode, 
            jobject invocObj, jobject argsObj, jobject obj)
{
    int datalen = 0;
    int arraylen = 0;

    /* Set the required lengths for args and data arrays. */
    KNI_SetIntField(invocObj, argsLenFid, invoc->argsLen);
    KNI_SetIntField(invocObj, dataLenFid, invoc->dataLen);

    /* Check if size of argument array and data array are correct. */
    KNI_GetObjectField(invocObj, dataFid, obj);
    datalen = KNI_GetArrayLength(obj);
    if (datalen != invoc->dataLen) {
        /* Data array allocated by Java is not correct size. */
        return -1;
    }
    KNI_GetObjectField(invocObj, argumentsFid, obj);
    arraylen = KNI_GetArrayLength(obj);
    if (arraylen != invoc->argsLen) {
        /* Args array allocated by Java is not correct size. */
        return -1;
    }

    /* Copy out all the string fields. */
    if (!(storeField(&invoc->url, invocObj, urlFid, obj) &&
          storeField(&invoc->type, invocObj, typeFid, obj) &&
          storeField(&invoc->action, invocObj, actionFid, obj) &&
          storeField(&invoc->ID, invocObj, IDFid, obj) &&
          storeField(&invoc->invokingClassname, 
                 invocObj, invokingClassnameFid, obj) &&
          storeField(&invoc->invokingAuthority,
                 invocObj, invokingAuthorityFid, obj) &&
          storeField(&invoc->invokingAppName,
                 invocObj, invokingAppNameFid, obj) &&
          storeField(&invoc->invokingID,
                 invocObj, invokingIDFid, obj) &&
          storeField(&invoc->username,
                 invocObj, usernameFid, obj) &&
          storeField(&invoc->password,
                 invocObj, passwordFid, obj))) {
        /* Some String allocation failed. */
        return 0;
    }
    KNI_SetIntField(invocObj, invokingSuiteIdFid, invoc->invokingSuiteId);
    /* See if the suite and classname are needed. */
    if (mode == MODE_TID || 
        mode == MODE_TID_PREV ||
        mode == MODE_TID_NEXT) {
        if (!storeField(&invoc->classname, invocObj, classnameFid, obj)) {
            /* A string allocation failed. */
            return 0;
        }
            KNI_SetIntField(invocObj, suiteIdFid, invoc->suiteId);
    }

    /* Return the arguments if any; array length already checked. */
    if (invoc->argsLen > 0) {
        int ndx;
        pcsl_string* args;
    
        /* For each stored arg create a string and store in the array.
         * No stored arg is null.  If a string cannot be created
         * it is due to insufficient heap memory. 
         */
        KNI_GetObjectField(invocObj, argumentsFid, argsObj);
        args = invoc->args;
        for (ndx = 0; ndx < invoc->argsLen; ndx++, args++) {
            if (!pcsl_string_is_null(args)) {
                if (PCSL_STRING_OK != 
                        midp_jstring_from_pcsl_string(args, obj)) {
                    /* String create failed; exit now. */
                    return 0;
                }
            } else {
                KNI_ReleaseHandle(obj);
            }
            KNI_SetObjectArrayElement(argsObj, ndx, obj);
        }
    }

    /* Return the data array if any; array length was already checked. */
    if (invoc->dataLen > 0) {
        KNI_GetObjectField(invocObj, dataFid, obj);
        KNI_SetRawArrayRegion(obj, 0, invoc->dataLen, invoc->data);
    }

    KNI_SetBooleanField(invocObj, responseRequiredFid,
            invoc->responseRequired);
    KNI_SetIntField(invocObj, statusFid, invoc->status);
    KNI_SetIntField(invocObj, tidFid, invoc->tid);
    KNI_SetIntField(invocObj, previousTidFid, invoc->previousTid);
    /* Successful copy out. */
    return 1;
}
Beispiel #12
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);
}
/*
 * Accepts incoming client connection request.
 *
 * Note: the method gets native connection handle directly from
 * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object.
 *
 * Note: new native connection handle to work with accepted incoming
 * client connection is setted directly to <code>handle</code> field of
 * appropriate <code>RFCOMMConnectionImpl</code> object.
 *
 * @throws IOException if an I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_jsr082_bluetooth_btspp_BTSPPNotifierImpl_accept0(void) {
    javacall_handle handle = JAVACALL_BT_INVALID_HANDLE;
    javacall_handle peer_handle = JAVACALL_BT_INVALID_HANDLE;
    MidpReentryData* info;
    int status = JAVACALL_FAIL;
    int processStatus = KNI_FALSE;
    void *context = NULL;
    javacall_bt_address peer_addr;
    jfieldID notifHandleID = NULL;
    jfieldID peerHandleID  = NULL;
    jfieldID peerAddrID    = NULL;
    jfieldID pushHandleID  = NULL;

    KNI_StartHandles(3);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(arrayHandle);
    KNI_DeclareHandle(classHandle);
    KNI_GetClassPointer(classHandle);

    GET_FIELDID(classHandle, "handle", "I", notifHandleID)
    GET_FIELDID(classHandle, "peerHandle", "I", peerHandleID)
    GET_FIELDID(classHandle, "peerAddress", "[B", peerAddrID)
    GET_FIELDID(classHandle, "pushHandle", "I", pushHandleID)
    KNI_GetThisPointer(thisHandle);
    handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID);
    KNI_GetObjectField(thisHandle, peerAddrID, arrayHandle);

    if (handle == JAVACALL_BT_INVALID_HANDLE) {
        REPORT_ERROR(LC_PROTOCOL,
            "RFCOMM notifier was closed before btspp_notif::accept");
        KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG(
            "RFCOMM notifier was closed"));
    } else {
#ifndef NO_PUSH
        bt_pushid_t pushid = KNI_GetIntField(thisHandle, pushHandleID);
        if (pushid != BT_INVALID_PUSH_HANDLE) {
            if (bt_push_checkout_client(pushid, &peer_handle, peer_addr,
                    NULL, NULL) == JAVACALL_OK) {
                pushcheckoutaccept((int)handle);
                processStatus = KNI_TRUE;
                status = JAVACALL_OK;
            }
        }
#endif
        if (peer_handle == JAVACALL_BT_INVALID_HANDLE) {

        info = (MidpReentryData*)SNI_GetReentryData(NULL);
		if (info == NULL) {   /* First invocation */
            REPORT_INFO1(LC_PROTOCOL,
                "btspp_notif::accept handle=%d\n", handle);

            // Need revisit: add resource counting
            /*
             * An incoming socket connection counts against the client socket
             * resource limit.
             */
/*
            if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                const char* pMsg =
                    "Resource limit exceeded for BT client sockets";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
*/
//            } else {
                status = javacall_bt_rfcomm_accept(
                    handle, &peer_handle, &peer_addr);
				processStatus = KNI_TRUE;
//            }
		} else {  /* Reinvocation after unblocking the thread */
			if ((javacall_handle)info->descriptor != handle) {
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "btspp_notif::accept handles mismatched %d != %d\n",
                    handle, info->descriptor);
                REPORT_CRIT(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIllegalStateException, EXCEPTION_MSG(
                    "Internal error in btspp_notif::accept"));
            } else {
                // Need revisit: add resource counting
/*
                if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                    const char* pMsg =
                        "Resource limit exceeded for BT client sockets"
                    REPORT_INFO(LC_PROTOCOL, pMsg);
                    KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
                } else {
*/
                    context = info->pResult;
				    status = javacall_bt_rfcomm_accept(
                        handle, &peer_handle, &peer_addr);
					processStatus = KNI_TRUE;
//                }
            }
        }

        }

        if (processStatus) {
            REPORT_INFO1(LC_PROTOCOL,
                "btspp_notif::accept server handle=%d\n", handle);
            if (status == JAVACALL_OK) {

                // Need revisit: add resource counting
/*
                if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) {
                    REPORT_INFO(LC_PROTOCOL,
                        "btspp_notif: Resource limit update error");
                }
*/

                // store client native connection handle for temporary storing
                KNI_SetIntField(thisHandle, peerHandleID, (jint)peer_handle);

                // copy address to Java object field
                KNI_SetRawArrayRegion(arrayHandle, 0, JAVACALL_BT_ADDRESS_SIZE, (jbyte*) peer_addr);

                REPORT_INFO(LC_PROTOCOL,
                    "btspp_notif::accept incoming connection accepted!");
            } else if (status == JAVACALL_WOULD_BLOCK) {
                midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context);
            } else if (status == JAVACALL_FAIL) {
                char* pError;
                javacall_bt_rfcomm_get_error(handle, &pError);
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "IO error in btspp_notif::accept (%s)\n", pError);
                REPORT_INFO(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer));

            } else {
                char* pMsg = "Unknown error during btspp_notif::accept";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
            }
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
/**
 * (Internal) Fill landmark structure from the Landmark Object.
 */
static jboolean fill_landmark(jobject landmarkObj, javacall_landmarkstore_landmark *landmark, 
                                jobject stringObj) {
    /* Fill javacall_landmarkstore_landmark structure */
    /* landmark.name */
    KNI_GetObjectField(landmarkObj, landmarkImplFieldID.name, stringObj);
    if (!KNI_IsNullHandle(stringObj) && 
        KNI_GetStringLength(stringObj)<=JAVACALL_LANDMARKSTORE_MAX_LANDMARK_NAME) {
        if (JAVACALL_OK != 
                jsrop_jstring_to_utf16(stringObj, landmark->name, JAVACALL_LANDMARKSTORE_MAX_LANDMARK_NAME)) {
            return KNI_FALSE;
        }
    } else {
        return KNI_FALSE;
    }
    /* landmark.description */
    KNI_GetObjectField(landmarkObj, landmarkImplFieldID.description, stringObj);
    jsr179_jstring_to_utf16(stringObj, landmark->description, JAVACALL_LANDMARKSTORE_MAX_LANDMARK_DESCRIPTION);

    landmark->isValidCoordinate = KNI_GetBooleanField(landmarkObj, 
                                landmarkImplFieldID.isCoordinates);
    if (landmark->isValidCoordinate) {
        /* landmark.latitude */
        landmark->latitude = KNI_GetDoubleField(landmarkObj, 
                                    landmarkImplFieldID.latitude);
        /* landmark.longitude */
        landmark->longitude = KNI_GetDoubleField(landmarkObj, 
                                    landmarkImplFieldID.longitude);
        /* landmark.altitude */
        landmark->altitude = KNI_GetFloatField(landmarkObj, 
                                    landmarkImplFieldID.altitude);
        /* landmark.horizontalAccuracy */
        landmark->horizontalAccuracy = KNI_GetFloatField(landmarkObj, 
                                    landmarkImplFieldID.horizontalAccuracy);
        /* landmark.altitude */
        landmark->verticalAccuracy = KNI_GetFloatField(landmarkObj, 
                                    landmarkImplFieldID.verticalAccuracy);
    }

    /* AddressInfo */
    landmark->addressInfoFieldNumber = KNI_GetIntField(landmarkObj, 
            landmarkImplFieldID.numAddressInfoFields);
    if (landmark->addressInfoFieldNumber > 0) {
            jint counter = 0;
            /* AddressInfo_EXTENSION */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_EXTENSION,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_EXTENSION) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_STREET */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_STREET,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_STREET) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_POSTAL_CODE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_POSTAL_CODE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_POSTAL_CODE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_CITY */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_CITY,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_CITY) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_COUNTY */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_COUNTY,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_COUNTY) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_STATE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_STATE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_STATE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_COUNTRY */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_COUNTRY,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_COUNTRY) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_COUNTRY_CODE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_COUNTRY_CODE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_COUNTRY_CODE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_DISTRICT */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_DISTRICT,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_DISTRICT) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_NAME */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_NAME,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_NAME) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_FLOOR */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_FLOOR,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_FLOOR) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_ROOM */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_ROOM,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ROOM) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_BUILDING_ZONE */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_BUILDING_ZONE,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_BUILDING_ZONE) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_CROSSING1 */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_CROSSING1,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_CROSSING1) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_CROSSING2 */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_CROSSING2,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_CROSSING2) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_URL */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_URL,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_URL) == KNI_TRUE)) {
                counter++;
            }
            /* AddressInfo_PHONE_NUMBER */
            if ((counter < landmark->addressInfoFieldNumber) &&
                (fill_adressInfoField(landmarkObj, 
                            landmarkImplFieldID.AddressInfo_PHONE_NUMBER,
                            stringObj, 
                            &landmark->fields[counter],
                            JAVACALL_LOCATION_ADDRESSINFO_PHONE_NUMBER) == KNI_TRUE)) {
                counter++;
            }
    }
    return KNI_TRUE;
}
/**
 * Save the state of the MIDlet suite loader.
 * <p>
 * Java declaration:
 * <pre>
 *    saveCommandState(Lcom/sun/midp/CommandState;)V
 * </pre>
 */
KNIEXPORT KNI_RETURNTYPE_VOID
KNIDECL(com_sun_midp_main_CommandState_saveCommandState) {
    KNI_StartHandles(5);
    KNI_DeclareHandle(runtimeInfo);
    KNI_DeclareHandle(commandState);
    KNI_DeclareHandle(clazz);
    KNI_DeclareHandle(rtiClazz);
    KNI_DeclareHandle(string);

    KNI_GetParameterAsObject(1, commandState);
    KNI_GetObjectClass(commandState, clazz);

    KNI_GetObjectField(commandState, midp_get_field_id(KNIPASSARGS clazz,
        "runtimeInfo", "Lcom/sun/midp/main/RuntimeInfo;"), runtimeInfo);
    KNI_GetObjectClass(runtimeInfo, rtiClazz);

    KNI_SAVE_INT_FIELD(commandState, clazz, "status",
                       MidpCommandState.status);
    KNI_SAVE_INT_FIELD(commandState, clazz, "suiteId",
                       MidpCommandState.suiteId);
    KNI_SAVE_INT_FIELD(commandState, clazz, "lastSuiteId",
                       MidpCommandState.lastSuiteId);
    KNI_SAVE_BOOLEAN_FIELD(commandState, clazz, "logoDisplayed",
                           MidpCommandState.logoDisplayed);
    KNI_SAVE_INT_FIELD(commandState, clazz, "debugMode",
                        MidpCommandState.debugMode);

    KNI_SAVE_INT_FIELD(runtimeInfo, rtiClazz, "memoryReserved",
                       MidpCommandState.runtimeInfo.memoryReserved);
    KNI_SAVE_INT_FIELD(runtimeInfo, rtiClazz, "memoryTotal",
                       MidpCommandState.runtimeInfo.memoryTotal);
    KNI_SAVE_INT_FIELD(runtimeInfo, rtiClazz, "priority",
                       MidpCommandState.runtimeInfo.priority);
    /*
     * We need to put these in the do/while block since the SAVE_STRING
     * macros may throw an OutOfMemoryException. If this happens, we
     * must exit the native function immediately.
     */
    do {
        KNI_SAVE_PCSL_STRING_FIELD(commandState, clazz, "midletClassName",
                                   &MidpCommandState.midletClassName, string);
        KNI_SAVE_PCSL_STRING_FIELD(commandState, clazz, "lastMidletClassName",
                                   &MidpCommandState.lastMidletClassName,
                                   string);
        KNI_SAVE_PCSL_STRING_FIELD(commandState, clazz, "lastArg0",
                                   &MidpCommandState.lastArg0, string);
        KNI_SAVE_PCSL_STRING_FIELD(commandState, clazz, "lastArg1",
                                   &MidpCommandState.lastArg1, string);
        KNI_SAVE_PCSL_STRING_FIELD(commandState, clazz, "arg0",
                                   &MidpCommandState.arg0, string);
        KNI_SAVE_PCSL_STRING_FIELD(commandState, clazz, "arg1",
                                   &MidpCommandState.arg1, string);
        KNI_SAVE_PCSL_STRING_FIELD(commandState, clazz, "arg2",
                                   &MidpCommandState.arg2, string);

        KNI_SAVE_PCSL_STRING_FIELD(runtimeInfo, rtiClazz, "profileName",
                                   &MidpCommandState.profileName, string);
    } while (0);

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #16
0
/**
 * Accepts incoming client connection request.
 *
 * Note: the method gets native connection handle directly from
 * <code>handle<code> field of <code>L2CAPNotifierImpl</code> object.
 *
 * Note: new native connection handle to work with accepted incoming
 * client connection is setted directly to <code>handle</code> field of
 * appropriate <code>L2CAPConnectionImpl</code> object.
 *
 * @return Negotiated ReceiveMTU and TransmitMTU.
 *               16 high bits is ReceiveMTU, 16 low bits is TransmitMTU.
 * @throws IOException if an I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_INT
Java_com_sun_midp_io_j2me_btl2cap_L2CAPNotifierImpl_accept0(void) {
    javacall_handle handle = BT_INVALID_HANDLE;
    javacall_handle peer_handle = BT_INVALID_HANDLE;
    MidpReentryData* info;
    int status = JAVACALL_FAIL;
    int processStatus = KNI_FALSE;
    int imtu, omtu, mtus;
    void *context = NULL;
    javacall_bt_address peer_addr;
    unsigned char *address = NULL;

    KNI_StartHandles(2);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(arrayHandle);
    KNI_GetThisPointer(thisHandle);
    handle = (javacall_handle)KNI_GetIntField(thisHandle, notifHandleID);
    KNI_GetObjectField(thisHandle, peerAddrID, arrayHandle);

    if (handle == BT_INVALID_HANDLE) {
        REPORT_ERROR(LC_PROTOCOL,
            "L2CAP server socket was closed before btl2cap_notif::accept");
        KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG(
            "L2CAP notifier was closed"));
    } else {
        bt_pushid_t pushid = KNI_GetIntField(thisHandle, pushHandleID);
        if (pushid != BT_INVALID_PUSH_HANDLE) {
            if (bt_push_checkout_client(pushid, &peer_handle, peer_addr,
                    &imtu, &omtu) == JAVACALL_OK) {
                pushcheckoutaccept((int)handle);
                processStatus = KNI_TRUE;
                status = JAVACALL_OK;
            }
        }
        if (peer_handle == BT_INVALID_HANDLE) {

        info = (MidpReentryData*)SNI_GetReentryData(NULL);
        if (info == NULL) {   /* First invocation */
            REPORT_INFO1(LC_PROTOCOL,
                "btl2cap_notif::accept handle=%d\n", handle);

            // Need revisit: add resource counting
            /*
             * An incoming socket connection counts against the client socket
             * resource limit.
             */
/*
            if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                const char* pMsg =
                    "Resource limit exceeded for BT client sockets";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
*/
//            } else {
                status = javacall_bt_l2cap_accept(
                    handle, &peer_handle, &peer_addr, &imtu, &omtu);
                processStatus = KNI_TRUE;
//            }
        } else {  /* Reinvocation after unblocking the thread */
            if ((javacall_handle)info->descriptor != handle) {
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "btl2cap_notif::accept handles mismatched %d != %d\n",
                    handle, info->descriptor);
                REPORT_CRIT(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIllegalStateException, EXCEPTION_MSG(
                    "Internal error in btl2cap_notif::accept"));
            } else {
                // Need revisit: add resource counting
/*
                if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                    const char* pMsg =
                        "Resource limit exceeded for BT client sockets"
                    REPORT_INFO(LC_PROTOCOL, pMsg);
                    KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
                } else {
*/
                    status = javacall_bt_l2cap_accept(
                        handle, &peer_handle, &peer_addr, &imtu, &omtu);
                    processStatus = KNI_TRUE;
//                }
            }
        }

        }

        if (processStatus) {
            REPORT_INFO1(LC_PROTOCOL,
                "btl2cap_notif::accept server handle=%d\n", handle);
            if (status == JAVACALL_OK) {
                int i;

                // Need revisit: add resource counting
/*
                if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) {
                    REPORT_INFO(LC_PROTOCOL,
                        "btl2cap_notif: Resource limit update error");
                }
*/

                // store client native connection handle for temporary storing
                KNI_SetIntField(thisHandle, peerHandleID, (jint)peer_handle);

                // copy address to Java object field
                SNI_BEGIN_RAW_POINTERS;
                address = JavaByteArray(arrayHandle);
                for (i = 0; i < BT_ADDRESS_SIZE; i++) {
                    address[i] = peer_addr[i];
                }
                SNI_END_RAW_POINTERS;

                REPORT_INFO(LC_PROTOCOL,
                    "btl2cap_notif::accept incoming connection accepted!");
            } else if (status == JAVACALL_WOULD_BLOCK) {
                midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context);
            } else if (status == JAVACALL_FAIL) {
                char* pError;
                javacall_bt_l2cap_get_error(handle, &pError);
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "IO error in btl2cap_notif::accept (%s)\n", pError);
                REPORT_INFO(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer));

            } else {
                char* pMsg = "Unknown error during btl2cap_notif::accept";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
            }
        }
    }

    mtus = (imtu << 16) & 0xFFFF0000;
    mtus |= omtu & 0xFFFF;

    KNI_EndHandles();
    KNI_ReturnInt(mtus);
}
Beispiel #17
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;
}
Beispiel #18
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();
}
Beispiel #19
0
/**
 * Implementation of native method to set the status of an Invocation.
 * If the status is set to a response status then the "finish"
 * behavior is performed.  If a response is required, the Invocation
 * is requeued to the invoking application. Otherwise, the Invocation
 * is discarded.
 *
 * @param invoc the InvocationImpl to update the native status
 * @see StoredInvoc
 * @see #invocQueue
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_content_InvocationStore_setStatus0(void) {
    StoredLink* link;
    StoredInvoc* invoc;
    int tid;

    KNI_StartHandles(3);
    KNI_DeclareHandle(invocObj);
    KNI_DeclareHandle(obj1);
    KNI_DeclareHandle(obj2);

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

    /* Find the matching entry in the queue */
    tid = KNI_GetIntField(invocObj, tidFid);
    link = invocFindTid(tid);
    if (link != NULL) {
        invoc = link->invoc;
        /* Update the status */
        invoc->status = KNI_GetIntField(invocObj, statusFid);
    
        switch (invoc->status) {
        case STATUS_OK:
        case STATUS_CANCELLED:
        case STATUS_ERROR:
        case STATUS_INITIATED:
            /* 
             * If a response is required, switch the target
             * application; if not then discard the Invocation.
             */
            if (invoc->responseRequired) {
                /* Swap the source and target suite and classname */
                SuiteIdType tmpSuiteId = invoc->invokingSuiteId;
                SuiteIdType tmpSuiteId2;
                pcsl_string tmpClassname = invoc->invokingClassname;
                invoc->invokingSuiteId = invoc->suiteId;
                invoc->invokingClassname = invoc->classname;
                invoc->suiteId = tmpSuiteId;
                invoc->classname = tmpClassname;
        
                /* Unmark the response it is "new" to the target */
                invoc->cleanup = KNI_FALSE;
                invoc->notified = KNI_FALSE;
        
                /* Swap the references in the Invocation object. */
                tmpSuiteId = KNI_GetIntField(invocObj, suiteIdFid);
                tmpSuiteId2 = KNI_GetIntField(invocObj, invokingSuiteIdFid);
                KNI_SetIntField(invocObj, invokingSuiteIdFid, tmpSuiteId);
                KNI_SetIntField(invocObj, suiteIdFid, tmpSuiteId2);

                KNI_GetObjectField(invocObj, invokingClassnameFid, obj1);
                KNI_GetObjectField(invocObj, classnameFid, obj2);
                KNI_SetObjectField(invocObj, classnameFid, obj1);
                KNI_SetObjectField(invocObj, invokingClassnameFid, obj2);
        
                /* Unblock any waiting threads so they can retrieve this. */
                unblockWaitingThreads(STATUS_OK);
                break;
            }
            /* If no response; Fall into DISPOSE */
    
        case STATUS_DISPOSE:
            /*
             * Free the Invocation, clean the Tid in the Invocation
             */
            invoc->tid = 0;
            KNI_SetIntField(invocObj, tidFid, 0);
            removeEntry(link);
            invocFree(invoc);
            break;
        case STATUS_ACTIVE:
        case STATUS_HOLD:
        case STATUS_WAITING:
            /* No Action. */
            break;
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}
Beispiel #20
0
/**
 * Accepts incoming client connection request.
 *
 * Note: the method gets native connection handle directly from
 * <code>handle<code> field of <code>BTSPPNotifierImpl</code> object.
 *
 * Note: new native connection handle to work with accepted incoming
 * client connection is setted directly to <code>handle</code> field of
 * appropriate <code>RFCOMMConnectionImpl</code> object.
 *
 * @throws IOException if an I/O error occurs
 */
KNIEXPORT KNI_RETURNTYPE_VOID
Java_com_sun_midp_io_j2me_btspp_BTSPPNotifierImpl_accept0(void) {
    bt_handle_t handle = BT_INVALID_HANDLE;
    bt_handle_t peer_handle = BT_INVALID_HANDLE;
    MidpReentryData* info;
    int status = BT_RESULT_FAILURE;
    int processStatus = KNI_FALSE;
    void *context = NULL;
    bt_bdaddr_t peer_addr;
    unsigned char *address = NULL;

    KNI_StartHandles(2);
    KNI_DeclareHandle(thisHandle);
    KNI_DeclareHandle(arrayHandle);
    KNI_GetThisPointer(thisHandle);
    handle = (bt_handle_t)KNI_GetIntField(thisHandle, notifHandleID);
    KNI_GetObjectField(thisHandle, peerAddrID, arrayHandle);

    if (handle == BT_INVALID_HANDLE) {
        REPORT_ERROR(LC_PROTOCOL,
            "RFCOMM notifier was closed before btspp_notif::accept");
        KNI_ThrowNew(midpInterruptedIOException, EXCEPTION_MSG(
            "RFCOMM notifier was closed"));
    } else {
        bt_pushid_t pushid = KNI_GetIntField(thisHandle, pushHandleID);
        if (pushid != BT_INVALID_PUSH_HANDLE) {
            if (bt_push_checkout_client(pushid, &peer_handle, peer_addr,
                    NULL, NULL) == BT_RESULT_SUCCESS) {
                pushcheckoutaccept((int)handle);
                processStatus = KNI_TRUE;
                status = BT_RESULT_SUCCESS;
            }
        }
        if (peer_handle == BT_INVALID_HANDLE) {

        info = (MidpReentryData*)SNI_GetReentryData(NULL);
        if (info == NULL) {   /* First invocation */
            REPORT_INFO1(LC_PROTOCOL,
                "btspp_notif::accept handle=%d\n", handle);

            // IMPL_NOTE: add resource counting
            /*
             * An incoming socket connection counts against the client socket
             * resource limit.
             */
/*
            if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                const char* pMsg =
                    "Resource limit exceeded for BT client sockets";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
*/
//            } else {
                status = bt_rfcomm_accept_start(
                    handle, &peer_handle, peer_addr, &context);
                processStatus = KNI_TRUE;
//            }
        } else {  /* Reinvocation after unblocking the thread */
            if ((bt_handle_t)info->descriptor != handle) {
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "btspp_notif::accept handles mismatched %d != %d\n",
                    handle, info->descriptor);
                REPORT_CRIT(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIllegalStateException, EXCEPTION_MSG(
                    "Internal error in btspp_notif::accept"));
            } else {
                // IMPL_NOTE: add resource counting
/*
                if (midpCheckResourceLimit(RSC_TYPE_BT_CLI, 1) == 0) {
                    const char* pMsg =
                        "Resource limit exceeded for BT client sockets"
                    REPORT_INFO(LC_PROTOCOL, pMsg);
                    KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
                } else {
*/
                    status = bt_rfcomm_accept_finish(
                        handle, &peer_handle, peer_addr, context);
                    processStatus = KNI_TRUE;
//                }
            }
        }

        }

        if (processStatus) {
            REPORT_INFO1(LC_PROTOCOL,
                "btspp_notif::accept server handle=%d\n", handle);
            if (status == BT_RESULT_SUCCESS) {
                int i;

                // IMPL_NOTE: add resource counting
/*
                if (midpIncResourceCount(RSC_TYPE_BT_CLI, 1) == 0) {
                    REPORT_INFO(LC_PROTOCOL,
                        "btspp_notif: Resource limit update error");
                }
*/

                // store client native connection handle for temporary storing
                KNI_SetIntField(thisHandle, peerHandleID, (jint)peer_handle);

                // copy address to Java object field
                SNI_BEGIN_RAW_POINTERS;
                address = (unsigned char*)JavaByteArray(arrayHandle);
                for (i = 0; i < BT_ADDRESS_SIZE; i++) {
                    address[i] = peer_addr[i];
                }
                SNI_END_RAW_POINTERS;

                RegisterRFCOMMConnection0(peer_addr, peer_handle);

                REPORT_INFO(LC_PROTOCOL,
                    "btspp_notif::accept incoming connection accepted!");
            } else if (status == BT_RESULT_WOULDBLOCK) {
                midp_thread_wait(NETWORK_READ_SIGNAL, (int)handle, context);
            } else if (status == BT_RESULT_FAILURE) {
                char* pError;
                bt_rfcomm_get_error(handle, &pError);
                midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE,
                    "IO error in btspp_notif::accept (%s)\n", pError);
                REPORT_INFO(LC_PROTOCOL, gKNIBuffer);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(gKNIBuffer));

            } else {
                char* pMsg = "Unknown error during btspp_notif::accept";
                REPORT_INFO(LC_PROTOCOL, pMsg);
                KNI_ThrowNew(midpIOException, EXCEPTION_MSG(pMsg));
            }
        }
    }

    KNI_EndHandles();
    KNI_ReturnVoid();
}