| Flutter Linux Embedder |

fl_dart_project.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. 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 "flutter/shell/platform/linux/public/flutter_linux/fl_dart_project.h"
6
7 #include <gmodule.h>
8
9 struct _FlDartProject {
10 GObject parent_instance;
11
12 gchar* aot_library_path;
13 gchar* assets_path;
14 gchar* icu_data_path;
15 gchar** dart_entrypoint_args;
16
17 FlUIThreadPolicy ui_thread_policy;
18 };
19
20 G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
21
22 // Gets the directory the current executable is in.
23 static gchar* get_executable_dir() {
24 g_autoptr(GError) error = nullptr;
25 g_autofree gchar* exe_path = g_file_read_link("/proc/self/exe", &error);
26 if (exe_path == nullptr) {
27 g_critical("Failed to determine location of executable: %s",
28 error->message);
29 return nullptr;
30 }
31
32 return g_path_get_dirname(exe_path);
33 }
34
35 static void fl_dart_project_dispose(GObject* object) {
36 FlDartProject* self = FL_DART_PROJECT(object);
37
38 g_clear_pointer(&self->aot_library_path, g_free);
39 g_clear_pointer(&self->assets_path, g_free);
40 g_clear_pointer(&self->icu_data_path, g_free);
41 g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
42
43 G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
44 }
45
46 static void fl_dart_project_class_init(FlDartProjectClass* klass) {
47 G_OBJECT_CLASS(klass)->dispose = fl_dart_project_dispose;
48 }
49
50 static void fl_dart_project_init(FlDartProject* self) {}
51
52 G_MODULE_EXPORT FlDartProject* fl_dart_project_new() {
53 FlDartProject* self =
54 FL_DART_PROJECT(g_object_new(fl_dart_project_get_type(), nullptr));
55
56 g_autofree gchar* executable_dir = get_executable_dir();
57 self->aot_library_path =
58 g_build_filename(executable_dir, "lib", "libapp.so", nullptr);
59 self->assets_path =
60 g_build_filename(executable_dir, "data", "flutter_assets", nullptr);
61 self->icu_data_path =
62 g_build_filename(executable_dir, "data", "icudtl.dat", nullptr);
63
64 return self;
65 }
66
67 G_MODULE_EXPORT void fl_dart_project_set_aot_library_path(FlDartProject* self,
68 const gchar* path) {
69 g_return_if_fail(FL_IS_DART_PROJECT(self));
70 g_clear_pointer(&self->aot_library_path, g_free);
71 self->aot_library_path = g_strdup(path);
72 }
73
74 G_MODULE_EXPORT const gchar* fl_dart_project_get_aot_library_path(
75 FlDartProject* self) {
76 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
77 return self->aot_library_path;
78 }
79
80 G_MODULE_EXPORT void fl_dart_project_set_assets_path(FlDartProject* self,
81 gchar* path) {
82 g_return_if_fail(FL_IS_DART_PROJECT(self));
83 g_clear_pointer(&self->assets_path, g_free);
84 self->assets_path = g_strdup(path);
85 }
86
87 G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
88 FlDartProject* self) {
89 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
90 return self->assets_path;
91 }
92
93 G_MODULE_EXPORT void fl_dart_project_set_icu_data_path(FlDartProject* self,
94 gchar* path) {
95 g_return_if_fail(FL_IS_DART_PROJECT(self));
96 g_clear_pointer(&self->icu_data_path, g_free);
97 self->icu_data_path = g_strdup(path);
98 }
99
100 G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
101 FlDartProject* self) {
102 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
103 return self->icu_data_path;
104 }
105
106 G_MODULE_EXPORT gchar** fl_dart_project_get_dart_entrypoint_arguments(
107 FlDartProject* self) {
108 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
109 return self->dart_entrypoint_args;
110 }
111
112 G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(
113 FlDartProject* self,
114 char** argv) {
115 g_return_if_fail(FL_IS_DART_PROJECT(self));
116 g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
117 self->dart_entrypoint_args = g_strdupv(argv);
118 }
119
120 G_MODULE_EXPORT
121 void fl_dart_project_set_ui_thread_policy(FlDartProject* project,
122 FlUIThreadPolicy policy) {
123 g_return_if_fail(FL_IS_DART_PROJECT(project));
124 project->ui_thread_policy = policy;
125 }
126
127 G_MODULE_EXPORT
128 FlUIThreadPolicy fl_dart_project_get_ui_thread_policy(FlDartProject* project) {
129 g_return_val_if_fail(FL_IS_DART_PROJECT(project),
130 FL_UI_THREAD_POLICY_DEFAULT);
131 return project->ui_thread_policy;
132 }
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
g_autoptr
g_autoptr(GMutexLocker) locker
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:52
fl_dart_project_get_aot_library_path
G_MODULE_EXPORT const gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
Definition: fl_dart_project.cc:74
fl_dart_project_dispose
static void fl_dart_project_dispose(GObject *object)
Definition: fl_dart_project.cc:35
fl_dart_project_get_dart_entrypoint_arguments
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
Definition: fl_dart_project.cc:106
fl_dart_project_set_ui_thread_policy
G_MODULE_EXPORT void fl_dart_project_set_ui_thread_policy(FlDartProject *project, FlUIThreadPolicy policy)
Definition: fl_dart_project.cc:121
get_executable_dir
static gchar * get_executable_dir()
Definition: fl_dart_project.cc:23
fl_dart_project_set_icu_data_path
G_MODULE_EXPORT void fl_dart_project_set_icu_data_path(FlDartProject *self, gchar *path)
Definition: fl_dart_project.cc:93
fl_dart_project_set_dart_entrypoint_arguments
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
Definition: fl_dart_project.cc:112
fl_dart_project_get_icu_data_path
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
Definition: fl_dart_project.cc:100
fl_dart_project_init
static void fl_dart_project_init(FlDartProject *self)
Definition: fl_dart_project.cc:50
fl_dart_project_get_assets_path
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)
Definition: fl_dart_project.cc:87
fl_dart_project_class_init
static void fl_dart_project_class_init(FlDartProjectClass *klass)
Definition: fl_dart_project.cc:46
fl_dart_project_set_assets_path
G_MODULE_EXPORT void fl_dart_project_set_assets_path(FlDartProject *self, gchar *path)
Definition: fl_dart_project.cc:80
fl_dart_project_get_ui_thread_policy
G_MODULE_EXPORT FlUIThreadPolicy fl_dart_project_get_ui_thread_policy(FlDartProject *project)
Definition: fl_dart_project.cc:128
fl_dart_project_set_aot_library_path
G_MODULE_EXPORT void fl_dart_project_set_aot_library_path(FlDartProject *self, const gchar *path)
Definition: fl_dart_project.cc:67
fl_dart_project.h
FlUIThreadPolicy
FlUIThreadPolicy
Definition: fl_dart_project.h:141
FL_UI_THREAD_POLICY_DEFAULT
@ FL_UI_THREAD_POLICY_DEFAULT
Definition: fl_dart_project.h:142
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
_FlDartProject
Definition: fl_dart_project.cc:9
_FlDartProject::dart_entrypoint_args
gchar ** dart_entrypoint_args
Definition: fl_dart_project.cc:15
_FlDartProject::icu_data_path
gchar * icu_data_path
Definition: fl_dart_project.cc:14
_FlDartProject::ui_thread_policy
FlUIThreadPolicy ui_thread_policy
Definition: fl_dart_project.cc:17
_FlDartProject::parent_instance
GObject parent_instance
Definition: fl_dart_project.cc:10
_FlDartProject::aot_library_path
gchar * aot_library_path
Definition: fl_dart_project.cc:12
_FlDartProject::assets_path
gchar * assets_path
Definition: fl_dart_project.cc:13