1/*
2 * Copyright (C) 2017 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 CHRE_PLATFORM_LINUX_PLATFORM_LOG_BASE_H_
18#define CHRE_PLATFORM_LINUX_PLATFORM_LOG_BASE_H_
19
20#include <condition_variable>
21#include <mutex>
22#include <thread>
23#include <queue>
24
25namespace chre {
26
27/**
28 * Storage for the Linux implementation of the PlatformLog class.
29 */
30class PlatformLogBase {
31 protected:
32  /**
33   * A looper method that idles on a condition variable on logs becoming
34   * available. When logs are available, they are output via std::cout.
35   */
36  void logLooper();
37
38  //! The thread that waits on incoming log messages and sends them out to
39  //! std::cout.
40  std::thread mLoggerThread;
41
42  //! A mutex to guard the shared queue and exit condition of this class.
43  std::mutex mMutex;
44
45  //! The condition variable to signal that the log looper has messages
46  //! available to output.
47  std::condition_variable mConditionVariable;
48
49  //! A queue of incoming log messages.
50  std::queue<std::unique_ptr<char>> mLogQueue;
51
52  //! A flag to indicate that the logger should shut down.
53  bool mStopLogger = false;
54};
55
56}  // namespace chre
57
58#endif  // CHRE_PLATFORM_LINUX_PLATFORM_LOG_BASE_H_
59