1 /*
2  * Copyright (C) 2019 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 #pragma once
18 
19 #include <stdint.h>
20 
21 __BEGIN_DECLS
22 
23 // For host builds, __INTRODUCED_IN is not defined.
24 #ifndef __INTRODUCED_IN
25 #define __INTRODUCED_IN(x)
26 #endif
27 
28 struct ACgroupController;
29 typedef struct ACgroupController ACgroupController;
30 
31 #if __ANDROID_API__ >= __ANDROID_API_Q__
32 
33 // ACgroupFile
34 
35 /**
36  * Returns file version. See android::cgrouprc::format::CgroupFile for a list of valid versions
37  * for the file.
38  * If ACgroupFile_init() isn't called, initialization will be done first.
39  * If initialization failed, return 0.
40  */
41 __attribute__((warn_unused_result)) uint32_t ACgroupFile_getVersion() __INTRODUCED_IN(29);
42 
43 /**
44  * Returns the number of controllers.
45  * If ACgroupFile_init() isn't called, initialization will be done first.
46  * If initialization failed, return 0.
47  */
48 __attribute__((warn_unused_result)) uint32_t ACgroupFile_getControllerCount() __INTRODUCED_IN(29);
49 
50 /**
51  * Returns the controller at the given index.
52  * Returnss nullptr if the given index exceeds getControllerCount().
53  * If ACgroupFile_init() isn't called, initialization will be done first.
54  * If initialization failed, return 0.
55  */
56 __attribute__((warn_unused_result)) const ACgroupController* ACgroupFile_getController(
57         uint32_t index) __INTRODUCED_IN(29);
58 
59 // ACgroupController
60 
61 /**
62  * Returns the version of the given controller.
63  * If the given controller is null, return 0.
64  */
65 __attribute__((warn_unused_result)) uint32_t ACgroupController_getVersion(const ACgroupController*)
66         __INTRODUCED_IN(29);
67 
68 /**
69  * Flag bitmask used in ACgroupController_getFlags
70  */
71 #define CGROUPRC_CONTROLLER_FLAG_MOUNTED 0x1
72 #define CGROUPRC_CONTROLLER_FLAG_NEEDS_ACTIVATION 0x2
73 
74 #if __ANDROID_API__ >= __ANDROID_API_R__
75 
76 /**
77  * Returns the flags bitmask of the given controller.
78  * If the given controller is null, return 0.
79  */
80 __attribute__((warn_unused_result, weak)) uint32_t ACgroupController_getFlags(
81         const ACgroupController*) __INTRODUCED_IN(30);
82 
83 #endif
84 
85 /**
86  * Returns the name of the given controller.
87  * If the given controller is null, return nullptr.
88  */
89 __attribute__((warn_unused_result)) const char* ACgroupController_getName(const ACgroupController*)
90         __INTRODUCED_IN(29);
91 
92 /**
93  * Returns the path of the given controller.
94  * If the given controller is null, return nullptr.
95  */
96 __attribute__((warn_unused_result)) const char* ACgroupController_getPath(const ACgroupController*)
97         __INTRODUCED_IN(29);
98 
99 __END_DECLS
100 
101 #endif
102