Skip to content

Commit

Permalink
use std::unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Dec 14, 2021
1 parent a0a5f35 commit c671f8c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions selfdrive/logcatd/logcatd_android.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <sys/time.h>
#include <sys/resource.h>

#include <memory>

#include <android/log.h>
#include <log/logger.h>
#include <log/logprint.h>
Expand All @@ -17,29 +19,28 @@ int main() {
struct timespec cur_time;
clock_gettime(CLOCK_REALTIME, &cur_time);
log_time last_log_time(cur_time);
logger_list *logger_list = nullptr;

while (!do_exit) {
// setup android logging
if (!logger_list) {
logger_list = android_logger_list_alloc_time(ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, last_log_time, 0);
}
std::unique_ptr<logger_list, decltype(&android_logger_list_free)> logger_list(
android_logger_list_alloc_time(ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, last_log_time, 0),
&android_logger_list_free);
assert(logger_list);

struct logger *main_logger = android_logger_open(logger_list, LOG_ID_MAIN);
struct logger *main_logger = android_logger_open(logger_list.get(), LOG_ID_MAIN);
assert(main_logger);
struct logger *radio_logger = android_logger_open(logger_list, LOG_ID_RADIO);
struct logger *radio_logger = android_logger_open(logger_list.get(), LOG_ID_RADIO);
assert(radio_logger);
struct logger *system_logger = android_logger_open(logger_list, LOG_ID_SYSTEM);
struct logger *system_logger = android_logger_open(logger_list.get(), LOG_ID_SYSTEM);
assert(system_logger);
struct logger *crash_logger = android_logger_open(logger_list, LOG_ID_CRASH);
struct logger *crash_logger = android_logger_open(logger_list.get(), LOG_ID_CRASH);
assert(crash_logger);
struct logger *kernel_logger = android_logger_open(logger_list, (log_id_t)5); // LOG_ID_KERNEL
struct logger *kernel_logger = android_logger_open(logger_list.get(), (log_id_t)5); // LOG_ID_KERNEL
assert(kernel_logger);

while (!do_exit) {
log_msg log_msg;
int err = android_logger_list_read(logger_list, &log_msg);
int err = android_logger_list_read(logger_list.get(), &log_msg);
if (err <= 0) break;

AndroidLogEntry entry;
Expand All @@ -61,14 +62,8 @@ int main() {
pm.send("androidLog", msg);
}

android_logger_list_free(logger_list);
logger_list = NULL;
util::sleep_for(500);
}

if (logger_list) {
android_logger_list_free(logger_list);
}

return 0;
}

0 comments on commit c671f8c

Please sign in to comment.