Camera: Add a script to generate files from XML: DO NOT MERGE
Change-Id: I638017934ddfcfe8ab8f9f56bebb587dae35f17f
diff --git a/camera/docs/camera_metadata_tag_info.mako b/camera/docs/camera_metadata_tag_info.mako
index ab6c404..13c24db 100644
--- a/camera/docs/camera_metadata_tag_info.mako
+++ b/camera/docs/camera_metadata_tag_info.mako
@@ -60,3 +60,40 @@
${path_name(i) | csyml},
% endfor
};
+
+int camera_metadata_enum_snprint(uint32_t tag,
+ uint32_t value,
+ char *dst,
+ size_t size) {
+ const char *msg = "error: not an enum";
+ int ret = -1;
+
+ switch(tag) {
+ % for sec in find_all_sections(metadata):
+ % for idx,entry in enumerate(find_unique_entries(sec)):
+ case ${entry.name | csym}: {
+ % if entry.type == 'enum':
+ switch (value) {
+ % for val in entry.enum.values:
+ case ${entry.name | csym}_${val.name}:
+ msg = "${val.name}";
+ ret = 0;
+ break;
+ % endfor
+ default:
+ msg = "error: enum value out of range";
+ }
+ % endif
+ break;
+ }
+ % endfor
+
+ %endfor
+ }
+
+ strncpy(dst, msg, size - 1);
+ dst[size - 1] = '\0';
+
+ return ret;
+}
+
diff --git a/camera/docs/camera_metadata_tags.mako b/camera/docs/camera_metadata_tags.mako
index d4a5e59..4d7ccfe 100644
--- a/camera/docs/camera_metadata_tags.mako
+++ b/camera/docs/camera_metadata_tags.mako
@@ -101,34 +101,4 @@
int camera_metadata_enum_snprint(uint32_t tag,
uint32_t value,
char *dst,
- size_t size) {
- const char *msg = "error: not an enum";
- int ret = -1;
-
- switch(tag) {
- % for sec in find_all_sections(metadata):
- % for idx,entry in enumerate(find_unique_entries(sec)):
- case ${entry.name | csym}: {
- % if entry.type == 'enum':
- switch (value) {
- % for val in entry.enum.values:
- case ${entry.name | csym}_${val.name}:
- msg = "${val.name}";
- ret = 0;
- break;
- % endfor
- default:
- msg = "error: enum value out of range";
- }
- % endif
- break;
- }
- % endfor
-
- %endfor
- }
-
- snprintf(dst, size, msg);
- return ret;
-}
-
+ size_t size);
diff --git a/camera/docs/metadata-generate b/camera/docs/metadata-generate
new file mode 100755
index 0000000..bf3e3ee
--- /dev/null
+++ b/camera/docs/metadata-generate
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# Generate all files we have templates for:
+# docs.html
+# ../src/camera_metadata_tag_info.c
+# ../src/camera_metadata_tags.h
+#
+
+thisdir=$(dirname $(readlink -f $0))
+
+function gen_file() {
+ local in=$thisdir/$1
+ local out=$thisdir/$2
+
+ $thisdir/metadata_parser_xml.py $thisdir/metadata_properties.xml $in > $out
+ return $?
+}
+
+$thisdir/metadata-parser-sanity-check || exit 1
+gen_file html.mako docs.html || exit 1
+gen_file camera_metadata_tag_info.mako ../src/camera_metadata_tag_info.c || exit 1
+gen_file camera_metadata_tags.mako ../include/system/camera_metadata_tags.h || exit 1
+
+echo "Successfully generated all metadata source files"
+
+exit 0