| Mark Salyzyn | c0cf90d | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2005-2017 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 |  | 
| Elliott Hughes | 66680bd | 2018-06-18 10:16:46 -0700 | [diff] [blame] | 17 | #pragma once | 
| Mark Salyzyn | c0cf90d | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 18 |  | 
| Mark Salyzyn | 6dabc81 | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 19 | #include <stdio.h> | 
|  | 20 |  | 
| Mark Salyzyn | c0cf90d | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 21 | /* | 
|  | 22 | * The opaque context | 
|  | 23 | */ | 
| Mark Salyzyn | c0cf90d | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 24 | typedef struct android_logcat_context_internal* android_logcat_context; | 
| Mark Salyzyn | c0cf90d | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 25 |  | 
|  | 26 | /* Creates a context associated with this logcat instance | 
|  | 27 | * | 
|  | 28 | * Returns a pointer to the context, or a NULL on error. | 
|  | 29 | */ | 
|  | 30 | android_logcat_context create_android_logcat(); | 
|  | 31 |  | 
|  | 32 | /* Collects and outputs the logcat data to output and error file descriptors | 
|  | 33 | * | 
|  | 34 | * Will block, performed in-thread and in-process | 
|  | 35 | * | 
|  | 36 | * The output file descriptor variable, if greater than or equal to 0, is | 
|  | 37 | * where the output (ie: stdout) will be sent. The file descriptor is closed | 
|  | 38 | * on android_logcat_destroy which terminates the instance, or when an -f flag | 
|  | 39 | * (output redirect to a file) is present in the command.  The error file | 
|  | 40 | * descriptor variable, if greater than or equal to 0, is where the error | 
|  | 41 | * stream (ie: stderr) will be sent, also closed on android_logcat_destroy. | 
|  | 42 | * The error file descriptor can be set to equal to the output file descriptor, | 
|  | 43 | * which will mix output and error stream content, and will defer closure of | 
|  | 44 | * the file descriptor on -f flag redirection.  Negative values for the file | 
|  | 45 | * descriptors will use stdout and stderr FILE references respectively | 
|  | 46 | * internally, and will not close the references as noted above. | 
|  | 47 | * | 
|  | 48 | * Return value is 0 for success, non-zero for errors. | 
|  | 49 | */ | 
| Elliott Hughes | 61b580e | 2018-06-15 15:16:20 -0700 | [diff] [blame] | 50 | int android_logcat_run_command(android_logcat_context ctx, int output, int error, int argc, | 
|  | 51 | char* const* argv, char* const* envp); | 
| Mark Salyzyn | 1d6928b | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 52 |  | 
| Mark Salyzyn | c0cf90d | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 53 | /* Finished with context | 
|  | 54 | * | 
| Mark Salyzyn | 1d6928b | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 55 | * Kill the command thread ASAP (if any), and free up all associated resources. | 
| Mark Salyzyn | c0cf90d | 2017-02-10 13:09:07 -0800 | [diff] [blame] | 56 | * | 
|  | 57 | * Return value is the result of the android_logcat_run_command, or | 
|  | 58 | * non-zero for any errors. | 
|  | 59 | */ | 
|  | 60 | int android_logcat_destroy(android_logcat_context* ctx); |