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;
115 voidxcosSimulationStartedID=NULL;
120 Xcos::Xcos(JavaVM * jvm_, jobject JObj) {
123 JNIEnv * curEnv = getCurrentEnv();
125 jclass localClass = curEnv->GetObjectClass(JObj);
126 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
127 curEnv->DeleteLocalRef(localClass);
129 if (this->instanceClass == NULL) {
130 throw GiwsException::JniObjectCreationException(curEnv, this->className());
133 this->instance = curEnv->NewGlobalRef(JObj) ;
134 if(this->instance == NULL){
135 throw GiwsException::JniObjectCreationException(curEnv, this->className());
137 /* Methods ID set to NULL */
138 voidxcosjstringjava_lang_Stringjstringjava_lang_StringID=NULL;
139 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
140 voidcloseXcosFromScilabID=NULL;
141 jintxcosDiagramToScilabjstringjava_lang_StringID=NULL;
142 voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID=NULL;
143 voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID=NULL;
144 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
145 voidupdateBlockjstringjava_lang_StringID=NULL;
146 voidxcosSimulationStartedID=NULL;
153 void Xcos::synchronize() {
154 if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
155 throw GiwsException::JniMonitorException(getCurrentEnv(), "Xcos");
159 void Xcos::endSynchronize() {
160 if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
161 throw GiwsException::JniMonitorException(getCurrentEnv(), "Xcos");
166 void Xcos::xcos (JavaVM * jvm_, char const* file, char const* variable){
168 JNIEnv * curEnv = NULL;
169 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
170 jclass cls = curEnv->FindClass( className().c_str() );
172 jmethodID voidxcosjstringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcos", "(Ljava/lang/String;Ljava/lang/String;)V" ) ;
173 if (voidxcosjstringjava_lang_Stringjstringjava_lang_StringID == NULL) {
174 throw GiwsException::JniMethodNotFoundException(curEnv, "xcos");
177 jstring file_ = curEnv->NewStringUTF( file );
178 if (file != NULL && file_ == NULL)
180 throw GiwsException::JniBadAllocException(curEnv);
184 jstring variable_ = curEnv->NewStringUTF( variable );
185 if (variable != NULL && variable_ == NULL)
187 throw GiwsException::JniBadAllocException(curEnv);
191 curEnv->CallStaticVoidMethod(cls, voidxcosjstringjava_lang_Stringjstringjava_lang_StringID ,file_, variable_);
192 curEnv->DeleteLocalRef(file_);
193 curEnv->DeleteLocalRef(variable_);
194 curEnv->DeleteLocalRef(cls);
195 if (curEnv->ExceptionCheck()) {
196 throw GiwsException::JniCallMethodException(curEnv);
200 void Xcos::warnCellByUID (JavaVM * jvm_, char const* const* uids, int uidsSize, char const* message){
202 JNIEnv * curEnv = NULL;
203 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
204 jclass cls = curEnv->FindClass( className().c_str() );
206 jmethodID voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "warnCellByUID", "([Ljava/lang/String;Ljava/lang/String;)V" ) ;
207 if (voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID == NULL) {
208 throw GiwsException::JniMethodNotFoundException(curEnv, "warnCellByUID");
210 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
212 // create java array of strings.
213 jobjectArray uids_ = curEnv->NewObjectArray( uidsSize, stringArrayClass, NULL);
216 throw GiwsException::JniBadAllocException(curEnv);
219 // convert each char * to java strings and fill the java array.
220 for ( int i = 0; i < uidsSize; i++)
222 jstring TempString = curEnv->NewStringUTF( uids[i] );
223 if (TempString == NULL)
225 throw GiwsException::JniBadAllocException(curEnv);
228 curEnv->SetObjectArrayElement( uids_, i, TempString);
230 // avoid keeping reference on to many strings
231 curEnv->DeleteLocalRef(TempString);
233 jstring message_ = curEnv->NewStringUTF( message );
234 if (message != NULL && message_ == NULL)
236 throw GiwsException::JniBadAllocException(curEnv);
240 curEnv->CallStaticVoidMethod(cls, voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID ,uids_, message_);
241 curEnv->DeleteLocalRef(stringArrayClass);
242 curEnv->DeleteLocalRef(uids_);
243 curEnv->DeleteLocalRef(message_);
244 curEnv->DeleteLocalRef(cls);
245 if (curEnv->ExceptionCheck()) {
246 throw GiwsException::JniCallMethodException(curEnv);
250 void Xcos::closeXcosFromScilab (JavaVM * jvm_){
252 JNIEnv * curEnv = NULL;
253 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
254 jclass cls = curEnv->FindClass( className().c_str() );
256 jmethodID voidcloseXcosFromScilabID = curEnv->GetStaticMethodID(cls, "closeXcosFromScilab", "()V" ) ;
257 if (voidcloseXcosFromScilabID == NULL) {
258 throw GiwsException::JniMethodNotFoundException(curEnv, "closeXcosFromScilab");
261 curEnv->CallStaticVoidMethod(cls, voidcloseXcosFromScilabID );
262 curEnv->DeleteLocalRef(cls);
263 if (curEnv->ExceptionCheck()) {
264 throw GiwsException::JniCallMethodException(curEnv);
268 int Xcos::xcosDiagramToScilab (JavaVM * jvm_, char const* xcosFile){
270 JNIEnv * curEnv = NULL;
271 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
272 jclass cls = curEnv->FindClass( className().c_str() );
274 jmethodID jintxcosDiagramToScilabjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcosDiagramToScilab", "(Ljava/lang/String;)I" ) ;
275 if (jintxcosDiagramToScilabjstringjava_lang_StringID == NULL) {
276 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramToScilab");
279 jstring xcosFile_ = curEnv->NewStringUTF( xcosFile );
280 if (xcosFile != NULL && xcosFile_ == NULL)
282 throw GiwsException::JniBadAllocException(curEnv);
286 jint res = static_cast<jint>( curEnv->CallStaticIntMethod(cls, jintxcosDiagramToScilabjstringjava_lang_StringID ,xcosFile_));
287 curEnv->DeleteLocalRef(xcosFile_);
288 curEnv->DeleteLocalRef(cls);
289 if (curEnv->ExceptionCheck()) {
290 throw GiwsException::JniCallMethodException(curEnv);
296 void Xcos::xcosDiagramOpen (JavaVM * jvm_, char const* const* UID, int UIDSize){
298 JNIEnv * curEnv = NULL;
299 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
300 jclass cls = curEnv->FindClass( className().c_str() );
302 jmethodID voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcosDiagramOpen", "([Ljava/lang/String;)V" ) ;
303 if (voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID == NULL) {
304 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramOpen");
306 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
308 // create java array of strings.
309 jobjectArray UID_ = curEnv->NewObjectArray( UIDSize, stringArrayClass, NULL);
312 throw GiwsException::JniBadAllocException(curEnv);
315 // convert each char * to java strings and fill the java array.
316 for ( int i = 0; i < UIDSize; i++)
318 jstring TempString = curEnv->NewStringUTF( UID[i] );
319 if (TempString == NULL)
321 throw GiwsException::JniBadAllocException(curEnv);
324 curEnv->SetObjectArrayElement( UID_, i, TempString);
326 // avoid keeping reference on to many strings
327 curEnv->DeleteLocalRef(TempString);
329 curEnv->CallStaticVoidMethod(cls, voidxcosDiagramOpenjobjectArray_java_lang_Stringjava_lang_StringID ,UID_);
330 curEnv->DeleteLocalRef(stringArrayClass);
331 curEnv->DeleteLocalRef(UID_);
332 curEnv->DeleteLocalRef(cls);
333 if (curEnv->ExceptionCheck()) {
334 throw GiwsException::JniCallMethodException(curEnv);
338 void Xcos::xcosDiagramClose (JavaVM * jvm_, char const* const* UID, int UIDSize){
340 JNIEnv * curEnv = NULL;
341 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
342 jclass cls = curEnv->FindClass( className().c_str() );
344 jmethodID voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "xcosDiagramClose", "([Ljava/lang/String;)V" ) ;
345 if (voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID == NULL) {
346 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramClose");
348 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
350 // create java array of strings.
351 jobjectArray UID_ = curEnv->NewObjectArray( UIDSize, stringArrayClass, NULL);
354 throw GiwsException::JniBadAllocException(curEnv);
357 // convert each char * to java strings and fill the java array.
358 for ( int i = 0; i < UIDSize; i++)
360 jstring TempString = curEnv->NewStringUTF( UID[i] );
361 if (TempString == NULL)
363 throw GiwsException::JniBadAllocException(curEnv);
366 curEnv->SetObjectArrayElement( UID_, i, TempString);
368 // avoid keeping reference on to many strings
369 curEnv->DeleteLocalRef(TempString);
371 curEnv->CallStaticVoidMethod(cls, voidxcosDiagramClosejobjectArray_java_lang_Stringjava_lang_StringID ,UID_);
372 curEnv->DeleteLocalRef(stringArrayClass);
373 curEnv->DeleteLocalRef(UID_);
374 curEnv->DeleteLocalRef(cls);
375 if (curEnv->ExceptionCheck()) {
376 throw GiwsException::JniCallMethodException(curEnv);
380 void Xcos::addToolsMenu (JavaVM * jvm_, char const* label, char const* command){
382 JNIEnv * curEnv = NULL;
383 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
384 jclass cls = curEnv->FindClass( className().c_str() );
386 jmethodID voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "addToolsMenu", "(Ljava/lang/String;Ljava/lang/String;)V" ) ;
387 if (voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID == NULL) {
388 throw GiwsException::JniMethodNotFoundException(curEnv, "addToolsMenu");
391 jstring label_ = curEnv->NewStringUTF( label );
392 if (label != NULL && label_ == NULL)
394 throw GiwsException::JniBadAllocException(curEnv);
398 jstring command_ = curEnv->NewStringUTF( command );
399 if (command != NULL && command_ == NULL)
401 throw GiwsException::JniBadAllocException(curEnv);
405 curEnv->CallStaticVoidMethod(cls, voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID ,label_, command_);
406 curEnv->DeleteLocalRef(label_);
407 curEnv->DeleteLocalRef(command_);
408 curEnv->DeleteLocalRef(cls);
409 if (curEnv->ExceptionCheck()) {
410 throw GiwsException::JniCallMethodException(curEnv);
414 void Xcos::updateBlock (JavaVM * jvm_, char const* h5File){
416 JNIEnv * curEnv = NULL;
417 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
418 jclass cls = curEnv->FindClass( className().c_str() );
420 jmethodID voidupdateBlockjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "updateBlock", "(Ljava/lang/String;)V" ) ;
421 if (voidupdateBlockjstringjava_lang_StringID == NULL) {
422 throw GiwsException::JniMethodNotFoundException(curEnv, "updateBlock");
425 jstring h5File_ = curEnv->NewStringUTF( h5File );
426 if (h5File != NULL && h5File_ == NULL)
428 throw GiwsException::JniBadAllocException(curEnv);
432 curEnv->CallStaticVoidMethod(cls, voidupdateBlockjstringjava_lang_StringID ,h5File_);
433 curEnv->DeleteLocalRef(h5File_);
434 curEnv->DeleteLocalRef(cls);
435 if (curEnv->ExceptionCheck()) {
436 throw GiwsException::JniCallMethodException(curEnv);
440 void Xcos::xcosSimulationStarted (JavaVM * jvm_){
442 JNIEnv * curEnv = NULL;
443 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
444 jclass cls = curEnv->FindClass( className().c_str() );
446 jmethodID voidxcosSimulationStartedID = curEnv->GetStaticMethodID(cls, "xcosSimulationStarted", "()V" ) ;
447 if (voidxcosSimulationStartedID == NULL) {
448 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosSimulationStarted");
451 curEnv->CallStaticVoidMethod(cls, voidxcosSimulationStartedID );
452 curEnv->DeleteLocalRef(cls);
453 if (curEnv->ExceptionCheck()) {
454 throw GiwsException::JniCallMethodException(curEnv);