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