summaryrefslogtreecommitdiff
path: root/src/proc-scanner.h
blob: 3759c3e7e8c5b8a1cc141ff03cea5d1aefae132e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Flora License, Version 1.1 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://floralicense.org/license/
 *
 * 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.
 */

#ifndef __PROC_SCANNER_H
#define __PROC_SCANNER_H

#include <stdbool.h>

#include "process.h"

/**
 * @brief Scanner object
 */
typedef struct proc_scanner proc_scanner_t;

/**
 * @brief Iterator callback
 *
 * @param[in]: proc the proccess structure
 * @param[in]: data passed to @proc_scanner_foreach_process
 *
 * @return: true to continue iterating, false otherwise.
*/
typedef bool (*foreach_t)(struct process *proc, void *data);

/**
 * @brief Sort callback
 *
 * @param[in]: proc the process
 * @param[in]: proc the process
 *
 * @return value < 0 if @proc1 goes before @proc2, value > 0 othersize, 0 if
 * equal
 */
typedef int (*sort_t)(struct process *proc1, struct process *proc2);

/**
 * @brief Creates new proc_scanner object
 *
 * @return scanner object poiter or NULL in case of error
 *
 * @note the scanner should be released with @proc_scanner_free
 */
proc_scanner_t *proc_scanner_new();

/**
 * @brief Releases resources allocated for scanner_object
 *
 * @param[in] scanner
 */
void proc_scanner_free(proc_scanner_t *scanner);

/**
 * @brief Performs scan of processes scanners contained in /proc/ scannerectory
 *
 * @param[in] scanner
 *
 * @return 0 on success, other value on failure.
 */
int proc_scanner_scan(proc_scanner_t *scanner);

/**
 * @brief Performs scan of processes scanners contained in /proc/ scannerectory
 *
 * @param[in] scanner
 *
 * @return 0 on success, other value on failure.
 */
int proc_scanner_scan_pids(proc_scanner_t *scanner, int *pids, int n_pids);

/**
 * @brief Iterate over processes scanned by @proc_scanner_scan_pids or
 * @proc_scanner_scan methods.
 *
 * @param[in] scanner
 * @param[in] cb iterator callback
 * @param[in] data user data passed to callback @cb
 *
 * @return 0 on success, other value on failure.
 */
int proc_scanner_foreach_process(proc_scanner_t *scanner, foreach_t cb, void *data);

/**
 * @brief Sort processes scanned by @proc_scanner_scan_pids or
 * @proc_scanner_scan methods. The sorting will affect process iteration
 * with @proc_scanner_foreach_process.
 *
 * @param[in] scanner
 * @param[in] cb sort callback
 *
 * @return 0 on success, other value on failure.
 */
int proc_scanner_sort_processes(proc_scanner_t *scanner, sort_t cb);

#endif