• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/uqmi/data/gen-header.pl

  1 #!/usr/bin/env perl
  2 use strict;
  3 
  4 use FindBin '$Bin';
  5 require "$Bin/gen-common.pm";
  6 
  7 our %tlv_types;
  8 
  9 my $data = get_json();
 10 
 11 sub gen_tlv_type($$$) {
 12         my $cname = shift;
 13         my $elem = shift;
 14         my $indent = shift;
 15 
 16         my $type = $elem->{"format"};
 17         my $ptype = $elem->{"public-format"};
 18         my $data;
 19 
 20         $type or return undef;
 21         $ptype or $ptype = $type;
 22 
 23         if ($type eq "guint-sized") {
 24                 my $size = $elem->{"guint-size"};
 25 
 26                 if ($size > 4 and $size < 8) {
 27                         $ptype = "guint64";
 28                 } elsif ($size > 2) {
 29                         $ptype = "guint32";
 30                 } else {
 31                         die "Invalid size for guint-sized";
 32                 }
 33         }
 34 
 35         if ($tlv_types{$ptype}) {
 36                 return $indent.$tlv_types{$ptype}." $cname;";
 37         } elsif ($tlv_types{$type}) {
 38                 return $indent.$tlv_types{$type}." $cname;";
 39         } elsif ($type eq "string") {
 40                 return $indent."char *$cname;", 1;
 41         } elsif ($type eq "array") {
 42                 if ($elem->{"fixed-size"}) {
 43                         my $len_f = '['.$elem->{"fixed-size"}.']';
 44                         return gen_tlv_type("$cname$len_f", $elem->{"array-element"}, $indent);
 45                 }
 46                 my ($type, $no_set_field) = gen_tlv_type("*$cname", $elem->{"array-element"}, $indent);
 47                 return undef if not defined $type;
 48                 return $indent."unsigned int ".substr($cname,1)."\_i;$type", 1 if (!rindex($cname,"*",0));
 49                 return $indent."unsigned int $cname\_n;$type", 1;
 50         } elsif ($type eq "sequence" or $type eq "struct") {
 51                 my $contents = $elem->{"contents"};
 52                 my $data = "struct {";
 53 
 54                 foreach my $field (@$contents) {
 55                         $field = gen_common_ref($field);
 56                         my $_cname = gen_cname($field->{name});
 57                         my ($_data, $no_set_field) = gen_tlv_type($_cname, $field, "$indent\t");
 58                         $data .= $_data;
 59                 }
 60                 return $indent.$data.$indent."} $cname;";
 61         } else {
 62                 die "Unknown type: $ptype\n";
 63         }
 64 }
 65 
 66 sub gen_tlv_struct($$) {
 67         my $name = shift;
 68         my $data = shift;
 69         my $_set = "";
 70         my $_data = "";
 71 
 72         foreach my $field (@$data) {
 73                 $field = gen_common_ref($field);
 74                 my $cname = gen_cname($field->{name});
 75                 my ($data, $no_set_field) = gen_tlv_type($cname, $field, "\n\t\t");
 76 
 77                 next if not defined $data;
 78                 $_data .= $data;
 79 
 80                 next if $no_set_field;
 81                 $_set .= "\n\t\tunsigned int $cname : 1;";
 82         }
 83 
 84         $name = gen_cname($name);
 85 
 86         $_data or return;
 87 
 88         $_set .= "\n\t";
 89         $_data .= "\n\t";
 90 
 91         print <<EOF
 92 struct qmi_$name {
 93         struct {$_set} set;
 94         struct {$_data} data;
 95 };
 96 
 97 EOF
 98 }
 99 
100 sub gen_set_func_header($$)
101 {
102         my $name = shift;
103         my $data = shift;
104 
105         my $func = gen_tlv_set_func($name, $data);
106         $func and print "$func;\n";
107 }
108 
109 sub gen_parse_func_header($$)
110 {
111         my $name = shift;
112         my $data = shift;
113 
114         my $func = gen_tlv_parse_func($name, $data);
115         $func and print "$func;\n\n";
116 }
117 
118 gen_foreach_message_type($data, \&gen_tlv_struct, \&gen_tlv_struct, \&gen_tlv_struct);
119 gen_foreach_message_type($data, \&gen_set_func_header, \&gen_parse_func_header, \&gen_parse_func_header);

This page was automatically generated by LXR 0.3.1.  •  OpenWrt