]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/types/roboortegen.pl
roboortegen: Fixed registration of subscribers with type != topic
[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 #include <roboorte.h>
209
210 #undef ROBOORTE_ROBOT_NAME
211 #define ROBOORTE_ROBOT_NAME     $roboorte_name
212
213 #ifndef ROBOORTE_ROBOT_NAME
214 #error No ROBOORTE_ROBOT_NAME defined!
215 #endif
216
217 /* ORTE data */
218 ROBOORTE_DATA {
219 \tORTEDomain *$orte_domain;
220 \tint strength;
221
222 \t/* orte data types */
223 (END)
224                 
225         foreach $var (@ortegen) {
226 print OUTFILE << "(END)";
227 \tstruct $var->{"type"}_type $var->{"topic"};
228 (END)
229         }
230
231 print OUTFILE << "(END)";
232
233 \t/* publishers */
234 (END)
235
236         foreach $var (@ortegen) {
237 print OUTFILE << "(END)";
238 \tORTEPublication *$publication_prefix$var->{"topic"};
239 (END)
240         }
241
242 print OUTFILE << "(END)";
243 };
244
245 #ifdef __cplusplus
246 extern "C" {
247 #endif 
248 ROBOORTE_INIT();
249 ROBOORTE_DESTROY();
250
251 (END)
252
253         foreach $var (@ortegen) {
254 print OUTFILE << "(END)";
255 ROBOORTE_PUBLISHER_CREATE($var->{"topic"});
256 (END)
257         }
258
259 print OUTFILE << "(END)";
260
261 (END)
262
263         foreach $var (@ortegen) {
264 print OUTFILE << "(END)";
265 ROBOORTE_PUBLISHER_DESTROY($var->{"topic"});
266 (END)
267         }
268
269 print OUTFILE << "(END)";
270
271 (END)
272
273         foreach $var (@ortegen) {
274 print OUTFILE << "(END)";
275 ROBOORTE_SUBSCRIBER_CREATE($var->{"topic"});
276 (END)
277         }
278
279 print OUTFILE << "(END)";
280 #ifdef __cplusplus
281 }
282 #endif 
283
284 #endif /* $library_name_prefix$roboorte_name\_H */
285 (END)
286
287         close(OUTFILE);
288
289         return 0;
290 }
291
292 #
293 #
294 #
295 sub generate_roboorte_library {
296         my(@ortegen) = @_;
297         my($libraryfile) = $library_name_prefix.$roboorte_name.".c";
298
299         unless (open (OUTFILE, ">$libraryfile")) {
300                 print "Unable to create file $libraryfile\n";
301                 exit(1);
302         }
303
304 print OUTFILE << "(END)";
305 /**
306  * Automatically generated RoboORTE library.
307  * \@warning DO NOT EDIT!!! Instead modify the *.ortegen and config file.
308  */
309
310 #include "$library_name_prefix$roboorte_name.h"
311
312 /* ---------------------------------------------------------------------- 
313  * CREATE PUBLISHERS
314  * ---------------------------------------------------------------------- */
315
316 (END)
317
318         foreach $var (@ortegen) {
319             ($pmsec, $psec) = POSIX::modf($var->{"persistence"});
320             $pmsec = POSIX::floor($pmsec*1000);
321             ($dmsec, $dsec) = POSIX::modf($var->{"pubdelay"});
322             $dmsec = POSIX::floor($dmsec*1000);
323 print OUTFILE << "(END)";
324 ROBOORTE_PUBLISHER_CREATE($var->{"topic"})
325 {
326 \tNtpTime persistence, delay;
327
328 \t$var->{"type"}_type_register($data_arg_name->$orte_domain);
329 \tNtpTimeAssembFromMs(persistence, $psec, $pmsec);
330 \tNtpTimeAssembFromMs(delay, $dsec, $dmsec); 
331 \t$data_arg_name->$publication_prefix$var->{"topic"} = ORTEPublicationCreate(
332 \t\t\t$data_arg_name->$orte_domain, "$var->{"topic"}", "$var->{"type"}",
333 \t\t\t&$data_arg_name->$var->{"topic"}, &persistence, $data_arg_name->strength, 
334 \t\t\t$callback_name, $callback_arg, &delay);
335 }
336
337 (END)
338         }
339
340
341 print OUTFILE << "(END)";
342 /* ---------------------------------------------------------------------- 
343  * DESTROY PUBLISHERS
344  * ---------------------------------------------------------------------- */
345
346 (END)
347
348         foreach $var (@ortegen) {
349 print OUTFILE << "(END)";
350 ROBOORTE_PUBLISHER_DESTROY($var->{"topic"})
351 {
352 \tORTEPublicationDestroy($data_arg_name->$publication_prefix$var->{"topic"});
353 }
354
355 (END)
356         }
357
358         
359 print OUTFILE << "(END)";
360 /* ---------------------------------------------------------------------- 
361  * CREATE SUBSCRIBERS
362  * ---------------------------------------------------------------------- */
363
364 (END)
365
366         foreach $var (@ortegen) {
367             ($mmsec, $msec) = POSIX::modf($var->{"minsep"});
368             $mmsec = POSIX::floor($mmsec*1000);
369             ($dmsec, $dsec) = POSIX::modf($var->{"deadline"});
370             $dmsec = POSIX::floor($dmsec*1000);
371 print OUTFILE << "(END)";
372 ROBOORTE_SUBSCRIBER_CREATE($var->{"topic"})
373 {
374 \tORTESubscription *s;
375 \tNtpTime deadline, minimumSeparation;
376 \t
377 \t$var->{"type"}_type_register($data_arg_name->$orte_domain);
378 \t
379 \tNtpTimeAssembFromMs(deadline, $dsec, $dmsec);
380 \tNtpTimeAssembFromMs(minimumSeparation, $msec, $mmsec);
381 \ts = ORTESubscriptionCreate(
382 \t\t\t$data_arg_name->$orte_domain, $subscription_mode, $subscription_type, 
383 \t\t\t"$var->{"topic"}", "$var->{"type"}", 
384 \t\t\t&$data_arg_name->$var->{"topic"}, &deadline, &minimumSeparation,
385 \t\t\t$callback_name, $callback_arg, $multicast_ip_address);
386 }
387
388 (END)
389         }
390
391
392 print OUTFILE << "(END)";
393
394 /* ---------------------------------------------------------------------- 
395  * ORTE INITILIZATION AND DESTROY
396  * ---------------------------------------------------------------------- */
397
398 ROBOORTE_INIT()
399 {
400 \tint rv = 0;
401 \t
402 \tORTEInit();
403
404 \tif ($data_arg_name->strength < 0)
405 \t\t$data_arg_name->strength = $publication_strength;
406
407 \tORTEVerbositySetOptions("ALL.0");
408 \t$data_arg_name->$orte_domain = ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,
409 \t                                      NULL, NULL, ORTE_FALSE);
410 \tif (!$data_arg_name->$orte_domain) {
411 \t\tprintf("ORTEDomainAppCreate failed!\\n");
412 \t\trv = -1;
413 \t}
414 \t
415 \treturn rv;
416 }
417
418 ROBOORTE_DESTROY()
419 {
420 \treturn ORTEDomainAppDestroy($data_arg_name->$orte_domain);
421 }
422 (END)
423
424         close(OUTFILE);
425
426         return 0;
427 }
428
429 #
430 #
431 #
432 sub generate_makefile {
433         my(@files) = @_;
434         my($makefile) = "Makefile.omk";
435
436         unless (open (OUTFILE, ">$makefile")) {
437                 print "Unable to create $makefile\n";
438                 exit(1);
439         }
440
441         if ($testdir = $options{"T"}) {
442                 $testmakefile = "$testdir/$makefile";
443                 unless (open (MKOUTFILE, ">$testmakefile")) {
444                         print "Unable to create $testmakefile\n";
445                         exit(1);
446                 }
447 print MKOUTFILE << "(END)";
448
449 # Automatically generated Makefile file.
450 # \@warning DO NOT EDIT!!!
451
452 # -*- makefile -*-
453 #  Robot's ORTE library
454
455 (END)
456         } else {
457                 *MKOUTFILE = *OUTFILE;
458 print OUTFILE << "(END)";
459 # Automatically generated Makefile file.
460 # \@warning DO NOT EDIT!!!
461
462 # -*- makefile -*-
463 #  Robot's ORTE library
464
465 (END)
466         }
467
468         my($i) = 0;
469         foreach $filename (@files) {
470                 $testfilename1 = $test_publisher_name_prefix.$filename;
471                 $testfilename2 = $test_subscriber_name_prefix.$filename;
472                 $libraryname = $library_name_prefix.$filename;
473
474 print OUTFILE << "(END)";
475 lib_LIBRARIES += $libraryname
476 $libraryname\_SOURCES = $libraryname.c
477 include_HEADERS += $libraryname.h
478
479 (END)
480
481                 if ($options{"t"} or $options{"T"}) {
482 print MKOUTFILE << "(END)";
483 test_PROGRAMS += $testfilename1
484 $testfilename1\_SOURCES = $testfilename1.c
485 $testfilename1\_LIBS = pthread $libraryname robottype $ortegenfilenames[$i] orte
486
487 test_PROGRAMS += $testfilename2
488 $testfilename2\_SOURCES = $testfilename2.c
489 $testfilename2\_LIBS = pthread $libraryname robottype $ortegenfilenames[$i] orte
490
491 (END)
492                 }
493                 $i++;
494         }
495
496         if ($options{"T"}) {
497 print OUTFILE << "(END)";
498 SUBDIRS = test
499
500 clean-custom:
501 \t\$(Q)rm -rf *.c *.h Makefile.omk test/
502 (END)
503                 `cp -p Makefile $testdir`
504         } else {
505 print OUTFILE << "(END)";
506 clean-custom:
507 \t\$(Q)rm -rf *.c *.h Makefile.omk
508 (END)
509         }
510
511         close(OUTFILE);
512         if ($options{"T"}) {
513                 close(MKOUTFILE);
514         }
515
516         return 0;
517 }
518
519 #
520 #
521 #
522 sub generate_test_publisher {
523         my(@ortegen) = @_;
524         my($testfile) = $test_publisher_name_prefix.$roboorte_name.".c";
525         my($testdir);
526
527         if ($testdir = $options{"T"}) {
528                 $testfile = "$testdir/$testfile";
529                 `mkdir -p $testdir`;
530         }
531
532         unless (open (OUTFILE, ">$testfile")) {
533                 print "Unable to create file $testfile\n";
534                 exit(1);
535         }
536
537 print OUTFILE << "(END)";
538 /**
539  * Automatically generated test file for RoboORTE libraries.
540  * \@warning DO NOT EDIT!!! Instead modify the *.ortegen and config file.
541  */
542
543 #include <stdio.h>
544 #include <stdlib.h>
545 #include <pthread.h>
546 #include <unistd.h>
547 #include <signal.h>
548 #include <orte.h>
549 #include <$library_name_prefix$roboorte_name.h>
550
551 /* ---------------------------------------------------------------------- 
552  * PUBLISHER CALLBACKS
553  * ---------------------------------------------------------------------- */
554
555 (END)
556
557         foreach $var (@ortegen) {
558 print OUTFILE << "(END)";
559 void send_$var->{"topic"}_cb(const ORTESendInfo *info, void *vinstance, 
560 \t\t\tvoid *sendCallBackParam)
561 {
562 }
563
564 (END)
565         }
566
567 print OUTFILE << "(END)";
568
569 /* Thread process. Do the job. */
570 void *process(void *arg)
571 {
572 \tstruct $roboorte_name\_orte_data *orte = (struct $roboorte_name\_orte_data*)arg;
573 \tint i = 0;
574
575 \twhile (1) {
576 \t\tswitch(i) {
577 (END)
578
579         my($i) = 0;
580         foreach $var (@ortegen) {
581                 my(@var) = (@{$var->{"var"}});
582 print OUTFILE << "(END)";
583 \t\t\t/* $var->{"topic"} */
584 \t\t\tcase $i:
585 \t\t\t\tprintf("$var->{"topic"}:\\n");
586 (END)
587                 foreach $var (@var) {
588                         if ($var->{"type"} eq "double") {
589 print OUTFILE << "(END)";
590 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = ($var->{"type"})(rand() % 255);
591 \t\t\t\tprintf("\\t$var->{"topic"} = %f\\n", orte->$var->{"topic"}.$var->{"topic"});
592 (END)
593                         } elsif ( $var->{"type"} eq "octet" ) {
594 print OUTFILE << "(END)";
595 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = (unsigned char)(rand() % 255);
596 \t\t\t\tprintf("\\t$var->{"topic"} = 0x%02x\\n", orte->$var->{"topic"}.$var->{"topic"});
597 (END)
598                         } elsif ( $var->{"type"} eq "unsigned short" ) {
599 print OUTFILE << "(END)";
600 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = ($var->{"type"})(rand() % 255);
601 \t\t\t\tprintf("\\t$var->{"topic"} = %d\\n", orte->$var->{"topic"}.$var->{"topic"});
602 (END)
603                         } else {
604 print OUTFILE << "(END)";
605 \t\t\t\torte->$var->{"topic"}.$var->{"topic"} = (int)(rand() % 255);
606 \t\t\t\tprintf("\\t$var->{"topic"} = %d\\n", orte->$var->{"topic"}.$var->{"topic"});
607 (END)
608                         }
609                 }
610
611                 if (defined($publication_callback_enabled)) {
612 print OUTFILE << "(END)";
613 \t\t\t\t/*ORTEPublicationSend(orte->$publication_prefix$var->{"topic"});*/
614 \t\t\t\tbreak;
615
616 (END)
617                 } else {
618 print OUTFILE << "(END)";
619 \t\t\t\tORTEPublicationSend(orte->$publication_prefix$var->{"topic"});
620 \t\t\t\tbreak;
621
622 (END)
623                 }
624
625                 $i++;
626         }
627
628 print OUTFILE << "(END)";
629 \t\t\tdefault:
630 \t\t\t\tbreak;
631 \t\t}
632 \t\ti++;
633 \t\ti = i % $i;
634 \t\tusleep($publisher_thread_usleep);
635 \t}
636 }
637
638 /* Start thread */
639 void start_thread(struct $roboorte_name\_orte_data *orte)
640 {
641 \tint retcode;
642 \tpthread_t th;
643 \tvoid * retval;
644
645 \tretcode = pthread_create(&th, NULL, process, orte);
646 \tif (retcode != 0) 
647 \t\tprintf("Failed to create thread %d\\n", retcode);
648
649 \tretcode = pthread_join(th, &retval);
650 \tif (retcode != 0) 
651 \t\tprintf("Failed to join thread %d\\n", retcode);
652 }
653
654 struct $roboorte_name\_orte_data orte;
655
656 /* SIGINT handler */
657 static void int_handler(int sig)
658 {
659 \t$roboorte_name\_roboorte_destroy(&orte);
660 \texit(0);
661 }
662
663 int main()
664 {
665 \tsrand(time(0));
666
667 \tsignal(SIGINT, int_handler);
668
669 \torte.strength = $publication_strength;
670
671 \t/* orte initialization */
672 \t$roboorte_name\_roboorte_init(&orte);
673
674 \t/* creating publishers */
675 (END)
676
677         foreach $var (@ortegen) {
678                 if (defined($publication_callback_enabled)) {
679                         $publication_callback = "send_".$var->{"topic"}."_cb";
680                 } else {
681                         $publication_callback = "NULL";
682                 }
683
684 print OUTFILE << "(END)";
685 \t$roboorte_name\_publisher_$var->{"topic"}_create(&orte, $publication_callback, &orte);
686 (END)
687         }
688
689 print OUTFILE << "(END)";
690
691 \tprintf("Publishers: sending data.\\n");
692
693 \t/* start thread and do the job */
694 \tstart_thread(&orte);
695
696 \t/* orte domain destroy */
697 \t$roboorte_name\_roboorte_destroy(&orte);
698
699 \treturn 0;
700 }
701
702 (END)
703
704         close(OUTFILE);
705
706         return 0;
707 }
708
709 #
710 #
711 #
712 sub generate_test_subscriber {
713         my(@ortegen) = @_;
714         my($testfile) = $test_subscriber_name_prefix.$roboorte_name.".c";
715
716         if ($testdir = $options{"T"}) {
717                 $testfile = "$testdir/$testfile";
718                 `mkdir -p $testdir`;
719         }
720
721         unless (open (OUTFILE, ">$testfile")) {
722                 print "Unable to create file $testfile\n";
723                 exit(1);
724         }
725
726 print OUTFILE << "(END)";
727 /**
728  * Automatically generated test file for RoboORTE libraries.
729  * \@warning DO NOT EDIT!!! Instead modify the *.ortegen and config file.
730  */
731
732 #include <stdio.h>
733 #include <stdlib.h>
734 #include <unistd.h>
735 #include <signal.h>
736 #include <time.h>
737 #include <sys/time.h>
738 #include <orte.h>
739 #include <$library_name_prefix$roboorte_name.h>
740
741
742 void print_time()
743 {
744 \tstruct timeval tv;
745 \ttime_t curtime;
746 \tchar buffer[30];
747
748 \tgettimeofday(&tv, NULL);
749 \tcurtime = tv.tv_sec;
750 \tstrftime(buffer, 30, "[%T.", localtime(&curtime));
751 \tprintf("%s%ld]\\n", buffer, tv.tv_usec);
752 }
753
754 /* ---------------------------------------------------------------------- 
755  * SUBSCRIBER CALLBACKS
756  * ---------------------------------------------------------------------- */
757
758 (END)
759
760         foreach $var (@ortegen) {
761 print OUTFILE << "(END)";
762 void rcv_$var->{"topic"}_cb(const ORTERecvInfo *info, void *vinstance,
763 \t\t\tvoid *recvCallBackParam)
764 {
765 \tstruct $roboorte_name\_orte_data *orte = 
766 \t\t\t(struct $roboorte_name\_orte_data *)recvCallBackParam;
767 \t
768 \tswitch (info->status) {
769 \t\tcase NEW_DATA:
770 (END)
771                 if (defined($subscriber_print_data)) {
772 print OUTFILE << "(END)";
773 \t\t\tprint_time();
774 \t\t\tprintf("\\t$var->{"topic"}:\\n");
775 (END)
776                         my(@var) = (@{$var->{"var"}});
777                         foreach $var (@var) {
778 print OUTFILE << "(END)";
779 \t\t\t\tprintf("\\t\\t");
780 (END)
781                                 if ($var->{"type"} eq "double") {
782 print OUTFILE << "(END)";
783 \t\t\t\tprintf("$var->{"topic"} = %f\\n", orte->$var->{"topic"}.$var->{"topic"});
784 (END)
785                                 } elsif ( $var->{"type"} eq "octet" ) {
786 print OUTFILE << "(END)";
787 \t\t\t\tprintf("$var->{"topic"} = 0x%02x\\n", orte->$var->{"topic"}.$var->{"topic"});
788 (END)
789                                 } else {
790 print OUTFILE << "(END)";
791 \t\t\t\tprintf("$var->{"topic"} = %d\\n", orte->$var->{"topic"}.$var->{"topic"});
792 (END)
793                                 }
794                         }
795                 }
796                         
797 print OUTFILE << "(END)";
798 \t\t\tbreak;
799 \t\tcase DEADLINE:
800 \t\t\tprintf("ORTE deadline occurred - $var->{"topic"} receive\\n");
801 \t\t\tbreak;
802 \t}
803 }
804
805 (END)
806         }
807
808 print OUTFILE << "(END)";
809 struct $roboorte_name\_orte_data orte;
810
811 /* SIGINT handler */
812 static void int_handler(int sig)
813 {
814 \t$roboorte_name\_roboorte_destroy(&orte);
815 \texit(0);
816 }
817
818 int main()
819 {
820 \tsignal(SIGINT, int_handler);
821
822 \t/* orte initialization */
823 \t$roboorte_name\_roboorte_init(&orte);
824
825 \t/* creating subscribers */
826 (END)
827
828         foreach $var (@ortegen) {
829 print OUTFILE << "(END)";
830 \t$roboorte_name\_subscriber_$var->{"topic"}_create(&orte, rcv_$var->{"topic"}_cb, &orte);
831 (END)
832         }
833
834         unless (defined($subscriber_print_data)) {
835 print OUTFILE << "(END)";
836 \tprintf("Subscribers: debug print turned off.\\n");
837 (END)
838         }
839 print OUTFILE << "(END)";
840
841 \tprintf("Subscribers: waiting for data.\\n");
842 \twhile (1) {
843 \t\tusleep($subscriber_wait_usleep);
844 \t}
845
846 \t/* orte domain destroy */
847 \t$roboorte_name\_roboorte_destroy(&orte);
848
849 \treturn 0;
850 }
851
852 (END)
853
854         close(OUTFILE);
855
856         return 0;
857 }
858
859 1