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__
27 IOStream(size_t bufSize) {
33 virtual void *allocBuffer(size_t minSize) = 0;
34 virtual int commitBuffer(size_t size) = 0;
35 virtual const unsigned char *readFully( void *buf, size_t len) = 0;
36 virtual const unsigned char *read( void *buf, size_t *inout_len) = 0;
37 virtual int writeFully(const void* buf, size_t len) = 0;
41 // NOTE: m_buf is 'owned' by the child class thus we expect it to be released by it
44 unsigned char *alloc(size_t len) {
46 if (m_buf && len > m_free) {
48 ERR("Failed to flush in alloc\n");
49 return NULL; // we failed to flush so something is wrong
53 if (!m_buf || len > m_bufsize) {
54 int allocLen = m_bufsize < len ? len : m_bufsize;
55 m_buf = (unsigned char *)allocBuffer(allocLen);
57 ERR("Alloc (%u bytes) failed\n", allocLen);
60 m_bufsize = m_free = allocLen;
65 ptr = m_buf + (m_bufsize - m_free);
73 if (!m_buf || m_free == m_bufsize) return 0;
75 int stat = commitBuffer(m_bufsize - m_free);
81 const unsigned char *readback(void *buf, size_t len) {
83 return readFully(buf, len);
94 // When a client opens a connection to the renderer, it should
95 // send unsigned int value indicating the "clientFlags".
96 // The following are the bitmask of the clientFlags.
97 // currently only one bit is used which flags the server
100 #define IOSTREAM_CLIENT_EXIT_SERVER 1