add native single process finder
This commit is contained in:
1 parent
697412d938
commit
a1a9f3f494
5 files changed
+104
-10
No files matched your search
@@ -1163,6 +1163,16 @@ static int jsigar_ptql_re_impl(void *data,
|
||||
JENV->NewStringUTF(env, needle));
|
||||
}
|
||||
|
||||
static void re_impl_set(JNIEnv *env, sigar_t *sigar, jobject obj, jni_ptql_re_data_t *re)
|
||||
{
|
||||
re->env = env;
|
||||
re->cls = NULL;
|
||||
re->obj = obj;
|
||||
re->id = NULL;
|
||||
|
||||
sigar_ptql_re_impl_set(sigar, re, jsigar_ptql_re_impl);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean SIGAR_JNI(ptql_SigarProcessQuery_match)
|
||||
(JNIEnv *env, jobject obj, jobject sigar_obj, jlong pid)
|
||||
{
|
||||
@@ -1172,12 +1182,7 @@ JNIEXPORT jboolean SIGAR_JNI(ptql_SigarProcessQuery_match)
|
||||
(sigar_ptql_query_t *)sigar_get_pointer(env, obj);
|
||||
dSIGAR(JNI_FALSE);
|
||||
|
||||
re.env = env;
|
||||
re.cls = NULL;
|
||||
re.obj = obj;
|
||||
re.id = NULL;
|
||||
|
||||
sigar_ptql_re_impl_set(sigar, &re, jsigar_ptql_re_impl);
|
||||
re_impl_set(env, sigar, obj, &re);
|
||||
|
||||
status = sigar_ptql_query_match(sigar, query, pid);
|
||||
|
||||
@@ -1233,6 +1238,32 @@ JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_destroy)
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jlong SIGAR_JNI(ptql_SigarProcessQuery_findProcess)
|
||||
(JNIEnv *env, jobject obj, jobject sigar_obj)
|
||||
{
|
||||
sigar_pid_t pid;
|
||||
int status;
|
||||
jni_ptql_re_data_t re;
|
||||
sigar_ptql_query_t *query =
|
||||
(sigar_ptql_query_t *)sigar_get_pointer(env, obj);
|
||||
dSIGAR(0);
|
||||
|
||||
re_impl_set(env, sigar, obj, &re);
|
||||
|
||||
status = sigar_ptql_query_find_process(sigar, query, &pid);
|
||||
|
||||
sigar_ptql_re_impl_set(sigar, NULL, NULL);
|
||||
|
||||
if (status < 0) {
|
||||
sigar_throw_ptql_malformed(env, sigar->errbuf);
|
||||
}
|
||||
else if (status != SIGAR_OK) {
|
||||
sigar_throw_error(env, jsigar, status);
|
||||
}
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
#include "sigar_getline.h"
|
||||
|
||||
JNIEXPORT jboolean SIGAR_JNI(util_Getline_isatty)
|
||||
|
||||
@@ -51,10 +51,10 @@ public class ProcessFinder {
|
||||
public long findSingleProcess(ProcessQuery query)
|
||||
throws SigarException, SigarNotImplementedException,
|
||||
MalformedQueryException {
|
||||
//XXX bring back in another form
|
||||
//if (query instanceof PidQuery) {
|
||||
// return ((PidQuery)query).getPid();
|
||||
//}
|
||||
|
||||
if (query instanceof SigarProcessQuery) {
|
||||
return ((SigarProcessQuery)query).findProcess(this.proxy);
|
||||
}
|
||||
|
||||
int i, matches = 0;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.hyperic.sigar.ptql;
|
||||
|
||||
import org.hyperic.sigar.Sigar;
|
||||
import org.hyperic.sigar.SigarException;
|
||||
import org.hyperic.sigar.SigarNotImplementedException;
|
||||
import org.hyperic.sigar.SigarProxy;
|
||||
import org.hyperic.sigar.SigarProxyCache;
|
||||
|
||||
@@ -45,6 +46,15 @@ public class SigarProcessQuery implements ProcessQuery {
|
||||
return match(SigarProxyCache.getSigar(sigar), pid);
|
||||
}
|
||||
|
||||
public native long findProcess(Sigar sigar)
|
||||
throws SigarException, SigarNotImplementedException, MalformedQueryException;
|
||||
|
||||
public long findProcess(SigarProxy sigar)
|
||||
throws SigarException, SigarNotImplementedException, MalformedQueryException {
|
||||
|
||||
return findProcess(SigarProxyCache.getSigar(sigar));
|
||||
}
|
||||
|
||||
static boolean re(String haystack, String needle) {
|
||||
if (haystack == null) {
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user