process args and query (ptql) string - support dbcs for windows

This commit is contained in:
root 2013-11-04 12:07:38 +00:00
parent 9c931654d7
commit f12b8e32d3
1 changed files with 30 additions and 8 deletions

View File

@ -665,6 +665,17 @@ JNIEXPORT jlongArray SIGAR_JNIx(getProcList)
return procarray; return procarray;
} }
jstring getProcArgStr(char *arg, JNIEnv *env) {
jstring s;
#ifdef WIN32
WCHAR warg[3000];
SIGAR_A2W(arg, warg, sizeof(warg));
s = JENV->NewString(env, (const jchar *)warg, wcslen(warg));
#else
s = JENV->NewStringUTF(env, arg);
#endif
return s;
}
JNIEXPORT jobjectArray SIGAR_JNIx(getProcArgs) JNIEXPORT jobjectArray SIGAR_JNIx(getProcArgs)
(JNIEnv *env, jobject sigar_obj, jlong pid) (JNIEnv *env, jobject sigar_obj, jlong pid)
@ -685,7 +696,8 @@ JNIEXPORT jobjectArray SIGAR_JNIx(getProcArgs)
SIGAR_CHEX; SIGAR_CHEX;
for (i=0; i<procargs.number; i++) { for (i=0; i<procargs.number; i++) {
jstring s = JENV->NewStringUTF(env, procargs.data[i]);
jstring s = getProcArgStr(procargs.data[i], env);
JENV->SetObjectArrayElement(env, argsarray, i, s); JENV->SetObjectArrayElement(env, argsarray, i, s);
SIGAR_CHEX; SIGAR_CHEX;
} }
@ -1298,16 +1310,26 @@ JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_create)
{ {
int status; int status;
jboolean is_copy; jboolean is_copy;
const char *ptql;
sigar_ptql_query_t *query; sigar_ptql_query_t *query;
sigar_ptql_error_t error; sigar_ptql_error_t error;
#ifdef WIN32
LPCTSTR ptql;
char ptql_ch[3000];
ptql = (LPCTSTR)JENV->GetStringChars(env, jptql, &is_copy);
SIGAR_W2A((LPCWSTR)ptql, ptql_ch, sizeof(ptql_ch));
status = sigar_ptql_query_create(&query, ptql_ch, &error);
if (is_copy) {
JENV->ReleaseStringChars(env, jptql, (const jchar *)ptql);
}
#else
const char *ptql;
ptql = JENV->GetStringUTFChars(env, jptql, &is_copy); ptql = JENV->GetStringUTFChars(env, jptql, &is_copy);
status = sigar_ptql_query_create(&query, (char *)ptql, &error); status = sigar_ptql_query_create(&query, (char *)ptql, &error);
if (is_copy) { if (is_copy) {
JENV->ReleaseStringUTFChars(env, jptql, ptql); JENV->ReleaseStringUTFChars(env, jptql, ptql);
} }
#endif
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
sigar_throw_ptql_malformed(env, error.message); sigar_throw_ptql_malformed(env, error.message);
} }