The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #ifndef NATIVE_HANDLE_H_ |
| 18 | #define NATIVE_HANDLE_H_ |
| 19 | |
Mathias Agopian | fee77ec | 2009-05-21 13:08:39 -0700 | [diff] [blame] | 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
Mathias Agopian | 8f13782 | 2009-05-20 14:16:34 -0700 | [diff] [blame] | 23 | |
Iliyan Malchev | 3ffd793 | 2011-04-13 14:01:38 -0700 | [diff] [blame] | 24 | typedef struct native_handle |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 25 | { |
Mathias Agopian | 8f13782 | 2009-05-20 14:16:34 -0700 | [diff] [blame] | 26 | int version; /* sizeof(native_handle_t) */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 27 | int numFds; /* number of file-descriptors at &data[0] */ |
| 28 | int numInts; /* number of ints at &data[numFds] */ |
| 29 | int data[0]; /* numFds + numInts ints */ |
Mathias Agopian | 8f13782 | 2009-05-20 14:16:34 -0700 | [diff] [blame] | 30 | } native_handle_t; |
| 31 | |
Mathias Agopian | 8f13782 | 2009-05-20 14:16:34 -0700 | [diff] [blame] | 32 | /* |
| 33 | * native_handle_close |
| 34 | * |
| 35 | * closes the file descriptors contained in this native_handle_t |
| 36 | * |
| 37 | * return 0 on success, or a negative error code on failure |
| 38 | * |
| 39 | */ |
| 40 | int native_handle_close(const native_handle_t* h); |
| 41 | |
| 42 | |
| 43 | /* |
| 44 | * native_handle_create |
| 45 | * |
| 46 | * creates a native_handle_t and initializes it. must be destroyed with |
| 47 | * native_handle_delete(). |
| 48 | * |
| 49 | */ |
| 50 | native_handle_t* native_handle_create(int numFds, int numInts); |
| 51 | |
| 52 | /* |
| 53 | * native_handle_delete |
| 54 | * |
| 55 | * frees a native_handle_t allocated with native_handle_create(). |
| 56 | * This ONLY frees the memory allocated for the native_handle_t, but doesn't |
| 57 | * close the file descriptors; which can be achieved with native_handle_close(). |
| 58 | * |
| 59 | * return 0 on success, or a negative error code on failure |
| 60 | * |
| 61 | */ |
| 62 | int native_handle_delete(native_handle_t* h); |
| 63 | |
| 64 | |
Mathias Agopian | fee77ec | 2009-05-21 13:08:39 -0700 | [diff] [blame] | 65 | #ifdef __cplusplus |
| 66 | } |
| 67 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 68 | |
| 69 | #endif /* NATIVE_HANDLE_H_ */ |