summaryrefslogtreecommitdiffstats
path: root/libril
diff options
context:
space:
mode:
authorDima Zavin <dima@android.com>2013-05-22 11:29:34 -0700
committerDima Zavin <dima@android.com>2013-05-23 10:28:58 -0700
commit622bf2bf79849127cbedd1f56631615bf58aaf78 (patch)
tree7eaf3fff7ce92ac97c8e2dfd965c5747284fef86 /libril
parentf467af616bbbc479771184731132d68e213a4419 (diff)
downloadandroid_hardware_ril-622bf2bf79849127cbedd1f56631615bf58aaf78.tar.gz
android_hardware_ril-622bf2bf79849127cbedd1f56631615bf58aaf78.tar.bz2
android_hardware_ril-622bf2bf79849127cbedd1f56631615bf58aaf78.zip
ril: move record_stream_xxx to librilutils and export header
Change-Id: I9986c8c5fb1777bbd2b686769ecc726319a73100 Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'libril')
-rw-r--r--libril/Android.mk12
-rw-r--r--libril/record_stream.c186
-rw-r--r--libril/record_stream.h43
-rw-r--r--libril/ril.cpp2
4 files changed, 7 insertions, 236 deletions
diff --git a/libril/Android.mk b/libril/Android.mk
index 7ccd37a..62aeb05 100644
--- a/libril/Android.mk
+++ b/libril/Android.mk
@@ -5,15 +5,15 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
ril.cpp \
- ril_event.cpp \
- record_stream.c
+ ril_event.cpp
LOCAL_SHARED_LIBRARIES := \
liblog \
libutils \
libbinder \
libcutils \
- libhardware_legacy
+ libhardware_legacy \
+ librilutils
LOCAL_CFLAGS :=
@@ -30,12 +30,12 @@ ifneq ($(ANDROID_BIONIC_TRANSITION),)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
- ril.cpp \
- record_stream.c
+ ril.cpp
LOCAL_STATIC_LIBRARIES := \
libutils_static \
- libcutils
+ libcutils \
+ librilutils_static
LOCAL_CFLAGS :=
diff --git a/libril/record_stream.c b/libril/record_stream.c
deleted file mode 100644
index 2add14d..0000000
--- a/libril/record_stream.c
+++ /dev/null
@@ -1,186 +0,0 @@
-/* libs/cutils/record_stream.c
-**
-** Copyright 2006, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <assert.h>
-#include <errno.h>
-#include "record_stream.h"
-#include <string.h>
-#include <stdint.h>
-#ifdef HAVE_WINSOCK
-#include <winsock2.h> /* for ntohl */
-#else
-#include <netinet/in.h>
-#endif
-
-#define HEADER_SIZE 4
-
-struct RecordStream {
- int fd;
- size_t maxRecordLen;
-
- unsigned char *buffer;
-
- unsigned char *unconsumed;
- unsigned char *read_end;
- unsigned char *buffer_end;
-};
-
-
-extern RecordStream *record_stream_new(int fd, size_t maxRecordLen)
-{
- RecordStream *ret;
-
- assert (maxRecordLen <= 0xffff);
-
- ret = (RecordStream *)calloc(1, sizeof(RecordStream));
-
- ret->fd = fd;
- ret->maxRecordLen = maxRecordLen;
- ret->buffer = (unsigned char *)malloc (maxRecordLen + HEADER_SIZE);
-
- ret->unconsumed = ret->buffer;
- ret->read_end = ret->buffer;
- ret->buffer_end = ret->buffer + maxRecordLen + HEADER_SIZE;
-
- return ret;
-}
-
-
-extern void record_stream_free(RecordStream *rs)
-{
- free(rs->buffer);
- free(rs);
-}
-
-
-/* returns NULL; if there isn't a full record in the buffer */
-static unsigned char * getEndOfRecord (unsigned char *p_begin,
- unsigned char *p_end)
-{
- size_t len;
- unsigned char * p_ret;
-
- if (p_end < p_begin + HEADER_SIZE) {
- return NULL;
- }
-
- //First four bytes are length
- len = ntohl(*((uint32_t *)p_begin));
-
- p_ret = p_begin + HEADER_SIZE + len;
-
- if (p_end < p_ret) {
- return NULL;
- }
-
- return p_ret;
-}
-
-static void *getNextRecord (RecordStream *p_rs, size_t *p_outRecordLen)
-{
- unsigned char *record_start, *record_end;
-
- record_end = getEndOfRecord (p_rs->unconsumed, p_rs->read_end);
-
- if (record_end != NULL) {
- /* one full line in the buffer */
- record_start = p_rs->unconsumed + HEADER_SIZE;
- p_rs->unconsumed = record_end;
-
- *p_outRecordLen = record_end - record_start;
-
- return record_start;
- }
-
- return NULL;
-}
-
-/**
- * Reads the next record from stream fd
- * Records are prefixed by a 16-bit big endian length value
- * Records may not be larger than maxRecordLen
- *
- * Doesn't guard against EINTR
- *
- * p_outRecord and p_outRecordLen may not be NULL
- *
- * Return 0 on success, -1 on fail
- * Returns 0 with *p_outRecord set to NULL on end of stream
- * Returns -1 / errno = EAGAIN if it needs to read again
- */
-int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord,
- size_t *p_outRecordLen)
-{
- void *ret;
-
- ssize_t countRead;
-
- /* is there one record already in the buffer? */
- ret = getNextRecord (p_rs, p_outRecordLen);
-
- if (ret != NULL) {
- *p_outRecord = ret;
- return 0;
- }
-
- // if the buffer is full and we don't have a full record
- if (p_rs->unconsumed == p_rs->buffer
- && p_rs->read_end == p_rs->buffer_end
- ) {
- // this should never happen
- //ALOGE("max record length exceeded\n");
- assert (0);
- errno = EFBIG;
- return -1;
- }
-
- if (p_rs->unconsumed != p_rs->buffer) {
- // move remainder to the beginning of the buffer
- size_t toMove;
-
- toMove = p_rs->read_end - p_rs->unconsumed;
- if (toMove) {
- memmove(p_rs->buffer, p_rs->unconsumed, toMove);
- }
-
- p_rs->read_end = p_rs->buffer + toMove;
- p_rs->unconsumed = p_rs->buffer;
- }
-
- countRead = read (p_rs->fd, p_rs->read_end, p_rs->buffer_end - p_rs->read_end);
-
- if (countRead <= 0) {
- /* note: end-of-stream drops through here too */
- *p_outRecord = NULL;
- return countRead;
- }
-
- p_rs->read_end += countRead;
-
- ret = getNextRecord (p_rs, p_outRecordLen);
-
- if (ret == NULL) {
- /* not enough of a buffer to for a whole command */
- errno = EAGAIN;
- return -1;
- }
-
- *p_outRecord = ret;
- return 0;
-}
diff --git a/libril/record_stream.h b/libril/record_stream.h
deleted file mode 100644
index 7a89ae4..0000000
--- a/libril/record_stream.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2006 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * A simple utility for reading fixed records out of a stream fd
- */
-
-#ifndef _LIBRIL_RECORD_STREAM_H
-#define _LIBRIL_RECORD_STREAM_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-typedef struct RecordStream RecordStream;
-
-extern RecordStream *record_stream_new(int fd, size_t maxRecordLen);
-extern void record_stream_free(RecordStream *p_rs);
-
-extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord,
- size_t *p_outRecordLen);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /*_LIBRIL_RECORD_STREAM_H*/
-
diff --git a/libril/ril.cpp b/libril/ril.cpp
index 5c7b243..7275903 100644
--- a/libril/ril.cpp
+++ b/libril/ril.cpp
@@ -23,7 +23,7 @@
#include <telephony/ril_cdma_sms.h>
#include <cutils/sockets.h>
#include <cutils/jstring.h>
-#include "record_stream.h"
+#include <telephony/record_stream.h>
#include <utils/Log.h>
#include <utils/SystemClock.h>
#include <pthread.h>