Skip to content
Snippets Groups Projects
Commit 335b4073 authored by Gabriele Svelto's avatar Gabriele Svelto
Browse files

Bug 1748647 - Simplify initialization. r=padenot, a=RyanVM

parent a9691a7c
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ StaticMutex midirMIDIPlatformService::gBackgroundThreadMutex;
nsCOMPtr<nsIThread> midirMIDIPlatformService::gBackgroundThread;
midirMIDIPlatformService::midirMIDIPlatformService()
: mIsInitialized(false), mImplementation(nullptr) {
: mImplementation(nullptr) {
StaticMutexAutoLock lock(gBackgroundThreadMutex);
gBackgroundThread = NS_GetCurrentThread();
}
......@@ -71,15 +71,13 @@ void midirMIDIPlatformService::AddPort(const nsString* aId,
}
void midirMIDIPlatformService::Init() {
if (mIsInitialized) {
if (mImplementation) {
return;
}
mImplementation = midir_impl_init();
mImplementation = midir_impl_init(AddPort);
if (mImplementation) {
mIsInitialized = true;
midir_impl_enum_ports(mImplementation, AddPort);
MIDIPlatformService::Get()->SendPortList();
} else {
LOG("midir_impl_init failure");
......@@ -126,7 +124,7 @@ void midirMIDIPlatformService::Open(MIDIPortParent* aPort) {
MIDIPortConnectionState::Open));
NS_DispatchToCurrentThread(r);
} else {
LOG("MIDI port open: %s", NS_ConvertUTF16toUTF8(id).get());
LOG("MIDI port open failed: %s", NS_ConvertUTF16toUTF8(id).get());
}
}
......
......@@ -41,9 +41,6 @@ class midirMIDIPlatformService : public MIDIPlatformService {
size_t aLength, const GeckoTimeStamp* aTimeStamp,
uint64_t aMicros);
// True if server has been brought up already.
bool mIsInitialized;
// Wrapper around the midir Rust implementation.
MidirWrapper* mImplementation;
......
......@@ -184,8 +184,10 @@ impl MidirWrapper {
/// This function deliberately leaks the wrapper because ownership is
/// transfered to the C++ code. Use [midir_impl_shutdown()] to free it.
#[no_mangle]
pub unsafe extern "C" fn midir_impl_init() -> *mut MidirWrapper {
pub unsafe extern "C" fn midir_impl_init(callback: unsafe extern "C" fn(id: &nsString, name: &nsString, input: bool)) -> *mut MidirWrapper {
if let Ok(midir_impl) = MidirWrapper::new() {
iterate_ports(&midir_impl.ports, callback);
let midir_box = Box::new(midir_impl);
// Leak the object as it will be owned by the C++ code from now on
Box::leak(midir_box) as *mut _
......@@ -210,21 +212,6 @@ pub unsafe extern "C" fn midir_impl_shutdown(wrapper: *mut MidirWrapper) {
let _midir_box = Box::from_raw(wrapper);
}
/// Enumerate the available MIDI ports.
///
/// This function will be exposed to C++
///
/// # Safety
///
/// `wrapper` must be the pointer returned by [midir_impl_init()].
#[no_mangle]
pub unsafe extern "C" fn midir_impl_enum_ports(
wrapper: *mut MidirWrapper,
callback: unsafe extern "C" fn(id: &nsString, name: &nsString, input: bool),
) {
iterate_ports(&(*wrapper).ports, callback);
}
/// Open a MIDI port.
///
/// This function will be exposed to C++
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment