EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
JSActionController.cpp
Go to the documentation of this file.
1
9
10#if defined(__EMSCRIPTEN__) || defined(__DOXYGEN__)
11
13
14#include <emscripten/em_js.h>
15
17#include "../utility/Logger.hpp"
18
19namespace echomap
20{
21
22#ifndef __DOXYGEN__
23
24// (Doxygen can't handle EM_JS declarations.)
25
33namespace js
34{
35
36#pragma clang diagnostic push // Ignore unknown attributes for used Emscripten JS linkage.
37#pragma clang diagnostic ignored "-Wunknown-attributes"
38
39EM_JS(void,
40 select_project_file,
41 (),
42 {
43 if (Module.echomapOpenProjectFileChooser) {
44 Module.echomapOpenProjectFileChooser();
45 } else {
46 console.error("Module.echomapOpenProjectFileChooser is not installed.");
47 }
48 });
49
50EM_JS(void,
51 register_vfs_mapping,
52 (std::size_t project_id,
53 const char * external),
54 {
55 if (Module.echomapOpenVFSFileMapper) {
56 const externalPath = UTF8ToString(external);
57 Module.echomapOpenVFSFileMapper(project_id, externalPath);
58 } else {
59 console.error("Module.echomapOpenVFSFileMapper is not installed.");
60 }
61 });
62
63#pragma clang diagnostic pop
64
65} // namespace js
66
67#endif
68
70{
71 js::select_project_file();
72}
73
75 const std::size_t project_id,
76 const std::filesystem::path& external
77)
78{
79 js::register_vfs_mapping(project_id, external.c_str());
80}
81
82} // namespace echomap
83
92extern "C" EMSCRIPTEN_KEEPALIVE int echomap_on_project_file_picked(
93 const char* const path
94) noexcept
95{
96 using namespace echomap;
97
98 if (path == nullptr)
99 return 2;
100
101 try {
103 return 0;
104 } catch (const ConfigurationError& error) {
105 LOG_F_ERROR("Could not load path {} due to error: {}", path, error.what());
106 return 3;
107 } catch (const std::exception& error) {
108 LOG_F_ERROR("Could not load path {} due to unexpected error: {}", path, error.what());
109 return 4;
110 } catch (...) {
111 LOG_F_ERROR("Could not load path {} due to unknown error.", path);
112 return 5;
113 }
114}
115
127extern "C" EMSCRIPTEN_KEEPALIVE int echomap_on_register_vfs_mapping(
128 const std::size_t project_id,
129 const char* const external,
130 const char* const internal
131) noexcept
132{
133 using namespace echomap;
134
135 if (external == nullptr || internal == nullptr)
136 return 2;
137
138 try {
140 return 0;
141 } catch (const ConfigurationError& error) {
142 LOG_F_ERROR("Could not load path {} due to error: {}", internal, error.what());
143 return 3;
144 } catch (const std::exception& error) {
145 LOG_F_ERROR("Could not load path {} due to unexpected error: {}", internal, error.what());
146 return 4;
147 } catch (...) {
148 LOG_F_ERROR("Could not load path {} due to unknown error.", internal);
149 return 5;
150 }
151}
152
153#endif // __EMSCRIPTEN__
EchoMap ConfigurationError exception specification.
JSActionController specification.
EchoMap portable logger specification.
#define LOG_F_ERROR(msg,...)
Logs a formatted error-level message using echomap::Logger::log_f.
Definition Logger.hpp:125
A ConfigurationError indicates an error encountered during the initial configuration of the EchoMap g...
static void select_project_file_impl()
Invokes the JS function for Project File Action.
EMSCRIPTEN_KEEPALIVE int echomap_on_project_file_picked(const char *const path) noexcept
Services the Project File Action callback for Emscripten.
static void register_vfs_mapping_impl(std::size_t project_id, const std::filesystem::path &external)
Invokes the JS function for Register VFS Mapping.
EMSCRIPTEN_KEEPALIVE int echomap_on_register_vfs_mapping(const std::size_t project_id, const char *const external, const char *const internal) noexcept
Services the Register VFS Mapping callback for Emscripten.
The main EchoMap outermost namespace for all non-exported symbols.
T what(T... args)