am 8dd3ea58: Merge "Revert "DO NOT MERGE Libnativebridge: Temporarily change back to late dlopen"" into lmp-dev

* commit '8dd3ea58fdd99912f631156c37bcb2555ce8aec3':
  Revert "DO NOT MERGE Libnativebridge: Temporarily change back to late dlopen"
This commit is contained in:
Andreas Gampe 2014-09-25 22:02:24 +00:00 committed by Android Git Automerger
commit ea52030bc6
2 changed files with 30 additions and 65 deletions

View file

@ -29,7 +29,6 @@ static constexpr const char* kNativeBridgeInterfaceSymbol = "NativeBridgeItf";
enum class NativeBridgeState { enum class NativeBridgeState {
kNotSetup, // Initial state. kNotSetup, // Initial state.
kOpened, // After successful dlopen. kOpened, // After successful dlopen.
// Temporary meaning: string copied. TODO: remove. b/17440362
kInitialized, // After successful initialization. kInitialized, // After successful initialization.
kClosed // Closed or errors. kClosed // Closed or errors.
}; };
@ -61,9 +60,6 @@ static NativeBridgeState state = NativeBridgeState::kNotSetup;
// Whether we had an error at some point. // Whether we had an error at some point.
static bool had_error = false; static bool had_error = false;
// Native bridge filename. TODO: Temporary, remove. b/17440362
static const char* native_bridge_filename;
// Handle of the loaded library. // Handle of the loaded library.
static void* native_bridge_handle = nullptr; static void* native_bridge_handle = nullptr;
// Pointer to the callbacks. Available as soon as LoadNativeBridge succeeds, but only initialized // Pointer to the callbacks. Available as soon as LoadNativeBridge succeeds, but only initialized
@ -135,32 +131,28 @@ bool LoadNativeBridge(const char* nb_library_filename,
state = NativeBridgeState::kClosed; state = NativeBridgeState::kClosed;
had_error = true; had_error = true;
} else { } else {
// Save the name. TODO: Remove this, return to old flow. b/17440362 // Try to open the library.
native_bridge_filename = nb_library_filename; void* handle = dlopen(nb_library_filename, RTLD_LAZY);
runtime_callbacks = runtime_cbs; if (handle != nullptr) {
state = NativeBridgeState::kOpened; callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle,
// // Try to open the library. kNativeBridgeInterfaceSymbol));
// void* handle = dlopen(nb_library_filename, RTLD_LAZY); if (callbacks != nullptr) {
// if (handle != nullptr) { // Store the handle for later.
// callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle, native_bridge_handle = handle;
// kNativeBridgeInterfaceSymbol)); } else {
// if (callbacks != nullptr) { dlclose(handle);
// // Store the handle for later. }
// native_bridge_handle = handle; }
// } else {
// dlclose(handle); // Two failure conditions: could not find library (dlopen failed), or could not find native
// } // bridge interface (dlsym failed). Both are an error and close the native bridge.
// } if (callbacks == nullptr) {
// had_error = true;
// // Two failure conditions: could not find library (dlopen failed), or could not find native state = NativeBridgeState::kClosed;
// // bridge interface (dlsym failed). Both are an error and close the native bridge. } else {
// if (callbacks == nullptr) { runtime_callbacks = runtime_cbs;
// had_error = true; state = NativeBridgeState::kOpened;
// state = NativeBridgeState::kClosed; }
// } else {
// runtime_callbacks = runtime_cbs;
// state = NativeBridgeState::kOpened;
// }
} }
return state == NativeBridgeState::kOpened; return state == NativeBridgeState::kOpened;
} }
@ -171,38 +163,15 @@ bool InitializeNativeBridge() {
// point we are not multi-threaded, so we do not need locking here. // point we are not multi-threaded, so we do not need locking here.
if (state == NativeBridgeState::kOpened) { if (state == NativeBridgeState::kOpened) {
// Open and initialize. TODO: Temporary, remove. b/17440362 // Try to initialize.
void* handle = dlopen(native_bridge_filename, RTLD_LAZY); if (callbacks->initialize(runtime_callbacks)) {
if (handle != nullptr) { state = NativeBridgeState::kInitialized;
callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle,
kNativeBridgeInterfaceSymbol));
if (callbacks != nullptr) {
if (callbacks->initialize(runtime_callbacks)) {
state = NativeBridgeState::kInitialized;
native_bridge_handle = handle;
} else {
callbacks = nullptr;
}
}
if (callbacks == nullptr) {
state = NativeBridgeState::kClosed;
had_error = true;
dlclose(handle);
}
} else { } else {
state = NativeBridgeState::kClosed; // Unload the library.
dlclose(native_bridge_handle);
had_error = true; had_error = true;
state = NativeBridgeState::kClosed;
} }
// // Try to initialize.
// if (callbacks->initialize(runtime_callbacks)) {
// state = NativeBridgeState::kInitialized;
// } else {
// // Unload the library.
// dlclose(native_bridge_handle);
// had_error = true;
// state = NativeBridgeState::kClosed;
// }
} else { } else {
had_error = true; had_error = true;
state = NativeBridgeState::kClosed; state = NativeBridgeState::kClosed;
@ -216,7 +185,7 @@ void UnloadNativeBridge() {
// point we are not multi-threaded, so we do not need locking here. // point we are not multi-threaded, so we do not need locking here.
switch(state) { switch(state) {
// case NativeBridgeState::kOpened: // TODO: Re-add this. b/17440362 case NativeBridgeState::kOpened:
case NativeBridgeState::kInitialized: case NativeBridgeState::kInitialized:
// Unload. // Unload.
dlclose(native_bridge_handle); dlclose(native_bridge_handle);
@ -227,7 +196,6 @@ void UnloadNativeBridge() {
had_error = true; had_error = true;
break; break;
case NativeBridgeState::kOpened: // TODO: Remove this. b/17440362
case NativeBridgeState::kClosed: case NativeBridgeState::kClosed:
// Ignore. // Ignore.
break; break;

View file

@ -27,12 +27,9 @@ TEST_F(NativeBridgeTest, ValidName) {
// Now check what happens on LoadNativeBridge. // Now check what happens on LoadNativeBridge.
EXPECT_EQ(false, NativeBridgeError()); EXPECT_EQ(false, NativeBridgeError());
LoadNativeBridge(kTestName, nullptr); LoadNativeBridge(kTestName, nullptr);
// TODO: Remove this call. b/17440362
InitializeNativeBridge();
// This will lead to an error as the library doesn't exist. // This will lead to an error as the library doesn't exist.
EXPECT_EQ(true, NativeBridgeError()); EXPECT_EQ(true, NativeBridgeError());
// TODO: Test again. b/17440362 EXPECT_EQ(false, NativeBridgeAvailable());
// EXPECT_EQ(false, NativeBridgeAvailable());
} }
} // namespace android } // namespace android