void AddOnManager::_LoadReplicant() { CALLED(); app_info info; be_app->GetAppInfo(&info); status_t err = BDeskbar().AddItem(&info.ref); if (err != B_OK) { ERROR("Deskbar refuses to add method replicant: %s\n", strerror(err)); } BMessage request(B_GET_PROPERTY); BMessenger to; BMessenger status; request.AddSpecifier("Messenger"); request.AddSpecifier("Shelf"); // In the Deskbar the Shelf is in the View "Status" in Window "Deskbar" request.AddSpecifier("View", "Status"); request.AddSpecifier("Window", "Deskbar"); to = BMessenger("application/x-vnd.Be-TSKB", -1); BMessage reply; if (to.SendMessage(&request, &reply) == B_OK && reply.FindMessenger("result", &status) == B_OK) { // enum replicant in Status view int32 index = 0; int32 uid; while ((uid = _GetReplicantAt(status, index++)) >= B_OK) { BMessage replicantInfo; if (_GetReplicantName(status, uid, &replicantInfo) != B_OK) continue; const char *name; if (replicantInfo.FindString("result", &name) == B_OK && !strcmp(name, REPLICANT_CTL_NAME)) { BMessage replicant; if (_GetReplicantView(status, uid, &replicant) == B_OK) { BMessenger result; if (replicant.FindMessenger("result", &result) == B_OK) { gInputServer->SetMethodReplicant(new BMessenger(result)); } } } } } if (!gInputServer->MethodReplicant()) { ERROR("LoadReplicant(): Method replicant not found!\n"); } }
//////////// == // Function to find a remote BLooper BMessenger *SLooper::FindOtherEnd(char *unique_name) { BMessenger *rc = new BMessenger(); int32 ignored; FORMULATE_UNIQUE(unique_name); // find port by name port_id port = find_port(unique); if (port < 0) { return NULL; } // create a port for the reply port_id myPort = create_port(1, "temporary port for answer"); // send the request to the other end with the port of our end write_port(port, 0xdeadbeef, &myPort, sizeof(myPort)); // wait for an answer ssize_t messageSize = port_buffer_size(myPort); char *message = new char[messageSize]; read_port(myPort, &ignored, message, messageSize); // get the BMessenger out of it BMessage msg; msg.Unflatten(message); msg.FindMessenger("messageTarget", rc); return rc; }
BMessenger GetMessenger(void) { BMessenger aResult; status_t aErr = B_OK; BMessenger aDeskbar(DBAR_SIGNATURE, -1, &aErr); if (aErr != B_OK)return aResult; BMessage aMessage(B_GET_PROPERTY); aMessage.AddSpecifier("Messenger"); aMessage.AddSpecifier("Shelf"); aMessage.AddSpecifier("View", "Status"); aMessage.AddSpecifier("Window", "Deskbar"); BMessage aReply; if (aDeskbar.SendMessage(&aMessage, &aReply, 1000000, 1000000) == B_OK) aReply.FindMessenger("result", &aResult); return aResult; }
status_t PeThemesAddon::FindPrefWindow(BMessenger &messenger) { BMessenger app(PE_SIG); BMessenger win; status_t err; int i; if (!app.IsValid()) return B_ERROR; BMessage answer; BMessage msgGetMsgr(B_GET_PROPERTY); msgGetMsgr.AddSpecifier("Windows"); err = app.SendMessage(&msgGetMsgr, &answer, 2000000LL, 2000000LL); if (B_OK == err) { for (i = 0; answer.FindMessenger("result", i, &win) == B_OK; i++) { BString title; //TODO: FIXME: title might get localized someday... BMessage m(B_GET_PROPERTY); m.AddSpecifier("Title"); err = win.SendMessage(&m, &m, 20000LL, 20000LL); if (m.FindString("result", &title) == B_OK && title == "Preferences") { // get the top level view BMessenger view; m = BMessage(B_GET_PROPERTY); m.AddSpecifier("View", 0L); err = win.SendMessage(&m, &m, 20000LL, 20000LL); if (m.FindMessenger("result", &view) == B_OK) { messenger = view; return B_OK; } } } } // force showing the prefs window BMessage msgShowPref(msg_Preferences); err = app.SendMessage(&msgShowPref); err = app.SendMessage(&msgGetMsgr, &answer, 2000000LL, 2000000LL); if (B_OK == err) { for (i = 0; answer.FindMessenger("result", i, &win) == B_OK; i++) { BString title; BMessage m(B_GET_PROPERTY); m.AddSpecifier("Title"); err = win.SendMessage(&m, &m, 20000LL, 20000LL); if (m.FindString("result", &title) == B_OK && title == "Preferences") { // hide the prefs window BMessage hide(B_SET_PROPERTY); hide.AddSpecifier("Hidden"); hide.AddBool("data", true); err = win.SendMessage(&hide); // get the top level view BMessenger view; m = BMessage(B_GET_PROPERTY); m.AddSpecifier("View", 0L); err = win.SendMessage(&m, &m, 20000LL, 20000LL); if (m.FindMessenger("result", &view) == B_OK) { messenger = view; return B_OK; } } } } return B_ERROR; }