Android-cuttlefish cvd tool
kernel_log_events_handler.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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 <atomic>
20#include <list>
21#include <map>
22#include <memory>
23#include <mutex>
24#include <thread>
25
26#include <json/json.h>
27
29
30namespace cuttlefish {
31
32// Listen to kernel log events and report them to clients.
34 explicit KernelLogEventsHandler(SharedFD kernel_log_fd);
35
37
38 int AddSubscriber(std::function<void(const Json::Value&)> subscriber);
39 void Unsubscribe(int subscriber_id);
40 private:
41 void ReadLoop();
42 void DeliverEvent(const Json::Value& event);
43
46 std::atomic<bool> running_;
47 std::thread read_thread_;
48 std::map<int, std::function<void(const Json::Value&)>> subscribers_;
50 std::mutex subscribers_mtx_;
51 std::list<Json::Value> last_events_;
52};
53
54} // namespace cuttlefish
Definition: shared_fd.h:129
Event event
Definition: kernel_log_server.cc:56
Definition: alloc_utils.cpp:23
Definition: kernel_log_events_handler.h:33
SharedFD kernel_log_fd_
Definition: kernel_log_events_handler.h:44
void ReadLoop()
Definition: kernel_log_events_handler.cpp:43
SharedFD eventfd_
Definition: kernel_log_events_handler.h:45
std::atomic< bool > running_
Definition: kernel_log_events_handler.h:46
int last_subscriber_id_
Definition: kernel_log_events_handler.h:49
KernelLogEventsHandler(SharedFD kernel_log_fd)
Definition: kernel_log_events_handler.cpp:30
std::list< Json::Value > last_events_
Definition: kernel_log_events_handler.h:51
std::thread read_thread_
Definition: kernel_log_events_handler.h:47
std::map< int, std::function< void(const Json::Value &)> > subscribers_
Definition: kernel_log_events_handler.h:48
void Unsubscribe(int subscriber_id)
Definition: kernel_log_events_handler.cpp:114
void DeliverEvent(const Json::Value &event)
Definition: kernel_log_events_handler.cpp:119
int AddSubscriber(std::function< void(const Json::Value &)> subscriber)
Definition: kernel_log_events_handler.cpp:102
std::mutex subscribers_mtx_
Definition: kernel_log_events_handler.h:50
~KernelLogEventsHandler()
Definition: kernel_log_events_handler.cpp:37