BMessage* LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) { int16 eventFound; int16 opcodeFound; int32 eventIndex; fEventsWanted.Lock(); // for each Petition for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { BMessage* msg = fEventsWanted.FindMessage(index); printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index, fEventsWanted.CountMessages(), msg); msg->PrintToStream(); eventIndex = 0; // for each Event while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { if (eventFound == event) { printf("%s:Event %d found@%ld...", __FUNCTION__, event, eventIndex); // there is an opcode specified.. if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) { // ensure the opcode if ((uint16)opcodeFound != opcode) { printf("%s:opcode does not match %d\n", __FUNCTION__, opcode); eventIndex++; continue; } printf("Opcode matches %d\n", opcode); } else { printf("No opcode specified\n"); } fEventsWanted.Unlock(); if (indexFound != NULL) *indexFound = eventIndex; return msg; } eventIndex++; } } printf("%s:Event %d not found\n", __FUNCTION__, event); fEventsWanted.Unlock(); return NULL; }
status_t get_keyboard_id(uint16 *id) { BMessage command(IS_GET_KEYBOARD_ID); BMessage reply; uint16 kid; _control_input_server_(&command, &reply); status_t err = reply.FindInt16("id", (int16 *)&kid); if (err != B_OK) return err; *id = kid; return B_OK; }
//------------------------------------------------------------------------------ void TMessageEasyFindTest::MessageEasyFindTest1() { BRect r(0, 0, -1, -1); BPoint p(0, 0); BMessage msg; CPPUNIT_ASSERT(msg.FindRect("data") == r); CPPUNIT_ASSERT(msg.FindPoint("data") == p); CPPUNIT_ASSERT(msg.FindString("data") == NULL); CPPUNIT_ASSERT(msg.FindInt8("data") == 0); CPPUNIT_ASSERT(msg.FindInt16("data") == 0); CPPUNIT_ASSERT(msg.FindInt32("data") == 0); CPPUNIT_ASSERT(msg.FindInt64("data") == 0); CPPUNIT_ASSERT(msg.FindBool("data") == false); CPPUNIT_ASSERT(msg.FindFloat("data") == 0); CPPUNIT_ASSERT(msg.FindDouble("data") == 0); }
void MainWindow::LoadSettings(void) { BFile file("/boot/home/config/settings/BeMines", B_READ_ONLY); if (file.InitCheck() != B_OK) return; BMessage settings; if (settings.Unflatten(&file) == B_OK) { BString s; if (settings.FindString("theme",&s) == B_OK) { gThemeName = s; gGameStyle->SetStyle(gThemeName.String()); } int32 diff; if (settings.FindInt32("level",&diff) == B_OK) gDifficulty = diff; bool b; if (settings.FindBool("playsounds",&b) == B_OK) gPlaySounds = b; uint16 seconds; if (settings.FindInt16("begbest",(int16*)&seconds) == B_OK) gBestTimes[DIFFICULTY_BEGINNER].time = seconds; if (settings.FindInt16("intbest",(int16*)&seconds) == B_OK) gBestTimes[DIFFICULTY_INTERMEDIATE].time = seconds; if (settings.FindInt16("expbest",(int16*)&seconds) == B_OK) gBestTimes[DIFFICULTY_EXPERT].time = seconds; if (settings.FindString("begname",&s) == B_OK) gBestTimes[DIFFICULTY_BEGINNER].name = s; if (settings.FindString("intname",&s) == B_OK) gBestTimes[DIFFICULTY_INTERMEDIATE].name = s; if (settings.FindString("expname",&s) == B_OK) gBestTimes[DIFFICULTY_EXPERT].name = s; uint16 size; if (settings.FindInt16("customwidth",(int16*)&size) == B_OK) gCustomWidth = size; if (settings.FindInt16("customheight",(int16*)&size) == B_OK) gCustomHeight = size; if (settings.FindInt16("customcount",(int16*)&size) == B_OK) gCustomMines = size; } }
status_t PoorManWindow::ReadSettings() { BPath p; BFile f; BMessage m; if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK) return B_ERROR; p.Append(STR_SETTINGS_FILE_NAME); f.SetTo(p.Path(), B_READ_ONLY); if (f.InitCheck() != B_OK) return B_ERROR; if (m.Unflatten(&f) != B_OK) return B_ERROR; if (MSG_PREF_FILE != m.what) return B_ERROR; //site tab if (m.FindString("fWebDirectory", &fWebDirectory) != B_OK) fWebDirectory.SetTo(STR_DEFAULT_WEB_DIRECTORY); if (m.FindString("fIndexFileName", &fIndexFileName) != B_OK) fIndexFileName.SetTo("index.html"); if (m.FindBool("fDirListFlag", &fDirListFlag) != B_OK) fDirListFlag = false; //logging tab if (m.FindBool("fLogConsoleFlag", &fLogConsoleFlag) != B_OK) fLogConsoleFlag = true; if (m.FindBool("fLogFileFlag", &fLogFileFlag) != B_OK) fLogFileFlag = false; if (m.FindString("fLogPath", &fLogPath) != B_OK) fLogPath.SetTo(""); //advance tab if (m.FindInt16("fMaxConnections", &fMaxConnections) != B_OK) fMaxConnections = (int16)32; //windows' position and size if (m.FindRect("frame", &fFrame) != B_OK) fFrame.Set(82.0f, 30.0f, 400.0f, 350.0f); if (m.FindRect("fSetwindowFrame", &fSetwindowFrame) != B_OK) fSetwindowFrame.Set(112.0f, 60.0f, 492.0f, 340.0f); if (m.FindBool("fIsZoomed", &fIsZoomed) != B_OK) fIsZoomed = true; if (m.FindFloat("fLastWidth", &fLastWidth) != B_OK) fLastWidth = 318.0f; if (m.FindFloat("fLastHeight", &fLastHeight) != B_OK) fLastHeight = 320.0f; fIsZoomed?ResizeTo(fLastWidth, fLastHeight):ResizeTo(318, 53); MoveTo(fFrame.left, fFrame.top); fLogFile = new BFile(fLogPath.String(), B_CREATE_FILE | B_WRITE_ONLY | B_OPEN_AT_END); if (fLogFile->InitCheck() != B_OK) { fLogFileFlag = false; //log it to console, "log to file unavailable." return B_OK; } SetDirLabel(fWebDirectory.String()); return B_OK; }
/*********************************************************** * CheckFromServer ***********************************************************/ status_t HDaemonApp::CheckFromServer(entry_ref &ref) { // Load account setting BFile file; BMessage msg; BEntry entry(&ref); char name[B_FILE_NAME_LENGTH+1]; entry.GetName(name); PRINT(("Account Name:%s\n",name)); if(file.SetTo(&entry,B_READ_ONLY) != B_OK) return B_ERROR; fAccountName = name; msg.Unflatten(&file); const char* password,*port; if(msg.FindString("pop_host",&fHost) != B_OK) return B_ERROR; if(msg.FindString("pop_port",&port) != B_OK) return B_ERROR; fPort = atoi(port); if(msg.FindString("pop_user",&fLogin) != B_OK) return B_ERROR; if(msg.FindInt16("protocol_type",&fProtocolType) != B_OK) fProtocolType = 0; if(msg.FindInt16("retrieve",&fRetrievingType) != B_OK) fRetrievingType = 0; if(fRetrievingType == 2) msg.FindInt32("delete_day",&fDeleteDays); else fDeleteDays = 0; if(msg.FindString("uidl",&fUidl) != B_OK) fUidl= ""; if(msg.FindString("pop_password",&password) != B_OK) return B_ERROR; int32 len = strlen(password); fPassword = ""; for(int32 k = 0;k < len;k++) fPassword += (char)(255-password[k]); if(fPopClient) fPopClient->PostMessage(B_QUIT_REQUESTED); fPopClient = new PopClient(NULL,this); if(fPopClient->Lock()) { fPopClient->InitBlackList(); fPopClient->Unlock(); } fDeleteMails.MakeEmpty(); fDeleteMails.what = H_DELETE_MESSAGE; fGotMails = false; BMessage sndMsg(H_CONNECT_MESSAGE); sndMsg.AddString("address",fHost); sndMsg.AddInt16("port",fPort); fPopClient->PostMessage(&sndMsg); return B_OK; }
status_t DefaultCatalog::Unflatten(BDataIO *dataIO) { fCatMap.Clear(); int32 count = 0; int16 version; BMessage archiveMsg; status_t res = archiveMsg.Unflatten(dataIO); if (res == B_OK) { res = archiveMsg.FindInt16("c:ver", &version) || archiveMsg.FindInt32("c:sz", &count); } if (res == B_OK) { fLanguageName = archiveMsg.FindString("c:lang"); fSignature = archiveMsg.FindString("c:sig"); uint32 foundFingerprint = archiveMsg.FindInt32("c:fpr"); // if a specific fingerprint has been requested and the catalog does in // fact have a fingerprint, both are compared. If they mismatch, we do // not accept this catalog: if (foundFingerprint != 0 && fFingerprint != 0 && foundFingerprint != fFingerprint) { fprintf(stderr, "default-catalog(sig=%s, lang=%s) " "has mismatching fingerprint (%ld instead of the requested %ld)" ", so this catalog is skipped.\n", fSignature.String(), fLanguageName.String(), foundFingerprint, fFingerprint); res = B_MISMATCHED_VALUES; } else fFingerprint = foundFingerprint; } if (res == B_OK && count > 0) { CatKey key; const char *keyStr; const char *keyCtx; const char *keyCmt; const char *translated; // fCatMap.resize(count); // There is no resize method in Antares Hash Map to prealloc space for (int i=0; res == B_OK && i < count; ++i) { res = archiveMsg.Unflatten(dataIO); if (res == B_OK) res = archiveMsg.FindString("c:ostr", &keyStr); if (res == B_OK) res = archiveMsg.FindString("c:ctxt", &keyCtx); if (res == B_OK) res = archiveMsg.FindString("c:comt", &keyCmt); if (res == B_OK) res = archiveMsg.FindInt32("c:hash", (int32*)&key.fHashVal); if (res == B_OK) res = archiveMsg.FindString("c:tstr", &translated); if (res == B_OK) { key.fString = keyStr; key.fContext = keyCtx; key.fComment = keyCmt; fCatMap.Put(key, translated); } } uint32 checkFP = ComputeFingerprint(); if (fFingerprint != checkFP) { fprintf(stderr, "default-catalog(sig=%s, lang=%s) " "has wrong fingerprint after load (%ld instead of the %ld). " "The catalog data may be corrupted, so this catalog is " "skipped.\n", fSignature.String(), fLanguageName.String(), checkFP, fFingerprint); return B_BAD_DATA; } } return res; }
status_t DefaultCatalog::Unflatten(BDataIO *dataIO) { fCatMap.Clear(); int32 count = 0; int16 version; BMessage archiveMsg; status_t res = archiveMsg.Unflatten(dataIO); if (res == B_OK) { res = archiveMsg.FindInt16("c:ver", &version) || archiveMsg.FindInt32("c:sz", &count); } if (res == B_OK) { fLanguageName = archiveMsg.FindString("c:lang"); fSignature = archiveMsg.FindString("c:sig"); uint32 foundFingerprint = archiveMsg.FindInt32("c:fpr"); // if a specific fingerprint has been requested and the catalog does in // fact have a fingerprint, both are compared. If they mismatch, we do // not accept this catalog: if (foundFingerprint != 0 && fFingerprint != 0 && foundFingerprint != fFingerprint) { res = B_MISMATCHED_VALUES; } else fFingerprint = foundFingerprint; } if (res == B_OK && count > 0) { CatKey key; const char *keyStr; const char *keyCtx; const char *keyCmt; const char *translated; // fCatMap.resize(count); // There is no resize method in Haiku's HashMap to preallocate // memory. for (int i=0; res == B_OK && i < count; ++i) { res = archiveMsg.Unflatten(dataIO); if (res == B_OK) res = archiveMsg.FindString("c:ostr", &keyStr); if (res == B_OK) res = archiveMsg.FindString("c:ctxt", &keyCtx); if (res == B_OK) res = archiveMsg.FindString("c:comt", &keyCmt); if (res == B_OK) res = archiveMsg.FindInt32("c:hash", (int32*)&key.fHashVal); if (res == B_OK) res = archiveMsg.FindString("c:tstr", &translated); if (res == B_OK) { key.fString = keyStr; key.fContext = keyCtx; key.fComment = keyCmt; fCatMap.Put(key, translated); } } uint32 checkFP = ComputeFingerprint(); if (fFingerprint != checkFP) return B_BAD_DATA; } return res; }