| 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
18 G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
19
20 // Gets the directory the current executable is in.
21 static gchar* get_executable_dir() {
22 g_autoptr(GError) error = nullptr;
23 g_autofree gchar* exe_path = g_file_read_link("/proc/self/exe", &error);
24 if (exe_path == nullptr) {
25 g_critical("Failed to determine location of executable: %s",
26 error->message);
27 return nullptr;
28 }
29
30 return g_path_get_dirname(exe_path);
31 }
32
33 static void fl_dart_project_dispose(GObject* object) {
34 FlDartProject* self = FL_DART_PROJECT(object);
35
36 g_clear_pointer(&self->aot_library_path, g_free);
37 g_clear_pointer(&self->assets_path, g_free);
38 g_clear_pointer(&self->icu_data_path, g_free);
39 g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
40
41 G_OBJECT_CLASS(fl_dart_project_parent_class)->dispose(object);
42 }
43
44 static void fl_dart_project_class_init(FlDartProjectClass* klass) {
45 G_OBJECT_CLASS(klass)->dispose = fl_dart_project_dispose;
46 }
47
48 static void fl_dart_project_init(FlDartProject* self) {}
49
50 G_MODULE_EXPORT FlDartProject* fl_dart_project_new() {
51 FlDartProject* self =
52 FL_DART_PROJECT(g_object_new(fl_dart_project_get_type(), nullptr));
53
54 g_autofree gchar* executable_dir = get_executable_dir();
55 self->aot_library_path =
56 g_build_filename(executable_dir, "lib", "libapp.so", nullptr);
57 self->assets_path =
58 g_build_filename(executable_dir, "data", "flutter_assets", nullptr);
59 self->icu_data_path =
60 g_build_filename(executable_dir, "data", "icudtl.dat", nullptr);
61
62 return self;
63 }
64
65 G_MODULE_EXPORT void fl_dart_project_set_aot_library_path(FlDartProject* self,
66 const gchar* path) {
67 g_return_if_fail(FL_IS_DART_PROJECT(self));
68 g_clear_pointer(&self->aot_library_path, g_free);
69 self->aot_library_path = g_strdup(path);
70 }
71
72 G_MODULE_EXPORT const gchar* fl_dart_project_get_aot_library_path(
73 FlDartProject* self) {
74 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
75 return self->aot_library_path;
76 }
77
78 G_MODULE_EXPORT void fl_dart_project_set_assets_path(FlDartProject* self,
79 gchar* path) {
80 g_return_if_fail(FL_IS_DART_PROJECT(self));
81 g_clear_pointer(&self->assets_path, g_free);
82 self->assets_path = g_strdup(path);
83 }
84
85 G_MODULE_EXPORT const gchar* fl_dart_project_get_assets_path(
86 FlDartProject* self) {
87 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
88 return self->assets_path;
89 }
90
91 G_MODULE_EXPORT void fl_dart_project_set_icu_data_path(FlDartProject* self,
92 gchar* path) {
93 g_return_if_fail(FL_IS_DART_PROJECT(self));
94 g_clear_pointer(&self->icu_data_path, g_free);
95 self->icu_data_path = g_strdup(path);
96 }
97
98 G_MODULE_EXPORT const gchar* fl_dart_project_get_icu_data_path(
99 FlDartProject* self) {
100 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
101 return self->icu_data_path;
102 }
103
104 G_MODULE_EXPORT gchar** fl_dart_project_get_dart_entrypoint_arguments(
105 FlDartProject* self) {
106 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
107 return self->dart_entrypoint_args;
108 }
109
110 G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(
111 FlDartProject* self,
112 char** argv) {
113 g_return_if_fail(FL_IS_DART_PROJECT(self));
114 g_clear_pointer(&self->dart_entrypoint_args, g_strfreev);
115 self->dart_entrypoint_args = g_strdupv(argv);
116 }
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
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
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:72
fl_dart_project_dispose
static void fl_dart_project_dispose(GObject *object)
Definition: fl_dart_project.cc:33
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:104
get_executable_dir
static gchar * get_executable_dir()
Definition: fl_dart_project.cc:21
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:91
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:110
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:98
fl_dart_project_init
static void fl_dart_project_init(FlDartProject *self)
Definition: fl_dart_project.cc:48
fl_dart_project_get_assets_path
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)
Definition: fl_dart_project.cc:85
fl_dart_project_class_init
static void fl_dart_project_class_init(FlDartProjectClass *klass)
Definition: fl_dart_project.cc:44
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:78
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:65
fl_dart_project.h
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::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