Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: samples/android_sample/jni/resource.h

Issue 11467028: Migrate files to embedder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review fixes Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/android_sample/jni/main.cc ('k') | samples/android_sample/jni/sound_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
5 #ifndef RESOURCE_H
6 #define RESOURCE_H
7
8 #include <android_native_app_glue.h>
9
10 #include "jni/log.h"
11
12 class Resource {
13 public:
14 Resource(android_app* application, const char* path)
15 : asset_manager_(application->activity->assetManager),
16 path_(path),
17 asset_(NULL),
18 descriptor_(-1),
19 start_(0),
20 length_(0) {
21 }
22
23 const char* path() {
24 return path_;
25 }
26
27 int32_t descriptor() {
28 return descriptor_;
29 }
30
31 off_t start() {
32 return start_;
33 }
34
35 off_t length() {
36 return length_;
37 }
38
39 int32_t open() {
40 asset_ = AAssetManager_open(asset_manager_, path_, AASSET_MODE_UNKNOWN);
41 if (asset_ != NULL) {
42 descriptor_ = AAsset_openFileDescriptor(asset_, &start_, &length_);
43 LOGI("%s has start %d, length %d, fd %d",
44 path_, start_, length_, descriptor_);
45 return 0;
46 }
47 return -1;
48 }
49
50 void close() {
51 if (asset_ != NULL) {
52 AAsset_close(asset_);
53 asset_ = NULL;
54 }
55 }
56
57 int32_t read(void* buffer, size_t count) {
58 int32_t actual = AAsset_read(asset_, buffer, count);
59 return (actual == count) ? 0 : -1;
60 }
61
62 private:
63 const char* path_;
64 AAssetManager* asset_manager_;
65 AAsset* asset_;
66 int32_t descriptor_;
67 off_t start_;
68 off_t length_;
69 };
70
71 #endif
OLDNEW
« no previous file with comments | « samples/android_sample/jni/main.cc ('k') | samples/android_sample/jni/sound_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698