EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
Loading...
Searching...
No Matches
JSActionController.cpp
Go to the documentation of this file.
1
9
10
#if defined(__EMSCRIPTEN__) || defined(__DOXYGEN__)
11
12
#include "
JSActionController.hpp
"
13
14
#include <emscripten/em_js.h>
15
16
#include "
../errors/ConfigurationError.hpp
"
17
#include "
../utility/Logger.hpp
"
18
19
namespace
echomap
20
{
21
22
#ifndef __DOXYGEN__
23
24
// (Doxygen can't handle EM_JS declarations.)
25
33
namespace
js
34
{
35
36
#pragma clang diagnostic push
// Ignore unknown attributes for used Emscripten JS linkage.
37
#pragma clang diagnostic ignored "-Wunknown-attributes"
38
39
EM_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
50
EM_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
69
void
JSActionController::select_project_file_impl
()
70
{
71
js::select_project_file();
72
}
73
74
void
JSActionController::register_vfs_mapping_impl
(
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
92
extern
"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
{
102
JSActionController::notify<ProjectSelectionCompleteNotification>
(path);
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
127
extern
"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
{
139
JSActionController::notify<RegisterVFSMappingNotification>
(project_id, external, internal);
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__
ConfigurationError.hpp
EchoMap ConfigurationError exception specification.
JSActionController.hpp
JSActionController specification.
Logger.hpp
EchoMap portable logger specification.
LOG_F_ERROR
#define LOG_F_ERROR(msg,...)
Logs a formatted error-level message using echomap::Logger::log_f.
Definition
Logger.hpp:125
echomap::ActionControllerBase< JSActionController >::notify
static void notify(Args &&... args)
Definition
ActionControllerBase.hpp:130
echomap::ConfigurationError
A ConfigurationError indicates an error encountered during the initial configuration of the EchoMap g...
Definition
ConfigurationError.hpp:20
std::exception
echomap::JSActionController::select_project_file_impl
static void select_project_file_impl()
Invokes the JS function for Project File Action.
Definition
JSActionController.cpp:69
echomap_on_project_file_picked
EMSCRIPTEN_KEEPALIVE int echomap_on_project_file_picked(const char *const path) noexcept
Services the Project File Action callback for Emscripten.
Definition
JSActionController.cpp:92
echomap::JSActionController::register_vfs_mapping_impl
static void register_vfs_mapping_impl(std::size_t project_id, const std::filesystem::path &external)
Invokes the JS function for Register VFS Mapping.
Definition
JSActionController.cpp:74
echomap_on_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.
Definition
JSActionController.cpp:127
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
std::filesystem::path::c_str
T c_str(T... args)
std::filesystem::path
std::size_t
std::runtime_error::what
T what(T... args)
src
actions
JSActionController.cpp
Generated by
1.17.0