Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e00a12bf authored by Dima Zavin's avatar Dima Zavin
Browse files

cutils: first pass at cleaning up legacy/obsolete code in cutils



Removed unused code and moved libraries with single clients
near their respective users.

Change-Id: I65f90f8659f27bd0f44ca5ddf33da2bce14674c1
Signed-off-by: default avatarDima Zavin <dima@android.com>
parent 69e9b17f
Loading
Loading
Loading
Loading

include/cutils/abort_socket.h

deleted100644 → 0
+0 −103
Original line number Diff line number Diff line
/*
 * Copyright 2009, 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.
 */

/* Helper to perform abortable blocking operations on a socket:
 *   asocket_connect()
 *   asocket_accept()
 *   asocket_read()
 *   asocket_write()
 * These calls are similar to the regular syscalls, but can be aborted with:
 *   asocket_abort()
 *
 * Calling close() on a regular POSIX socket does not abort blocked syscalls on
 * that socket in other threads.
 *
 * After calling asocket_abort() the socket cannot be reused.
 *
 * Call asocket_destory() *after* all threads have finished with the socket to
 * finish closing the socket and free the asocket structure.
 *
 * The helper is implemented by setting the socket non-blocking to initiate
 * syscalls connect(), accept(), read(), write(), then using a blocking poll()
 * on both the primary socket and a local pipe. This makes the poll() abortable
 * by writing a byte to the local pipe in asocket_abort().
 *
 * asocket_create() sets the fd to non-blocking mode. It must not be changed to
 * blocking mode.
 *
 * Using asocket will triple the number of file descriptors required per
 * socket, due to the local pipe. It may be possible to use a global pipe per
 * process rather than per socket, but we have not been able to come up with a
 * race-free implementation yet.
 *
 * All functions except asocket_init() and asocket_destroy() are thread safe.
 */

#include <stdlib.h>
#include <sys/socket.h>

#ifndef __CUTILS_ABORT_SOCKET_H__
#define __CUTILS_ABORT_SOCKET_H__
#ifdef __cplusplus
extern "C" {
#endif

struct asocket {
    int fd;           /* primary socket fd */
    int abort_fd[2];  /* pipe used to abort */
};

/* Create an asocket from fd.
 * Sets the socket to non-blocking mode.
 * Returns NULL on error with errno set.
 */
struct asocket *asocket_init(int fd);

/* Blocking socket I/O with timeout.
 * Calling asocket_abort() from another thread will cause each of these
 * functions to immediately return with value -1 and errno ECANCELED.
 * timeout is in ms, use -1 to indicate no timeout. On timeout -1 is returned
 * with errno ETIMEDOUT.
 * EINTR is handled in-call.
 * Other semantics are identical to the regular syscalls.
 */
int asocket_connect(struct asocket *s, const struct sockaddr *addr,
        socklen_t addrlen, int timeout);

int asocket_accept(struct asocket *s, struct sockaddr *addr,
        socklen_t *addrlen, int timeout);

int asocket_read(struct asocket *s, void *buf, size_t count, int timeout);

int asocket_write(struct asocket *s, const void *buf, size_t count,
        int timeout);

/* Abort above calls and shutdown socket.
 * Further I/O operations on this socket will immediately fail after this call.
 * asocket_destroy() should be used to release resources once all threads
 * have returned from blocking calls on the socket.
 */
void asocket_abort(struct asocket *s);

/* Close socket and free asocket structure.
 * Must not be called until all calls on this structure have completed.
 */
void asocket_destroy(struct asocket *s);

#ifdef __cplusplus
}
#endif
#endif //__CUTILS_ABORT_SOCKET__H__

include/cutils/array.h

deleted100644 → 0
+0 −67
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 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 pointer array which intelligently expands its capacity ad needed.
 */

#ifndef __ARRAY_H
#define __ARRAY_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>

/** An array. */
typedef struct Array Array;

/** Constructs a new array. Returns NULL if we ran out of memory. */
Array* arrayCreate();

/** Frees an array. Does not free elements themselves. */
void arrayFree(Array* array);

/** Adds a pointer. Returns 0 is successful, < 0 otherwise. */
int arrayAdd(Array* array, void* pointer);

/** Gets the pointer at the specified index. */
void* arrayGet(Array* array, int index);

