Input.h revision 4510de26e5361f3a9f07057ec6f26483c888c1fa
1/*
2 * Copyright 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef IMG_UTILS_INPUT_H
18#define IMG_UTILS_INPUT_H
19
20#include <cutils/compiler.h>
21#include <utils/Errors.h>
22#include <stdint.h>
23
24namespace android {
25namespace img_utils {
26
27/**
28 * Utility class used as a source of bytes.
29 */
30class ANDROID_API Input {
31    public:
32        virtual ~Input();
33
34        /**
35         * Open this Input.
36         *
37         * Returns OK on success, or a negative error code.
38         */
39        virtual status_t open();
40
41        /**
42         * Read bytes into the given buffer.  At most, the number of bytes given in the
43         * count argument will be read.  Bytes will be written into the given buffer starting
44         * at the index given in the offset argument.
45         *
46         * Returns the number of bytes read, or NOT_ENOUGH_DATA if at the end of the file.  If an
47         * error has occurred, this will return a negative error code other than NOT_ENOUGH_DATA.
48         */
49        virtual ssize_t read(uint8_t* buf, size_t offset, size_t count) = 0;
50
51        /**
52         * Skips bytes in the input.
53         *
54         * Returns the number of bytes skipped, or NOT_ENOUGH_DATA if at the end of the file.  If an
55         * error has occurred, this will return a negative error code other than NOT_ENOUGH_DATA.
56         */
57        virtual ssize_t skip(size_t count);
58
59        /**
60         * Close the Input.  It is not valid to call open on a previously closed Input.
61         *
62         * Returns OK on success, or a negative error code.
63         */
64        virtual status_t close();
65};
66
67} /*namespace img_utils*/
68} /*namespace android*/
69
70
71#endif /*IMG_UTILS_INPUT_H*/
72