void WriterImplBase::RegisterPackageResolvableExpressionList( PackageAttributeList& attributeList, const BObjectList<BPackageResolvableExpression>& expressionList, uint8 id) { for (int i = 0; i < expressionList.CountItems(); ++i) { BPackageResolvableExpression* resolvableExpr = expressionList.ItemAt(i); bool hasVersion = resolvableExpr->Version().InitCheck() == B_OK; PackageAttribute* name = new PackageAttribute((BHPKGAttributeID)id, B_HPKG_ATTRIBUTE_TYPE_STRING, B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE); name->string = fPackageStringCache.Get(resolvableExpr->Name().String()); attributeList.Add(name); if (hasVersion) { PackageAttribute* op = new PackageAttribute( B_HPKG_ATTRIBUTE_ID_PACKAGE_RESOLVABLE_OPERATOR, B_HPKG_ATTRIBUTE_TYPE_UINT, B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT); op->unsignedInt = resolvableExpr->Operator(); name->children.Add(op); RegisterPackageVersion(name->children, resolvableExpr->Version()); } } }
BSolverPackage* PackageManager::_GetSolverPackage(PackageInfoRef package) { int32 flags = BSolver::B_FIND_IN_NAME; if (package->State() == ACTIVATED || package->State() == INSTALLED) flags |= BSolver::B_FIND_INSTALLED_ONLY; BObjectList<BSolverPackage> packages; status_t result = Solver()->FindPackages(package->Title(), flags, packages); if (result == B_OK) { for (int32 i = 0; i < packages.CountItems(); i++) { BSolverPackage* solverPackage = packages.ItemAt(i); if (solverPackage->Name() != package->Title()) continue; else if (package->State() == NONE && dynamic_cast<BPackageManager::RemoteRepository*>( solverPackage->Repository()) == NULL) { continue; } return solverPackage; } } return NULL; }
static const entry_ref* AddOneUniqueDocumentType(const entry_ref* ref, void* castToList) { BObjectList<BString>* list = (BObjectList<BString>*)castToList; BEntry entry(ref, true); // traverse symlinks // get this documents type char type[B_MIME_TYPE_LENGTH]; BFile file(&entry, O_RDONLY); if (file.InitCheck() != B_OK) return 0; BNodeInfo info(&file); if (info.GetType(type) != B_OK) return 0; if (list->EachElement(FindOne, &type)) // type already in list, bail return 0; // add type to list list->AddItem(new BString(type)); return 0; }
/*static*/ status_t SpecificImageDebugInfo::GetFunctionsFromSymbols( const BObjectList<SymbolInfo>& symbols, BObjectList<FunctionDebugInfo>& functions, DebuggerInterface* interface, const ImageInfo& imageInfo, SpecificImageDebugInfo* info) { // create the function infos int32 functionsAdded = 0; for (int32 i = 0; SymbolInfo* symbol = symbols.ItemAt(i); i++) { if (symbol->Type() != B_SYMBOL_TYPE_TEXT) continue; FunctionDebugInfo* function = new(std::nothrow) BasicFunctionDebugInfo( info, symbol->Address(), symbol->Size(), symbol->Name(), Demangler::Demangle(symbol->Name())); if (function == NULL || !functions.AddItem(function)) { delete function; int32 index = functions.CountItems() - 1; for (; functionsAdded >= 0; functionsAdded--, index--) { function = functions.RemoveItemAt(index); delete function; } return B_NO_MEMORY; } functionsAdded++; } return B_OK; }
void PairsView::Draw(BRect updateRect) { BObjectList<BBitmap>* bitmapsList; switch (fIconSize) { case kSmallIconSize: bitmapsList = fSmallBitmapsList; break; case kLargeIconSize: bitmapsList = fLargeBitmapsList; break; case kMediumIconSize: default: bitmapsList = fMediumBitmapsList; } for (int32 i = 0; i < fButtonsCount; i++) { SetDrawingMode(B_OP_ALPHA); DrawBitmap(bitmapsList->ItemAt(i % (fButtonsCount / 2)), BPoint(fPositionX[i], fPositionY[i])); SetDrawingMode(B_OP_COPY); } }
void PlayMediaFile(const char* media_type, const char* media_name) { entry_ref ref; if (BMediaFiles().GetRefFor(media_type, media_name, &ref) != B_OK || !BEntry(&ref).Exists()) return; MediaFilePlayer* player = list.EachElement(FindMediaFilePlayer, (void*)media_name); if (player != NULL) { if (*(player->Ref()) == ref) { player->Restart(); return; } list.RemoveItem(player); delete player; player = NULL; } if (player == NULL) { player = new MediaFilePlayer(media_type, media_name, &ref); if (player->InitCheck() == B_OK) list.AddItem(player); else delete player; } }
void TTracker::MoveRefsToTrash(const BMessage *message) { int32 count; uint32 type; message->GetInfo("refs", &type, &count); if (count <= 0) return; BObjectList<entry_ref> *srcList = new BObjectList<entry_ref>(count, true); for (int32 index = 0; index < count; index++) { entry_ref ref; ASSERT(message->FindRef("refs", index, &ref) == B_OK); if (message->FindRef("refs", index, &ref) != B_OK) continue; AutoLock<WindowList> lock(&fWindowList); BContainerWindow *window = FindParentContainerWindow(&ref); if (window) // if we have a window open for this entry, ask the pose to // delete it, this will select the next entry window->PoseView()->MoveEntryToTrash(&ref); else // add all others to a list that gets deleted separately srcList->AddItem(new entry_ref(ref)); } if (srcList->CountItems()) // async move to trash FSMoveToTrash(srcList); }
void reconnect_bitmaps_to_app_server() { BAutolock _(sBitmapListLock); for (int32 i = 0; i < sBitmapList.CountItems(); i++) { BBitmap::Private bitmap(sBitmapList.ItemAt(i)); bitmap.ReconnectToAppServer(); } }
/** We share one global list for all BMediaFormats in the team - since the * format data can change at any time, we have to update the list to ensure * that we are working on the latest data set. The list is always sorted by * description. The formats lock has to be held when you call this function. */ static status_t update_media_formats() { if (!sLock.IsLocked()) return B_NOT_ALLOWED; // We want the add-ons to register themselves with the format manager, so // the list is up to date. AddOnManager::GetInstance()->RegisterAddOns(); BMessage reply; FormatManager::GetInstance()->GetFormats(sLastFormatsUpdate, reply); // do we need an update at all? bool needUpdate; if (reply.FindBool("need_update", &needUpdate) < B_OK) return B_ERROR; if (!needUpdate) return B_OK; // update timestamp and check if the message is okay type_code code; int32 count; if (reply.FindInt64("timestamp", &sLastFormatsUpdate) < B_OK || reply.GetInfo("formats", &code, &count) < B_OK) return B_ERROR; // overwrite already existing formats int32 index = 0; for (; index < sFormats.CountItems() && index < count; index++) { meta_format* item = sFormats.ItemAt(index); const meta_format* newItem; ssize_t size; if (reply.FindData("formats", MEDIA_META_FORMAT_TYPE, index, (const void**)&newItem, &size) == B_OK) *item = *newItem; } // allocate additional formats for (; index < count; index++) { const meta_format* newItem; ssize_t size; if (reply.FindData("formats", MEDIA_META_FORMAT_TYPE, index, (const void**)&newItem, &size) == B_OK) sFormats.AddItem(new meta_format(*newItem)); } // remove no longer used formats while (count < sFormats.CountItems()) delete sFormats.RemoveItemAt(count); return B_OK; }
void ChannelAgent::RemoveNickFromList(BObjectList<BString>& list, const char* data) { int32 count(list.CountItems()); for (int32 i = 0; i < count; i++) { if (list.ItemAt(i)->ICompare(data) == 0) { delete list.RemoveItemAt(i); break; } } }
BObjectList<TaskList>* TaskMerge::GetTaskLists() { //run throught all TaskSyncer and get the TaskLists BObjectList<TaskList> *listOfLists = new BObjectList<TaskList>(); int32 i = 0; for (i=0;i<syncerList->CountItems();i++){ listOfLists->AddList(syncerList->ItemAt(i)->GetTaskLists()); } return listOfLists; }
// TODO: move this to the KeyStore or the registrar backend if needed static bool CompareLists(BObjectList<BString> a, BObjectList<BString> b) { if (a.CountItems() != b.CountItems()) return false; for (int32 i = 0; i < a.CountItems(); i++) { if (*a.ItemAt(i) != *b.ItemAt(i)) return false; } return true; }
void TFilePanel::OpenDirectory() { BObjectList<BPose>* list = PoseView()->SelectionList(); if (list->CountItems() != 1) return; Model* model = list->FirstItem()->TargetModel(); if (model->ResolveIfLink()->IsDirectory()) { BMessage message(B_REFS_RECEIVED); message.AddRef("refs", model->EntryRef()); PostMessage(&message); } }
BObjectList<Task>* TaskFS::GetTasks(TaskList forList) { Task *tmpTask = NULL; BObjectList<Task> *taskTaskList = new BObjectList<Task>(); int32 i; //grab a up to date List of Items GetTasks(); for (i = 0; i<tasks->CountItems();i++) { tmpTask=tasks->ItemAt(i); if (*(tmpTask->GetTaskList()) == forList) taskTaskList->AddItem(tmpTask); } return taskTaskList; }
status_t ImageDebugInfo::FinishInit(DebuggerInterface* interface) { BObjectList<SymbolInfo> symbols(50, true); status_t error = interface->GetSymbolInfos(fImageInfo.TeamID(), fImageInfo.ImageID(), symbols); if (error != B_OK) return error; symbols.SortItems(&_CompareSymbols); // get functions -- get them from most expressive debug info first and add // missing functions from less expressive debug infos for (int32 i = 0; SpecificImageDebugInfo* specificInfo = fSpecificInfos.ItemAt(i); i++) { BObjectList<FunctionDebugInfo> functions; error = specificInfo->GetFunctions(symbols, functions); if (error != B_OK) return error; for (int32 k = 0; FunctionDebugInfo* function = functions.ItemAt(k); k++) { if (FunctionAtAddress(function->Address()) != NULL) continue; FunctionInstance* instance = new(std::nothrow) FunctionInstance( this, function); if (instance == NULL || !fFunctions.BinaryInsert(instance, &_CompareFunctions)) { delete instance; error = B_NO_MEMORY; break; } if (function->IsMain()) fMainFunction = instance; } // Remove references returned by the specific debug info -- the // FunctionInstance objects have references, now. for (int32 k = 0; FunctionDebugInfo* function = functions.ItemAt(k); k++) { function->ReleaseReference(); } if (error != B_OK) return error; } return B_OK; }
status_t DebugReportGenerator::_DumpRunningThreads(BFile& _output) { AutoLocker< ::Team> locker(fTeam); BString data("\nActive Threads:\n"); WRITE_AND_CHECK(_output, data); BObjectList< ::Thread> threads; ::Thread* thread; for (ThreadList::ConstIterator it = fTeam->Threads().GetIterator(); (thread = it.Next());) { threads.AddItem(thread); } threads.SortItems(&_CompareThreads); for (int32 i = 0; (thread = threads.ItemAt(i)) != NULL; i++) { try { data.SetToFormat("\tthread %" B_PRId32 ": %s %s\n", thread->ID(), thread->Name(), thread->IsMainThread() ? "(main)" : ""); WRITE_AND_CHECK(_output, data); if (thread->State() == THREAD_STATE_STOPPED) { data.SetToFormat("\t\tstate: %s", UiUtils::ThreadStateToString(thread->State(), thread->StoppedReason())); const BString& stoppedInfo = thread->StoppedReasonInfo(); if (stoppedInfo.Length() != 0) data << " (" << stoppedInfo << ")"; data << "\n\n"; WRITE_AND_CHECK(_output, data); // we need to release our lock on the team here // since we might need to block and wait // on the stack trace. BReference< ::Thread> threadRef(thread); locker.Unlock(); status_t error = _DumpDebuggedThreadInfo(_output, thread); if (error != B_OK) return error; locker.Lock(); } } catch (...) { return B_NO_MEMORY; } } return B_OK; }
status_t ModuleManager::_GetAddOn(const char *name, ModuleAddOn **_addon) { // search list first for (int32 i = 0; ModuleAddOn *addon = fAddOns.ItemAt(i); i++) { BString addonName(addon->Name()); addonName << "/"; if (!strcmp(name, addon->Name()) || !strncmp(addonName.String(), name, addonName.Length())) { addon->Get(); *_addon = addon; return B_OK; } } // not in list yet, load from disk // iterate through module dirs for (int32 i = 0; gModuleDirs[i]; i++) { BPath path; if (path.SetTo(gModuleDirs[i]) == B_OK && path.SetTo(path.Path(), name) == B_OK) { BEntry entry; for (;;) { if (entry.SetTo(path.Path()) == B_OK && entry.Exists()) { // found an entry: if it is a file, try to load it if (entry.IsFile()) { ModuleAddOn *addon = new ModuleAddOn; if (addon->Load(path.Path(), gModuleDirs[i]) == B_OK) { status_t status = addon->Get(); if (status < B_OK) { delete addon; return status; } fAddOns.AddItem(addon); *_addon = addon; return B_OK; } delete addon; } break; } // chop off last path component if (path.GetParent(&path) != B_OK) break; } } } return B_ENTRY_NOT_FOUND; }
BMenu* MenuBuilder::BuildMenu(KeyBind* bind, MenuFilter* filter, CustomMenuCreator* custom) { if (bind == NULL) return NULL; // The first item describe the menu BMenu* menu = new BMenu(bind[0].label); if (filter != NULL) filter->FilterMenu(menu, bind[0].message); BObjectList<BMenu> menuList; menuList.AddItem(menu); for (int i = 1; bind[i].itemType != FABER_EOF; i++) { menu = menuList.ItemAt(menuList.CountItems()-1); if (bind[i].itemType == FABER_ITEM_START) { BMenu* subMenu = NULL; subMenu = new BMenu(bind[i].label); if (filter != NULL) filter->FilterMenu(subMenu, bind[i].message); menu->AddItem(subMenu); menuList.AddItem(subMenu); } else if (bind[i].itemType == FABER_ITEM_END) { if (menuList.CountItems() > 1) menuList.RemoveItemAt(menuList.CountItems()-1); } else if (bind[i].itemType == FABER_CUSTOM_ITEM) { if (custom == NULL) continue; BMenu* customMenu = custom->CreateCustomMenu(bind[i].message); if (customMenu != NULL) menu->AddItem(customMenu); } else if (bind[i].itemType == FABER_SUBITEM) { BMenuItem* item = BuildMenuItem(bind[i].message, bind[i].label); if (filter != NULL) filter->FilterItem(item, bind[i].message); menu->AddItem(item); } else if (bind[i].itemType == FABER_SPLITTER) menu->AddItem(new BSeparatorItem()); } return menuList.ItemAt(0); }
void PreferencesAccounts::_LoadListView(ProtocolSettings* settings) { if (!settings) return; BObjectList<BString> accounts = settings->Accounts(); // Add accounts to list view for (int32 i = 0; i < accounts.CountItems(); i++) { BString* account = accounts.ItemAt(i); AccountListItem* listItem = new AccountListItem(settings, account->String()); fListView->AddItem(listItem); } }
/*! \brief Cleans up any memory allocated by the bitmap and informs the server to do so as well (if needed). */ void BBitmap::_CleanUp() { if (fWindow != NULL) { if (fWindow->Lock()) delete fWindow; fWindow = NULL; // this will leak fWindow if it couldn't be locked } if (fBasePointer == NULL) return; if ((fFlags & B_BITMAP_NO_SERVER_LINK) != 0) { free(fBasePointer); } else if (fServerToken != -1) { BPrivate::AppServerLink link; // AS_DELETE_BITMAP: // Attached Data: // 1) int32 server token link.StartMessage(AS_DELETE_BITMAP); link.Attach<int32>(fServerToken); link.Flush(); // The server areas are deleted via kMsgDeleteServerMemoryArea message fArea = -1; fServerToken = -1; fAreaOffset = -1; BAutolock _(sBitmapListLock); sBitmapList.RemoveItem(this); } fBasePointer = NULL; }
status_t Message::StartSaver(BView *view, bool preview) { fPreview = preview; // Scale factor is based on the system I developed this on, in // other words other factors below depend on this. fScaleFactor = view->Bounds().Height() / 1024; // Get font families int numFamilies = count_font_families(); for (int32 i = 0; i < numFamilies; i++) { font_family* family = new font_family[1]; uint32 flags; if (get_font_family(i, family, &flags) == B_OK && (flags & B_IS_FIXED) == 0) { // Do not add fixed fonts fFontFamilies.AddItem(family); } else delete[] family; } // Seed the random number generator srand((int)system_time()); // Set tick size to 30,000,000 microseconds = 30 seconds SetTickSize(30000000); return B_OK; }
status_t BMediaFormats::GetFormatFor(const media_format_description& description, media_format* _format) { BAutolock locker(sLock); status_t status = update_media_formats(); if (status < B_OK) { ERROR("BMediaFormats: updating formats from server failed: %s!\n", strerror(status)); return status; } TRACE("search for description family = %d, a = 0x%" B_PRId32 "x, b = 0x%" B_PRId32 "x\n", description.family, description.u.misc.file_format, description.u.misc.codec); // search for a matching format description meta_format other(description); const meta_format* metaFormat = sFormats.BinarySearch(other, meta_format::CompareDescriptions); TRACE("meta format == %p\n", metaFormat); if (metaFormat == NULL) { memset(_format, 0, sizeof(*_format)); // clear to widlcard return B_MEDIA_BAD_FORMAT; } // found it! *_format = metaFormat->format; return B_OK; }
void Team::GetBreakpointsForSourceCode(SourceCode* sourceCode, BObjectList<UserBreakpoint>& breakpoints) const { if (DisassembledCode* disassembledCode = dynamic_cast<DisassembledCode*>(sourceCode)) { GetBreakpointsInAddressRange(disassembledCode->StatementAddressRange(), breakpoints); return; } LocatableFile* sourceFile = sourceCode->GetSourceFile(); if (sourceFile == NULL) return; // TODO: This can probably be optimized. Maybe by registering the user // breakpoints with the team and sorting them by source code. for (int32 i = 0; Breakpoint* breakpoint = fBreakpoints.ItemAt(i); i++) { UserBreakpointInstance* userBreakpointInstance = breakpoint->FirstUserBreakpoint(); if (userBreakpointInstance == NULL) continue; UserBreakpoint* userBreakpoint = userBreakpointInstance->GetUserBreakpoint(); if (userBreakpoint->Location().SourceFile() == sourceFile) breakpoints.AddItem(userBreakpoint); } }
status_t ExternalEventSource::AddListener(BaseJob* job) { if (fListeners.AddItem(job)) return B_OK; return B_NO_MEMORY; }
status_t RegisteredEvent::AddListener(BaseJob* job) { if (fListeners.AddItem(job)) return B_OK; return B_NO_MEMORY; }
status_t DebugReportGenerator::_DumpLoadedImages(BFile& _output) { AutoLocker< ::Team> locker(fTeam); BString data("\nLoaded Images:\n"); WRITE_AND_CHECK(_output, data); BObjectList<Image> images; for (ImageList::ConstIterator it = fTeam->Images().GetIterator(); Image* image = it.Next();) { images.AddItem(image); } images.SortItems(&_CompareImages); Image* image = NULL; data.SetToFormat("\tID\t\tText Base\tText End\tData Base\tData" " End\tType\tName\n\t"); WRITE_AND_CHECK(_output, data); data.Truncate(0L); data.Append('-', 80); data.Append("\n"); WRITE_AND_CHECK(_output, data); for (int32 i = 0; (image = images.ItemAt(i)) != NULL; i++) { const ImageInfo& info = image->Info(); char buffer[32]; try { target_addr_t textBase = info.TextBase(); target_addr_t dataBase = info.DataBase(); data.SetToFormat("\t%" B_PRId32 "\t0x%08" B_PRIx64 "\t" "0x%08" B_PRIx64 "\t0x%08" B_PRIx64 "\t0x%08" B_PRIx64 "\t" "%-7s\t%s\n", info.ImageID(), textBase, textBase + info.TextSize(), dataBase, dataBase + info.DataSize(), UiUtils::ImageTypeToString(info.Type(), buffer, sizeof(buffer)), info.Name().String()); WRITE_AND_CHECK(_output, data); } catch (...) { return B_NO_MEMORY; } } return B_OK; }
void LiveQuery::MessageReceived(BMessage* message) { switch (message->what) { case kMsgAddQuery: { int32 device; const char* predicate; if (message->FindInt32("volume", &device) != B_OK || message->FindString("predicate", &predicate) != B_OK) break; BVolume volume(device); BQuery* query = new BQuery; // Set up the volume and predicate for the query. query->SetVolume(&volume); query->SetPredicate(predicate); query->SetTarget(this); fQueries.AddItem(query); _PerformQuery(*query); break; } case B_QUERY_UPDATE: { int32 what; message->FindInt32("opcode", &what); int32 device; int64 directory; int64 node; const char* name; message->FindInt32("device", &device); message->FindInt64("directory", &directory); message->FindInt64("node", &node); message->FindString("name", &name); switch (what) { case B_ENTRY_CREATED: { printf("CREATED %s\n", name); break; } case B_ENTRY_REMOVED: printf("REMOVED %s\n", name); break; } break; } default: BApplication::MessageReceived(message); break; } }
static void add_resolvables(Repo *repo, Offset &dependencies, const BObjectList<BPackageResolvable> &resolvables) { for (int32 i = 0; BPackageResolvable *resolvable = resolvables.ItemAt(i); i++) { add_dependency(repo, dependencies, resolvable->Name(), resolvable->Version().ToString(), REL_EQ, resolvable->CompatibleVersion().ToString()); } }
// _PutAddOn void ModuleManager::_PutAddOn(ModuleAddOn *addon) { if (addon) { if (addon->Put()) { fAddOns.RemoveItem(addon); delete addon; } } }
void WPASupplicantApp::_NotifyInterfaceStateChanged(BMessage *message) { const wpa_supplicant *interface; if (message->FindPointer("interface", (void **)&interface) != B_OK) return; if (!fWatchingEntryListLocker.Lock()) return; for (int32 i = 0; i < fWatchingEntryList.CountItems(); i++) { StateChangeWatchingEntry *entry = fWatchingEntryList.ItemAt(i); if (entry->MessageReceived(interface, message)) { delete fWatchingEntryList.RemoveItemAt(i); i--; } } fWatchingEntryListLocker.Unlock(); }