summaryrefslogtreecommitdiff
path: root/src/proc-scanner.h
diff options
context:
space:
mode:
authorLukasz Stanislawski <l.stanislaws@samsung.com>2018-07-11 20:02:29 +0200
committerLukasz Stanislawski <l.stanislaws@samsung.com>2018-07-16 16:32:28 +0200
commitd9cdf0617f87029e9525479388a13b1a844b488f (patch)
tree5f77ee6ee19f22691c836afc910301eefb22b080 /src/proc-scanner.h
parent6470182364f780033db8fa401ad5b3da31251d06 (diff)
downloadttsd-worker-task-d9cdf0617f87029e9525479388a13b1a844b488f.tar.gz
ttsd-worker-task-d9cdf0617f87029e9525479388a13b1a844b488f.tar.bz2
ttsd-worker-task-d9cdf0617f87029e9525479388a13b1a844b488f.zip
report-generator: implement top report generator
This patch adds additional objects: proc-scanner - for scanning whole /proc/ dir process - to gather information from /proc/<pid>/* Change-Id: Ic0ad58fb9a0ae59e9390b3d109440d91d25e90da
Diffstat (limited to 'src/proc-scanner.h')
-rw-r--r--src/proc-scanner.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/proc-scanner.h b/src/proc-scanner.h
new file mode 100644
index 0000000..3759c3e
--- /dev/null
+++ b/src/proc-scanner.h
@@ -0,0 +1,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