1 /* 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 #pragma once 18 19 #include <sys/types.h> 20 21 #include <string.h> 22 #include <list> 23 24 #include "LogBufferElement.h" 25 26 class Prune { 27 public: 28 static const uid_t UID_ALL = (uid_t)-1; 29 static const pid_t PID_ALL = (pid_t)-1; 30 Prune(uid_t uid,pid_t pid)31 Prune(uid_t uid, pid_t pid) : uid_(uid), pid_(pid) {} 32 33 bool Matches(LogBufferElement* element) const; 34 std::string Format() const; 35 uid()36 uid_t uid() const { return uid_; } pid()37 pid_t pid() const { return pid_; } 38 39 private: 40 const uid_t uid_; 41 const pid_t pid_; 42 }; 43 44 class PruneList { 45 public: 46 PruneList(); 47 48 bool Init(const char* str); 49 std::string Format() const; 50 51 bool IsHighPriority(LogBufferElement* element) const; 52 bool IsLowPriority(LogBufferElement* element) const; 53 HasHighPriorityPruneRules()54 bool HasHighPriorityPruneRules() const { return !high_priority_prune_.empty(); } HasLowPriorityPruneRules()55 bool HasLowPriorityPruneRules() const { return !low_priority_prune_.empty(); } 56 worst_uid_enabled()57 bool worst_uid_enabled() const { return worst_uid_enabled_; } worst_pid_of_system_enabled()58 bool worst_pid_of_system_enabled() const { return worst_pid_of_system_enabled_; } 59 60 private: 61 std::list<Prune> high_priority_prune_; 62 std::list<Prune> low_priority_prune_; 63 64 bool worst_uid_enabled_; 65 bool worst_pid_of_system_enabled_; 66 }; 67