OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "DMJsonWriter.h" | 8 #include "DMJsonWriter.h" |
9 | 9 |
10 #include "SkCommonFlags.h" | 10 #include "SkCommonFlags.h" |
| 11 #include "SkData.h" |
11 #include "SkJSONCPP.h" | 12 #include "SkJSONCPP.h" |
12 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
13 #include "SkStream.h" | 14 #include "SkStream.h" |
14 #include "SkTArray.h" | 15 #include "SkTArray.h" |
15 #include "SkThread.h" | 16 #include "SkThread.h" |
16 | 17 |
17 namespace DM { | 18 namespace DM { |
18 | 19 |
19 SkTArray<JsonWriter::BitmapResult> gBitmapResults; | 20 SkTArray<JsonWriter::BitmapResult> gBitmapResults; |
20 SK_DECLARE_STATIC_MUTEX(gBitmapResultLock); | 21 SK_DECLARE_STATIC_MUTEX(gBitmapResultLock); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 root["test_results"]["failures"].append(result); | 73 root["test_results"]["failures"].append(result); |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); | 77 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); |
77 SkFILEWStream stream(path.c_str()); | 78 SkFILEWStream stream(path.c_str()); |
78 stream.writeText(Json::StyledWriter().write(root).c_str()); | 79 stream.writeText(Json::StyledWriter().write(root).c_str()); |
79 stream.flush(); | 80 stream.flush(); |
80 } | 81 } |
81 | 82 |
| 83 bool JsonWriter::ReadJson(const char* path, void(*callback)(BitmapResult)) { |
| 84 SkAutoTUnref<SkData> json(SkData::NewFromFileName(path)); |
| 85 if (!json) { |
| 86 return false; |
| 87 } |
| 88 |
| 89 Json::Reader reader; |
| 90 Json::Value root; |
| 91 const char* data = (const char*)json->data(); |
| 92 if (!reader.parse(data, data+json->size(), root)) { |
| 93 return false; |
| 94 } |
| 95 |
| 96 const Json::Value& results = root["results"]; |
| 97 BitmapResult br; |
| 98 for (unsigned i = 0; i < results.size(); i++) { |
| 99 const Json::Value& r = results[i]; |
| 100 br.name = r["key"]["name"].asCString(); |
| 101 br.config = r["key"]["config"].asCString(); |
| 102 br.sourceType = r["key"]["source_type"].asCString(); |
| 103 br.ext = r["ext"].asCString(); |
| 104 br.md5 = r["md5"].asCString(); |
| 105 callback(br); |
| 106 } |
| 107 return true; |
| 108 } |
| 109 |
82 } // namespace DM | 110 } // namespace DM |
OLD | NEW |