blob: 8b8e02f7d92d17a1a35b8bfa2b745233c958ee5c [file] [log] [blame]
Mark Salyzyndfa7a072014-02-11 12:29:31 -08001/*
2 * Copyright (C) 2014 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#ifndef _LOGD_LOG_WHITE_BLACK_LIST_H__
18#define _LOGD_LOG_WHITE_BLACK_LIST_H__
19
20#include <sys/types.h>
21
Mark Salyzyne0ed16c2015-08-19 13:31:31 -070022#include <list>
Mark Salyzyn73160ac2015-08-20 10:01:44 -070023#include <string.h>
Mark Salyzyndfa7a072014-02-11 12:29:31 -080024
Mark Salyzyn5ac5c6b2015-08-28 08:02:59 -070025#include "LogBufferElement.h"
Mark Salyzyndfa7a072014-02-11 12:29:31 -080026
27// White and Blacklist
28
29class Prune {
30 friend class PruneList;
31
32 const uid_t mUid;
33 const pid_t mPid;
34 int cmp(uid_t uid, pid_t pid) const;
35
36public:
37 static const uid_t uid_all = (uid_t) -1;
38 static const pid_t pid_all = (pid_t) -1;
39
40 Prune(uid_t uid, pid_t pid);
41
42 uid_t getUid() const { return mUid; }
43 pid_t getPid() const { return mPid; }
44
45 int cmp(LogBufferElement *e) const { return cmp(e->getUid(), e->getPid()); }
46
Mark Salyzyn73160ac2015-08-20 10:01:44 -070047 std::string format();
Mark Salyzyndfa7a072014-02-11 12:29:31 -080048};
49
Mark Salyzyne0ed16c2015-08-19 13:31:31 -070050typedef std::list<Prune> PruneCollection;
Mark Salyzyndfa7a072014-02-11 12:29:31 -080051
52class PruneList {
53 PruneCollection mNaughty;
54 PruneCollection mNice;
55 bool mWorstUidEnabled;
Mark Salyzynbec3c3d2015-08-28 08:02:59 -070056 bool mWorstPidOfSystemEnabled;
Mark Salyzyndfa7a072014-02-11 12:29:31 -080057
58public:
59 PruneList();
60 ~PruneList();
61
Mark Salyzyn73160ac2015-08-20 10:01:44 -070062 int init(const char *str);
Mark Salyzyndfa7a072014-02-11 12:29:31 -080063
64 bool naughty(LogBufferElement *element);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -070065 bool naughty(void) { return !mNaughty.empty(); }
Mark Salyzyndfa7a072014-02-11 12:29:31 -080066 bool nice(LogBufferElement *element);
Mark Salyzyn97c1c2b2015-03-10 13:51:35 -070067 bool nice(void) { return !mNice.empty(); }
Mark Salyzyndfa7a072014-02-11 12:29:31 -080068 bool worstUidEnabled() const { return mWorstUidEnabled; }
Mark Salyzynbec3c3d2015-08-28 08:02:59 -070069 bool worstPidOfSystemEnabled() const { return mWorstPidOfSystemEnabled; }
Mark Salyzyndfa7a072014-02-11 12:29:31 -080070
Mark Salyzyn73160ac2015-08-20 10:01:44 -070071 std::string format();
Mark Salyzyndfa7a072014-02-11 12:29:31 -080072};
73
74#endif // _LOGD_LOG_WHITE_BLACK_LIST_H__