blob: 85ed7dac65076fa7e64f7d176971b10363d49aaf [file] [log] [blame]
Mark Salyzync0cf90d2017-02-10 13:09:07 -08001/*
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 Hughes66680bd2018-06-18 10:16:46 -070017#pragma once
Mark Salyzync0cf90d2017-02-10 13:09:07 -080018
Mark Salyzyn6dabc812017-02-10 13:09:07 -080019#include <stdio.h>
20
Mark Salyzync0cf90d2017-02-10 13:09:07 -080021/*
22 * The opaque context
23 */
Mark Salyzync0cf90d2017-02-10 13:09:07 -080024typedef struct android_logcat_context_internal* android_logcat_context;
Mark Salyzync0cf90d2017-02-10 13:09:07 -080025
26/* Creates a context associated with this logcat instance
27 *
28 * Returns a pointer to the context, or a NULL on error.
29 */
30android_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 Hughes61b580e2018-06-15 15:16:20 -070050int android_logcat_run_command(android_logcat_context ctx, int output, int error, int argc,
51 char* const* argv, char* const* envp);
Mark Salyzyn1d6928b2017-02-10 13:09:07 -080052
Mark Salyzync0cf90d2017-02-10 13:09:07 -080053/* Finished with context
54 *
Mark Salyzyn1d6928b2017-02-10 13:09:07 -080055 * Kill the command thread ASAP (if any), and free up all associated resources.
Mark Salyzync0cf90d2017-02-10 13:09:07 -080056 *
57 * Return value is the result of the android_logcat_run_command, or
58 * non-zero for any errors.
59 */
60int android_logcat_destroy(android_logcat_context* ctx);