1 #include "BrowseVar.hxx"
2 /* Generated by GIWS (version 2.0.1) with command:
3 giws --disable-return-size-array --output-dir src/jni/ --throws-exception-on-error --description-file src/jni/BrowseVar.giws.xml
7 This is generated code.
9 This software is a computer program whose purpose is to hide the complexity
10 of accessing Java objects/methods from C++ code.
12 This software is governed by the CeCILL-B license under French law and
13 abiding by the rules of distribution of free software. You can use,
14 modify and/ or redistribute the software under the terms of the CeCILL-B
15 license as circulated by CEA, CNRS and INRIA at the following URL
16 "http://www.cecill.info".
18 As a counterpart to the access to the source code and rights to copy,
19 modify and redistribute granted by the license, users are provided only
20 with a limited warranty and the software's author, the holder of the
21 economic rights, and the successive licensors have only limited
24 In this respect, the user's attention is drawn to the risks associated
25 with loading, using, modifying and/or developing or reproducing the
26 software by the user in light of its specific status of free software,
27 that may mean that it is complicated to manipulate, and that also
28 therefore means that it is reserved for developers and experienced
29 professionals having in-depth computer knowledge. Users are therefore
30 encouraged to load and test the software's suitability as regards their
31 requirements in conditions enabling the security of their systems and/or
32 data to be ensured and, more generally, to use and operate it in the
33 same conditions as regards security.
35 The fact that you are presently reading this means that you have had
36 knowledge of the CeCILL-B license and that you accept its terms.
39 namespace org_scilab_modules_ui_data {
41 // Static declarations (if any)
43 // Returns the current env
45 JNIEnv * BrowseVar::getCurrentEnv() {
46 JNIEnv * curEnv = NULL;
47 jint res=this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
49 throw GiwsException::JniException(getCurrentEnv());
55 BrowseVar::~BrowseVar() {
56 JNIEnv * curEnv = NULL;
57 this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
59 curEnv->DeleteGlobalRef(this->instance);
60 curEnv->DeleteGlobalRef(this->instanceClass);
61 curEnv->DeleteGlobalRef(this->stringArrayClass);}
63 BrowseVar::BrowseVar(JavaVM * jvm_) {
64 jmethodID constructObject = NULL ;
65 jobject localInstance ;
68 const std::string construct="<init>";
69 const std::string param="()V";
72 JNIEnv * curEnv = getCurrentEnv();
74 localClass = curEnv->FindClass( this->className().c_str() ) ;
75 if (localClass == NULL) {
76 throw GiwsException::JniClassNotFoundException(curEnv, this->className());
79 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
81 /* localClass is not needed anymore */
82 curEnv->DeleteLocalRef(localClass);
84 if (this->instanceClass == NULL) {
85 throw GiwsException::JniObjectCreationException(curEnv, this->className());
89 constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ;
90 if(constructObject == NULL){
91 throw GiwsException::JniObjectCreationException(curEnv, this->className());
94 localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ;
95 if(localInstance == NULL){
96 throw GiwsException::JniObjectCreationException(curEnv, this->className());
99 this->instance = curEnv->NewGlobalRef(localInstance) ;
100 if(this->instance == NULL){
101 throw GiwsException::JniObjectCreationException(curEnv, this->className());
103 /* localInstance not needed anymore */
104 curEnv->DeleteLocalRef(localInstance);
106 /* Methods ID set to NULL */
107 voidopenVariableBrowserjbooleanbooleanjobjectArray_java_lang_Stringjava_lang_StringjintArray_intintjintArray_intintjintArray_intintjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjbooleanArray_booleanbooleanID=NULL;
108 jbooleanisVariableBrowserOpenedID=NULL;
109 voidcloseVariableBrowserID=NULL;
114 BrowseVar::BrowseVar(JavaVM * jvm_, jobject JObj) {
117 JNIEnv * curEnv = getCurrentEnv();
119 jclass localClass = curEnv->GetObjectClass(JObj);
120 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
121 curEnv->DeleteLocalRef(localClass);
123 if (this->instanceClass == NULL) {
124 throw GiwsException::JniObjectCreationException(curEnv, this->className());
127 this->instance = curEnv->NewGlobalRef(JObj) ;
128 if(this->instance == NULL){
129 throw GiwsException::JniObjectCreationException(curEnv, this->className());
131 /* Methods ID set to NULL */
132 voidopenVariableBrowserjbooleanbooleanjobjectArray_java_lang_Stringjava_lang_StringjintArray_intintjintArray_intintjintArray_intintjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjbooleanArray_booleanbooleanID=NULL;
133 jbooleanisVariableBrowserOpenedID=NULL;
134 voidcloseVariableBrowserID=NULL;
141 void BrowseVar::synchronize() {
142 if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
143 throw GiwsException::JniMonitorException(getCurrentEnv(), "BrowseVar");
147 void BrowseVar::endSynchronize() {
148 if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
149 throw GiwsException::JniMonitorException(getCurrentEnv(), "BrowseVar");
154 void BrowseVar::openVariableBrowser (JavaVM * jvm_, bool update, char const* const* variableNames, int variableNamesSize, int const* variableBytes, int variableBytesSize, int const* variableTypes, int variableTypesSize, int const* variableIntegerTypes, int variableIntegerTypesSize, char const* const* variableListTypes, int variableListTypesSize, char const* const* variableSize, int variableSizeSize, char const* const* variableVisibility, int variableVisibilitySize, bool const* variableFromUser, int variableFromUserSize){
156 JNIEnv * curEnv = NULL;
157 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
158 jclass cls = curEnv->FindClass( className().c_str() );
160 jmethodID voidopenVariableBrowserjbooleanbooleanjobjectArray_java_lang_Stringjava_lang_StringjintArray_intintjintArray_intintjintArray_intintjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjbooleanArray_booleanbooleanID = curEnv->GetStaticMethodID(cls, "openVariableBrowser", "(Z[Ljava/lang/String;[I[I[I[Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;[Z)V" ) ;
161 if (voidopenVariableBrowserjbooleanbooleanjobjectArray_java_lang_Stringjava_lang_StringjintArray_intintjintArray_intintjintArray_intintjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjbooleanArray_booleanbooleanID == NULL) {
162 throw GiwsException::JniMethodNotFoundException(curEnv, "openVariableBrowser");
165 jboolean update_ = (static_cast<bool>(update) ? JNI_TRUE : JNI_FALSE);
166 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
168 // create java array of strings.
169 jobjectArray variableNames_ = curEnv->NewObjectArray( variableNamesSize, stringArrayClass, NULL);
170 if (variableNames_ == NULL)
172 throw GiwsException::JniBadAllocException(curEnv);
175 // convert each char * to java strings and fill the java array.
176 for ( int i = 0; i < variableNamesSize; i++)
178 jstring TempString = curEnv->NewStringUTF( variableNames[i] );
179 if (TempString == NULL)
181 throw GiwsException::JniBadAllocException(curEnv);
184 curEnv->SetObjectArrayElement( variableNames_, i, TempString);
186 // avoid keeping reference on to many strings
187 curEnv->DeleteLocalRef(TempString);
189 jintArray variableBytes_ = curEnv->NewIntArray( variableBytesSize ) ;
191 if (variableBytes_ == NULL)
193 // check that allocation succeed
194 throw GiwsException::JniBadAllocException(curEnv);
197 curEnv->SetIntArrayRegion( variableBytes_, 0, variableBytesSize, (jint*)(variableBytes) ) ;
200 jintArray variableTypes_ = curEnv->NewIntArray( variableTypesSize ) ;
202 if (variableTypes_ == NULL)
204 // check that allocation succeed
205 throw GiwsException::JniBadAllocException(curEnv);
208 curEnv->SetIntArrayRegion( variableTypes_, 0, variableTypesSize, (jint*)(variableTypes) ) ;
211 jintArray variableIntegerTypes_ = curEnv->NewIntArray( variableIntegerTypesSize ) ;
213 if (variableIntegerTypes_ == NULL)
215 // check that allocation succeed
216 throw GiwsException::JniBadAllocException(curEnv);
219 curEnv->SetIntArrayRegion( variableIntegerTypes_, 0, variableIntegerTypesSize, (jint*)(variableIntegerTypes) ) ;
223 // create java array of strings.
224 jobjectArray variableListTypes_ = curEnv->NewObjectArray( variableListTypesSize, stringArrayClass, NULL);
225 if (variableListTypes_ == NULL)
227 throw GiwsException::JniBadAllocException(curEnv);
230 // convert each char * to java strings and fill the java array.
231 for ( int i = 0; i < variableListTypesSize; i++)
233 jstring TempString = curEnv->NewStringUTF( variableListTypes[i] );
234 if (TempString == NULL)
236 throw GiwsException::JniBadAllocException(curEnv);
239 curEnv->SetObjectArrayElement( variableListTypes_, i, TempString);
241 // avoid keeping reference on to many strings
242 curEnv->DeleteLocalRef(TempString);
245 // create java array of strings.
246 jobjectArray variableSize_ = curEnv->NewObjectArray( variableSizeSize, stringArrayClass, NULL);
247 if (variableSize_ == NULL)
249 throw GiwsException::JniBadAllocException(curEnv);
252 // convert each char * to java strings and fill the java array.
253 for ( int i = 0; i < variableSizeSize; i++)
255 jstring TempString = curEnv->NewStringUTF( variableSize[i] );
256 if (TempString == NULL)
258 throw GiwsException::JniBadAllocException(curEnv);
261 curEnv->SetObjectArrayElement( variableSize_, i, TempString);
263 // avoid keeping reference on to many strings
264 curEnv->DeleteLocalRef(TempString);
267 // create java array of strings.
268 jobjectArray variableVisibility_ = curEnv->NewObjectArray( variableVisibilitySize, stringArrayClass, NULL);
269 if (variableVisibility_ == NULL)
271 throw GiwsException::JniBadAllocException(curEnv);
274 // convert each char * to java strings and fill the java array.
275 for ( int i = 0; i < variableVisibilitySize; i++)
277 jstring TempString = curEnv->NewStringUTF( variableVisibility[i] );
278 if (TempString == NULL)
280 throw GiwsException::JniBadAllocException(curEnv);
283 curEnv->SetObjectArrayElement( variableVisibility_, i, TempString);
285 // avoid keeping reference on to many strings
286 curEnv->DeleteLocalRef(TempString);
288 jbooleanArray variableFromUser_ = curEnv->NewBooleanArray( variableFromUserSize ) ;
289 curEnv->SetBooleanArrayRegion( variableFromUser_, 0, variableFromUserSize, (jboolean*)variableFromUser ) ;
291 curEnv->CallStaticVoidMethod(cls, voidopenVariableBrowserjbooleanbooleanjobjectArray_java_lang_Stringjava_lang_StringjintArray_intintjintArray_intintjintArray_intintjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjobjectArray_java_lang_Stringjava_lang_StringjbooleanArray_booleanbooleanID ,update_, variableNames_, variableBytes_, variableTypes_, variableIntegerTypes_, variableListTypes_, variableSize_, variableVisibility_, variableFromUser_);
292 curEnv->DeleteLocalRef(stringArrayClass);
293 curEnv->DeleteLocalRef(variableNames_);
294 curEnv->DeleteLocalRef(variableBytes_);
295 curEnv->DeleteLocalRef(variableTypes_);
296 curEnv->DeleteLocalRef(variableIntegerTypes_);
297 curEnv->DeleteLocalRef(variableListTypes_);
298 curEnv->DeleteLocalRef(variableSize_);
299 curEnv->DeleteLocalRef(variableVisibility_);
300 curEnv->DeleteLocalRef(variableFromUser_);
301 curEnv->DeleteLocalRef(cls);
302 if (curEnv->ExceptionCheck()) {
303 throw GiwsException::JniCallMethodException(curEnv);
307 bool BrowseVar::isVariableBrowserOpened (JavaVM * jvm_){
309 JNIEnv * curEnv = NULL;
310 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
311 jclass cls = curEnv->FindClass( className().c_str() );
313 jmethodID jbooleanisVariableBrowserOpenedID = curEnv->GetStaticMethodID(cls, "isVariableBrowserOpened", "()Z" ) ;
314 if (jbooleanisVariableBrowserOpenedID == NULL) {
315 throw GiwsException::JniMethodNotFoundException(curEnv, "isVariableBrowserOpened");
318 jboolean res = static_cast<jboolean>( curEnv->CallStaticBooleanMethod(cls, jbooleanisVariableBrowserOpenedID ));
319 curEnv->DeleteLocalRef(cls);
320 if (curEnv->ExceptionCheck()) {
321 throw GiwsException::JniCallMethodException(curEnv);
323 return (res == JNI_TRUE);
327 void BrowseVar::closeVariableBrowser (JavaVM * jvm_){
329 JNIEnv * curEnv = NULL;
330 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
331 jclass cls = curEnv->FindClass( className().c_str() );
333 jmethodID voidcloseVariableBrowserID = curEnv->GetStaticMethodID(cls, "closeVariableBrowser", "()V" ) ;
334 if (voidcloseVariableBrowserID == NULL) {
335 throw GiwsException::JniMethodNotFoundException(curEnv, "closeVariableBrowser");
338 curEnv->CallStaticVoidMethod(cls, voidcloseVariableBrowserID );
339 curEnv->DeleteLocalRef(cls);
340 if (curEnv->ExceptionCheck()) {
341 throw GiwsException::JniCallMethodException(curEnv);