1 #include "Xcos.hxx"
2 /* Generated by GIWS (version 2.0.2) with command:
3 giws --disable-return-size-array --output-dir src/jni/ --throws-exception-on-error --description-file src/jni/Xcos.giws.xml
4 */
5 /*
6
7 This is generated code.
8
9 This software is a computer program whose purpose is to hide the complexity
10 of accessing Java objects/methods from C++ code.
11
12 Copyright (C) 2012 - 2016 - Scilab Enterprises
13
14 This file is hereby licensed under the terms of the GNU GPL v2.0,
15 pursuant to article 5.3.4 of the CeCILL v.2.1.
16 This file was originally licensed under the terms of the CeCILL v2.1,
17 and continues to be available under such terms.
18 For more information, see the COPYING file which you should have received
19 along with this program.
20 */
21
22 namespace org_scilab_modules_xcos {
23
24 // Static declarations (if any)
25
26 // Returns the current env
27
getCurrentEnv()28 JNIEnv * Xcos::getCurrentEnv() {
29 JNIEnv * curEnv = NULL;
30 jint res=this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
31 if (res != JNI_OK) {
32 throw GiwsException::JniException(getCurrentEnv());
33 }
34 return curEnv;
35 }
36 // Destructor
37
~Xcos()38 Xcos::~Xcos() {
39 JNIEnv * curEnv = NULL;
40 this->jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
41 curEnv->DeleteGlobalRef(this->instance);
42 curEnv->DeleteGlobalRef(this->instanceClass);
43 curEnv->DeleteGlobalRef(this->stringArrayClass);}
44 // Constructors
Xcos(JavaVM * jvm_)45 Xcos::Xcos(JavaVM * jvm_) {
46 jmethodID constructObject = NULL ;
47 jobject localInstance ;
48 jclass localClass ;
49
50 const std::string construct="<init>";
51 const std::string param="()V";
52 jvm=jvm_;
53
54 JNIEnv * curEnv = getCurrentEnv();
55
56 localClass = curEnv->FindClass( this->className().c_str() ) ;
57 if (localClass == NULL) {
58 throw GiwsException::JniClassNotFoundException(curEnv, this->className());
59 }
60
61 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
62
63 /* localClass is not needed anymore */
64 curEnv->DeleteLocalRef(localClass);
65
66 if (this->instanceClass == NULL) {
67 throw GiwsException::JniObjectCreationException(curEnv, this->className());
68 }
69
70
71 constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ;
72 if(constructObject == NULL){
73 throw GiwsException::JniObjectCreationException(curEnv, this->className());
74 }
75
76 localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ;
77 if(localInstance == NULL){
78 throw GiwsException::JniObjectCreationException(curEnv, this->className());
79 }
80
81 this->instance = curEnv->NewGlobalRef(localInstance) ;
82 if(this->instance == NULL){
83 throw GiwsException::JniObjectCreationException(curEnv, this->className());
84 }
85 /* localInstance not needed anymore */
86 curEnv->DeleteLocalRef(localInstance);
87
88 /* Methods ID set to NULL */
89 voidxcosjstringjava_lang_StringjlonglongID=NULL;
90 voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID=NULL;
91 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
92 voidcloseXcosFromScilabID=NULL;
93 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
94 voidxcosSimulationStartedID=NULL;
95
96
97 }
98
Xcos(JavaVM * jvm_,jobject JObj)99 Xcos::Xcos(JavaVM * jvm_, jobject JObj) {
100 jvm=jvm_;
101
102 JNIEnv * curEnv = getCurrentEnv();
103
104 jclass localClass = curEnv->GetObjectClass(JObj);
105 this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));
106 curEnv->DeleteLocalRef(localClass);
107
108 if (this->instanceClass == NULL) {
109 throw GiwsException::JniObjectCreationException(curEnv, this->className());
110 }
111
112 this->instance = curEnv->NewGlobalRef(JObj) ;
113 if(this->instance == NULL){
114 throw GiwsException::JniObjectCreationException(curEnv, this->className());
115 }
116 /* Methods ID set to NULL */
117 voidxcosjstringjava_lang_StringjlonglongID=NULL;
118 voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID=NULL;
119 voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID=NULL;
120 voidcloseXcosFromScilabID=NULL;
121 voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID=NULL;
122 voidxcosSimulationStartedID=NULL;
123
124
125 }
126
127 // Generic methods
128
synchronize()129 void Xcos::synchronize() {
130 if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
131 throw GiwsException::JniMonitorException(getCurrentEnv(), "Xcos");
132 }
133 }
134
endSynchronize()135 void Xcos::endSynchronize() {
136 if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
137 throw GiwsException::JniMonitorException(getCurrentEnv(), "Xcos");
138 }
139 }
140 // Method(s)
141
xcos(JavaVM * jvm_,char const * file,long long diagramId)142 void Xcos::xcos (JavaVM * jvm_, char const* file, long long diagramId){
143
144 JNIEnv * curEnv = NULL;
145 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
146 jclass cls = initClass(curEnv);
147 if ( cls == NULL) {
148 throw GiwsException::JniCallMethodException(curEnv);
149 }
150
151 static jmethodID voidxcosjstringjava_lang_StringjlonglongID = curEnv->GetStaticMethodID(cls, "xcos", "(Ljava/lang/String;J)V" ) ;
152 if (voidxcosjstringjava_lang_StringjlonglongID == NULL) {
153 throw GiwsException::JniMethodNotFoundException(curEnv, "xcos");
154 }
155
156 jstring file_ = curEnv->NewStringUTF( file );
157 if (file != NULL && file_ == NULL)
158 {
159 throw GiwsException::JniBadAllocException(curEnv);
160 }
161
162
163 curEnv->CallStaticVoidMethod(cls, voidxcosjstringjava_lang_StringjlonglongID ,file_, diagramId);
164 curEnv->DeleteLocalRef(file_);
165 if (curEnv->ExceptionCheck()) {
166 throw GiwsException::JniCallMethodException(curEnv);
167 }
168 }
169
xcosDiagramToScilab(JavaVM * jvm_,char const * file,long long diagramId,bool exported)170 void Xcos::xcosDiagramToScilab (JavaVM * jvm_, char const* file, long long diagramId, bool exported){
171
172 JNIEnv * curEnv = NULL;
173 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
174 jclass cls = initClass(curEnv);
175 if ( cls == NULL) {
176 throw GiwsException::JniCallMethodException(curEnv);
177 }
178
179 static jmethodID voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID = curEnv->GetStaticMethodID(cls, "xcosDiagramToScilab", "(Ljava/lang/String;JZ)V" ) ;
180 if (voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID == NULL) {
181 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosDiagramToScilab");
182 }
183
184 jstring file_ = curEnv->NewStringUTF( file );
185 if (file != NULL && file_ == NULL)
186 {
187 throw GiwsException::JniBadAllocException(curEnv);
188 }
189
190
191 jboolean exported_ = (static_cast<bool>(exported) ? JNI_TRUE : JNI_FALSE);
192
193 curEnv->CallStaticVoidMethod(cls, voidxcosDiagramToScilabjstringjava_lang_StringjlonglongjbooleanbooleanID ,file_, diagramId, exported_);
194 curEnv->DeleteLocalRef(file_);
195 if (curEnv->ExceptionCheck()) {
196 throw GiwsException::JniCallMethodException(curEnv);
197 }
198 }
199
warnCellByUID(JavaVM * jvm_,char const * const * uids,int uidsSize,char const * message)200 void Xcos::warnCellByUID (JavaVM * jvm_, char const* const* uids, int uidsSize, char const* message){
201
202 JNIEnv * curEnv = NULL;
203 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
204 jclass cls = initClass(curEnv);
205 if ( cls == NULL) {
206 throw GiwsException::JniCallMethodException(curEnv);
207 }
208
209 static jmethodID voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "warnCellByUID", "([Ljava/lang/String;Ljava/lang/String;)V" ) ;
210 if (voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID == NULL) {
211 throw GiwsException::JniMethodNotFoundException(curEnv, "warnCellByUID");
212 }
213 jclass stringArrayClass = curEnv->FindClass("java/lang/String");
214
215 // create java array of strings.
216 jobjectArray uids_ = curEnv->NewObjectArray( uidsSize, stringArrayClass, NULL);
217 if (uids_ == NULL)
218 {
219 throw GiwsException::JniBadAllocException(curEnv);
220 }
221
222 // convert each char * to java strings and fill the java array.
223 for ( int i = 0; i < uidsSize; i++)
224 {
225 jstring TempString = curEnv->NewStringUTF( uids[i] );
226 if (TempString == NULL)
227 {
228 throw GiwsException::JniBadAllocException(curEnv);
229 }
230
231 curEnv->SetObjectArrayElement( uids_, i, TempString);
232
233 // avoid keeping reference on too many strings
234 curEnv->DeleteLocalRef(TempString);
235 }
236 jstring message_ = curEnv->NewStringUTF( message );
237 if (message != NULL && message_ == NULL)
238 {
239 throw GiwsException::JniBadAllocException(curEnv);
240 }
241
242
243 curEnv->CallStaticVoidMethod(cls, voidwarnCellByUIDjobjectArray_java_lang_Stringjava_lang_Stringjstringjava_lang_StringID ,uids_, message_);
244 curEnv->DeleteLocalRef(stringArrayClass);
245 curEnv->DeleteLocalRef(uids_);
246 curEnv->DeleteLocalRef(message_);
247 if (curEnv->ExceptionCheck()) {
248 throw GiwsException::JniCallMethodException(curEnv);
249 }
250 }
251
closeXcosFromScilab(JavaVM * jvm_)252 void Xcos::closeXcosFromScilab (JavaVM * jvm_){
253
254 JNIEnv * curEnv = NULL;
255 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
256 jclass cls = initClass(curEnv);
257 if ( cls == NULL) {
258 throw GiwsException::JniCallMethodException(curEnv);
259 }
260
261 static jmethodID voidcloseXcosFromScilabID = curEnv->GetStaticMethodID(cls, "closeXcosFromScilab", "()V" ) ;
262 if (voidcloseXcosFromScilabID == NULL) {
263 throw GiwsException::JniMethodNotFoundException(curEnv, "closeXcosFromScilab");
264 }
265
266 curEnv->CallStaticVoidMethod(cls, voidcloseXcosFromScilabID );
267 if (curEnv->ExceptionCheck()) {
268 throw GiwsException::JniCallMethodException(curEnv);
269 }
270 }
271
addToolsMenu(JavaVM * jvm_,char const * label,char const * command)272 void Xcos::addToolsMenu (JavaVM * jvm_, char const* label, char const* command){
273
274 JNIEnv * curEnv = NULL;
275 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
276 jclass cls = initClass(curEnv);
277 if ( cls == NULL) {
278 throw GiwsException::JniCallMethodException(curEnv);
279 }
280
281 static jmethodID voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID = curEnv->GetStaticMethodID(cls, "addToolsMenu", "(Ljava/lang/String;Ljava/lang/String;)V" ) ;
282 if (voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID == NULL) {
283 throw GiwsException::JniMethodNotFoundException(curEnv, "addToolsMenu");
284 }
285
286 jstring label_ = curEnv->NewStringUTF( label );
287 if (label != NULL && label_ == NULL)
288 {
289 throw GiwsException::JniBadAllocException(curEnv);
290 }
291
292
293 jstring command_ = curEnv->NewStringUTF( command );
294 if (command != NULL && command_ == NULL)
295 {
296 throw GiwsException::JniBadAllocException(curEnv);
297 }
298
299
300 curEnv->CallStaticVoidMethod(cls, voidaddToolsMenujstringjava_lang_Stringjstringjava_lang_StringID ,label_, command_);
301 curEnv->DeleteLocalRef(label_);
302 curEnv->DeleteLocalRef(command_);
303 if (curEnv->ExceptionCheck()) {
304 throw GiwsException::JniCallMethodException(curEnv);
305 }
306 }
307
xcosSimulationStarted(JavaVM * jvm_)308 void Xcos::xcosSimulationStarted (JavaVM * jvm_){
309
310 JNIEnv * curEnv = NULL;
311 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
312 jclass cls = initClass(curEnv);
313 if ( cls == NULL) {
314 throw GiwsException::JniCallMethodException(curEnv);
315 }
316
317 static jmethodID voidxcosSimulationStartedID = curEnv->GetStaticMethodID(cls, "xcosSimulationStarted", "()V" ) ;
318 if (voidxcosSimulationStartedID == NULL) {
319 throw GiwsException::JniMethodNotFoundException(curEnv, "xcosSimulationStarted");
320 }
321
322 curEnv->CallStaticVoidMethod(cls, voidxcosSimulationStartedID );
323 if (curEnv->ExceptionCheck()) {
324 throw GiwsException::JniCallMethodException(curEnv);
325 }
326 }
327
328 }
329