Beispiel #1
0
StoreEntry * allocateEntry(JNIEnv* pEnv, Store* pStore, jstring jstrKey) {
	// If entry already exists in the store, releases its content
	// and keep its key.
	int32_t lError = 0;
	StoreEntry* lEntry = findEntry(pEnv, pStore, jstrKey, &lError);
	if (NULL != lEntry) {
		releaseEntryValue(pEnv, lEntry);
	}
	// If entry does not exist, create a new entry right after
	// already allocated entries.
	else if (!lError) {
		// Checks store can accept a new entry.
		if (pStore->mLength >= STORE_MAX_CAPACITY) {
			throwStoreFullException(pEnv);
			return NULL;
		}

		lEntry = pStore->mEntries + pStore->mLength;

		// Copies the new key into its final C string buffer.
		const char* lKeyTmp = (*pEnv)->GetStringUTFChars(pEnv, jstrKey, NULL);

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

		lEntry->mKey = (char*) malloc(strlen(lKeyTmp));
		strcpy(lEntry->mKey, lKeyTmp);
		(*pEnv)->ReleaseStringUTFChars(pEnv, jstrKey, lKeyTmp);

		++pStore->mLength;
	}

	return lEntry;
}
Beispiel #2
0
StoreEntry* allocateEntry(JNIEnv* env, Store* rStore, jstring rKey)
{
	LOGV("allocateEntry is called");
	int32_t error = 0;
	StoreEntry* rEntry = findEntry(env, rStore, rKey, &error);

	if(rEntry != NULL) freeEntry(env, rEntry);

	else if(!error)
	{
		LOGV("No error while allocation");
		if(rStore->numentries >= STORE_MAX_CAPACITY)
		{
			LOGV("Store is full");
			throwStoreFullException(env);
			return NULL;
		}
		rEntry = rStore->allentries + rStore->numentries;

		const char* tmpKeyString = (*env)->GetStringUTFChars(env, rKey, NULL);
		if(tmpKeyString == NULL) return NULL;

		rEntry->nKey = (char*) malloc(strlen(tmpKeyString));
		strcpy(rEntry->nKey, tmpKeyString);

		(*env)->ReleaseStringUTFChars(env, rKey, tmpKeyString);

		rStore->numentries++;
	}

	return rEntry;
}
Beispiel #3
0
StoreEntry *allocateEntry(JNIEnv *pEnv, Store *pStore, jstring pKey) {
  int32_t lError = 0;
  StoreEntry *lEntry = findEntry(pEnv, pStore, pKey, &lError);
  
  if (lEntry != NULL) {
    releaseEntryValue(pEnv, lEntry);
  } else if (!lError) {
    if (pStore->mLength >= STORE_MAX_CAPACITY) {
      throwStoreFullException(pEnv);
      return NULL;
    }
    lEntry = pStore->mEntries + pStore->mLength;
    const char *lKeyTmp = pEnv->GetStringUTFChars(pKey, NULL);
    if (lKeyTmp == NULL)
      return NULL;
    lEntry->mKey = (char*) malloc(strlen(lKeyTmp));
    strcpy(lEntry->mKey, lKeyTmp);
    pEnv->ReleaseStringUTFChars(pKey, lKeyTmp);
    ++pStore->mLength;
  }
  return lEntry;
}