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