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