JNIEXPORT jint SIGAR_JNIx(nativeClose)
(JNIEnv *env, jobject sigar_obj)
{
    jint status;
    int i;
    dSIGAR(0);

    /* only place it is possible this would be something other than
     * SIGAR_OK is on win32 if RegCloseKey fails, which i don't think
     * is possible either.
     */
    status = sigar_close(sigar);

    if (jsigar->logger != NULL) {
        JENV->DeleteGlobalRef(env, jsigar->logger);
    }

    if (jsigar->not_impl != NULL) {
        JENV->DeleteGlobalRef(env, jsigar->not_impl);
    }

    for (i=0; i<JSIGAR_FIELDS_MAX; i++) {
        if (jsigar->fields[i]) {
            JENV->DeleteGlobalRef(env,
                                  jsigar->fields[i]->classref);
            free(jsigar->fields[i]->ids);
            free(jsigar->fields[i]);
        }
    }

    free(jsigar);
    sigar_set_pointer(env, sigar_obj, NULL);

    return status;
}
JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_create)
(JNIEnv *env, jobject obj, jstring jptql)
{
	int status;
    jboolean is_copy;    
    sigar_ptql_query_t *query;
    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);
    status = sigar_ptql_query_create(&query, (char *)ptql, &error);
    if (is_copy) {
        JENV->ReleaseStringUTFChars(env, jptql, ptql);
    }
#endif
    if (status != SIGAR_OK) {
        sigar_throw_ptql_malformed(env, error.message);
    }
    else {
        sigar_set_pointer(env, obj, query);
    }
}
JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_destroy)
(JNIEnv *env, jobject obj)
{
    sigar_ptql_query_t *query =
        (sigar_ptql_query_t *)sigar_get_pointer(env, obj);

    if (query) {
        sigar_ptql_query_destroy(query);
        sigar_set_pointer(env, obj, 0);
    }
}
JNIEXPORT void SIGAR_JNIx(open)
(JNIEnv *env, jobject obj)
{
    jni_sigar_t *jsigar = malloc(sizeof(*jsigar));

    memset(jsigar, '\0', sizeof(*jsigar));

    sigar_set_pointer(env, obj, jsigar);
        
    /* this method is called by the constructor.
     * if != SIGAR_OK save status and throw exception
     * when methods are invoked (see sigar_get_pointer).
     */
    if ((jsigar->open_status = sigar_open(&jsigar->sigar)) != SIGAR_OK) {
        sigar_throw_error(env, jsigar, jsigar->open_status);
        return;
    }
}
Ejemplo n.º 5
0
JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_create)
(JNIEnv *env, jobject obj, jstring jptql)
{
    int status;
    jboolean is_copy;
    const char *ptql;
    sigar_ptql_query_t *query;
    sigar_ptql_error_t error;

    ptql = JENV->GetStringUTFChars(env, jptql, &is_copy);
    status = sigar_ptql_query_create(&query, (char *)ptql, &error);
    if (is_copy) {
        JENV->ReleaseStringUTFChars(env, jptql, ptql);
    }

    if (status != SIGAR_OK) {
        sigar_throw_ptql_malformed(env, error.message);
    }
    else {
        sigar_set_pointer(env, obj, query);
    }
}