Skip to content

Commit e23e70e

Browse files
stuartmorganfranciscojma86
authored andcommitted
Move most C++ library code to common/ and include/ (#177)
* Move most C++ library code to common/ and include/ This is a preperatory change for Windows using all of this code. Since it will be shared between multiple platforms, it should live in a shared location. Because the GN build flattens the headers in the generated out/include/, some files have #if/#else branches for #includes. Once there is a final decision on whether to use GN, this can be re-evaluated. * Update header guards for new paths
1 parent 157ab9b commit e23e70e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+193
-148
lines changed

example/linux/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ALL_LIBS=$(FLUTTER_EMBEDDER_LIB) $(FLUTTER_ENGINE_LIB) $(PLUGIN_LIBS)
3737
# Headers
3838
PLUGIN_DIRS=$(patsubst %,$(PLUGINS_DIR)/%/linux,$(PLUGIN_NAMES))
3939
LIBRARY_DIRS=$(FLUTTER_EMBEDDER_LIB_DIR) $(PLUGIN_DIRS)
40-
INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS))
40+
INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) $(PROJECT_ROOT)/library/include
4141

4242
# Tools
4343
BUILD_ASSETS_BIN=$(TOOLS_DIR)/build_flutter_assets
@@ -85,6 +85,9 @@ endif
8585
CXX=g++ -std=c++14
8686
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp)
8787
CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS))
88+
ifdef USE_GN
89+
CPPFLAGS+=-DUSE_FLATTENED_INCLUDES
90+
endif
8891
LDFLAGS=-L$(OUT_LIB_DIR) \
8992
-lglfw \
9093
$(shell pkg-config --libs jsoncpp) \

example/linux/flutter_embedder_example.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121

2222
#include <color_panel/color_panel_plugin.h>
2323
#include <file_chooser/file_chooser_plugin.h>
24-
#include <flutter_desktop_embedding/embedder.h>
2524
#include <menubar/menubar_plugin.h>
2625

