Skip to content

Commit 7e50d5d

Browse files
authored
Separate logging threads for stdout and stderr (#41)
* Format files * Separate stdout and stderr in dlog output
1 parent 2b257bf commit 7e50d5d

19 files changed

+98
-74
lines changed

shell/platform/tizen/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ source_set("flutter_tizen") {
5050
"key_event_handler.cc",
5151
"tizen_embedder_engine.cc",
5252
"tizen_event_loop.cc",
53+
"tizen_log.cc",
5354
"tizen_renderer.cc",
5455
"tizen_vsync_waiter.cc",
5556
"touch_event_handler.cc",

shell/platform/tizen/channels/lifecycle_channel.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ class LifecycleChannel {
2020
private:
2121
FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine_;
2222
};
23+
2324
#endif // EMBEDDER_LIFECYCLE_CHANNEL_H_

shell/platform/tizen/channels/platform_view_channel.cc

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ std::string ExtractStringFromMap(const flutter::EncodableValue& arguments,
2424
}
2525
return std::string();
2626
}
27+
2728
int ExtractIntFromMap(const flutter::EncodableValue& arguments,
2829
const char* key) {
2930
if (std::holds_alternative<flutter::EncodableMap>(arguments)) {
@@ -33,6 +34,7 @@ int ExtractIntFromMap(const flutter::EncodableValue& arguments,
3334
}
3435
return -1;
3536
}
37+
3638
double ExtractDoubleFromMap(const flutter::EncodableValue& arguments,
3739
const char* key) {
3840
if (std::holds_alternative<flutter::EncodableMap>(arguments)) {

shell/platform/tizen/channels/settings_channel.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ static constexpr char PLATFORM_BRIGHTNESS[] = "platformBrightness";
1212
SettingsChannel::SettingsChannel(flutter::BinaryMessenger* messenger)
1313
: channel_(
1414
std::make_unique<flutter::BasicMessageChannel<rapidjson::Document>>(
15-
messenger,
16-
CHANNEL_NAME,
15+
messenger, CHANNEL_NAME,
1716
&flutter::JsonMessageCodec::GetInstance())) {
1817
system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR,
1918
OnSettingsChangedCallback, this);

shell/platform/tizen/channels/settings_channel.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define EMBEDDER_SETTINGS_CHANNEL_H_
77

88
#include <system/system_settings.h>
9+
910
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/basic_message_channel.h"
1011
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h"
1112
#include "flutter/shell/platform/common/cpp/json_message_codec.h"
@@ -22,4 +23,5 @@ class SettingsChannel {
2223
void* user_data);
2324
void SendSettingsEvent();
2425
};
26+
2527
#endif // EMBEDDER_SETTINGS_CHANNEL_H_

shell/platform/tizen/channels/text_input_channel.cc

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#include "flutter/shell/platform/tizen/tizen_embedder_engine.h"
1111
#include "flutter/shell/platform/tizen/tizen_log.h"
12-
#include "stdlib.h"
13-
#include "string.h"
1412

1513
static constexpr char kSetEditingStateMethod[] = "TextInput.setEditingState";
1614
static constexpr char kClearClientMethod[] = "TextInput.clearClient";

shell/platform/tizen/channels/text_input_channel.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef EMBEDDER_TEXT_INPUT_PLUGIN_H_
6-
#define EMBEDDER_TEXT_INPUT_PLUGIN_H_
5+
#ifndef EMBEDDER_TEXT_INPUT_CHANNEL_H_
6+
#define EMBEDDER_TEXT_INPUT_CHANNEL_H_
77

88
#define EFL_BETA_API_SUPPORT
99
#include <Ecore_IMF.h>
@@ -82,4 +82,5 @@ class TextInputChannel {
8282
TizenEmbedderEngine* engine_;
8383
SoftwareKeyboardGeometry current_keyboard_geometry_;
8484
};
85-
#endif
85+
86+
#endif // EMBEDDER_TEXT_INPUT_CHANNEL_H_

shell/platform/tizen/flutter_tizen.cc

+2-56
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
#include "public/flutter_tizen.h"
77

8-
#include <inttypes.h>
9-
#include <unistd.h>
10-
118
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h"
129
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h"
1310
#include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h"
@@ -21,62 +18,10 @@ struct FlutterWindowControllerState {
2118
std::unique_ptr<TizenEmbedderEngine> engine;
2219
};
2320

24-
// The pipe used for logging to dlog.
25-
static int logging_pipe[2];
26-
// The thread that constantly writes out stdout to dlog through the pipe.
27-
// Only one logging thread should exist per process.
28-
static pthread_t logging_thread;
29-
30-
static void* LoggingFunction(void*) {
31-
ssize_t size;
32-
char buffer[1024];
33-
34-
while ((size = read(logging_pipe[0], buffer, sizeof(buffer) - 1)) > 0) {
35-
buffer[size] = 0;
36-
__dlog_print(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, "%s", buffer);
37-
}
38-
39-
close(logging_pipe[0]);
40-
close(logging_pipe[1]);
41-
42-
return nullptr;
43-
}
44-
45-
// Redirects the process's standard output/error to dlog for use by the flutter
46-
// tools.
47-
bool InitializeLogging() {
48-
if (logging_thread) {
49-
FT_LOGD("The logging thread already exists.");
50-
return true;
51-
}
52-
53-
if (pipe(logging_pipe) < 0) {
54-
FT_LOGE("Failed to create a pipe.");
55-
return false;
56-
}
57-
58-
if (dup2(logging_pipe[1], 1) < 0 || dup2(logging_pipe[1], 2) < 0) {
59-
FT_LOGE("Failed to duplicate file descriptors.");
60-
return false;
61-
}
62-
63-
if (pthread_create(&logging_thread, 0, LoggingFunction, 0) != 0) {
64-
FT_LOGE("Failed to create a logging thread.");
65-
logging_thread = 0;
66-
return false;
67-
}
68-
69-
if (pthread_detach(logging_thread) != 0) {
70-
FT_LOGE("Failed to detach the logging thread.");
71-
return false;
72-
}
73-
return true;
74-
}
75-
7621
FlutterWindowControllerRef FlutterCreateWindow(
7722
const FlutterWindowProperties& window_properties,
7823
const FlutterEngineProperties& engine_properties) {
79-
InitializeLogging();
24+
StartLogging();
8025

8126
auto state = std::make_unique<FlutterWindowControllerState>();
8227
state->engine = std::make_unique<TizenEmbedderEngine>(window_properties);
@@ -221,6 +166,7 @@ void FlutterNotifyLowMemoryWarning(FlutterWindowControllerRef controller) {
221166

222167
void FlutterRotateWindow(FlutterWindowControllerRef controller,
223168
int32_t degree) {
169+
FT_LOGW("Deprecated API. Use SystemChrome.setPreferredOrientations instead.");
224170
}
225171

226172
int64_t FlutterRegisterExternalTexture(

shell/platform/tizen/public/flutter_platform_view.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ FLUTTER_EXPORT void FlutterRegisterViewFactory(
7979
} // extern "C"
8080
#endif
8181

82-
#endif // FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_
82+
#endif // FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_

shell/platform/tizen/public/flutter_texture_registrar.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ FLUTTER_EXPORT bool FlutterMarkExternalTextureFrameAvailable(
4040
} // extern "C"
4141
#endif
4242

43-
#endif // FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_
43+
#endif // FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_

shell/platform/tizen/tizen_embedder_engine.h

+1
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,5 @@ class TizenEmbedderEngine : public TizenRenderer::Delegate {
159159
// The current renderer transformation.
160160
FlutterTransformation transformation_;
161161
};
162+
162163
#endif // EMBEDDER_TIZEN_EMBEDDER_ENGINE_H_

shell/platform/tizen/tizen_log.cc

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "tizen_log.h"
6+
7+
#include <pthread.h>
8+
#include <unistd.h>
9+
10+
static int stdout_pipe[2];
11+
static int stderr_pipe[2];
12+
static pthread_t stdout_thread;
13+
static pthread_t stderr_thread;
14+
static bool is_running = false;
15+
16+
static void* LoggingFunction(void* arg) {
17+
int* pipe = (int*)arg;
18+
int priority = pipe == stdout_pipe ? DLOG_INFO : DLOG_ERROR;
19+
20+
ssize_t size;
21+
char buffer[1024];
22+
23+
while ((size = read(pipe[0], buffer, sizeof(buffer) - 1)) > 0) {
24+
buffer[size] = 0;
25+
__dlog_print(LOG_ID_MAIN, priority, LOG_TAG, "%s", buffer);
26+
}
27+
28+
close(pipe[0]);
29+
close(pipe[1]);
30+
31+
return nullptr;
32+
}
33+
34+
void StartLogging() {
35+
if (is_running) {
36+
FT_LOGD("The threads are already running.");
37+
return;
38+
}
39+
40+
if (pipe(stdout_pipe) < 0 || pipe(stderr_pipe) < 0) {
41+
FT_LOGE("Failed to create pipes.");
42+
return;
43+
}
44+
45+
if (dup2(stdout_pipe[1], 1) < 0 || dup2(stderr_pipe[1], 2) < 0) {
46+
FT_LOGE("Failed to duplicate file descriptors.");
47+
return;
48+
}
49+
50+
if (pthread_create(&stdout_thread, 0, LoggingFunction, stdout_pipe) != 0 ||
51+
pthread_create(&stderr_thread, 0, LoggingFunction, stderr_pipe) != 0) {
52+
FT_LOGE("Failed to create threads.");
53+
return;
54+
}
55+
56+
if (pthread_detach(stdout_thread) != 0 ||
57+
pthread_detach(stderr_thread) != 0) {
58+
FT_LOGW("Failed to detach threads.");
59+
}
60+
is_running = true;
61+
}

shell/platform/tizen/tizen_log.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
#ifndef EMBEDDER_TIZEN_LOG_H_
66
#define EMBEDDER_TIZEN_LOG_H_
7+
78
#include <dlog.h>
89

910
#include <cassert>
1011
#include <cstdlib>
11-
#include <string>
12+
13+
// Start logging threads which constantly redirect stdout/stderr to dlog.
14+
// The threads can be started only once per process.
15+
void StartLogging();
1216

1317
#ifdef LOG_TAG
1418
#undef LOG_TAG
@@ -47,7 +51,7 @@
4751
FT_LOGE("RELEASE_ASSERT"); \
4852
abort(); \
4953
} \
50-
} while (0);
54+
} while (0)
5155

5256
#define FT_RELEASE_ASSERT_NOT_REACHED() \
5357
do { \

shell/platform/tizen/tizen_renderer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,5 @@ class TizenRenderer {
6363
bool ChooseEGLConfiguration();
6464
void PrintEGLError();
6565
};
66-
#endif //EMBEDDER_TIZEN_RENDERER_H
66+
67+
#endif // EMBEDDER_TIZEN_RENDERER_H

shell/platform/tizen/tizen_renderer_ecore_wl.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Eina_Bool TizenRendererEcoreWl::RotationEventCb(void *data, int type,
6565
}
6666

6767
void TizenRendererEcoreWl::Show() { ecore_wl_window_show(ecore_wl_window_); }
68+
6869
void TizenRendererEcoreWl::SetRotate(int degree) {
6970
ecore_wl_window_rotation_set(ecore_wl_window_, degree);
7071
received_rotation = true;
@@ -129,4 +130,4 @@ TizenRenderer::TizenWindowGeometry TizenRendererEcoreWl::GetGeometry() {
129130

130131
int TizenRendererEcoreWl::GetEcoreWindowId() {
131132
return ecore_wl_window_id_get(ecore_wl_window_);
132-
}
133+
}

shell/platform/tizen/tizen_renderer_ecore_wl.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#include <wayland-client.h>
99
#include <wayland-egl.h>
1010

11-
#include "tizen_renderer.h"
1211
#define EFL_BETA_API_SUPPORT
1312
#include <Ecore_Wayland.h>
13+
14+
#include "flutter/shell/platform/tizen/tizen_renderer.h"
15+
1416
class TizenRendererEcoreWl : public TizenRenderer {
1517
public:
1618
TizenRendererEcoreWl(TizenRenderer::Delegate& delegate, int32_t x, int32_t y,
@@ -40,4 +42,5 @@ class TizenRendererEcoreWl : public TizenRenderer {
4042
wl_display* wl_display_ = nullptr;
4143
static Eina_Bool RotationEventCb(void* data, int type, void* event);
4244
};
43-
#endif //EMBEDDER_TIZEN_RENDERER_ECORE_WL_H
45+
46+
#endif // EMBEDDER_TIZEN_RENDERER_ECORE_WL_H

shell/platform/tizen/tizen_renderer_ecore_wl2.cc

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TizenRendererEcoreWl2::TizenRendererEcoreWl2(TizenRenderer::Delegate &delegate,
1414
}
1515

1616
TizenRendererEcoreWl2::~TizenRendererEcoreWl2() { DestoryRenderer(); }
17+
1718
bool TizenRendererEcoreWl2::SetupDisplay() {
1819
if (!ecore_wl2_init()) {
1920
FT_LOGE("Could not initialize ecore_wl2");

shell/platform/tizen/tizen_renderer_ecore_wl2.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#ifndef EMBEDDER_TIZEN_RENDERER_ECORE_WL2_H
66
#define EMBEDDER_TIZEN_RENDERER_ECORE_WL2_H
77

8-
#include "tizen_renderer.h"
9-
108
#define EFL_BETA_API_SUPPORT
119
#include <Ecore_Wl2.h>
1210

11+
#include "flutter/shell/platform/tizen/tizen_renderer.h"
12+
1313
class TizenRendererEcoreWl2 : public TizenRenderer {
1414
public:
1515
TizenRendererEcoreWl2(TizenRenderer::Delegate &delegate, int32_t x, int32_t y,
@@ -39,4 +39,5 @@ class TizenRendererEcoreWl2 : public TizenRenderer {
3939
Ecore_Wl2_Egl_Window *ecore_wl2_egl_window_ = nullptr;
4040
static Eina_Bool RotationEventCb(void *data, int type, void *event);
4141
};
42-
#endif //EMBEDDER_TIZEN_RENDERER_ECORE_WL2_H
42+
43+
#endif // EMBEDDER_TIZEN_RENDERER_ECORE_WL2_H

shell/platform/tizen/touch_event_handler.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define EMBEDDER_TOUCH_EVENT_HANDLER_H_
77

88
#include <Ecore_Input.h>
9+
910
#include <vector>
1011

1112
#include "flutter/shell/platform/embedder/embedder.h"

0 commit comments

Comments
 (0)