2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __IO_STREAM_H__
17 #define __IO_STREAM_H__
24 IOStream(size_t bufSize) {
30 virtual void *allocBuffer(size_t minSize) = 0;
31 virtual size_t commitBuffer(size_t size) = 0;
32 virtual const unsigned char *read(void *buf, size_t *inout_len) = 0;
33 virtual void forceStop() = 0;
36 // NOTE: m_buf is 'owned' by the child class thus we expect it to be released by it
39 unsigned char *alloc(size_t len) {
40 if (m_buf && len > m_free) {
42 return NULL; // we failed to flush so something is wrong
45 if (!m_buf || len > m_bufsize) {
46 int allocLen = m_bufsize < len ? len : m_bufsize;
47 m_buf = static_cast<unsigned char *>(allocBuffer(allocLen));
50 m_bufsize = m_free = allocLen;
55 ptr = m_buf + (m_bufsize - m_free);
62 if (!m_buf || m_free == m_bufsize) return 0;
64 int stat = commitBuffer(m_bufsize - m_free);
77 // When a client opens a connection to the renderer, it should
78 // send unsigned int value indicating the "clientFlags".
79 // The following are the bitmask of the clientFlags.
80 // currently only one bit is used which flags the server
83 #define IOSTREAM_CLIENT_EXIT_SERVER 1