OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/rtc_base/logsinks.h" | |
12 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | |
13 | |
14 namespace webrtc_jni { | |
15 | |
16 JOW(jlong, CallSessionFileRotatingLogSink_nativeAddSink) | |
17 (JNIEnv* jni, jclass, jstring j_dirPath, jint j_maxFileSize, jint j_severity) { | |
18 std::string dir_path = JavaToStdString(jni, j_dirPath); | |
19 rtc::CallSessionFileRotatingLogSink* sink = | |
20 new rtc::CallSessionFileRotatingLogSink(dir_path, j_maxFileSize); | |
21 if (!sink->Init()) { | |
22 LOG_V(rtc::LoggingSeverity::LS_WARNING) | |
23 << "Failed to init CallSessionFileRotatingLogSink for path " | |
24 << dir_path; | |
25 delete sink; | |
26 return 0; | |
27 } | |
28 rtc::LogMessage::AddLogToStream( | |
29 sink, static_cast<rtc::LoggingSeverity>(j_severity)); | |
30 return (jlong)sink; | |
31 } | |
32 | |
33 JOW(void, CallSessionFileRotatingLogSink_nativeDeleteSink) | |
34 (JNIEnv* jni, jclass, jlong j_sink) { | |
35 rtc::CallSessionFileRotatingLogSink* sink = | |
36 reinterpret_cast<rtc::CallSessionFileRotatingLogSink*>(j_sink); | |
37 rtc::LogMessage::RemoveLogToStream(sink); | |
38 delete sink; | |
39 } | |
40 | |
41 JOW(jbyteArray, CallSessionFileRotatingLogSink_nativeGetLogData) | |
42 (JNIEnv* jni, jclass, jstring j_dirPath) { | |
43 std::string dir_path = JavaToStdString(jni, j_dirPath); | |
44 std::unique_ptr<rtc::CallSessionFileRotatingStream> stream( | |
45 new rtc::CallSessionFileRotatingStream(dir_path)); | |
46 if (!stream->Open()) { | |
47 LOG_V(rtc::LoggingSeverity::LS_WARNING) | |
48 << "Failed to open CallSessionFileRotatingStream for path " << dir_path; | |
49 return jni->NewByteArray(0); | |
50 } | |
51 size_t log_size = 0; | |
52 if (!stream->GetSize(&log_size) || log_size == 0) { | |
53 LOG_V(rtc::LoggingSeverity::LS_WARNING) | |
54 << "CallSessionFileRotatingStream returns 0 size for path " << dir_path; | |
55 return jni->NewByteArray(0); | |
56 } | |
57 | |
58 size_t read = 0; | |
59 std::unique_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); | |
60 stream->ReadAll(buffer.get(), log_size, &read, nullptr); | |
61 | |
62 jbyteArray result = jni->NewByteArray(read); | |
63 jni->SetByteArrayRegion(result, 0, read, buffer.get()); | |
64 | |
65 return result; | |
66 } | |
67 | |
68 } // namespace webrtc_jni | |
OLD | NEW |