26+
#ifdef USE_FLATTENED_INCLUDES
27+
#include <flutter_desktop_embedding/embedder.h>
28+
#else
29+
#include <flutter_desktop_embedding/linux/embedder.h>
30+
#endif
31+
2732
namespace {
2833

2934
// Returns the path of the directory containing this executable, or an empty

library/BUILD.gn

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,51 @@ import("//library/engine.gni")
1919
published_shared_library("flutter_embedder") {
2020
if (is_linux) {
2121
sources = [
22-
"linux/src/internal/engine_method_result.cc",
23-
"linux/src/internal/engine_method_result.h",
24-
"linux/src/internal/json_message_codec.cc",
25-
"linux/src/internal/json_message_codec.h",
26-
"linux/src/internal/key_event_handler.cc",
27-
"linux/src/internal/key_event_handler.h",
28-
"linux/src/internal/keyboard_hook_handler.h",
29-
"linux/src/internal/plugin_handler.cc",
30-
"linux/src/internal/plugin_handler.h",
31-
"linux/src/internal/text_input_model.cc",
32-
"linux/src/internal/text_input_model.h",
33-
"linux/src/internal/text_input_plugin.cc",
34-
"linux/src/internal/text_input_plugin.h",
3522
"linux/src/embedder.cc",
36-
"linux/src/json_method_call.cc",
37-
"linux/src/json_method_codec.cc",
38-
"linux/src/json_plugin.cc",
39-
"linux/src/method_call.cc",
40-
"linux/src/method_channel.cc",
41-
"linux/src/method_codec.cc",
42-
"linux/src/method_result.cc",
43-
"linux/src/plugin.cc",
4423
]
4524
public = [
46-
"linux/include/flutter_desktop_embedding/binary_messenger.h",
47-
"linux/include/flutter_desktop_embedding/embedder.h",
48-
"linux/include/flutter_desktop_embedding/json_method_call.h",
49-
"linux/include/flutter_desktop_embedding/json_method_codec.h",
50-
"linux/include/flutter_desktop_embedding/json_plugin.h",
51-
"linux/include/flutter_desktop_embedding/method_call.h",
52-
"linux/include/flutter_desktop_embedding/method_channel.h",
53-
"linux/include/flutter_desktop_embedding/method_codec.h",
54-
"linux/include/flutter_desktop_embedding/method_result.h",
55-
"linux/include/flutter_desktop_embedding/plugin.h",
25+
"include/flutter_desktop_embedding/linux/embedder.h",
26+
]
27+
}
28+
if (is_linux || is_win) {
29+
sources += [
30+
"common/internal/engine_method_result.cc",
31+
"common/internal/engine_method_result.h",
32+
"common/internal/json_message_codec.cc",
33+
"common/internal/json_message_codec.h",
34+
"common/internal/plugin_handler.cc",
35+
"common/internal/plugin_handler.h",
36+
"common/internal/text_input_model.cc",
37+
"common/internal/text_input_model.h",
38+
"common/json_method_call.cc",
39+
"common/json_method_codec.cc",
40+
"common/json_plugin.cc",
41+
"common/method_call.cc",
42+
"common/method_channel.cc",
43+
"common/method_codec.cc",
44+
"common/method_result.cc",
45+
"common/plugin.cc",
46+
]
47+
public += [
48+
"include/flutter_desktop_embedding/binary_messenger.h",
49+
"include/flutter_desktop_embedding/json_method_call.h",
50+
"include/flutter_desktop_embedding/json_method_codec.h",
51+
"include/flutter_desktop_embedding/json_plugin.h",
52+
"include/flutter_desktop_embedding/method_call.h",
53+
"include/flutter_desktop_embedding/method_channel.h",
54+
"include/flutter_desktop_embedding/method_codec.h",
55+
"include/flutter_desktop_embedding/method_result.h",
56+
"include/flutter_desktop_embedding/plugin.h",
57+
]
58+
}
59+
# GLFW-specific code.
60+
if (is_linux || is_win) {
61+
sources += [
62+
"common/glfw/key_event_handler.cc",
63+
"common/glfw/key_event_handler.h",
64+
"common/glfw/keyboard_hook_handler.h",
65+
"common/glfw/text_input_plugin.cc",
66+
"common/glfw/text_input_plugin.h",
5667
]
5768
}
5869

library/GN.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ $ tools/gn_dart gen out
2424
$ ninja -C out flutter_embedder
2525
```
2626

27-
The build results will be in the top-level `out/` directory.
27+
The build results will be in the top-level `out/` directory. `out/include/` will
28+
have the public headers for all build libraries, so you can point dependent
29+
builds at that single location rather than the `include/` directories in the
30+
source tree. You will need to set USE\_FLATTENED\_INCLUDES in your build, since
31+
the embedding header library layout is slightly different under `out/include/`.
2832

2933
Subsequent builds only require the `ninja` step, as the build will automatically
3034
re-run GN generation if necessary.

library/linux/src/internal/key_event_handler.cc renamed to library/common/glfw/key_event_handler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/src/internal/key_event_handler.h"
14+
#include "library/common/glfw/key_event_handler.h"
1515

1616
#include <json/json.h>
1717
#include <iostream>
1818

19-
#include "library/linux/src/internal/json_message_codec.h"
19+
#include "library/common/internal/json_message_codec.h"
2020

2121
static constexpr char kChannelName[] = "flutter/keyevent";
2222

library/linux/src/internal/key_event_handler.h renamed to library/common/glfw/key_event_handler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_HANDLER_H_
15-
#define LIBRARY_LINUX_SRC_INTERNAL_kEY_EVENT_HANDLER_H_
14+
#ifndef LIBRARY_COMMON_GLFW_KEY_EVENT_HANDLER_H_
15+
#define LIBRARY_COMMON_GLFW_kEY_EVENT_HANDLER_H_
1616

17-
#include "library/linux/include/flutter_desktop_embedding/binary_messenger.h"
18-
#include "library/linux/src/internal/keyboard_hook_handler.h"
17+
#include "library/common/glfw/keyboard_hook_handler.h"
18+
#include "library/include/flutter_desktop_embedding/binary_messenger.h"
1919

2020
namespace flutter_desktop_embedding {
2121

@@ -41,4 +41,4 @@ class KeyEventHandler : public KeyboardHookHandler {
4141

4242
} // namespace flutter_desktop_embedding
4343

44-
#endif // LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_HANDLER_H_
44+
#endif // LIBRARY_COMMON_GLFW_KEY_EVENT_HANDLER_H_

library/linux/src/internal/keyboard_hook_handler.h renamed to library/common/glfw/keyboard_hook_handler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_SRC_INTERNAL_INPUT_KEYBOARD_HOOK_HANDLER_H_
15-
#define LIBRARY_LINUX_SRC_INTERNAL_INPUT_KEYBOARD_HOOK_HANDLER_H_
14+
#ifndef LIBRARY_COMMON_GLFW_KEYBOARD_HOOK_HANDLER_H_
15+
#define LIBRARY_COMMON_GLFW_KEYBOARD_HOOK_HANDLER_H_
1616

1717
#include <GLFW/glfw3.h>
1818

@@ -31,4 +31,4 @@ class KeyboardHookHandler {
3131

3232
} // namespace flutter_desktop_embedding
3333

34-
#endif // LIBRARY_LINUX_SRC_INTERNAL_INPUT_KEYBOARD_HOOK_HANDLER_H_
34+
#endif // LIBRARY_COMMON_GLFW_KEYBOARD_HOOK_HANDLER_H_

library/linux/src/internal/text_input_plugin.cc renamed to library/common/glfw/text_input_plugin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/src/internal/text_input_plugin.h"
14+
#include "library/common/glfw/text_input_plugin.h"
1515

1616
#include <cstdint>
1717
#include <iostream>

library/linux/src/internal/text_input_plugin.h renamed to library/common/glfw/text_input_plugin.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_PLUGIN_H_
15-
#define LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_PLUGIN_H_
14+
#ifndef LIBRARY_COMMON_GLFW_TEXT_INPUT_PLUGIN_H_
15+
#define LIBRARY_COMMON_GLFW_TEXT_INPUT_PLUGIN_H_
1616

1717
#include <map>
1818
#include <memory>
1919

20-
#include "library/linux/include/flutter_desktop_embedding/json_plugin.h"
21-
#include "library/linux/src/internal/keyboard_hook_handler.h"
22-
#include "library/linux/src/internal/text_input_model.h"
20+
#include "library/common/glfw/keyboard_hook_handler.h"
21+
#include "library/common/internal/text_input_model.h"
22+
#include "library/include/flutter_desktop_embedding/json_plugin.h"
2323

2424
namespace flutter_desktop_embedding {
2525

@@ -58,4 +58,4 @@ class TextInputPlugin : public KeyboardHookHandler, public JsonPlugin {
5858

5959
} // namespace flutter_desktop_embedding
6060

61-
#endif // LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_PLUGIN_H_
61+
#endif // LIBRARY_COMMON_GLFW_TEXT_INPUT_PLUGIN_H_

library/linux/src/internal/engine_method_result.cc renamed to library/common/internal/engine_method_result.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/src/internal/engine_method_result.h"
14+
#include "library/common/internal/engine_method_result.h"
1515

1616
#include <iostream>
1717

library/linux/src/internal/engine_method_result.h renamed to library/common/internal/engine_method_result.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_SRC_INTERNAL_ENGINE_METHOD_RESULT_H_
15-
#define LIBRARY_LINUX_SRC_INTERNAL_ENGINE_METHOD_RESULT_H_
14+
#ifndef LIBRARY_COMMON_INTERNAL_ENGINE_METHOD_RESULT_H_
15+
#define LIBRARY_COMMON_INTERNAL_ENGINE_METHOD_RESULT_H_
1616

1717
#include <string>
1818
#include <vector>
1919

20-
#include "library/linux/include/flutter_desktop_embedding/binary_messenger.h"
21-
#include "library/linux/include/flutter_desktop_embedding/method_codec.h"
22-
#include "library/linux/include/flutter_desktop_embedding/method_result.h"
20+
#include "library/include/flutter_desktop_embedding/binary_messenger.h"
21+
#include "library/include/flutter_desktop_embedding/method_codec.h"
22+
#include "library/include/flutter_desktop_embedding/method_result.h"
2323

2424
namespace flutter_desktop_embedding {
2525

@@ -54,4 +54,4 @@ class EngineMethodResult : public MethodResult {
5454

5555
} // namespace flutter_desktop_embedding
5656

57-
#endif // LIBRARY_LINUX_SRC_INTERNAL_ENGINE_METHOD_RESULT_H_
57+
#endif // LIBRARY_COMMON_INTERNAL_ENGINE_METHOD_RESULT_H_

library/linux/src/internal/json_message_codec.cc renamed to library/common/internal/json_message_codec.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/src/internal/json_message_codec.h"
14+
#include "library/common/internal/json_message_codec.h"
1515

1616
#include <iostream>
1717
#include <string>

library/linux/src/internal/json_message_codec.h renamed to library/common/internal/json_message_codec.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_MESSAGE_CODEC_H_
15-
#define LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_MESSAGE_CODEC_H_
14+
#ifndef LIBRARY_COMMON_INTERNAL_JSON_MESSAGE_CODEC_H_
15+
#define LIBRARY_COMMON_INTERNAL_JSON_MESSAGE_CODEC_H_
1616

1717
#include <memory>
1818
#include <vector>
@@ -56,4 +56,4 @@ class JsonMessageCodec {
5656

5757
} // namespace flutter_desktop_embedding
5858

59-
#endif // LIBRARY_LINUX_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_JSON_MESSAGE_CODEC_H_
59+
#endif // LIBRARY_COMMON_INTERNAL_JSON_MESSAGE_CODEC_H_

library/linux/src/internal/plugin_handler.cc renamed to library/common/internal/plugin_handler.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/src/internal/plugin_handler.h"
14+
#include "library/common/internal/plugin_handler.h"
1515

16-
#include "library/linux/include/flutter_desktop_embedding/method_channel.h"
17-
#include "library/linux/src/internal/engine_method_result.h"
16+
#include "library/common/internal/engine_method_result.h"
17+
#include "library/include/flutter_desktop_embedding/method_channel.h"
1818

1919
#include <iostream>
2020

@@ -81,10 +81,10 @@ void PluginHandler::HandleMethodCallMessage(
8181
void PluginHandler::Send(const std::string &channel, const uint8_t *message,
8282
const size_t message_size) const {
8383
FlutterPlatformMessage platform_message = {
84-
.struct_size = sizeof(FlutterPlatformMessage),
85-
.channel = channel.c_str(),
86-
.message = message,
87-
.message_size = message_size,
84+
sizeof(FlutterPlatformMessage),
85+
channel.c_str(),
86+
message,
87+
message_size,
8888
};
8989
FlutterEngineSendPlatformMessage(engine_, &platform_message);
9090
}

library/linux/src/internal/plugin_handler.h renamed to library/common/internal/plugin_handler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_SRC_INTERNAL_PLUGIN_HANDLER_H_
15-
#define LIBRARY_LINUX_SRC_INTERNAL_PLUGIN_HANDLER_H_
14+
#ifndef LIBRARY_COMMON_INTERNAL_PLUGIN_HANDLER_H_
15+
#define LIBRARY_COMMON_INTERNAL_PLUGIN_HANDLER_H_
1616

1717
#include <map>
1818
#include <memory>
1919
#include <string>
2020

2121
#include <flutter_embedder.h>
2222

23-
#include "library/linux/include/flutter_desktop_embedding/binary_messenger.h"
24-
#include "library/linux/include/flutter_desktop_embedding/plugin.h"
23+
#include "library/include/flutter_desktop_embedding/binary_messenger.h"
24+
#include "library/include/flutter_desktop_embedding/plugin.h"
2525

2626
namespace flutter_desktop_embedding {
2727

@@ -74,4 +74,4 @@ class PluginHandler : public BinaryMessenger {
7474

7575
} // namespace flutter_desktop_embedding
7676

77-
#endif // LIBRARY_LINUX_SRC_INTERNAL_PLUGIN_HANDLER_H_
77+
#endif // LIBRARY_COMMON_INTERNAL_PLUGIN_HANDLER_H_

library/linux/src/internal/text_input_model.cc renamed to library/common/internal/text_input_model.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/src/internal/text_input_model.h"
14+
#include "library/common/internal/text_input_model.h"
1515

1616
#include <iostream>
1717

library/linux/src/internal/text_input_model.h renamed to library/common/internal/text_input_model.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_MODEL_H_
15-
#define LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_MODEL_H_
14+
#ifndef LIBRARY_COMMON_INTERNAL_TEXT_INPUT_MODEL_H_
15+
#define LIBRARY_COMMON_INTERNAL_TEXT_INPUT_MODEL_H_
1616

1717
#include <string>
1818

@@ -95,4 +95,4 @@ class TextInputModel {
9595

9696
} // namespace flutter_desktop_embedding
9797

98-
#endif // LIBRARY_LINUX_SRC_INTERNAL_TEXT_INPUT_MODEL_H_
98+
#endif // LIBRARY_COMMON_INTERNAL_TEXT_INPUT_MODEL_H_

library/linux/src/json_method_call.cc renamed to library/common/json_method_call.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/include/flutter_desktop_embedding/json_method_call.h"
14+
#include "library/include/flutter_desktop_embedding/json_method_call.h"
1515

1616
namespace flutter_desktop_embedding {
1717

library/linux/src/json_method_codec.cc renamed to library/common/json_method_codec.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "library/linux/include/flutter_desktop_embedding/json_method_codec.h"
14+
#include "library/include/flutter_desktop_embedding/json_method_codec.h"
1515

16-
#include "library/linux/include/flutter_desktop_embedding/json_method_call.h"
17-
#include "library/linux/src/internal/json_message_codec.h"
16+
#include "library/common/internal/json_message_codec.h"
17+
#include "library/include/flutter_desktop_embedding/json_method_call.h"
1818

1919
namespace flutter_desktop_embedding {
2020

0 commit comments

Comments
 (0)