Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
11
16};
17
18G_DEFINE_TYPE(FlDartProject, fl_dart_project, G_TYPE_OBJECT)
19
20// Gets the directory the current executable is in.
21static 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
33static 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
44static void fl_dart_project_class_init(FlDartProjectClass* klass) {
45 G_OBJECT_CLASS(klass)->dispose = fl_dart_project_dispose;
46}
47
48static void fl_dart_project_init(FlDartProject* self) {}
49
50G_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
65G_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
72G_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
78G_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
85G_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
91G_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
98G_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
105 FlDartProject* self) {
106 g_return_val_if_fail(FL_IS_DART_PROJECT(self), nullptr);
107 return self->dart_entrypoint_args;
108}
109
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(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
G_MODULE_EXPORT const gchar * fl_dart_project_get_assets_path(FlDartProject *self)
G_MODULE_EXPORT const gchar * fl_dart_project_get_aot_library_path(FlDartProject *self)
static void fl_dart_project_dispose(GObject *object)
G_MODULE_EXPORT void fl_dart_project_set_icu_data_path(FlDartProject *self, gchar *path)
G_MODULE_EXPORT void fl_dart_project_set_dart_entrypoint_arguments(FlDartProject *self, char **argv)
G_MODULE_EXPORT const gchar * fl_dart_project_get_icu_data_path(FlDartProject *self)
G_MODULE_EXPORT gchar ** fl_dart_project_get_dart_entrypoint_arguments(FlDartProject *self)
static void fl_dart_project_init(FlDartProject *self)
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
static void fl_dart_project_class_init(FlDartProjectClass *klass)
static gchar * get_executable_dir()
G_MODULE_EXPORT void fl_dart_project_set_assets_path(FlDartProject *self, gchar *path)
G_MODULE_EXPORT void fl_dart_project_set_aot_library_path(FlDartProject *self, const gchar *path)
const uint8_t uint32_t uint32_t GError ** error
char ** argv
Definition: library.h:9
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
gchar ** dart_entrypoint_args
GObject parent_instance
gchar * aot_library_path