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

Sources/uqmi/data/gen-common.pm

  1 use lib "$Bin/lib";
  2 use JSON;
  3 
  4 @ARGV < 2 and die "Usage: $0 <prefix> <file>\n";
  5 my $prefix = shift @ARGV;
  6 
  7 our $ctl;
  8 our %tlv_types = (
  9         gint8 => "int8_t",
 10         guint8 => "uint8_t",
 11         gint16 => "int16_t",
 12         guint16 => "uint16_t",
 13         gint32 => "int32_t",
 14         guint32 => "uint32_t",
 15         gint64 => "int64_t",
 16         guint64 => "uint64_t",
 17         gfloat => "float",
 18         gboolean => "bool",
 19 );
 20 our %common_ref = ();
 21 
 22 my @c_reserved_keywords = (
 23         "alignas",
 24         "alignof",
 25         "auto",
 26         "bool",
 27         "break",
 28         "case",
 29         "char",
 30         "const",
 31         "constexpr",
 32         "continue",
 33         "default",
 34         "do",
 35         "double",
 36         "else",
 37         "enum",
 38         "extern",
 39         "false",
 40         "float",
 41         "for",
 42         "goto",
 43         "if",
 44         "inline",
 45         "int",
 46         "long",
 47         "nullptr",
 48         "register",
 49         "restrict",
 50         "return",
 51         "short",
 52         "signed",
 53         "sizeof",
 54         "static",
 55         "static_assert",
 56         "struct",
 57         "switch",
 58         "thread_local",
 59         "true",
 60         "typedef",
 61         "typeof",
 62         "typeof_unqual",
 63         "union",
 64         "unsigned",
 65         "void",
 66         "volatile",
 67         "while"
 68 );
 69 
 70 $prefix eq 'ctl_' and $ctl = 1;
 71 
 72 sub get_json() {
 73         local $/;
 74         my $json = <>;
 75         $json =~ s/^\s*\/\/.*$//mg;
 76         return decode_json($json);
 77 }
 78 
 79 sub gen_cname($) {
 80         my $name = shift;
 81 
 82         $name =~ s/[^a-zA-Z0-9_]/_/g;
 83         $name = "_${name}" if $name =~ /^\d/;
 84         $name = lc($name);
 85         $name = "_${name}" if (grep {$_ eq $name} @c_reserved_keywords);
 86         return $name;
 87 }
 88 
 89 sub gen_has_types($) {
 90         my $data = shift;
 91 
 92         foreach my $field (@$data) {
 93                 $field = gen_common_ref($field);
 94                 my $type = $field->{"format"};
 95                 $type and return 1;
 96         }
 97         return undef
 98 }
 99 
100 sub gen_tlv_set_func($$) {
101         my $name = shift;
102         my $data = shift;
103 
104         $name = gen_cname($name);
105         if (gen_has_types($data)) {
106                 return "int qmi_set_$name(struct qmi_msg *msg, struct qmi_$name *req)"
107         } else {
108                 return "int qmi_set_$name(struct qmi_msg *msg)"
109         }
110 }
111 
112 sub gen_tlv_parse_func($$) {
113         my $name = shift;
114         my $data = shift;
115 
116         $name = gen_cname($name);
117         if (gen_has_types($data)) {
118                 return "int qmi_parse_$name(struct qmi_msg *msg, struct qmi_$name *res)"
119         } else {
120                 return "int qmi_parse_$name(struct qmi_msg *msg)"
121         }
122 }
123 
124 sub gen_common_ref($$) {
125         my $field = shift;
126         $field = $common_ref{$field->{'common-ref'}} if $field->{'common-ref'} ne '';
127         return $field;
128 }
129 
130 sub gen_foreach_message_type($$$)
131 {
132         my $data = shift;
133         my $req_sub = shift;
134         my $res_sub = shift;
135         my $ind_sub = shift;
136 
137         foreach my $entry (@$data) {
138                 my $args = [];
139                 my $fields = [];
140 
141                 $common_ref{$entry->{'common-ref'}} = $entry if $entry->{'common-ref'} ne '';
142 
143                 next if $entry->{type} ne 'Message';
144                 next if not defined $entry->{input} and not defined $entry->{output};
145 
146                 &$req_sub($prefix.$entry->{name}." Request", $entry->{input}, $entry);
147                 &$res_sub($prefix.$entry->{name}." Response", $entry->{output}, $entry);
148         }
149 
150         foreach my $entry (@$data) {
151                 my $args = [];
152                 my $fields = [];
153 
154                 $common_ref{$entry->{'common-ref'}} = $entry if $entry->{'common-ref'} ne '';
155 
156                 next if $entry->{type} ne 'Indication';
157                 next if not defined $entry->{input} and not defined $entry->{output};
158 
159                 &$ind_sub($prefix.$entry->{name}." Indication", $entry->{output}, $entry);
160         }
161 }
162 
163 
164 1;

This page was automatically generated by LXR 0.3.1.  •  OpenWrt