diff --git a/protocols/purple/PurpleProtocol.cpp b/protocols/purple/PurpleProtocol.cpp index e48227e..ac29725 100644 --- a/protocols/purple/PurpleProtocol.cpp +++ b/protocols/purple/PurpleProtocol.cpp @@ -19,12 +19,15 @@ #include "PurpleProtocol.h" +#include + #include #include #include #include #include +#include #include #include "Purple.h" @@ -42,6 +45,8 @@ ChatProtocol* protocol_at(int32 i) { BMessenger* msgr = ensure_app_messenger(); + if (msgr == NULL) + return NULL; BMessage* msg = new BMessage(PURPLE_REQUEST_PROTOCOL_INFO); msg->AddInt64("thread_id", find_thread(NULL)); @@ -59,9 +64,13 @@ protocol_at(int32 i) int32 protocol_count() { + BMessenger* msgr = ensure_app_messenger(); + if (msgr == NULL) + return 0; + BMessage* msg = new BMessage(PURPLE_REQUEST_PROTOCOL_COUNT); msg->AddInt64("thread_id", find_thread(NULL)); - ensure_app_messenger()->SendMessage(msg); + msgr->SendMessage(msg); thread_id sender; return receive_data(&sender, NULL, 0); @@ -93,30 +102,40 @@ BMessenger* ensure_app_messenger() { if (kAppMessenger == NULL || kAppMessenger->IsValid() == false) { - ensure_app(); - kAppMessenger = new BMessenger(PURPLE_SIGNATURE); + if (ensure_app() == true) + kAppMessenger = new BMessenger(PURPLE_SIGNATURE); } return kAppMessenger; } -void +bool ensure_app() { BRoster roster; if (roster.IsRunning(PURPLE_SIGNATURE) == true) - return; + return true; + + if (roster.Launch(PURPLE_SIGNATURE) == B_OK) { + snooze(100000); + return true; + } app_info aInfo; be_app->GetAppInfo(&aInfo); BPath protoPath(&aInfo.ref); protoPath.GetParent(&protoPath); - protoPath.Append("protocols/purple"); + protoPath.Append(BString(APP_NAME).ToLower().Append("/purple")); entry_ref protoRef; BEntry(protoPath.Path()).GetRef(&protoRef); - roster.Launch(&protoRef); - snooze(100000); + if (roster.Launch(&protoRef) == B_OK) { + snooze(100000); + return true; + } + + std::cerr << "libpurple add-on could not find its binary! All is lost!\n"; + return false; } diff --git a/protocols/purple/PurpleProtocol.h b/protocols/purple/PurpleProtocol.h index e690dc5..a1c5bd6 100644 --- a/protocols/purple/PurpleProtocol.h +++ b/protocols/purple/PurpleProtocol.h @@ -35,7 +35,7 @@ extern "C" _EXPORT const char* friendly_signature(); extern "C" _EXPORT uint32 version(); BMessenger* ensure_app_messenger(); -void ensure_app(); +bool ensure_app(); status_t connect_thread(void* data); BMessage receive_message();