midputilkni.h
来自「This is a resource based on j2me embedde」· C头文件 代码 · 共 538 行 · 第 1/2 页
H
538 行
* to GET_PARAMETER_AS_PCSL_STRING is declared within this block. * You do not have to make explicit declaration for this variable * (parameter_name in the above example). * * If the object specified by index cannot be converted to a pcsl_string, * the code between GET_PARAMETER_AS_PCSL_STRING and * RELEASE_PCSL_STRING_PARAMETER is not executed; instead, an out-of-memory * error is signaled (by executing * <code>KNI_ThrowNew(midpOutOfMemoryError, NULL);</code>). * * To access more than one argument string, nest the construct, as shown below: * * Usage 3: * <pre><code> * KNI_StartHandles(2); * GET_PARAMETER_AS_PCSL_STRING(1,someString) * GET_PARAMETER_AS_PCSL_STRING(2,anotherString) * some code using someString and anotherString * RELEASE_PCSL_STRING_PARAMETER * RELEASE_PCSL_STRING_PARAMETER * KNI_EndHandles(); * </code></pre> * * The macros GET_PARAMETER_AS_PCSL_STRING and RELEASE_PCSL_STRING_PARAMETER * must be balanced both at compile time and at runtime. In particular, you * MUST NOT use <code>return</code> from within this construct, because this * will lead to memory leaks. * * @param index the index of a string parameter in the native method * invocation. Index value 1 refers to the leftmost * parameter in the Java platform method. * @param id the name of a variable that receives the string value. * The variable is declared and visible within the scope * starting from GET_PARAMETER_AS_PCSL_STRING and ending * at the corresponding RELEASE_PCSL_STRING_PARAMETER. */#define GET_PARAMETER_AS_PCSL_STRING(index,id) \ { \ pcsl_string id; \ pcsl_string * const latest_pcsl_string_arg = &id; \ KNI_DeclareHandle(id##_handle); \ KNI_GetParameterAsObject(index, id##_handle); \ if(PCSL_STRING_OK != midp_jstring_to_pcsl_string(id##_handle, &id)) { \ KNI_ThrowNew(midpOutOfMemoryError, NULL); \ } else { {/** * Given a Java platform string handle (declared with KNI_DeclareHandle), * obtain the string text represented as a pcsl_string. * Must be balanced with RELEASE_PCSL_STRING_PARAMETER. * Declares a pcsl_string variable visible inside the * GET_JSTRING_AS_PCSL_STRING...RELEASE_PCSL_STRING_PARAMETER block. * This macro is particularly useful when we obtain a Java platform * string handle accessing a field of some Java object using * KNI_GetObjectField, and want it to ba converted to a pcsl_string. * See GET_PARAMETER_AS_PCSL_STRING. * * @param handle a Java platform string handle (declared with KNI_DeclareHandle) * @param id name for the declared and initialized pcsl_string. */#define GET_JSTRING_AS_PCSL_STRING(handle,id) \ { \ pcsl_string id; \ pcsl_string * const latest_pcsl_string_arg = &id; \ if(PCSL_STRING_OK != midp_jstring_to_pcsl_string(handle, &id)) { \ KNI_ThrowNew(midpOutOfMemoryError, NULL); \ } else { {/** * Closes the GET_PARAMETER_AS_PCSL_STRING...RELEASE_PCSL_STRING_PARAMETER * construct. * * Closes the block scope opened with the * matching GET_PARAMETER_AS_PCSL_STRING. * Frees the last pcsl_string argument. * */#define RELEASE_PCSL_STRING_PARAMETER \ } pcsl_string_free(latest_pcsl_string_arg); \ } \ }/** * Given variable <code>id</code> of type pcsl_string*, * declare: <ul> * <li>id_data of type jchar const * const pointing to the string UTF-16 data, </li> * <li>id_len of type jint containing the string length.</li> </ul> * * The scope of the above two names is the * GET_PCSL_STRING_DATA_AND_LENGTH...RELEASE_PCSL_STRING_DATA_AND_LENGTH * construct. * * @param id the variable name, from which new names are derived. */#define GET_PCSL_STRING_DATA_AND_LENGTH(id) \ { \ const jint id##_len = pcsl_string_utf16_length(id); \ const jchar * const id##_data = pcsl_string_get_utf16_data(id); \ const jchar * const * const last_pcsl_string_data = & id##_data; \ const pcsl_string* const last_pcsl_string_itself = id; \ {/** * closes the * GET_PCSL_STRING_DATA_AND_LENGTH...RELEASE_PCSL_STRING_DATA_AND_LENGTH * construct. */#define RELEASE_PCSL_STRING_DATA_AND_LENGTH \ } pcsl_string_release_utf16_data(*last_pcsl_string_data, last_pcsl_string_itself); \ }/** * Given name of pcsl_string specified as the GET_PCSL_STRING_DATA_AND_LENGTH * macro parameter, returns true if out-of-memory error has happened. * * @param id the variable name, from which new names are derived in * GET_PCSL_STRING_DATA_AND_LENGTH macro */#define PCSL_STRING_PARAMETER_ERROR(id) \ ((id##_data) == NULL && (id##_len) > 0)/** * Print a pcsl_string to the standard output. Useful for debugging. * Uses <code>printf</code>, requires <code>#include <stdio.h></code>. * * @param fmt string literal, specifying the printf format, * for example, "result=[%s]\n" * @param id address of a string, of type pcsl_string* **/#define PRINTF_PCSL_STRING(fmt,id) \ { \ const jbyte * const __data = pcsl_string_get_utf8_data(id); \ printf(fmt,__data); \ pcsl_string_release_utf8_data(__data, id); \ }/** * Print a MidpString to stdout. * Requires <code>#include <stdio.h></code> */#define PRINTF_MIDP_STRING(fmt,id) \ GET_PCSL_STRING_FOR_MIDP_STRING(id) \ PRINTF_PCSL_STRING(fmt,&id##_str); \ RELEASE_PCSL_STRING_FOR_MIDP_STRING/** * This macro is used for migration from MidpString to pcsl_string * Given a pointer to pcsl_string called someName, * defined a MidpString called midp_someName. * Opens a block, must be balanced with RELEASE_MIDP_STRING_FOR_PCSL_STRING. */#define GET_MIDP_STRING_FOR_PCSL_STRING_PTR(id) \ { \ MidpString midp_##id; \ MidpString * lastMidpString = &midp_##id; \ midp_string_from_pcsl_string(id,&midp_##id); \ {/** * This macro is used for migration from MidpString to pcsl_string * Given a pcsl_string called someName, * defined a MidpString called midp_someName. * Opens a block, must be balanced with RELEASE_MIDP_STRING_FOR_PCSL_STRING. */#define GET_MIDP_STRING_FOR_PCSL_STRING(id) \ { \ MidpString midp_##id; \ MidpString * lastMidpString = &midp_##id; \ midp_string_from_pcsl_string(&id,&midp_##id); \ {/** * This macro is used for migration from MidpString to pcsl_string * See GET_MIDP_STRING_FOR_PCSL_STRING, GET_MIDP_STRING_FOR_PCSL_STRING_PTR. */#define RELEASE_MIDP_STRING_FOR_PCSL_STRING \ } \ MIDP_FREE_STRING(*lastMidpString); \ }/** * This macro is used for migration from MidpString to pcsl_string * Given a MidpString called someName, * defined a pcsl_string called someName_str. * Opens a block, must be balanced with RELEASE_PCSL_STRING_FOR_MIDP_STRING. */#define GET_PCSL_STRING_FOR_MIDP_STRING(id) \ { \ pcsl_string id##_str; \ pcsl_string * lastPcslString = &id##_str; \ midp_string_to_pcsl_string(&id,&id##_str); \ {/** * This macro is used for migration from MidpString to pcsl_string. * See GET_PCSL_STRING_FOR_MIDP_STRING. */#define RELEASE_PCSL_STRING_FOR_MIDP_STRING \ } \ pcsl_string_free(lastPcslString); \ }/** * The pair of macros AUX_MIDP_STRING...AUX_MIDP_STRING_TO_PCSL_STRING * is used for migration from MidpString to pcsl_string. * It enables us to get a MidpString output parameter as a pcsl_string. * See AUX_PCSL_STRING_TO_MIDP_STRING. */#define AUX_MIDP_STRING(id) \ { MidpString id = { NULL_LEN, NULL };/** * The pair of macros AUX_MIDP_STRING...AUX_MIDP_STRING_TO_PCSL_STRING * is used for migration from MidpString to pcsl_string. * It enables us to get a MidpString output parameter as a pcsl_string. * See AUX_PCSL_STRING_TO_MIDP_STRING. */#define AUX_MIDP_STRING_TO_PCSL_STRING(id,pid) \ pcsl_string_convert_from_utf16(id.data,id.len,&pid); \ if(id.data){ MIDP_FREE_STRING(id); } \ }/** * The pair of macros AUX_PCSL_STRING...AUX_PCSL_STRING_TO_MIDP_STRING * is used for migration from MidpString to pcsl_string. * It enables us to get a pcsl_string output parameter as a MidpString. * See AUX_PCSL_STRING_TO_MIDP_STRING. */#define AUX_PCSL_STRING(pid) \ { pcsl_string pid = PCSL_STRING_NULL;/** * The pair of macros AUX_PCSL_STRING...AUX_PCSL_STRING_TO_MIDP_STRING * is used for migration from MidpString to pcsl_string. * It enables us to get a pcsl_string output parameter as a MidpString. * Usage example: * <pre><code> * MIDP_ERROR midpExampleGetSuiteResourceFile(MidpString suiteId, * MidpString resourceName, * jboolean checkSuiteExists, * MidpString *filename) { * MIDP_ERROR rc = MIDP_ERROR_OUT_MEM; * GET_PCSL_STRING_FOR_MIDP_STRING(suiteId) * GET_PCSL_STRING_FOR_MIDP_STRING(resourceName) * AUX_PCSL_STRING(fn) * rc = midp_example_get_suite_resource_file(&suiteId_str, * &resourceName_str, checkSuiteExists, &fn); * AUX_PCSL_STRING_TO_MIDP_STRING(fn,*filename) * RELEASE_PCSL_STRING_FOR_MIDP_STRING * RELEASE_PCSL_STRING_FOR_MIDP_STRING * return rc; * } * </code></pre> * */#define AUX_PCSL_STRING_TO_MIDP_STRING(pid,mid) \ midp_string_from_pcsl_string(&pid,&mid); \ pcsl_string_free(&pid); \ }#ifdef __cplusplus}#endif#endif /* _MIDP_UTIL_KNI_H_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?