summaryrefslogtreecommitdiff
path: root/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp
blob: 2d8c655fcf009335feac9948d1b21383e948d493 (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
//===-- LogFilterChain.cpp --------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "LogFilterChain.h"

#include "LogFilter.h"

LogFilterChain::LogFilterChain(bool default_accept)
    : m_filters(), m_default_accept(default_accept) {}

void LogFilterChain::AppendFilter(const LogFilterSP &filter_sp) {
  if (filter_sp)
    m_filters.push_back(filter_sp);
}

void LogFilterChain::ClearFilterChain() { m_filters.clear(); }

bool LogFilterChain::GetDefaultAccepts() const { return m_default_accept; }

void LogFilterChain::SetDefaultAccepts(bool default_accept) {
  m_default_accept = default_accept;
}

bool LogFilterChain::GetAcceptMessage(const LogMessage &message) const {
  for (auto filter_sp : m_filters) {
    if (filter_sp->DoesMatch(message)) {
      // This message matches this filter.  If the filter accepts matches,
      // this message matches; otherwise, it rejects matches.
      return filter_sp->MatchesAreAccepted();
    }
  }

  // None of the filters matched.  Therefore, we do whatever the
  // default fall-through rule says.
  return m_default_accept;
}