]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTEDomainAppCreate.c
JORTE: fix typo
[orte.git] / orte / libjorte / JORTEDomainAppCreate.c
1 /* JORTEDomainAppCreate.c */
2
3 /**
4   * This code provides conversion between JAVA a C environments.
5   * The C functions are calling here and results are send to JAVA
6   * native functions. It uses the header pregenerated by JAVA
7   * (by command 'javah -jni class_with_native_function')
8   *
9   * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
10   * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
11   * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
12   * @author dedication to Kj
13   * @version 0.1
14   *
15   *
16   * This program is free software; you can redistribute it and/or modify
17   * it under the terms of the GNU General Public License as published by
18   * the Free Software Foundation; either version 2 of the License, or
19   * (at your option) any later version.
20   *
21   * This program is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24   * GNU General Public License for more details.
25   *
26   */
27
28 #include <stdlib.h>
29 // origin orte headers
30 #include "orte.h"
31 // pregenerated header
32 #include "jorte/org_ocera_orte_DomainApp.h"
33 // enable TEST_STAGE run level
34 #include "jorte/4all.h"
35 // new data types
36 #include "jorte/jorte_typedefs_defines.h"
37 #include "jorte/jorte_protos_api.h"
38
39 // /////////////////////////////////////////////////////////////////////
40 //  public void onRegFail()
41 // /////////////////////////////////////////////////////////////////////
42 Boolean
43 onRegFail(void *param)
44 {
45 // ///////////////////////////////// SPOLECNA CAST //
46   JavaVM          *jvm = NULL;
47   JNIEnv          *env = NULL; // local reference
48   jclass           cls;
49   jmethodID        mid;
50   //
51   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
52   int flag_ok = 0;
53
54   #ifdef TEST_STAGE
55       printf(":c: event func. 'onRegFail()' called.. \n");
56   #endif
57
58   do
59   {
60 // ///////////////////////////////// SPOLECNA CAST //
61     if(domain_events_cont->jvm == 0)
62     {
63      #ifdef TEST_STAGE
64        printf(":!c: jvm = NULL! \n");
65      #endif
66      break;
67     }
68     jvm = domain_events_cont->jvm;
69     // get env
70     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
71     if(env == 0)
72     {
73      #ifdef TEST_STAGE
74        printf(":!c: env = NULL! \n");
75      #endif
76      break;
77     }
78     // find class
79     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
80     if(cls == 0)
81     {
82      #ifdef TEST_STAGE
83        printf(":!c: cls = NULL! \n");
84      #endif
85      break;
86     }
87 // ///////////////////////////////// SPOLECNA CAST //
88     // get method ID
89     mid = (*env)->GetMethodID(env,
90                               cls,
91                               "onRegFail",
92                               "()V");
93     if(mid == 0)
94     {
95      #ifdef TEST_STAGE
96        printf(":!c: mid = NULL! \n");
97      #endif
98      break;
99     }
100     // call method
101     (*env)->CallVoidMethod(env,
102                            domain_events_cont->obj_de,
103                            mid);
104     flag_ok = 1;
105   } while(0);
106   // while broken
107   if(flag_ok)
108   {
109     if((*jvm)->DetachCurrentThread(jvm) != 0)
110     {
111       printf(":c!: DetachCurrentThread fault! \n");
112       return  ORTE_FALSE;
113     }
114   }
115
116   return ORTE_TRUE;
117 }
118
119
120 // /////////////////////////////////////////////////////////////////////
121 //  Event - public void onMgrNew()
122 // /////////////////////////////////////////////////////////////////////
123 Boolean
124 onMgrNew(const struct ORTEAppInfo *appInfo, void *param)
125 {
126 // ///////////////////////////////// SPOLECNA CAST //
127   JavaVM          *jvm = NULL;
128   JNIEnv          *env = NULL; // local reference
129   jclass           cls;
130   jobject          obj_ainfo;
131   jmethodID        mid;
132   //
133   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
134   int flag_ok = 0;
135
136   #ifdef TEST_STAGE
137       printf(":c: event func. 'onMgrNew()' called.. \n");
138   #endif
139
140   do
141   {
142 // ///////////////////////////////// SPOLECNA CAST //
143     if(domain_events_cont->jvm == 0)
144     {
145      #ifdef TEST_STAGE
146        printf(":!c: jvm = NULL! \n");
147      #endif
148      break;
149     }
150     jvm = domain_events_cont->jvm;
151     // get env
152     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
153     if(env == 0)
154     {
155      #ifdef TEST_STAGE
156        printf(":!c: env = NULL! \n");
157      #endif
158      break;
159     }
160     // find class
161     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
162     if(cls == 0)
163     {
164      #ifdef TEST_STAGE
165        printf(":!c: cls = NULL! \n");
166      #endif
167      break;
168     }
169     // create AppInfo instance
170     obj_ainfo = createAppInfo(env, appInfo);
171     if(obj_ainfo == 0)
172     {
173      #ifdef TEST_STAGE
174        printf(":!c: obj_ainfo = NULL! \n");
175      #endif
176      break;
177     }
178 // ///////////////////////////////// SPOLECNA CAST //
179     // get method ID
180     mid = (*env)->GetMethodID(env,
181                               cls,
182                               "onMgrNew",
183                               "(Lorg/ocera/orte/types/AppInfo;)V");
184     if(mid == 0)
185     {
186      #ifdef TEST_STAGE
187        printf(":!c: mid = NULL! \n");
188      #endif
189      break;
190     }
191     // call method
192     (*env)->CallVoidMethod(env,
193                            domain_events_cont->obj_de,
194                            mid,
195                            obj_ainfo);
196     flag_ok = 1;
197   } while(0);
198   // while broken
199   if(flag_ok)
200   {
201     if((*jvm)->DetachCurrentThread(jvm) != 0)
202     {
203       printf(":c!: DetachCurrentThread fault! \n");
204       return  ORTE_FALSE;
205     }
206   }
207
208   return ORTE_TRUE;
209 }
210
211
212 // /////////////////////////////////////////////////////////////////////
213 //  Event - public void onMgrDelete()
214 // /////////////////////////////////////////////////////////////////////
215 Boolean
216 onMgrDelete(const struct ORTEAppInfo *appInfo, void *param)
217 {
218 // ///////////////////////////////// SPOLECNA CAST //
219   JavaVM          *jvm = NULL;
220   JNIEnv          *env = NULL; // local reference
221   jclass           cls;
222   jobject          obj_ainfo;
223   jmethodID        mid;
224   //
225   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
226   int flag_ok = 0;
227
228   #ifdef TEST_STAGE
229       printf(":c: event func. 'onMgrDelete()' called.. \n");
230   #endif
231
232   do
233   {
234 // ///////////////////////////////// SPOLECNA CAST //
235     if(domain_events_cont->jvm == 0)
236     {
237      #ifdef TEST_STAGE
238        printf(":!c: jvm = NULL! \n");
239      #endif
240      break;
241     }
242     jvm = domain_events_cont->jvm;
243     // get env
244     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
245     if(env == 0)
246     {
247      #ifdef TEST_STAGE
248        printf(":!c: env = NULL! \n");
249      #endif
250      break;
251     }
252     // find class
253     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
254     if(cls == 0)
255     {
256      #ifdef TEST_STAGE
257        printf(":!c: cls = NULL! \n");
258      #endif
259      break;
260     }
261     // create AppInfo instance
262     obj_ainfo = createAppInfo(env, appInfo);
263     if(obj_ainfo == 0)
264     {
265      #ifdef TEST_STAGE
266        printf(":!c: obj_ainfo = NULL! \n");
267      #endif
268      break;
269     }
270 // ///////////////////////////////// SPOLECNA CAST //
271     // get method ID
272     mid = (*env)->GetMethodID(env,
273                               cls,
274                               "onMgrDelete",
275                               "(Lorg/ocera/orte/types/AppInfo;)V");
276     if(mid == 0)
277     {
278      #ifdef TEST_STAGE
279        printf(":!c: mid = NULL! \n");
280      #endif
281      break;
282     }
283     // call method
284     (*env)->CallVoidMethod(env,
285                            domain_events_cont->obj_de,
286                            mid,
287                            obj_ainfo);
288     flag_ok = 1;
289   } while(0);
290   // while broken
291   if(flag_ok)
292   {
293     if((*jvm)->DetachCurrentThread(jvm) != 0)
294     {
295       printf(":c!: DetachCurrentThread fault! \n");
296       return  ORTE_FALSE;
297     }
298   }
299
300   return ORTE_TRUE;
301 }
302
303
304
305 // /////////////////////////////////////////////////////////////////////
306 //  Event - onAppRemoteNew
307 // /////////////////////////////////////////////////////////////////////
308 Boolean
309 onAppRemoteNew(const struct ORTEAppInfo *appInfo, void *param)
310 {
311 // ///////////////////////////////// SPOLECNA CAST //
312   JavaVM          *jvm = NULL;
313   JNIEnv          *env = NULL; // local reference
314   jclass           cls;
315   jobject          obj_ainfo;
316   jmethodID        mid;
317   //
318   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
319   int flag_ok = 0;
320
321   #ifdef TEST_STAGE
322       printf(":c: event func. 'onAppRemoteNew()' called.. \n");
323   #endif
324
325   do
326   {
327 // ///////////////////////////////// SPOLECNA CAST //
328     if(domain_events_cont->jvm == 0)
329     {
330      #ifdef TEST_STAGE
331        printf(":!c: jvm = NULL! \n");
332      #endif
333      break;
334     }
335     jvm = domain_events_cont->jvm;
336     // get env
337     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
338     if(env == 0)
339     {
340      #ifdef TEST_STAGE
341        printf(":!c: env = NULL! \n");
342      #endif
343      break;
344     }
345     // find class
346     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
347     if(cls == 0)
348     {
349      #ifdef TEST_STAGE
350        printf(":!c: cls = NULL! \n");
351      #endif
352      break;
353     }
354     // create AppInfo instance
355     obj_ainfo = createAppInfo(env, appInfo);
356     if(obj_ainfo == 0)
357     {
358      #ifdef TEST_STAGE
359        printf(":!c: obj_ainfo = NULL! \n");
360      #endif
361      break;
362     }
363 // ///////////////////////////////// SPOLECNA CAST //
364
365     // get method ID
366     mid = (*env)->GetMethodID(env,
367                               cls,
368                               "onAppRemoteNew",
369                               "(Lorg/ocera/orte/types/AppInfo;)V");
370     if(mid == 0)
371     {
372      #ifdef TEST_STAGE
373        printf(":!c: mid = NULL! \n");
374      #endif
375      break;
376     }
377     // call method
378     (*env)->CallVoidMethod(env,
379                            domain_events_cont->obj_de,
380                            mid,
381                            obj_ainfo);
382     flag_ok = 1;
383   } while(0);
384   // while broken
385   if(flag_ok)
386   {
387     if((*jvm)->DetachCurrentThread(jvm) != 0)
388     {
389       printf(":c!: DetachCurrentThread fault! \n");
390       return  ORTE_FALSE;
391     }
392   }
393
394   return ORTE_TRUE;
395 }
396
397
398 // /////////////////////////////////////////////////////////////////////
399 //  public void onAppDelete() { }
400 // /////////////////////////////////////////////////////////////////////
401 Boolean
402 onAppDelete(const struct ORTEAppInfo *appInfo, void *param)
403 {
404 // ///////////////////////////////// SPOLECNA CAST //
405   JavaVM          *jvm = NULL;
406   JNIEnv          *env = NULL; // local reference
407   jclass           cls;
408   jobject          obj_ainfo;
409   jmethodID        mid;
410   //
411   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
412   int flag_ok = 0;
413
414   #ifdef TEST_STAGE
415       printf(":c: event func. 'onAppDelete()' called.. \n");
416   #endif
417
418   do
419   {
420 // ///////////////////////////////// SPOLECNA CAST //
421     if(domain_events_cont->jvm == 0)
422     {
423      #ifdef TEST_STAGE
424        printf(":!c: jvm = NULL! \n");
425      #endif
426      break;
427     }
428     jvm = domain_events_cont->jvm;
429     // get env
430     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
431     if(env == 0)
432     {
433      #ifdef TEST_STAGE
434        printf(":!c: env = NULL! \n");
435      #endif
436      break;
437     }
438     // find class
439     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
440     if(cls == 0)
441     {
442      #ifdef TEST_STAGE
443        printf(":!c: cls = NULL! \n");
444      #endif
445      break;
446     }
447     // create AppInfo instance
448     obj_ainfo = createAppInfo(env, appInfo);
449     if(obj_ainfo == 0)
450     {
451      #ifdef TEST_STAGE
452        printf(":!c: obj_ainfo = NULL! \n");
453      #endif
454      break;
455     }
456 // ///////////////////////////////// SPOLECNA CAST //
457     // get method ID
458     mid = (*env)->GetMethodID(env,
459                               cls,
460                               "onAppDelete",
461                               "(Lorg/ocera/orte/types/AppInfo;)V");
462     if(mid == 0)
463     {
464      #ifdef TEST_STAGE
465        printf(":!c: mid = NULL! \n");
466      #endif
467      break;
468     }
469     // call method
470     (*env)->CallVoidMethod(env,
471                            domain_events_cont->obj_de,
472                            mid,
473                            obj_ainfo);
474     flag_ok = 1;
475   } while(0);
476   // while broken
477   if(flag_ok)
478   {
479     if((*jvm)->DetachCurrentThread(jvm) != 0)
480     {
481       printf(":c!: DetachCurrentThread fault! \n");
482       return  ORTE_FALSE;
483     }
484   }
485
486   return ORTE_TRUE;
487 }
488
489
490 // /////////////////////////////////////////////////////////////////////
491 //  public void onPubRemoteNew()
492 // /////////////////////////////////////////////////////////////////////
493 Boolean
494 onPubRemoteNew(const struct ORTEAppInfo *appInfo,
495                const struct ORTEPubInfo *pubInfo,
496                void *param)
497 {
498 // ///////////////////////////////// SPOLECNA CAST //
499   JavaVM          *jvm = NULL;
500   JNIEnv          *env = NULL; // local reference
501   jclass           cls;
502   jobject          obj_ainfo;
503   jobject          obj_pinfo;
504   jmethodID        mid;
505   //
506   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
507   int flag_ok = 0;
508
509   #ifdef TEST_STAGE
510       printf(":c: event func. 'onPubRemoteNew()' called.. \n");
511   #endif
512
513   do
514   {
515 // ///////////////////////////////// SPOLECNA CAST //
516     if(domain_events_cont->jvm == 0)
517     {
518      #ifdef TEST_STAGE
519        printf(":!c: jvm = NULL! \n");
520      #endif
521      break;
522     }
523     jvm = domain_events_cont->jvm;
524     // get env
525     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
526     if(env == 0)
527     {
528      #ifdef TEST_STAGE
529        printf(":!c: env = NULL! \n");
530      #endif
531      break;
532     }
533     // find class
534     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
535     if(cls == 0)
536     {
537      #ifdef TEST_STAGE
538        printf(":!c: cls = NULL! \n");
539      #endif
540      break;
541     }
542     // create AppInfo instance
543     obj_ainfo = createAppInfo(env, appInfo);
544     if(obj_ainfo == 0)
545     {
546      #ifdef TEST_STAGE
547        printf(":!c: obj_ainfo = NULL! \n");
548      #endif
549      break;
550     }
551     // create PubInfo instance
552     obj_pinfo = createPubInfo(env, pubInfo);
553     if(obj_pinfo == 0)
554     {
555      #ifdef TEST_STAGE
556        printf(":!c: obj_pinfo = NULL! \n");
557      #endif
558      break;
559     }
560 // ///////////////////////////////// SPOLECNA CAST //
561     // get method ID
562     mid = (*env)->GetMethodID(env,
563                               cls,
564                               "onPubRemoteNew",
565                               "(Lorg/ocera/orte/types/AppInfo;Lorg/ocera/orte/types/PubInfo;)V");
566     if(mid == 0)
567     {
568      #ifdef TEST_STAGE
569        printf(":!c: mid = NULL! \n");
570      #endif
571      break;
572     }
573     // call method
574     (*env)->CallVoidMethod(env,
575                            domain_events_cont->obj_de,
576                            mid,
577                            obj_ainfo,
578                            obj_pinfo);
579     flag_ok = 1;
580   } while(0);
581   // while broken
582   if(flag_ok)
583   {
584     if((*jvm)->DetachCurrentThread(jvm) != 0)
585     {
586       printf(":c!: DetachCurrentThread fault! \n");
587       return  ORTE_FALSE;
588     }
589   }
590
591   return ORTE_TRUE;
592 }
593
594
595 // /////////////////////////////////////////////////////////////////////
596 //public void onPubRemoteChanged()
597 // /////////////////////////////////////////////////////////////////////
598 Boolean
599 onPubRemoteChanged(const struct ORTEAppInfo *appInfo,
600                    const struct ORTEPubInfo *pubInfo,
601                    void *param)
602 {
603 // ///////////////////////////////// SPOLECNA CAST //
604   JavaVM          *jvm = NULL;
605   JNIEnv          *env = NULL; // local reference
606   jclass           cls;
607   jobject          obj_ainfo;
608   jobject          obj_pinfo;
609   jmethodID        mid;
610   //
611   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
612   int flag_ok = 0;
613
614   #ifdef TEST_STAGE
615       printf(":c: event func. 'onPubRemoteChanged()' called.. \n");
616   #endif
617
618   do
619   {
620 // ///////////////////////////////// SPOLECNA CAST //
621     if(domain_events_cont->jvm == 0)
622     {
623      #ifdef TEST_STAGE
624        printf(":!c: jvm = NULL! \n");
625      #endif
626      break;
627     }
628     jvm = domain_events_cont->jvm;
629     // get env
630     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
631     if(env == 0)
632     {
633      #ifdef TEST_STAGE
634        printf(":!c: env = NULL! \n");
635      #endif
636      break;
637     }
638     // find class
639     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
640     if(cls == 0)
641     {
642      #ifdef TEST_STAGE
643        printf(":!c: cls = NULL! \n");
644      #endif
645      break;
646     }
647     // create AppInfo instance
648     obj_ainfo = createAppInfo(env, appInfo);
649     if(obj_ainfo == 0)
650     {
651      #ifdef TEST_STAGE
652        printf(":!c: obj_ainfo = NULL! \n");
653      #endif
654      break;
655     }
656     // create PubInfo instance
657     obj_pinfo = createPubInfo(env, pubInfo);
658     if(obj_pinfo == 0)
659     {
660      #ifdef TEST_STAGE
661        printf(":!c: obj_pinfo = NULL! \n");
662      #endif
663      break;
664     }
665 // ///////////////////////////////// SPOLECNA CAST //
666     // get method ID
667     mid = (*env)->GetMethodID(env,
668                               cls,
669                               "onPubRemoteChanged",
670                               "(Lorg/ocera/orte/types/AppInfo;Lorg/ocera/orte/types/PubInfo;)V");
671     if(mid == 0)
672     {
673      #ifdef TEST_STAGE
674        printf(":!c: mid = NULL! \n");
675      #endif
676      break;
677     }
678     // call method
679     (*env)->CallVoidMethod(env,
680                            domain_events_cont->obj_de,
681                            mid,
682                            obj_ainfo,
683                            obj_pinfo);
684     flag_ok = 1;
685   } while(0);
686   // while broken
687   if(flag_ok)
688   {
689     if((*jvm)->DetachCurrentThread(jvm) != 0)
690     {
691       printf(":c!: DetachCurrentThread fault! \n");
692       return  ORTE_FALSE;
693     }
694   }
695
696   return ORTE_TRUE;
697 }
698
699
700
701
702 // /////////////////////////////////////////////////////////////////////
703 //  public void onPubDelete()
704 // /////////////////////////////////////////////////////////////////////
705 Boolean
706 onPubDelete(const struct ORTEAppInfo *appInfo,
707             const struct ORTEPubInfo *pubInfo,
708             void *param)
709 {
710 // ///////////////////////////////// SPOLECNA CAST //
711   JavaVM          *jvm = NULL;
712   JNIEnv          *env = NULL; // local reference
713   jclass           cls;
714   jobject          obj_ainfo;
715   jobject          obj_pinfo;
716   jmethodID        mid;
717   //
718   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
719   int flag_ok = 0;
720
721   #ifdef TEST_STAGE
722       printf(":c: event func. 'onPubDelete()' called.. \n");
723   #endif
724
725   do
726   {
727 // ///////////////////////////////// SPOLECNA CAST //
728     if(domain_events_cont->jvm == 0)
729     {
730      #ifdef TEST_STAGE
731        printf(":!c: jvm = NULL! \n");
732      #endif
733      break;
734     }
735     jvm = domain_events_cont->jvm;
736     // get env
737     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
738     if(env == 0)
739     {
740      #ifdef TEST_STAGE
741        printf(":!c: env = NULL! \n");
742      #endif
743      break;
744     }
745     // find class
746     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
747     if(cls == 0)
748     {
749      #ifdef TEST_STAGE
750        printf(":!c: cls = NULL! \n");
751      #endif
752      break;
753     }
754     // create AppInfo instance
755     obj_ainfo = createAppInfo(env, appInfo);
756     if(obj_ainfo == 0)
757     {
758      #ifdef TEST_STAGE
759        printf(":!c: obj_ainfo = NULL! \n");
760      #endif
761      break;
762     }
763     // create PubInfo instance
764     obj_pinfo = createPubInfo(env, pubInfo);
765     if(obj_pinfo == 0)
766     {
767      #ifdef TEST_STAGE
768        printf(":!c: obj_pinfo = NULL! \n");
769      #endif
770      break;
771     }
772 // ///////////////////////////////// SPOLECNA CAST //
773     // get method ID
774     mid = (*env)->GetMethodID(env,
775                               cls,
776                               "onPubDelete",
777                               "(Lorg/ocera/orte/types/AppInfo;Lorg/ocera/orte/types/PubInfo;)V");
778     if(mid == 0)
779     {
780      #ifdef TEST_STAGE
781        printf(":!c: mid = NULL! \n");
782      #endif
783      break;
784     }
785     // call method
786     (*env)->CallVoidMethod(env,
787                            domain_events_cont->obj_de,
788                            mid,
789                            obj_ainfo,
790                            obj_pinfo);
791     flag_ok = 1;
792   } while(0);
793   // while broken
794   if(flag_ok)
795   {
796     if((*jvm)->DetachCurrentThread(jvm) != 0)
797     {
798       printf(":c!: DetachCurrentThread fault! \n");
799       return  ORTE_FALSE;
800     }
801   }
802
803   return ORTE_TRUE;
804 }
805
806
807 // /////////////////////////////////////////////////////////////////////
808 //  Event - onSubRemoteNew
809 // /////////////////////////////////////////////////////////////////////
810 Boolean
811 onSubRemoteNew(const struct ORTEAppInfo *appInfo,
812                const struct ORTESubInfo *subInfo,
813                void *param)
814 {
815 // ///////////////////////////////// SPOLECNA CAST //
816   JavaVM          *jvm = NULL;
817   JNIEnv          *env = NULL; // local reference
818   jobject          obj_ainfo;
819   jobject          obj_sinfo;
820   jclass           cls;
821   jmethodID        mid;
822   //
823   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
824   int flag_ok = 0;
825
826   #ifdef TEST_STAGE
827       printf(":c: event func. 'onSubRemoteNew()' called.. \n");
828   #endif
829
830   do
831   {
832 // ///////////////////////////////// SPOLECNA CAST //
833     if(domain_events_cont->jvm == 0)
834     {
835      #ifdef TEST_STAGE
836        printf(":!c: jvm = NULL! \n");
837      #endif
838      break;
839     }
840     jvm = domain_events_cont->jvm;
841     // get env
842     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
843     if(env == 0)
844     {
845      #ifdef TEST_STAGE
846        printf(":!c: env = NULL! \n");
847      #endif
848      break;
849     }
850     // find class
851     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
852     if(cls == 0)
853     {
854      #ifdef TEST_STAGE
855        printf(":!c: cls = NULL! \n");
856      #endif
857      break;
858     }
859     // create AppInfo instance
860     obj_ainfo = createAppInfo(env, appInfo);
861     if(obj_ainfo == 0)
862     {
863      #ifdef TEST_STAGE
864        printf(":!c: obj_ainfo = NULL! \n");
865      #endif
866      break;
867     }
868     // create SubInfo instance
869     obj_sinfo = createSubInfo(env, subInfo);
870     if(obj_sinfo == 0)
871     {
872      #ifdef TEST_STAGE
873        printf(":!c: obj_sinfo = NULL! \n");
874      #endif
875      break;
876     }
877 // ///////////////////////////////// SPOLECNA CAST //
878     // get method ID
879     mid = (*env)->GetMethodID(env,
880                               cls,
881                               "onSubRemoteNew",
882                               "(Lorg/ocera/orte/types/AppInfo;Lorg/ocera/orte/types/SubInfo;)V");
883     if(mid == 0)
884     {
885      #ifdef TEST_STAGE
886        printf(":!c: mid = NULL! \n");
887      #endif
888      break;
889     }
890     // call method
891     (*env)->CallVoidMethod(env,
892                            domain_events_cont->obj_de,
893                            mid,
894                            obj_ainfo,
895                            obj_sinfo);
896     flag_ok = 1;
897   } while(0);
898   // while broken
899   if(flag_ok)
900   {
901     if((*jvm)->DetachCurrentThread(jvm) != 0)
902     {
903       printf(":c!: DetachCurrentThread fault! \n");
904       return  ORTE_FALSE;
905     }
906   }
907
908   return ORTE_TRUE;
909 }
910
911
912 // /////////////////////////////////////////////////////////////////////
913 //  public void onSubRemoteChanged() { }
914 // /////////////////////////////////////////////////////////////////////
915 Boolean
916 onSubRemoteChanged(const struct ORTEAppInfo *appInfo,
917                    const struct ORTESubInfo *subInfo,
918                    void *param)
919 {
920 // ///////////////////////////////// SPOLECNA CAST //
921   JavaVM          *jvm = NULL;
922   JNIEnv          *env = NULL; // local reference
923   jclass           cls;
924   jobject          obj_ainfo;
925   jobject          obj_sinfo;
926   jmethodID        mid;
927   //
928   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
929   int flag_ok = 0;
930
931   #ifdef TEST_STAGE
932       printf(":c: event func. 'onSubRemoteChanged()' called.. \n");
933   #endif
934
935   do
936   {
937 // ///////////////////////////////// SPOLECNA CAST //
938     if(domain_events_cont->jvm == 0)
939     {
940      #ifdef TEST_STAGE
941        printf(":!c: jvm = NULL! \n");
942      #endif
943      break;
944     }
945     jvm = domain_events_cont->jvm;
946     // get env
947     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
948     if(env == 0)
949     {
950      #ifdef TEST_STAGE
951        printf(":!c: env = NULL! \n");
952      #endif
953      break;
954     }
955     // find class
956     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
957     if(cls == 0)
958     {
959      #ifdef TEST_STAGE
960        printf(":!c: cls = NULL! \n");
961      #endif
962      break;
963     }
964     // create AppInfo instance
965     obj_ainfo = createAppInfo(env, appInfo);
966     if(obj_ainfo == 0)
967     {
968      #ifdef TEST_STAGE
969        printf(":!c: obj_ainfo = NULL! \n");
970      #endif
971      break;
972     }
973     // create SubInfo instance
974     obj_sinfo = createSubInfo(env, subInfo);
975     if(obj_sinfo == 0)
976     {
977      #ifdef TEST_STAGE
978        printf(":!c: obj_sinfo = NULL! \n");
979      #endif
980      break;
981     }
982 // ///////////////////////////////// SPOLECNA CAST //
983     // get method ID
984     mid = (*env)->GetMethodID(env,
985                               cls,
986                               "onSubRemoteChanged",
987                               "(Lorg/ocera/orte/types/AppInfo;Lorg/ocera/orte/types/SubInfo;)V");
988     if(mid == 0)
989     {
990      #ifdef TEST_STAGE
991        printf(":!c: mid = NULL! \n");
992      #endif
993      break;
994     }
995     // call method
996     (*env)->CallVoidMethod(env,
997                            domain_events_cont->obj_de,
998                            mid,
999                            obj_ainfo,
1000                            obj_sinfo);
1001     flag_ok = 1;
1002   } while(0);
1003   // while broken
1004   if(flag_ok)
1005   {
1006     if((*jvm)->DetachCurrentThread(jvm) != 0)
1007     {
1008       printf(":c!: DetachCurrentThread fault! \n");
1009       return  ORTE_FALSE;
1010     }
1011   }
1012
1013   return ORTE_TRUE;
1014 }
1015
1016
1017 // /////////////////////////////////////////////////////////////////////
1018 //  public void onSubDelete() { }
1019 // /////////////////////////////////////////////////////////////////////
1020 Boolean
1021 onSubDelete(const struct ORTEAppInfo *appInfo,
1022             const struct ORTESubInfo *subInfo,
1023             void *param)
1024 {
1025 // ///////////////////////////////// SPOLECNA CAST //
1026   JavaVM          *jvm = NULL;
1027   JNIEnv          *env = NULL; // local reference
1028   jclass           cls;
1029   jobject          obj_ainfo;
1030   jobject          obj_sinfo;
1031   jmethodID        mid;
1032   //
1033   JORTEDomainEventsContext_t   *domain_events_cont = (JORTEDomainEventsContext_t*) param;
1034   int flag_ok = 0;
1035
1036   #ifdef TEST_STAGE
1037       printf(":c: event func. 'onSubDelete()' called.. \n");
1038   #endif
1039
1040   do
1041   {
1042 // ///////////////////////////////// SPOLECNA CAST //
1043     if(domain_events_cont->jvm == 0)
1044     {
1045      #ifdef TEST_STAGE
1046        printf(":!c: jvm = NULL! \n");
1047      #endif
1048      break;
1049     }
1050     jvm = domain_events_cont->jvm;
1051     // get env
1052     (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
1053     if(env == 0)
1054     {
1055      #ifdef TEST_STAGE
1056        printf(":!c: env = NULL! \n");
1057      #endif
1058      break;
1059     }
1060     // find class
1061     cls = (*env)->FindClass(env, "org/ocera/orte/types/DomainEvents");
1062     if(cls == 0)
1063     {
1064      #ifdef TEST_STAGE
1065        printf(":!c: cls = NULL! \n");
1066      #endif
1067      break;
1068     }
1069     // create AppInfo instance
1070     obj_ainfo = createAppInfo(env, appInfo);
1071     if(obj_ainfo == 0)
1072     {
1073      #ifdef TEST_STAGE
1074        printf(":!c: obj_ainfo = NULL! \n");
1075      #endif
1076      break;
1077     }
1078     // create SubInfo instance
1079     obj_sinfo = createSubInfo(env, subInfo);
1080     if(obj_sinfo == 0)
1081     {
1082      #ifdef TEST_STAGE
1083        printf(":!c: obj_sinfo = NULL! \n");
1084      #endif
1085      break;
1086     }
1087 // ///////////////////////////////// SPOLECNA CAST //
1088     // get method ID
1089     mid = (*env)->GetMethodID(env,
1090                               cls,
1091                               "onSubDelete",
1092                               "(Lorg/ocera/orte/types/AppInfo;Lorg/ocera/orte/types/SubInfo;)V");
1093     if(mid == 0)
1094     {
1095      #ifdef TEST_STAGE
1096        printf(":!c: mid = NULL! \n");
1097      #endif
1098      break;
1099     }
1100     // call method
1101     (*env)->CallVoidMethod(env,
1102                            domain_events_cont->obj_de,
1103                            mid,
1104                            obj_ainfo,
1105                            obj_sinfo);
1106     flag_ok = 1;
1107   } while(0);
1108   // while broken
1109   if(flag_ok)
1110   {
1111     if((*jvm)->DetachCurrentThread(jvm) != 0)
1112     {
1113       printf(":c!: DetachCurrentThread fault! \n");
1114       return  ORTE_FALSE;
1115     }
1116   }
1117
1118   return ORTE_TRUE;
1119 }
1120
1121
1122 // /////////////////////////////////////////////////////////////////////
1123 // create default application domain
1124 // /////////////////////////////////////////////////////////////////////
1125 JNIEXPORT jint JNICALL
1126 Java_org_ocera_orte_DomainApp_jORTEDomainDefaultAppCreate
1127 (JNIEnv *env, jclass class, jint jdomain, jboolean jsusp)
1128 {
1129   jint      d;
1130
1131   #ifdef TEST_STAGE
1132     printf(":c: jsem pred ORTEDomainDefaultAppCreate() \n");
1133   #endif
1134   // call ORTE function
1135   d = (jint) ORTEDomainAppCreate((int)jdomain,
1136                                  NULL,
1137                                  NULL,
1138                                  (Boolean) jsusp);
1139   if(!d) {
1140     printf(":!c: ORTEDomainDefaultAppCreate() FAILED.. \n");
1141     return 0;
1142   }
1143   #ifdef TEST_STAGE
1144     printf(":c: ORTEDomainDefautlAppCreate() ok.. + %d \n", d);
1145   #endif
1146   return (d);
1147 }
1148
1149 // //////////////////////////////////////////////////////////////////////
1150 // create user application domain
1151 // //////////////////////////////////////////////////////////////////////
1152 JNIEXPORT jint JNICALL
1153 Java_org_ocera_orte_DomainApp_jORTEDomainAppCreate
1154 (JNIEnv *env, jclass cls,
1155  jint jdomain,
1156  jint propHandle,
1157  jint eventsHandle,
1158  jobject obj_de,
1159  jboolean jsusp)
1160 {
1161   // jni varibles
1162   JavaVM                 *jvm;
1163   jint                    d;
1164   //
1165   ORTEDomainAppEvents    *dom_events;
1166   JORTEDomainEventsContext_t  *domain_events_cont;
1167
1168   #ifdef TEST_STAGE
1169     printf(":c: ORTEDomainAppCreate() called.. \n");
1170   #endif
1171   // memory alocation
1172   // don't forget free memory - free()!!
1173   domain_events_cont = (JORTEDomainEventsContext_t *) malloc(sizeof(JORTEDomainEventsContext_t));
1174   // get jvm
1175   jint b = (*env)->GetJavaVM(env,&jvm);
1176   if (b < 0)
1177   {
1178     printf(":!c: getJavaVM() failed! \n");
1179     return 0;
1180   }
1181   // create global references
1182   domain_events_cont->jvm = jvm;
1183   // domain events
1184   domain_events_cont->obj_de = (*env)->NewGlobalRef(env, obj_de);
1185   // get new events
1186   dom_events = (ORTEDomainAppEvents *) eventsHandle;
1187   ////////////////////////////////////////////////
1188   // set new events & their prarameters
1189   // onRegFail
1190   dom_events->onRegFail = (ORTEOnRegFail) onRegFail;
1191   dom_events->onRegFailParam = (void *) domain_events_cont;
1192   // onMgrNew
1193   dom_events->onMgrNew = (ORTEOnMgrNew) onMgrNew;
1194   dom_events->onMgrNewParam = (void *) domain_events_cont;
1195   // onMgrDelete
1196   dom_events->onMgrDelete = (ORTEOnMgrDelete) onMgrDelete;
1197   dom_events->onMgrDeleteParam = (void *) domain_events_cont;
1198   // onAppRemoteNew
1199   dom_events->onAppRemoteNew = (ORTEOnAppRemoteNew) onAppRemoteNew;
1200   dom_events->onAppRemoteNewParam = (void *) domain_events_cont;
1201   // onAppDelete
1202   dom_events->onAppDelete = (ORTEOnAppDelete) onAppDelete;
1203   dom_events->onAppDeleteParam = (void *) domain_events_cont;
1204   // onPubRemoteNew
1205   dom_events->onPubRemoteNew = (ORTEOnPubRemote) onPubRemoteNew;
1206   dom_events->onPubRemoteNewParam = (void *) domain_events_cont;
1207   // onPubRemoteChanged
1208   dom_events->onPubRemoteChanged = (ORTEOnPubRemote) onPubRemoteChanged;
1209   dom_events->onPubRemoteChangedParam = (void *) domain_events_cont;
1210   // onPubDelete
1211   dom_events->onPubDelete = (ORTEOnPubDelete) onPubDelete;
1212   dom_events->onPubDeleteParam = (void *) domain_events_cont;
1213   // onSubRemoteNew
1214   dom_events->onSubRemoteNew = (ORTEOnSubRemote) onSubRemoteNew;
1215   dom_events->onSubRemoteNewParam = (void *) domain_events_cont;
1216   // onSubRemoteChanged
1217   dom_events->onSubRemoteChanged = (ORTEOnSubRemote) onSubRemoteChanged;
1218   dom_events->onSubRemoteChangedParam = (void *) domain_events_cont;
1219   // onSubDelete
1220   dom_events->onSubDelete = (ORTEOnSubDelete) onSubDelete;
1221   dom_events->onSubDeleteParam = (void *) domain_events_cont;
1222   ////////////////////////////////////////////////
1223   // call ORTE function
1224   d = (jint) ORTEDomainAppCreate((int)jdomain,
1225                                  (ORTEDomainProp *) propHandle,
1226                                  (ORTEDomainAppEvents *) eventsHandle,
1227                                  (Boolean) jsusp);
1228   if(!d) {
1229     printf(":!c: creating app domain failed! [NULL handle]  \n");
1230     return 0;
1231   }
1232   #ifdef TEST_STAGE
1233     printf(":c: ORTEDomainAppCreate() ok.. + %d \n", d);
1234   #endif
1235   return (d);
1236 }