/** Removes the pointer at the given index and returns it. */
void* arrayRemove(Array* array, int index);

/** Sets pointer at the given index. Returns old pointer. */
void* arraySet(Array* array, int index, void* pointer);

/** Sets the array size. Sets new pointers to NULL. Returns 0 if successful, < 0 otherwise . */
int arraySetSize(Array* array, int size);

/** Returns the size of the given array. */
int arraySize(Array* array);

/** 
 * Returns a pointer to a C-style array which will be valid until this array 
 * changes.
 */
const void** arrayUnwrap(Array* array);

#ifdef __cplusplus
}
#endif

#endif /* __ARRAY_H */ 

include/cutils/mq.h

deleted100644 → 0
+0 −124
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 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.
 */

/**
 * IPC messaging library.
 */

#ifndef __MQ_H
#define __MQ_H

#ifdef __cplusplus
extern "C" {
#endif

/** A message. */
typedef struct MqMessage MqMessage;

/** A destination to which messages can be sent. */
typedef struct MqDestination MqDestination;

/* Array of bytes. */
typedef struct MqBytes MqBytes;

/** 
 * Hears messages. 
 * 
 * @param destination to which the message was sent
 * @param message the message to hear
 */
typedef void MqMessageListener(MqDestination* destination, MqMessage* message);

/** 
 * Hears a destination close.
 * 
 * @param destination that closed
 */
typedef void MqCloseListener(MqDestination* destination);

/** Message functions. */

/** 
 * Creates a new Message.
 * 
 * @param header as defined by user
 * @param body as defined by user
 * @param replyTo destination to which replies should be sent, NULL if none
 */
MqMessage* mqCreateMessage(MqBytes header, MqBytes body, 
        MqDestination* replyTo);

/** Sends a message to a destination. */
void mqSendMessage(MqMessage* message, MqDestination* destination);

/** Destination functions. */

/** 
 * Creates a new destination. Acquires a reference implicitly.
 *
 * @param messageListener function to call when a message is recieved
 * @param closeListener function to call when the destination closes
 * @param userData user-specific data to associate with the destination.
 *  Retrieve using mqGetDestinationUserData().
 */
MqDestination* mqCreateDestination(MqMessageListener* messageListener, 
        MqCloseListener* closeListener, void* userData);

/**
 * Gets user data which was associated with the given destination at 
 * construction time. 
 * 
 * It is only valid to call this function in the same process that the 
 * given destination was created in.
 * This function returns a null pointer if you call it on a destination
 * created in a remote process.
 */
void* mqGetUserData(MqDestination* destination);

/**
 * Returns 1 if the destination was created in this process, or 0 if
 * the destination was created in a different process, in which case you have
 * a remote stub.
 */
int mqIsDestinationLocal(MqDestination* destination);

/**
 * Increments the destination's reference count.
 */
void mqKeepDestination(MqDesintation* destination);

/**
 * Decrements the destination's reference count. 
 */
void mqFreeDestination(MqDestination* desintation);

/** Registry API. */

/**
 * Gets the destination bound to a name.
 */
MqDestination* mqGetDestination(char* name);

/**
 * Binds a destination to a name.
 */
void mqPutDestination(char* name, MqDestination* desintation);

#ifdef __cplusplus
}
#endif

#endif /* __MQ_H */ 

include/cutils/qsort_r_compat.h

deleted100644 → 0
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

/*
 * Provides a portable version of qsort_r, called qsort_r_compat, which is a
 * reentrant variant of qsort that passes a user data pointer to its comparator.
 * This implementation follows the BSD parameter convention.
 */

#ifndef _LIBS_CUTILS_QSORT_R_COMPAT_H
#define _LIBS_CUTILS_QSORT_R_COMPAT_H

#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

void qsort_r_compat(void* base, size_t nel, size_t width, void* thunk,
        int (*compar)(void*, const void* , const void* ));

#ifdef __cplusplus
}
#endif

#endif // _LIBS_CUTILS_QSORT_R_COMPAT_H

include/cutils/record_stream.h

deleted100644 → 0
+0 −43
Original line number Diff line number Diff line
/*
 * 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 _CUTILS_RECORD_STREAM_H
#define _CUTILS_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 /*_CUTILS_RECORD_STREAM_H*/
Loading