Fix freeze coin info (#73)
* Enable stdout/stderr logging to logcat on android * coin control fix
This commit is contained in:
@@ -9,6 +9,71 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOG_TAG "moneroc"
|
||||
#define BUFFER_SIZE 1024*32
|
||||
|
||||
static int stdoutToLogcat(const char *buf, int size) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, buf);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int stderrToLogcat(const char *buf, int size) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, LOG_TAG, buf);
|
||||
return size;
|
||||
}
|
||||
|
||||
void redirectStdoutThread(int pipe_stdout[2]) {
|
||||
char bufferStdout[BUFFER_SIZE];
|
||||
while (true) {
|
||||
int read_size = read(pipe_stdout[0], bufferStdout, sizeof(bufferStdout) - 1);
|
||||
if (read_size > 0) {
|
||||
bufferStdout[read_size] = '\0';
|
||||
stdoutToLogcat(bufferStdout, read_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void redirectStderrThread(int pipe_stderr[2]) {
|
||||
char bufferStderr[BUFFER_SIZE];
|
||||
while (true) {
|
||||
int read_size = read(pipe_stderr[0], bufferStderr, sizeof(bufferStderr) - 1);
|
||||
if (read_size > 0) {
|
||||
bufferStderr[read_size] = '\0';
|
||||
stderrToLogcat(bufferStderr, read_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setupAndroidLogging() {
|
||||
static int pfdStdout[2];
|
||||
static int pfdStderr[2];
|
||||
|
||||
pipe(pfdStdout);
|
||||
pipe(pfdStderr);
|
||||
|
||||
dup2(pfdStdout[1], STDOUT_FILENO);
|
||||
dup2(pfdStderr[1], STDERR_FILENO);
|
||||
|
||||
std::thread stdoutThread(redirectStdoutThread, pfdStdout);
|
||||
std::thread stderrThread(redirectStderrThread, pfdStderr);
|
||||
|
||||
stdoutThread.detach();
|
||||
stderrThread.detach();
|
||||
}
|
||||
|
||||
#endif // __ANDROID__
|
||||
|
||||
__attribute__((constructor))
|
||||
void library_init() {
|
||||
#ifdef __ANDROID__
|
||||
setupAndroidLogging(); // This will now run automatically when the library is loaded
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* vectorToString(const std::vector<std::string>& vec, const std::string separator) {
|
||||
// Check if the vector is empty
|
||||
@@ -195,4 +260,4 @@ std::vector<uint64_t> splitStringUint(const std::string& str, const std::string&
|
||||
}
|
||||
tokens.push_back(std::stoull(content)); // Inserting the last token
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user