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/Xcos.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_xcos {
41 // Static declarations (if any)
43 // Returns the current env
45 JNIEnv * Xcos::getCurrentEnv() {
46 JNIEnv * curEnv = NULL;
47 jint res=this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
49 throw GiwsException::JniException(getCurrentEnv());
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 Xcos::Xcos(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 voidxcosjstringjava_lang_Stringjstringjava_lang_StringID=NULL;
108 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
109 voidcloseXcosFromScilabID=NULL;
110 jintxcosDiagramToScilabjstringjava_lang_StringID=NULL;
111 voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID=NULL;
112 voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID=NULL;
113 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
114 voidupdateBlockjstringjava_lang_StringID=NULL;
119 Xcos::Xcos(JavaVM * jvm_, jobject JObj) {
122 JNIEnv * curEnv = getCurrentEnv();
124 jclass localClass = curEnv->GetObjectClass(JObj);
125 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
126 curEnv->DeleteLocalRef(localClass);
128 if (this->instanceClass == NULL) {
129 throw GiwsException::JniObjectCreationException(curEnv, this->className());
132 this->instance = curEnv->NewGlobalRef(JObj) ;
133 if(this->instance == NULL){
134 throw GiwsException::JniObjectCreationException(curEnv, this->className());
136 /* Methods ID set to NULL */
137 voidxcosjstringjava_lang_Stringjstringjava_lang_StringID=NULL;
138 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
139 voidcloseXcosFromScilabID=NULL;
140 jintxcosDiagramToScilabjstringjava_lang_StringID=NULL;
141 voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID=NULL;
142 voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID=NULL;
143 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
144 voidupdateBlockjstringjava_lang_StringID=NULL;
151 void Xcos::synchronize() {
152 if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
153 throw GiwsException::JniMonitorException(getCurrentEnv(), "Xcos");
157 void Xcos::endSynchronize() {
158 if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
159 throw GiwsException::JniMonitorException(getCurrentEnv(), "Xcos");
164 void Xcos::xcos (JavaVM * jvm_, char const* file, char const* variable){
166 JNIEnv * curEnv = NULL;
167 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
168 jclass cls = curEnv->FindClass( className().c_str() );
170 jmethodID voidxcosjstringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcos", "(Ljava/lang/String;Ljava/lang/String;)V" ) ;
171 if (voidxcosjstringjava_lang_Stringjstringjava_lang_StringID == NULL) {
172 throw GiwsException::JniMethodNotFoundException(curEnv, "xcos");
175 jstring file_ = curEnv->NewStringUTF( file );
176 if (file != NULL && file_ == NULL)
178 throw GiwsException::JniBadAllocException(curEnv);
182 jstring variable_ = curEnv->NewStringUTF( variable );
183 if (variable != NULL && variable_ == NULL)
185 throw GiwsException::JniBadAllocException(curEnv);
189 curEnv->CallStaticVoidMethod(cls, voidxcosjstringjava_lang_Stringjstringjava_lang_StringID ,file_, variable_);
190 curEnv->DeleteLocalRef(file_);
191 curEnv->DeleteLocalRef(variable_);
192 curEnv->DeleteLocalRef(cls);
193 if (curEnv->ExceptionCheck()) {
194 throw GiwsException::JniCallMethodException(curEnv);
198 void Xcos::warnCellByUID (JavaVM * jvm_, char const* const* uids, int uidsSize, char const* message){
200 JNIEnv * curEnv = NULL;
201 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
202 jclass cls = curEnv->FindClass( className().c_str() );
204 jmethodID voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "warnCellByUID", "([Ljava/lang/String;Ljava/lang/String;)V" ) ;
205 if (voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID == NULL) {
206 throw GiwsException::JniMethodNotFoundException(curEnv, "warnCellByUID");
208 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
210 // create java array of strings.
211 jobjectArray uids_ = curEnv->NewObjectArray( uidsSize, stringArrayClass, NULL);
214 throw GiwsException::JniBadAllocException(curEnv);
217 // convert each char * to java strings and fill the java array.
218 for ( int i = 0; i < uidsSize; i++)
220 jstring TempString = curEnv->NewStringUTF( uids[i] );
221 if (TempString == NULL)
223 throw GiwsException::JniBadAllocException(curEnv);
226 curEnv->SetObjectArrayElement( uids_, i, TempString);
228 // avoid keeping reference on to many strings
229 curEnv->DeleteLocalRef(TempString);
231 jstring message_ = curEnv->NewStringUTF( message );
232 if (message != NULL && message_ == NULL)
234 throw GiwsException::JniBadAllocException(curEnv);
238 curEnv->CallStaticVoidMethod(cls, voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID ,uids_, message_);
239 curEnv->DeleteLocalRef(stringArrayClass);
240 curEnv->DeleteLocalRef(uids_);
241 curEnv->DeleteLocalRef(message_);
242 curEnv->DeleteLocalRef(cls);
243 if (curEnv->ExceptionCheck()) {
244 throw GiwsException::JniCallMethodException(curEnv);
248 void Xcos::closeXcosFromScilab (JavaVM * jvm_){
250 JNIEnv * curEnv = NULL;
251 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
252 jclass cls = curEnv->FindClass( className().c_str() );
254 jmethodID voidcloseXcosFromScilabID = curEnv->GetStaticMethodID(cls, "closeXcosFromScilab", "()V" ) ;
255 if (voidcloseXcosFromScilabID == NULL) {
256 throw GiwsException::JniMethodNotFoundException(curEnv, "closeXcosFromScilab");
259 curEnv->CallStaticVoidMethod(cls, voidcloseXcosFromScilabID );
260 curEnv->DeleteLocalRef(cls);
261 if (curEnv->ExceptionCheck()) {
262 throw GiwsException::JniCallMethodException(curEnv);
266 int Xcos::xcosDiagramToScilab (JavaVM * jvm_, char const* xcosFile){
268 JNIEnv * curEnv = NULL;
269 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
270 jclass cls = curEnv->FindClass( className().c_str() );
272 jmethodID jintxcosDiagramToScilabjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcosDiagramToScilab", "(Ljava/lang/String;)I" ) ;
273 if (jintxcosDiagramToScilabjstringjava_lang_StringID == NULL) {
274 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramToScilab");
277 jstring xcosFile_ = curEnv->NewStringUTF( xcosFile );
278 if (xcosFile != NULL && xcosFile_ == NULL)
280 throw GiwsException::JniBadAllocException(curEnv);
284 jint res = static_cast<jint>( curEnv->CallStaticIntMethod(cls, jintxcosDiagramToScilabjstringjava_lang_StringID ,xcosFile_));
285 curEnv->DeleteLocalRef(xcosFile_);
286 curEnv->DeleteLocalRef(cls);
287 if (curEnv->ExceptionCheck()) {
288 throw GiwsException::JniCallMethodException(curEnv);
294 void Xcos::xcosDiagramOpen (JavaVM * jvm_, char const* const* UID, int UIDSize){
296 JNIEnv * curEnv = NULL;
297 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
298 jclass cls = curEnv->FindClass( className().c_str() );
300 jmethodID voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcosDiagramOpen", "([Ljava/lang/String;)V" ) ;
301 if (voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID == NULL) {
302 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramOpen");
304 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
306 // create java array of strings.
307 jobjectArray UID_ = curEnv->NewObjectArray( UIDSize, stringArrayClass, NULL);
310 throw GiwsException::JniBadAllocException(curEnv);
313 // convert each char * to java strings and fill the java array.
314 for ( int i = 0; i < UIDSize; i++)
316 jstring TempString = curEnv->NewStringUTF( UID[i] );
317 if (TempString == NULL)
319 throw GiwsException::JniBadAllocException(curEnv);
322 curEnv->SetObjectArrayElement( UID_, i, TempString);
324 // avoid keeping reference on to many strings
325 curEnv->DeleteLocalRef(TempString);
327 curEnv->CallStaticVoidMethod(cls, voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID ,UID_);
328 curEnv->DeleteLocalRef(stringArrayClass);
329 curEnv->DeleteLocalRef(UID_);
330 curEnv->DeleteLocalRef(cls);
331 if (curEnv->ExceptionCheck()) {
332 throw GiwsException::JniCallMethodException(curEnv);
336 void Xcos::xcosDiagramClose (JavaVM * jvm_, char const* const* UID, int UIDSize){
338 JNIEnv * curEnv = NULL;
339 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
340 jclass cls = curEnv->FindClass( className().c_str() );
342 jmethodID voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcosDiagramClose", "([Ljava/lang/String;)V" ) ;
343 if (voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID == NULL) {
344 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramClose");
346 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
348 // create java array of strings.
349 jobjectArray UID_ = curEnv->NewObjectArray( UIDSize, stringArrayClass, NULL);
352 throw GiwsException::JniBadAllocException(curEnv);
355 // convert each char * to java strings and fill the java array.
356 for ( int i = 0; i < UIDSize; i++)
358 jstring TempString = curEnv->NewStringUTF( UID[i] );
359 if (TempString == NULL)
361 throw GiwsException::JniBadAllocException(curEnv);
364 curEnv->SetObjectArrayElement( UID_, i, TempString);
366 // avoid keeping reference on to many strings
367 curEnv->DeleteLocalRef(TempString);
369 curEnv->CallStaticVoidMethod(cls, voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID ,UID_);
370 curEnv->DeleteLocalRef(stringArrayClass);
371 curEnv->DeleteLocalRef(UID_);
372 curEnv->DeleteLocalRef(cls);
373 if (curEnv->ExceptionCheck()) {
374 throw GiwsException::JniCallMethodException(curEnv);
378 void Xcos::addToolsMenu (JavaVM * jvm_, char const* label, char const* command){
380 JNIEnv * curEnv = NULL;
381 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
382 jclass cls = curEnv->FindClass( className().c_str() );
384 jmethodID voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "addToolsMenu", "(Ljava/lang/String;Ljava/lang/String;)V" ) ;
385 if (voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID == NULL) {
386 throw GiwsException::JniMethodNotFoundException(curEnv, "addToolsMenu");
389 jstring label_ = curEnv->NewStringUTF( label );
390 if (label != NULL && label_ == NULL)
392 throw GiwsException::JniBadAllocException(curEnv);
396 jstring command_ = curEnv->NewStringUTF( command );
397 if (command != NULL && command_ == NULL)
399 throw GiwsException::JniBadAllocException(curEnv);
403 curEnv->CallStaticVoidMethod(cls, voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID ,label_, command_);
404 curEnv->DeleteLocalRef(label_);
405 curEnv->DeleteLocalRef(command_);
406 curEnv->DeleteLocalRef(cls);
407 if (curEnv->ExceptionCheck()) {
408 throw GiwsException::JniCallMethodException(curEnv);
412 void Xcos::updateBlock (JavaVM * jvm_, char const* h5File){
414 JNIEnv * curEnv = NULL;
415 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
416 jclass cls = curEnv->FindClass( className().c_str() );
418 jmethodID voidupdateBlockjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "updateBlock", "(Ljava/lang/String;)V" ) ;
419 if (voidupdateBlockjstringjava_lang_StringID == NULL) {
420 throw GiwsException::JniMethodNotFoundException(curEnv, "updateBlock");
423 jstring h5File_ = curEnv->NewStringUTF( h5File );
424 if (h5File != NULL && h5File_ == NULL)
426 throw GiwsException::JniBadAllocException(curEnv);
430 curEnv->CallStaticVoidMethod(cls, voidupdateBlockjstringjava_lang_StringID ,h5File_);
431 curEnv->DeleteLocalRef(h5File_);
432 curEnv->DeleteLocalRef(cls);
433 if (curEnv->ExceptionCheck()) {
434 throw GiwsException::JniCallMethodException(curEnv);