Input.h revision e507721000647a7d8afe44c63ef7fd04ef8971b1
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.  If an error has occurred, the value pointed
47         * to by the given status_t pointer will be set to a negative error code.
48         */
49        virtual size_t read(uint8_t* buf, size_t offset, size_t count, status_t* err) = 0;
50
51        /**
52         * Close the Input.  It is not valid to call open on a previously closed Input.
53         *
54         * Returns OK on success, or a negative error code.
55         */
56        virtual status_t close();
57};
58
59} /*namespace img_utils*/
60} /*namespace android*/
61
62
63#endif /*IMG_UTILS_INPUT_H*/
64