~ubuntu-branches/ubuntu/raring/geotranz/raring

« back to all changes in this revision

Viewing changes to geotrans2/java_gui/geotrans/jni/JNISource.c

  • Committer: Bazaar Package Importer
  • Author(s): Roberto Lumbreras
  • Date: 2008-10-17 14:43:09 UTC
  • Revision ID: james.westby@ubuntu.com-20081017144309-jb7uzfi1y1lvez8j
Tags: upstream-2.4.2
ImportĀ upstreamĀ versionĀ 2.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <jni.h>
 
2
#include "string.h"
 
3
#include "source.h"
 
4
#include "ThrowException.h"
 
5
 
 
6
 
 
7
 
 
8
JNIEXPORT jlong JNICALL Java_geotrans_jni_JNISource_JNISourceCount(JNIEnv *env, jobject obj)
 
9
{
 
10
    long count = 0;
 
11
 
 
12
    Source_Count(&count);
 
13
 
 
14
    return count;
 
15
}
 
16
 
 
17
 
 
18
JNIEXPORT jlong JNICALL Java_geotrans_jni_JNISource_JNISourceIndex(JNIEnv *env, jobject obj, jstring name)
 
19
{
 
20
    long index = 0;
 
21
    const char *sourceName;
 
22
 
 
23
    sourceName = (*env)->GetStringUTFChars(env, name, NULL);
 
24
    if (sourceName == NULL)
 
25
    {
 
26
        throwException(env, "geotrans/jni/JNIException", "JNI Exception: Out of memory.");
 
27
        return index;
 
28
    }
 
29
 
 
30
    if (Source_Index(sourceName, &index))
 
31
        throwException(env, "geotrans/jni/GeotransError", "Error getting source index.");
 
32
 
 
33
    (*env)->ReleaseStringUTFChars(env, name, sourceName);
 
34
 
 
35
    return index;
 
36
}
 
37
 
 
38
 
 
39
JNIEXPORT jstring JNICALL Java_geotrans_jni_JNISource_JNISourceName(JNIEnv *env, jobject obj, jlong index)
 
40
{
 
41
    char sourceName[50];
 
42
    jstring jStr = NULL;
 
43
 
 
44
    if (Source_Name((long)index, sourceName))
 
45
    {
 
46
        throwException(env, "geotrans/jni/GeotransError", "Error getting source name.");
 
47
        return jStr;
 
48
    }
 
49
 
 
50
    jStr = (*env)->NewStringUTF(env, sourceName);
 
51
    if (jStr == NULL)
 
52
        throwException(env, "geotrans/jni/JNIException", "JNI Exception: Out of memory.");
 
53
 
 
54
    return jStr;
 
55
}
 
56
 
 
57
 
 
58
JNIEXPORT jobject JNICALL Java_geotrans_jni_JNISource_JNISourceAccuracy(JNIEnv *env, jobject obj, jlong index)
 
59
{
 
60
 
 
61
    double ce90, le90, se90;
 
62
    long errorCode = 0;
 
63
    jclass cls;
 
64
    jmethodID cid;
 
65
    
 
66
    if(Source_Accuracy((long)index, &ce90, &le90, &se90))
 
67
    {
 
68
        throwException(env, "geotrans/jni/GeotransError", "Error getting source accuracy");
 
69
        return NULL;
 
70
    }
 
71
 
 
72
    cls = (*env)->FindClass(env, "geotrans/gui/Accuracy");
 
73
    if(cls == NULL)
 
74
    {
 
75
        throwException(env, "geotrans/jni/JNIException", "JNI Exception: Accuracy class not found.");
 
76
        return NULL;
 
77
    }
 
78
 
 
79
    cid = (*env)->GetMethodID(env, cls, "<init>", "(DDD)V");
 
80
    if(cid == NULL)
 
81
    {
 
82
        throwException(env, "geotrans/jni/JNIException", "JNI Exception: Accuracy method id not found.");
 
83
        return NULL;
 
84
    }
 
85
 
 
86
    obj = (*env)->NewObject(env, cls, cid, ce90, le90, se90);
 
87
    if (obj == NULL)
 
88
        throwException(env, "geotrans/jni/JNIException", "JNI Exception: Accuracy object could not be created.");
 
89
 
 
90
    return obj;
 
91
}
 
92