コード例 #1
0
ファイル: driver_list.c プロジェクト: pcercuei/dcplaya
static int specific_register(any_driver_t * driver)
{
  int err = 0;
  switch(driver->type) {
  case INP_DRIVER:
    {
      inp_driver_t * d = (inp_driver_t *) driver;
      d->id = filetype_add(filetype_major_add("music"),
			   driver->name, d->extensions);
      SDDEBUG("Driver '%s' : filetype %d\n", driver->name, d->id);
    } break;
      
  case IMG_DRIVER:
    {
      img_driver_t * d = (img_driver_t *) driver;
      /* Add to translator */
      err = AddTranslator(d->translator);
      if (!err) {
	/* Add filetype. */
	d->id = filetype_add(filetype_major_add("image"),
			     driver->name, d->extensions);
	SDDEBUG("Driver '%s' : filetype %d\n", driver->name, d->id);
      }
    } break;
  }
  return err;
}
コード例 #2
0
ファイル: TranslatorRoster.cpp プロジェクト: mylegacy/haiku
status_t
BTranslatorRoster::Private::CreateTranslators(const entry_ref& ref,
	int32& count, BMessage* update)
{
	BAutolock locker(this);

	BPrivate::QuarantineTranslatorImage quarantine(*this);

	const translator_item* item = _FindTranslator(ref.name);
	if (item != NULL) {
		// check if the known translator has a higher priority
		if (_CompareTranslatorDirectoryPriority(item->ref, ref) <= 0) {
			// keep the existing add-on
			return B_OK;
		}

		// replace existing translator(s) if the new translator succeeds
		quarantine.Put(item->ref);
	}

	BEntry entry(&ref);
	node_ref nodeRef;
	status_t status = entry.GetNodeRef(&nodeRef);
	if (status < B_OK)
		return status;

	BPath path(&ref);
	image_id image = load_add_on(path.Path());
	if (image < B_OK)
		return image;

	// Function pointer used to create post R4.5 style translators
	BTranslator *(*makeNthTranslator)(int32 n, image_id you, uint32 flags, ...);

	status = get_image_symbol(image, "make_nth_translator",
		B_SYMBOL_TYPE_TEXT, (void**)&makeNthTranslator);
	if (status == B_OK) {
		// If the translator add-on supports the post R4.5
		// translator creation mechanism, keep loading translators
		// until MakeNthTranslator stops returning them.
		BTranslator* translator = NULL;
		int32 created = 0;
		for (int32 n = 0; (translator = makeNthTranslator(n, image, 0)) != NULL;
				n++) {
			if (AddTranslator(translator, image, &ref, nodeRef.node) == B_OK) {
				if (update)
					update->AddInt32("translator_id", translator->fID);
				count++;
				created++;
			} else {
				translator->Release();
					// this will delete the translator
			}
		}

		if (created == 0)
			unload_add_on(image);

		quarantine.Remove();
		return B_OK;
	}

	// If this is a translator add-on, it is in the C format
	translator_data translatorData;
	status = GetTranslatorData(image, translatorData);

	// add this translator to the list
	BPrivate::BFuncTranslator* translator = NULL;
	if (status == B_OK) {
		translator = new (std::nothrow) BPrivate::BFuncTranslator(
			translatorData);
		if (translator == NULL)
			status = B_NO_MEMORY;
	}

	if (status == B_OK)
		status = AddTranslator(translator, image, &ref, nodeRef.node);

	if (status == B_OK) {
		if (update)
			update->AddInt32("translator_id", translator->fID);
		quarantine.Remove();
		count++;
	} else
		unload_add_on(image);

	return status;
}