]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/types/roboortegen.pl
8061347095b08c67e1a1640d9d1b1827d9e470c6
[eurobot/public.git] / src / types / roboortegen.pl
1 #!/usr/bin/perl
2
3 use CGI;                        # CGI
4 use CGI qw/:standard/;
5 use Getopt::Std;
6 use Data::Dumper;
7 use POSIX;
8
9 require "config.pl";
10
11 # getopts
12 &getopts("mtT:", \%options);
13 $target = $ARGV[0];
14 # $target = "../../types/robottype_eb2007.ortegen";
15 if (@ARGV < 1) {
16         &print_usage();
17         exit(1);
18 }
19 if (@ARGV > 1) {
20         $force_roboorte_name = $ARGV[1];
21 }
22
23 &main();
24
25 #
26 # main()
27 #
28 sub main {
29         my(@ortegen);
30         my(@files);
31         my($name);
32         my(@libnames);
33
34         if ( -d $target ) {
35                 @files = &get_files($target);
36         } else {
37                 push(@files, $target);
38                 $one_file = 1;
39         }
40
41         foreach $ortegenfile (@files) {
42                 $ortegenfilename = $ortegenfile;
43                 $ortegenfilename =~ s#(.*[/]+)?([^/]+).ortegen#$2#gs;
44
45                 if (defined($force_roboorte_name) and $one_file) {
46                         $roboorte_name = $force_roboorte_name;
47                 } else {
48                         $roboorte_name = $ortegenfilename;
49                 }
50
51                 @ortegen = &parse_ortegen($ortegenfile);
52 #               print Dumper(@ortegen);
53                 @ortegen = &fill_default_values(@ortegen);
54 #               print Dumper(@ortegen);
55
56                 &generate_roboorte_header(@ortegen);
57
58                 &generate_roboorte_library(@ortegen);
59
60                 if ($options{"t"} or $options{"T"}) {
61                         &generate_test_publisher(@ortegen);
62                         &generate_test_subscriber(@ortegen);
63                 }
64
65                 push(@libnames, $roboorte_name);
66                 push(@ortegenfilenames, $ortegenfilename);
67         }
68
69         if ($options{"m"}) {
70                 &generate_makefile(@libnames);
71         }
72
73         return 0;
74 }
75
76 #
77 #
78 #
79 sub print_usage {
80
81 print << "(END OF PRINT USAGE)";
82 Robot\'s ORTE library and test programs generator.
83
84 Usage: $0 <ORTEGEN directory or file> [force_roboorte_name]
85
86 \t-m            create Makefile
87 \t-t            create test files
88 \t-T <dir>      test directory
89
90 Example:
91 1) generate libraries, test programs and makefiles for all ORTEGEN file in
92 the directory <some_dir>, place all test files to directory test/
93
94 \t $0 -T test -m <some_dir>
95
96 2) generate libraries, test programs and makefiles and use name <some_name>
97 for this programs
98
99 \t $0 -t -m ../../types/file.ortegen <some_name>
100
101 (END OF PRINT USAGE)
102
103         return 0;
104 }
105
106 #
107 # Get ORTEGENs files list from a directory
108 #
109 # IN :
110 # OUT:
111 sub get_files {
112         my($dir) = @_;
113         
114         my(@file_list) = glob($dir."/*.ortegen");
115         
116         return @file_list;
117 }
118
119 #
120 # parse ORTE ORTEGEN file and return a data structure containing ORTE topics and their parameters
121 #
122 # IN    file name
123 # OUT   data structure
124 #
125 sub parse_ortegen {
126         my ($ortegenfile) = @_;
127         my ($content);
128         my (@ortegen);
129
130         # read 
131         unless (open(INFILE, "$ortegenfile")) {
132                 print "Unable to open file $ortegenfile\n";
133                 exit(1);
134         }
135         while (<INFILE>) {
136             $line = $_;
137             # removing C/C++ style comments
138             $line =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
139             # removing shell comments
140             $line =~ s!#.*!!gs;
141
142             next if $line =~ /^[\s]*$/;
143
144             my (%ortevar);
145
146             @fields = qw/topic type strength deadline persistance minsep pubdelay/;
147             foreach $field(@fields) {
148                 # Read the field value
149                 ($val) = $line =~ /\b$field=([\S]+)/;
150                 # Delete the field
151                 $line =~ s/$field=([\S]+)//g;
152                 
153                 $ortevar{$field} = $val;
154             }
155             if (!$ortevar{"type"}) { die("$ortegenfile:$.: type not defined\n"); }
156             if (!$ortevar{"topic"}) { die("$ortegenfile:$.: topic not defined\n"); }
157
158             $line =~ s/\s+/ /gs;
159             if ($line =~ /\S/) { die ("$ortegenfile:$.: unknown fields '$line'\nValid fields are: @fields\n"); }
160
161             push(@ortegen, \%ortevar);
162         }
163
164         close(INFILE);
165         return @ortegen;
166 }
167
168 sub fill_default_values {
169     my (@ortegen) = @_;
170     
171     foreach $var (@ortegen) {
172         if (!$var->{"persistence"}) { $var->{"persistence"} = $publication_persistence; }
173         if (!$var->{"strength"})    { $var->{"strength"} =    $publication_strength; }
174         if (!$var->{"deadline"})    { $var->{"deadline"} =    $subscription_deadline; }
175         if (!$var->{"minsep"})     { $var->{"minsep"} =             $minimum_separation; }
176         if (!$var->{"pubdelay"}) { $var->{"pubdelay"} = $publication_callback_delay; }
177         if (!$var->{"deadline"}) { $var->{"deadline"} = $subscription_deadline; }
178     }
179     return @ortegen;
180 }
181
182 #
183 #
184 #
185 sub generate_roboorte_header {
186         my(@ortegen) = @_;
187         my($headerfile) = $library_name_prefix.$roboorte_name.".h";
188
189         unless (open (OUTFILE, ">$headerfile")) {
190                 print "Unable to create file $headerfile\n";
191                 exit(1);
192         }
193
194 print OUTFILE << "(END)";
195 /**
196  * Automatically generated RoboORTE library.
197  * \@warning DO NOT EDIT!!! Instead modify the *.ortegen and config file.
198  */
199
200 #ifndef $library_name_prefix$roboorte_name\_H
201 #define $library_name_prefix$roboorte_name\_H
202
203 #include <stdio.h>
204
205 #include <orte.h>
206 #include <robottype.h>
207 #include <$ortegenfilename.h>
208
209 /* ORTE data */
210 struct ${roboorte_name}_orte_data {
211 \tORTEDomain *$orte_domain;
212 \tint strength;
213
214 \t/* orte data types */
215 (END)
216                 
217         foreach $var (@ortegen) {
218 print OUTFILE << "(END)";
219 \tstruct $var->{"type"}_type $var->{"topic"};
220 (END)
221         }
222
223 print OUTFILE << "(END)";
224
225 \t/* publishers */
226 (END)
227
228         foreach $var (@ortegen) {
229 print OUTFILE << "(END)";
230 \tORTEPublication *$publication_prefix$var->{"topic"};
231 (END)
232         }
233
234 print OUTFILE << "(END)";
235 };
236
237 #ifdef __cplusplus
238 extern "C" {
239 #endif
240 int ${roboorte_name}_roboorte_init(struct ${roboorte_name}_orte_data *data) __attribute ((warn_unused_result));
241 int ${roboorte_name}_roboorte_destroy(struct ${roboorte_name}_orte_data *data);
242
243 (END)
244
245         foreach $var (@ortegen) {
246 print OUTFILE << "(END)";
247 void ${roboorte_name}_publisher_$var->{"topic"}_create(struct ${roboorte_name}_orte_data *data, ORTESendCallBack callback, void *arg);
248 (END)
249         }
250
251 print OUTFILE << "(END)";
252
253 (END)
254
255         foreach $var (@ortegen) {
256 print OUTFILE << "(END)";
257 void ${roboorte_name}_publisher_$var->{"topic"}_destroy(struct ${roboorte_name}_orte_data *data);
258 (END)
259         }
260
261 print OUTFILE << "(END)";
262
263 (END)
264
265         foreach $var (@ortegen) {
266 print OUTFILE << "(END)";
267 void ${roboorte_name}_subscriber_$var->{"topic"}_create(struct ${roboorte_name}_orte_data *data, ORTERecvCallBack callback, void *arg);
268 (END)
269         }
270
271 print OUTFILE << "(END)";
272 #ifdef __cplusplus
273 }
274 #endif 
275
276 #endif /* $library_name_prefix$roboorte_name\_H */
277 (END)
278
279         close(OUTFILE);
280
281         return 0;
282 }
283
284 #
285 #
286 #
287 sub generate_roboorte_library {
288         my(@ortegen) = @_;
289         my($libraryfile) = $library_name_prefix.$roboorte_name.".c";
290
291         unless (open (OUTFILE, ">$libraryfile")) {
292                 print "Unable to create file $libraryfile\n";
293                 exit(1);
294         }
295
296 print OUTFILE << "(END)";
297 /**
298  * Automatically generated RoboORTE library.
299  * \@warning DO NOT EDIT!!! Instead modify the *.ortegen and config file.
300  */
301
302 #include "$library_name_prefix$roboorte_name.h"
303
304 /* ---------------------------------------------------------------------- 
305  * CREATE PUBLISHERS
306  * ---------------------------------------------------------------------- */
307
308 (END)
309
310         foreach $var (@ortegen) {
311             ($pmsec, $psec) = POSIX::modf($var->{"persistence"});
312             $pmsec = POSIX::floor($pmsec*1000);
313             ($dmsec, $dsec) = POSIX::modf($var->{"pubdelay"});
314             $dmsec = POSIX::floor($dmsec*1000);
315 print OUTFILE << "(END)";
316 void ${roboorte_name}_publisher_$var->{"topic"}_create(struct ${roboorte_name}_orte_data *data, ORTESendCallBack callback, void *arg)
317 {
318 \tNtpTime persistence, delay;
319
320 \t$var->{"type"}_type_register($data_arg_name->$orte_domain);
321 \tNtpTimeAssembFromMs(persistence, $psec, $pmsec);
322 \tNtpTimeAssembFromMs(delay, $dsec, $dmsec); 
323 \t$data_arg_name->$publication_prefix$var->{"topic"} = ORTEPublicationCreate(
324 \t\t\t$data_arg_name->$orte_domain, "$var->{"topic"}", "$var->{"type"}",
325 \t\t\t&$data_arg_name->$var->{"topic"}, &persistence, $data_arg_name->strength, 
326 \t\t\t$callback_name, $callback_arg, &delay);
327 }
328
329 (END)
330         }
331
332
333 print OUTFILE << "(END)";
334 /* ---------------------------------------------------------------------- 
335  * DESTROY PUBLISHERS
336  * ---------------------------------------------------------------------- */
337
338 (END)
339
340         foreach $var (@ortegen) {
341 print OUTFILE << "(END)";
342 void ${roboorte_name}_publisher_$var->{"topic"}_destroy(struct ${roboorte_name}_orte_data *data)
343 {
344 \tORTEPublicationDestroy($data_arg_name->$publication_prefix$var->{"topic"});
345 }
346
347 (END)
348         }
349
350         
351 print OUTFILE << "(END)";
352 /* ---------------------------------------------------------------------- 
353  * CREATE SUBSCRIBERS
354  * ---------------------------------------------------------------------- */
355
356 (END)
357
358         foreach $var (@ortegen) {
359             ($mmsec, $msec) = POSIX::modf($var->{"minsep"});
360             $mmsec = POSIX::floor($mmsec*1000);
361             ($dmsec, $dsec) = POSIX::modf($var->{"deadline"});
362             $dmsec = POSIX::floor($dmsec*1000);
363 print OUTFILE << "(END)";
364 void ${roboorte_name}_subscriber_$var->{"topic"}_create(struct ${roboorte_name}_orte_data *data, ORTERecvCallBack callback, void *arg)
365 {
366 \tORTESubscription *s;
367 \tNtpTime deadline, minimumSeparation;
368 \t
369 \t$var->{"type"}_type_register($data_arg_name->$orte_domain);
370 \t
371 \tNtpTimeAssembFromMs(deadline, $dsec, $dmsec);
372 \tNtpTimeAssembFromMs(minimumSeparation, $msec, $mmsec);
373 \ts = ORTESubscriptionCreate(
374 \t\t\t$data_arg_name->$orte_domain, $subscription_mode, $subscription_type, 
375 \t\t\t"$var->{"topic"}", "$var->{"type"}", 
376 \t\t\t&$data_arg_name->$var->{"topic"}, &deadline, &minimumSeparation,
377 \t\t\t$callback_name, $callback_arg, $multicast_ip_address);
378 }
379
380 (END)
381         }
382
383
384 print OUTFILE << "(END)";
385
386 /* ---------------------------------------------------------------------- 
387  * ORTE INITILIZATION AND DESTROY
388  * ---------------------------------------------------------------------- */
389
390 int ${roboorte_name}_roboorte_init(struct ${roboorte_name}_orte_data *data)
391 {
392 \tint rv = 0;
393 \tORTEDomainProp prop;
394 \tORTEInit();
395
396 \tif ($data_arg_name->strength <= 0)
397 \t\t$data_arg_name->strength = $publication_strength;
398
399 \tORTEVerbositySetOptions("ALL.0");
400 \tORTEDomainPropDefaultGet(&prop);
401 \tNTPTIME_BUILD(prop.baseProp.refreshPeriod, $refresh_period);
402 \tNTPTIME_BUILD(prop.baseProp.expirationTime, $expiration_time);
403 \t$data_arg_name->$orte_domain = ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,
404 \t                                      &prop, NULL, ORTE_FALSE);
405 \tif (!$data_arg_name->$orte_domain) {
406 \t\tprintf("ORTEDomainAppCreate failed!\\n");
407 \t\trv = -1;
408 \t}
409 \t
410 \treturn rv;
411 }
412
413 int ${roboorte_name}_roboorte_destroy(struct ${roboorte_name}_orte_data *data)
414 {
415 \treturn ORTEDomainAppDestroy($data_arg_name->$orte_domain);
416 }
417 (END)
418
419         close(OUTFILE);
420
421         return 0;
422 }
423
424 #
425 #
426 #
427 sub generate_makefile {
428         my(@files) = @_;
429         my($makefile) = "Makefile.omk";
430
431         unless (open (OUTFILE, ">$makefile")) {
432                 print "Unable to create $makefile\n";
433                 exit(1);
434         }
435
436         if ($testdir = $options{"T"}) {
437                 $testmakefile = "$testdir/$makefile";
438                 unless (open (MKOUTFILE, ">$testmakefile")) {
439                         print "Unable to create $testmakefile\n";
440                         exit(1);
441                 }
442 print MKOUTFILE << "(END)";
443
444 # Automatically generated Makefile file.
445 # \@warning DO NOT EDIT!!!
446
447 # -*- makefile -*-
448 #  Robot's ORTE library
449
450 (END)
451         } else {
452                 *MKOUTFILE = *OUTFILE;
453 print OUTFILE << "(END)";
454 # Automatically generated Makefile file.
455 # \@warning DO NOT EDIT!!!
456
457 # -*- makefile -*-
458 #  Robot's ORTE library
459
460 (END)
461         }
462
463         my($i) = 0;
464         foreach $filename (@files) {
465                 $testfilename1 = $test_publisher_name_prefix.$filename;
466                 $testfilename2 = $test_subscriber_name_prefix.$filename;
467                 $libraryname = $library_name_prefix.$filename;
468
469 print OUTFILE << "(END)";
470 lib_LIBRARIES += $libraryname
471 $libraryname\_SOURCES = $libraryname.c
472 include_HEADERS += $libraryname.h
473
474 (END)
475
476                 if ($options{"t"} or $options{"T"}) {
477 print MKOUTFILE << "(END)";
478 test_PROGRAMS += $testfilename1
479 $testfilename1\_SOURCES = $testfilename1.c
480 $testfilename1\_LIBS = pthread $libraryname robottype $ortegenfilenames[$i] orte
481
482 test_PROGRAMS += $testfilename2
483 $testfilename2\_SOURCES = $testfilename2.c
484 $testfilename2\_LIBS = pthread $libraryname robottype $ortegenfilenames[$i] orte
485
486 (END)
487                 }
488                 $i++;
489         }
490
491         if ($options{"T"}) {
492 print OUTFILE << "(END)";
493 SUBDIRS = test
494
495 clean-custom:
496 \t\$(Q)rm -rf *.c *.h Makefile.omk test/
497 (END)
498                 `cp -p Makefile $testdir`
499         } else {
500 print OUTFILE << "(END)";
501 clean-custom:
502 \t\$(Q)rm -rf *.c *.h Makefile.omk
503 (END)
504         }
505
506         close(OUTFILE);
507         if ($options{"T"}) {
508                 close(MKOUTFILE);
509         }
510
511         return 0;
512 }
513
514 #
515 #
516 #
517 sub generate_test_publisher {
518         my(@ortegen) = @_;
519         my($testfile) = $test_publisher_name_prefix.$roboorte_name.".c";
520         my($testdir);
521
522         if ($testdir = $options{"T"}) {
523                 $testfile = "$testdir/$testfile";
524                 `mkdir -p $testdir`;
525         }
526
527         unless (open (OUTFILE, ">$testfile")) {
528                 print "Unable to create file $testfile\n";
529                 exit(1);
530         }
531
532 print OUTFILE << "(END)";
533 /**
534  * Automatically generated test file for RoboORTE libraries.
535  * \@warning DO NOT EDIT!!! Instead modify the *.ortegen and config file.
536  */
537
538 #include <stdio.h>
539 #include <stdlib.h>
540 #include <pthread.h>
541 #include <unistd.h>
542 #include <signal.h>
543 #include <orte.h>
544 #include <$library_name_prefix$roboorte_name.h>
545
546 /* ---------------------------------------------------------------------- 
547  * PUBLISHER CALLBACKS
548  * ---------------------------------------------------------------------- */
549
550 (END)
551
552         foreach $var (@ortegen) {
553 print OUTFILE << "(END)";
554 void send_$var->{"topic"}_cb(const ORTESendInfo *info, void *vinstance, 
555 \t\t\tvoid *sendCallBackParam)
556 {
557 }
558
559 (END)
560         }
561
562 print OUTFILE << "(END)";
563
564 /* Thread process. Do the job. */
565 void *process(void *arg)
566 {
567 \tstruct $roboorte_name\_orte_data *orte = (struct $roboorte_name\_orte_data*)arg;
568 \tint i = 0;
569
570 \twhile (1) {
571 \t\tswitch(i) {
572 (END)
573
574         my($i) = 0;
575         foreach $var (@ortegen) {
576                 my(@var) = (@{$var->{"var"}});
577 print OUTFILE << "(END)";
578 \t\t\t/* $var->{"topic"} */
579 \t\t\tcase $i:
580 \t\t\t\tprintf("$var->{"topic"}:\\n");
581 (END)
582                 foreach $var (@var) {
583                         if ($var->{"type"} eq "double") {
584 print OUTFILE << "(END)";
585 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = ($var->{"type"})(rand() % 255);
586 \t\t\t\tprintf("\\t$var->{"topic"} = %f\\n", orte->$var->{"topic"}.$var->{"topic"});
587 (END)
588                         } elsif ( $var->{"type"} eq "octet" ) {
589 print OUTFILE << "(END)";
590 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = (unsigned char)(rand() % 255);
591 \t\t\t\tprintf("\\t$var->{"topic"} = 0x%02x\\n", orte->$var->{"topic"}.$var->{"topic"});
592 (END)
593                         } elsif ( $var->{"type"} eq "unsigned short" ) {
594 print OUTFILE << "(END)";
595 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = ($var->{"type"})(rand() % 255);
596 \t\t\t\tprintf("\\t$var->{"topic"} = %d\\n", orte->$var->{"topic"}.$var->{"topic"});
597 (END)
598                         } else {
599 print OUTFILE << "(END)";
600 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = (int)(rand() % 255);
601 \t\t\t\tprintf("\\t$var->{"topic"} = %d\\n", orte->$var->{"topic"}.$var->{"topic"});
602 (END)
603                         }
604                 }
605
606                 if (defined($publication_callback_enabled)) {
607 print OUTFILE << "(END)";
608 \t\t\t\t/*ORTEPublicationSend(orte->$publication_prefix$var->{"topic"});*/
609 \t\t\t\tbreak;
610
611 (END)
612                 } else {
613 print OUTFILE << "(END)";
614 \t\t\t\tORTEPublicationSend(orte->$publication_prefix$var->{"topic"});
615 \t\t\t\tbreak;
616
617 (END)
618                 }
619
620                 $i++;
621         }
622
623 print OUTFILE << "(END)";
624 \t\t\tdefault:
625 \t\t\t\tbreak;
626 \t\t}
627 \t\ti++;
628 \t\ti = i % $i;
629 \t\tusleep($publisher_thread_usleep);
630 \t}
631 }
632
633 /* Start thread */
634 void start_thread(struct $roboorte_name\_orte_data *orte)
635 {
636 \tint retcode;
637 \tpthread_t th;
638 \tvoid * retval;
639
640 \tretcode = pthread_create(&th, NULL, process, orte);
641 \tif (retcode != 0) 
642 \t\tprintf("Failed to create thread %d\\n", retcode);
643
644 \tretcode = pthread_join(th, &retval);
645 \tif (retcode != 0) 
646 \t\tprintf("Failed to join thread %d\\n", retcode);
647 }
648
649 struct $roboorte_name\_orte_data orte;
650
651 /* SIGINT handler */
652 static void int_handler(int sig)
653 {
654 \t$roboorte_name\_roboorte_destroy(&orte);
655 \texit(0);
656 }
657
658 int main()
659 {
660 \tsrand(time(0));
661
662 \tsignal(SIGINT, int_handler);
663
664 \torte.strength = $publication_strength;
665
666 \t/* orte initialization */
667 \t$roboorte_name\_roboorte_init(&orte);
668
669 \t/* creating publishers */
670 (END)
671
672         foreach $var (@ortegen) {
673                 if (defined($publication_callback_enabled)) {
674                         $publication_callback = "send_".$var->{"topic"}."_cb";
675                 } else {
676                         $publication_callback = "NULL";
677                 }
678
679 print OUTFILE << "(END)";
680 \t$roboorte_name\_publisher_$var->{"topic"}_create(&orte, $publication_callback, &orte);
681 (END)
682         }
683
684 print OUTFILE << "(END)";
685
686 \tprintf("Publishers: sending data.\\n");
687
688 \t/* start thread and do the job */
689 \tstart_thread(&orte);
690
691 \t/* orte domain destroy */
692 \t$roboorte_name\_roboorte_destroy(&orte);
693
694 \treturn 0;
695 }
696
697 (END)
698
699         close(OUTFILE);
700
701         return 0;
702 }
703
704 #
705 #
706 #
707 sub generate_test_subscriber {
708         my(@ortegen) = @_;
709         my($testfile) = $test_subscriber_name_prefix.$roboorte_name.".c";
710
711         if ($testdir = $options{"T"}) {
712                 $testfile = "$testdir/$testfile";
713                 `mkdir -p $testdir`;
714         }
715
716         unless (open (OUTFILE, ">$testfile")) {
717                 print "Unable to create file $testfile\n";
718                 exit(1);
719         }
720
721 print OUTFILE << "(END)";
722 /**
723  * Automatically generated test file for RoboORTE libraries.
724  * \@warning DO NOT EDIT!!! Instead modify the *.ortegen and config file.
725  */
726
727 #include <stdio.h>
728 #include <stdlib.h>
729 #include <unistd.h>
730 #include <signal.h>
731 #include <time.h>
732 #include <sys/time.h>
733 #include <orte.h>
734 #include <$library_name_prefix$roboorte_name.h>
735
736
737 void print_time()
738 {
739 \tstruct timeval tv;
740 \ttime_t curtime;
741 \tchar buffer[30];
742
743 \tgettimeofday(&tv, NULL);
744 \tcurtime = tv.tv_sec;
745 \tstrftime(buffer, 30, "[%T.", localtime(&curtime));
746 \tprintf("%s%ld]\\n", buffer, tv.tv_usec);
747 }
748
749 /* ---------------------------------------------------------------------- 
750  * SUBSCRIBER CALLBACKS
751  * ---------------------------------------------------------------------- */
752
753 (END)
754
755         foreach $var (@ortegen) {
756 print OUTFILE << "(END)";
757 void rcv_$var->{"topic"}_cb(const ORTERecvInfo *info, void *vinstance,
758 \t\t\tvoid *recvCallBackParam)
759 {
760 \tstruct $roboorte_name\_orte_data *orte = 
761 \t\t\t(struct $roboorte_name\_orte_data *)recvCallBackParam;
762 \t
763 \tswitch (info->status) {
764 \t\tcase NEW_DATA:
765 (END)
766                 if (defined($subscriber_print_data)) {
767 print OUTFILE << "(END)";
768 \t\t\tprint_time();
769 \t\t\tprintf("\\t$var->{"topic"}:\\n");
770 (END)
771                         my(@var) = (@{$var->{"var"}});
772                         foreach $var (@var) {
773 print OUTFILE << "(END)";
774 \t\t\t\tprintf("\\t\\t");
775 (END)
776                                 if ($var->{"type"} eq "double") {
777 print OUTFILE << "(END)";
778 \t\t\t\tprintf("$var->{"topic"} = %f\\n", orte->$var->{"topic"}.$var->{"topic"});
779 (END)
780                                 } elsif ( $var->{"type"} eq "octet" ) {
781 print OUTFILE << "(END)";
782 \t\t\t\tprintf("$var->{"topic"} = 0x%02x\\n", orte->$var->{"topic"}.$var->{"topic"});
783 (END)
784                                 } else {
785 print OUTFILE << "(END)";
786 \t\t\t\tprintf("$var->{"topic"} = %d\\n", orte->$var->{"topic"}.$var->{"topic"});
787 (END)
788                                 }
789                         }
790                 }
791                         
792 print OUTFILE << "(END)";
793 \t\t\tbreak;
794 \t\tcase DEADLINE:
795 \t\t\tprintf("ORTE deadline occurred - $var->{"topic"} receive\\n");
796 \t\t\tbreak;
797 \t}
798 }
799
800 (END)
801         }
802
803 print OUTFILE << "(END)";
804 struct $roboorte_name\_orte_data orte;
805
806 /* SIGINT handler */
807 static void int_handler(int sig)
808 {
809 \t$roboorte_name\_roboorte_destroy(&orte);
810 \texit(0);
811 }
812
813 int main()
814 {
815 \tsignal(SIGINT, int_handler);
816
817 \t/* orte initialization */
818 \t$roboorte_name\_roboorte_init(&orte);
819
820 \t/* creating subscribers */
821 (END)
822
823         foreach $var (@ortegen) {
824 print OUTFILE << "(END)";
825 \t$roboorte_name\_subscriber_$var->{"topic"}_create(&orte, rcv_$var->{"topic"}_cb, &orte);
826 (END)
827         }
828
829         unless (defined($subscriber_print_data)) {
830 print OUTFILE << "(END)";
831 \tprintf("Subscribers: debug print turned off.\\n");
832 (END)
833         }
834 print OUTFILE << "(END)";
835
836 \tprintf("Subscribers: waiting for data.\\n");
837 \twhile (1) {
838 \t\tusleep($subscriber_wait_usleep);
839 \t}
840
841 \t/* orte domain destroy */
842 \t$roboorte_name\_roboorte_destroy(&orte);
843
844 \treturn 0;
845 }
846
847 (END)
848
849         close(OUTFILE);
850
851         return 0;
852 }
853
854 1