| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 1 #ifndef RESOURCE_H | 5 #ifndef RESOURCE_H |
| 2 #define RESOURCE_H | 6 #define RESOURCE_H |
| 3 | 7 |
| 4 #include <android_native_app_glue.h> | 8 #include <android_native_app_glue.h> |
| 5 | 9 |
| 10 #include "jni/log.h" |
| 11 |
| 6 class Resource { | 12 class Resource { |
| 7 public: | 13 public: |
| 8 Resource(android_app* application, const char* path) | 14 Resource(android_app* application, const char* path) |
| 9 : asset_manager_(application->activity->assetManager), | 15 : asset_manager_(application->activity->assetManager), |
| 10 path_(path), | 16 path_(path), |
| 11 asset_(NULL), | 17 asset_(NULL), |
| 12 descriptor_(-1), | 18 descriptor_(-1), |
| 13 start_(0), | 19 start_(0), |
| 14 length_(0) { | 20 length_(0) { |
| 15 } | 21 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 } | 33 } |
| 28 | 34 |
| 29 off_t length() { | 35 off_t length() { |
| 30 return length_; | 36 return length_; |
| 31 } | 37 } |
| 32 | 38 |
| 33 int32_t open() { | 39 int32_t open() { |
| 34 asset_ = AAssetManager_open(asset_manager_, path_, AASSET_MODE_UNKNOWN); | 40 asset_ = AAssetManager_open(asset_manager_, path_, AASSET_MODE_UNKNOWN); |
| 35 if (asset_ != NULL) { | 41 if (asset_ != NULL) { |
| 36 descriptor_ = AAsset_openFileDescriptor(asset_, &start_, &length_); | 42 descriptor_ = AAsset_openFileDescriptor(asset_, &start_, &length_); |
| 37 Log::Print("%s has start %d, length %d, fd %d", | 43 LOGI("%s has start %d, length %d, fd %d", |
| 38 path_, start_, length_, descriptor_); | 44 path_, start_, length_, descriptor_); |
| 39 return 0; | 45 return 0; |
| 40 } | 46 } |
| 41 return -1; | 47 return -1; |
| 42 } | 48 } |
| 43 | 49 |
| 44 void close() { | 50 void close() { |
| 45 if (asset_ != NULL) { | 51 if (asset_ != NULL) { |
| 46 AAsset_close(asset_); | 52 AAsset_close(asset_); |
| 47 asset_ = NULL; | 53 asset_ = NULL; |
| 48 } | 54 } |
| 49 } | 55 } |
| 50 | 56 |
| 51 int32_t read(void* buffer, size_t count) { | 57 int32_t read(void* buffer, size_t count) { |
| 52 int32_t actual = AAsset_read(asset_, buffer, count); | 58 int32_t actual = AAsset_read(asset_, buffer, count); |
| 53 return (actual == count) ? 0 : -1; | 59 return (actual == count) ? 0 : -1; |
| 54 } | 60 } |
| 55 | 61 |
| 56 private: | 62 private: |
| 57 const char* path_; | 63 const char* path_; |
| 58 AAssetManager* asset_manager_; | 64 AAssetManager* asset_manager_; |
| 59 AAsset* asset_; | 65 AAsset* asset_; |
| 60 int32_t descriptor_; | 66 int32_t descriptor_; |
| 61 off_t start_; | 67 off_t start_; |
| 62 off_t length_; | 68 off_t length_; |
| 63 }; | 69 }; |
| 64 | 70 |
| 65 #endif | 71 #endif |
| 66 | |
| OLD | NEW |