예제 #1
0
파일: load_add_on.c 프로젝트: 12019/SDKs
/* A function called through the vtable to open a module with this
   loader.  Returns an opaque representation of the newly opened
   module for processing with this loader's other vtable functions.  */
static lt_module
vm_open (lt_user_data LT__UNUSED loader_data, const char *filename,
         lt_dladvise LT__UNUSED advise)
{
  image_id image = 0;

  if (filename)
    {
      image = load_add_on (filename);
    }
  else
    {
      image_info info;
      int32 cookie = 0;
      if (get_next_image_info (0, &cookie, &info) == B_OK)
	image = load_add_on (info.name);
    }

  if (image <= 0)
    {
      LT__SETERROR (CANNOT_OPEN);
      image = 0;
    }

  return (lt_module) image;
}
예제 #2
0
status_t PrintTransport::Open(BNode* printerFolder)
{
	// already opened?
	if (fDataIO != NULL) {
		return B_ERROR;
	}

	// retrieve transport add-on name from printer folder attribute
	BString transportName;
	if (printerFolder->ReadAttrString("transport", &transportName) != B_OK) {
		return B_ERROR;
	}

	// try first in user add-ons directory
	BPath path;
	find_directory(B_USER_ADDONS_DIRECTORY, &path);
	path.Append("Print/transport");
	path.Append(transportName.String());
	fAddOnID = load_add_on(path.Path());

	if (fAddOnID < 0) {
		// on failure try in system add-ons directory
		find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
		path.Append("Print/transport");
		path.Append(transportName.String());
		fAddOnID = load_add_on(path.Path());
	}

	if (fAddOnID < 0) {
		// failed to load transport add-on
		return B_ERROR;
	}

	// get init & exit proc
	BDataIO* (*initProc)(BMessage*);
	get_image_symbol(fAddOnID, "init_transport", B_SYMBOL_TYPE_TEXT, (void **) &initProc);
	get_image_symbol(fAddOnID, "exit_transport", B_SYMBOL_TYPE_TEXT, (void **) &fExitProc);

	if (initProc == NULL || fExitProc == NULL) {
		// transport add-on has not the proper interface
		return B_ERROR;
	}

	// now, initialize the transport add-on
	node_ref   ref;
	BDirectory dir;

	printerFolder->GetNodeRef(&ref);
	dir.SetTo(&ref);

	if (path.SetTo(&dir, NULL) != B_OK) {
		return B_ERROR;
	}

	// request BDataIO object from transport add-on
	BMessage input('TRIN');
	input.AddString("printer_file", path.Path());
	fDataIO = (*initProc)(&input);
	return B_OK;
}
예제 #3
0
void *ILDynLibraryOpen(const char *name)
{
	image_id handle;
	const char *error;
	handle = load_add_on(name);
	if(!handle)
	{
		/* If the name does not start with "lib" and does not
		   contain a path, then prepend "lib" and try again */
		if(strncmp(name, "lib", 3) != 0)
		{
			error = name;
			while(*error != '\0' && *error != '/' && *error != '\\')
			{
				++error;
			}
			if(*error == '\0')
			{
				/* Try adding "lib" to the start */
				char *temp = (char *)ILMalloc(strlen(name) + 4);
				if(temp)
				{
					strcpy(temp, "lib");
					strcat(temp, name);
					handle = load_add_on(temp);
					ILFree(temp);
					if(handle >= B_NO_ERROR) /* errors are < B_NO_ERROR */
					{
						return handle;
					}
				}

				/* Reload the original error state */
				handle = load_add_on(name);
			}
		}

		/* Report the error */
	#ifdef IL_DYNLIB_DEBUG
		error = strerror(handle); 
		fprintf(stderr, "%s: \n", name,
				(error ? error : "could not load dynamic library"));
	#endif
		return 0;
	}
	else
	{
		return handle;
	}
}
status_t TEncoderAddonManager::LoadAddons(const char *addondDir)
{
	fp_text_convert_t fp_text_convert;
	image_id id;
	BDirectory dir(addondDir);
	BEntry entry;
	
	// load encoders add-on
	while (dir.GetNextEntry(&entry) == B_OK) {
		BPath addonPath(&entry);
		if ((id = load_add_on(addonPath.Path())) < 0) continue;
		if (get_image_symbol(id, "fp_text_convert", B_SYMBOL_TYPE_TEXT, (void **)&fp_text_convert)) {
			unload_add_on(id);
			continue;
		}
		encoder_addon_t *addon = (encoder_addon_t *)malloc(sizeof(encoder_addon_t));
		if (!addon) {
			fprintf(stderr, "%s\n", strerror(ENOMEM));
			unload_add_on(id);
			return ENOMEM;
		}
		addon->id = id;
		addon->fp_text_convert = fp_text_convert;
		strncpy(addon->name, addonPath.Leaf(), sizeof(addon->name));
		fEncoderAddonList.AddItem(addon);
		fprintf(stderr, "load: %s\n", addon->name);
	}
	return B_OK;
}
예제 #5
0
bool
BTranslatorRoster::IsTranslator(entry_ref* ref)
{
	if (ref == NULL)
		return false;

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

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

	status_t status = get_image_symbol(image, "make_nth_translator",
		B_SYMBOL_TYPE_TEXT, (void**)&makeNthTranslator);
	if (status < B_OK) {
		// If this is a translator add-on, it is in the C format
		translator_data translatorData;
		status = fPrivate->GetTranslatorData(image, translatorData);
	}

	unload_add_on(image);
	return status == B_OK;
}
예제 #6
0
파일: dso_beos.c 프로젝트: 274914765/C
static int beos_load (DSO * dso)
{
    image_id id;

    /* See applicable comments from dso_dl.c */
    char *filename = DSO_convert_filename (dso, NULL);

    if (filename == NULL)
    {
        DSOerr (DSO_F_BEOS_LOAD, DSO_R_NO_FILENAME);
        goto err;
    }
    id = load_add_on (filename);
    if (id < 1)
    {
        DSOerr (DSO_F_BEOS_LOAD, DSO_R_LOAD_FAILED);
        ERR_add_error_data (3, "filename(", filename, ")");
        goto err;
    }
    if (!sk_push (dso->meth_data, (char *) id))
    {
        DSOerr (DSO_F_BEOS_LOAD, DSO_R_STACK_ERROR);
        goto err;
    }
    /* Success */
    dso->loaded_filename = filename;
    return (1);
  err:
    /* Cleanup ! */
    if (filename != NULL)
        OPENSSL_free (filename);
    if (id > 0)
        unload_add_on (id);
    return (0);
}
예제 #7
0
bool BeHappy::CheckAddOn(const char *path,bool alert,BString *pName)
{
	image_id addOnImage = load_add_on(path);
	void *instFunc;
	const char **projName;
	const uint16 *BHVersion,*BHVLastCompatible;
	bool ok = false;
	BPath aoPath(path);
	
	BString alTxt(aoPath.Leaf());		// chaîne utilisée pour générer des alertes d'erreur

	if ((addOnImage>=0) &&
		(get_image_symbol(addOnImage,"InstantiateProject",B_SYMBOL_TYPE_ANY,&instFunc) == B_OK) &&
		(get_image_symbol(addOnImage,"projectName",B_SYMBOL_TYPE_ANY,(void**)&projName) == B_OK) &&
		(get_image_symbol(addOnImage,"BHVersion",B_SYMBOL_TYPE_ANY,(void**)&BHVersion) == B_OK) &&
		(get_image_symbol(addOnImage,"BHVLastCompatible",B_SYMBOL_TYPE_ANY,(void**)&BHVLastCompatible) == B_OK))
	{
		if ((*BHVLastCompatible) > bhv_application)
		{
			if (alert)
			{
				alTxt << " " << T("isn't compatible with this (old) version of BeHappy. Please download a more recent version of BeHappy.");
				BAlert *myAlert = new BAlert("BeHappy",alTxt.String(),"OK",
					NULL,NULL,B_WIDTH_AS_USUAL,B_WARNING_ALERT);
				myAlert->Go();
			}
		}
		else if ((*BHVersion) < bhv_last_addon)
		{
			if (alert)
			{
				alTxt << " " << T("is too old, and isn't compatible with this version of BeHappy. Please find a more recent version of the add-on.");
				BAlert *myAlert = new BAlert("BeHappy",alTxt.String(),"OK",
					NULL,NULL,B_WIDTH_AS_USUAL,B_WARNING_ALERT);
				myAlert->Go();
			}
		}
		else
		{
			ok = true;
			if (pName != NULL)
				*pName=*projName;
		}					
	}
	else	
	{
		if (alert)
		{
			alTxt << " " << T("is an invalid BeHappy add-on.");
			BAlert *myAlert = new BAlert("BeHappy",alTxt.String(),"OK",
				NULL,NULL,B_WIDTH_AS_USUAL,B_WARNING_ALERT);
			myAlert->Go();
		}
	}
	
	if (addOnImage>=0)
		unload_add_on(addOnImage);

	return ok;
}
예제 #8
0
image_id ArpAddonManager::BasicAddon::Open(void)
{
	if( image < 0 ) {
		image = load_add_on(Path().Path());
	}
	if( image >= 0 ) ref_count++;
	return image;
}
예제 #9
0
int
main(int argc, char **argv)
{
	// Parse command line arguments

	bool ignorePunctuation = false;
	char *addon = NULL;
	BCollator *collator = NULL;

	while ((++argv)[0]) {
		if (argv[0][0] == '-') {
			if (!strcmp(argv[0], "-i"))
				ignorePunctuation = true;
			else if (!strcmp(argv[0], "--help"))
				usage();
		} else {
			// this will be the add-on to be loaded
			addon = argv[0];
		}
	}

	// load the collator add-on if necessary

	if (addon != NULL) {
		image_id image = load_add_on(addon);
		if (image < B_OK)
			fprintf(stderr, "could not load add-on at \"%s\": %s.\n", addon, strerror(image));

		BCollatorAddOn *(*instantiate)(void);
		if (get_image_symbol(image, "instantiate_collator",
				B_SYMBOL_TYPE_TEXT, (void **)&instantiate) == B_OK) {
			BCollatorAddOn *collatorAddOn = instantiate();
			if (collatorAddOn != NULL)
				collator = new BCollator(collatorAddOn, B_COLLATE_PRIMARY, true);
		} else if (image >= B_OK) {
			fprintf(stderr, "could not find instantiate_collator() function in add-on!\n");
			unload_add_on(image);
		}
	}

	if (collator == NULL) {
		collator = be_locale->Collator();
		addon = (char*)"default";
	}

	// test key creation speed

	collator->SetIgnorePunctuation(ignorePunctuation);

	printf("%s:\n", addon);
	test(collator, "primary:   ", B_COLLATE_PRIMARY);
	test(collator, "secondary: ", B_COLLATE_SECONDARY);
	test(collator, "tertiary:  ", B_COLLATE_TERTIARY);
	test(collator, "quaternary:", B_COLLATE_QUATERNARY);
	test(collator, "identical: ", B_COLLATE_IDENTICAL);

	return 0;
}
예제 #10
0
static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
{
    image_id lib = load_add_on(fname);
    void *retval = NULL;
    if ((lib < 0) || (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR)) {
        retval = NULL;
    }
    return retval;
}
예제 #11
0
image_id
BPrinter::_LoadDriver() const
{
	BPath driverPath(_DriverPath());
	if (driverPath.InitCheck() != B_OK)
		return -1;

	return load_add_on(driverPath.Path());
}
예제 #12
0
파일: sys_loadso.c 프로젝트: CCQIU/CC
void* CC_CALL cc_load_object(const tchar_t *sofile)
{
    image_id library_id = load_add_on(sofile);
    if (library_id < 0) {
        CC_ERROR_LOG(_T("Failed loading %s : %s"),sofile,strerror((int) library_id));
        return NULL;
    }
    
    return (void *) (library_id);
}
예제 #13
0
void *
SDL_LoadObject(const char *sofile)
{
    void *handle = NULL;
    image_id library_id = load_add_on(sofile);
    if (library_id < 0) {
        SDL_SetError(strerror((int) library_id));
    } else {
        handle = (void *) (library_id);
    }
    return (handle);
}
예제 #14
0
// Load
status_t
AddOnImage::Load(const char* path)
{
	Unload();
	status_t error = (path ? B_OK : B_BAD_VALUE);
	if (error == B_OK) {
		image_id id = load_add_on(path);
		if (id >= 0)
			fID = id;
		else
			error = id;
	}
	return error;
}
예제 #15
0
void
DecorManager::RescanDecorators()
{
	BDirectory dir(DECORATORS_DIR);

	if (dir.InitCheck() != B_OK)
		return;

	entry_ref ref;
	while (dir.GetNextRef(&ref) == B_OK) {
		BPath path;
		path.SetTo(DECORATORS_DIR);
		path.Append(ref.name);

		// Because this function is used for both initialization and for keeping
		// the list up to date, check for existence in the list. Note that we
		// do not check to see if a decorator has been removed. This is for
		// stability. If there is a decorator in memory already whose file has
		// been deleted, it is still available until the next boot, at which point
		// it will obviously not be loaded.

		if (_FindDecor(ref.name))
			continue;

		image_id image = load_add_on(path.Path());
		if (image < 0)
			continue;

		// As of now, we do nothing with decorator versions, but the possibility
		// exists that the API will change even though I cannot forsee any reason
		// to do so. If we *did* do anything with decorator versions, the 
		// assignment would go here.

		create_decorator* createFunc;

		// Get the instantiation function
		status_t status = get_image_symbol(image, "instantiate_decorator",
								B_SYMBOL_TYPE_TEXT, (void**)&createFunc);
		if (status != B_OK) {
			unload_add_on(image);
			continue;
		}

		// TODO: unload images until they are actually used!
		fDecorList.AddItem(new DecorInfo(image, ref.name, createFunc));
	}
}
void					
BF_GUI_FilesPanel::Action_Tracker_Addons_Run(const char *pc_AddOn)
{
	ASSERT(pc_AddOn);
		
	image_id 	uImage;	
	uImage = load_add_on(pc_AddOn);
	if(0==uImage) return;
	
	BEntry 		oEntry(oPath.Path());
	entry_ref	uEntryRef;
	
	if(B_OK!=oEntry.GetRef(&uEntryRef)) return;
	
	void (*Func_AddOn)(entry_ref dir_ref, BMessage *msg, void *);
	if(B_OK!=get_image_symbol(uImage, "process_refs", B_SYMBOL_TYPE_TEXT, (void**)&Func_AddOn)) return;
	
	BMessage 			*poMessage = new BMessage();	
	BF_NodeCollection	loSelNode;
	loNode.GetSelecting(loSelNode);
	if(loSelNode.CountItems()==0) loSelNode.AddItem(Nodes_Focus());
	if(loSelNode.CountItems()==0) return;
	ASSERT(poMessage);
	
	BF_Node 	*poNode=NULL;
	entry_ref	uNodeRef;	
	BL_String	s;
	for(int iNode=0;iNode<loSelNode.CountItems();iNode++){
		poNode = loSelNode.NodeAt(iNode);
		s=oPath.Path();
		s<<"/";
		s<<poNode->sName;
		if(B_OK!=oEntry.SetTo(s.String()) || B_OK!=oEntry.GetRef(&uNodeRef)) continue;
		poMessage->AddRef("refs",&uNodeRef);
	}
	
	
	poMessage->AddRef("folder_ref",&uEntryRef);
	poMessage->AddPointer("func",(void*)Func_AddOn);
	
	// run thread //
	thread_id idThread = spawn_thread(BF_GUI_FilesPanel_Action_Tracker_Addons_Run_Thread,"tracker_addon_thread",B_THREAD_SUSPENDED,(void*)poMessage);	
	ASSERT(idThread>0,"can`t start thread\n");	
	ASSERT(B_OK==resume_thread(idThread));		
	set_thread_priority(idThread,1);				
}
예제 #17
0
status_t
AddOnManager::_RegisterAddOn(BEntry& entry)
{
	BPath path(&entry);

	entry_ref ref;
	status_t status = entry.GetRef(&ref);
	if (status < B_OK)
		return status;

	TRACE("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n",
		path.Path());

	image_id image = load_add_on(path.Path());
	if (image < B_OK) {
		ERROR("load addon %s failed\n", path.Path());
		return image;
	}

	status = B_ERROR;

	if (_IsDevice(path.Path())) {
		BInputServerDevice* device = instantiate_add_on<BInputServerDevice>(
			image, path.Path(), "device");
		if (device != NULL)
			status = _RegisterDevice(device, ref, image);
	} else if (_IsFilter(path.Path())) {
		BInputServerFilter* filter = instantiate_add_on<BInputServerFilter>(
			image, path.Path(), "filter");
		if (filter != NULL)
			status = _RegisterFilter(filter, ref, image);
	} else if (_IsMethod(path.Path())) {
		BInputServerMethod* method = instantiate_add_on<BInputServerMethod>(
			image, path.Path(), "method");
		if (method != NULL)
			status = _RegisterMethod(method, ref, image);
	} else {
		ERROR("AddOnManager::_RegisterAddOn(): addon type not found for "
			"\"%s\" \n", path.Path());
	}

	if (status != B_OK)
		unload_add_on(image);

	return status;
}
예제 #18
0
//------------------------------------------------------------------------------
void TInstantiateObjectTester::LoadAddon()
{
	if (fAddonId > 0)
		return;

	// We're not testing the roster, so I'm going to just
	// find the add-on manually.
	std::string libPath = std::string(BTestShell::GlobalTestDir()) + gRemoteLib;
	cout << "dir == '" << libPath << "'" << endl;
	fAddonId = load_add_on(libPath.c_str());

	RES(fAddonId);
	if (fAddonId <= 0)
	{
		FORMAT_AND_THROW(" failed to load addon: ", fAddonId);
	}
}
예제 #19
0
status_t
DormantNodeManager::_LoadAddOn(const char* path, media_addon_id id,
	BMediaAddOn** _newAddOn, image_id* _newImage)
{
	image_id image = load_add_on(path);
	if (image < 0) {
		ERROR("DormantNodeManager::LoadAddon: loading \"%s\" failed: %s\n",
			path, strerror(image));
		return image;
	}

	BMediaAddOn* (*makeAddOn)(image_id);
	status_t status = get_image_symbol(image, "make_media_addon",
		B_SYMBOL_TYPE_TEXT, (void**)&makeAddOn);
	if (status != B_OK) {
		ERROR("DormantNodeManager::LoadAddon: loading failed, function not "
			"found: %s\n", strerror(status));
		unload_add_on(image);
		return status;
	}

	BMediaAddOn* addOn = makeAddOn(image);
	if (addOn == NULL) {
		ERROR("DormantNodeManager::LoadAddon: creating BMediaAddOn failed\n");
		unload_add_on(image);
		return B_ERROR;
	}

	ASSERT(addOn->ImageID() == image);
		// this should be true for a well behaving add-ons

	// We are a friend class of BMediaAddOn and initialize these member
	// variables
	addOn->fAddon = id;
	addOn->fImage = image;

	// everything ok
	*_newAddOn = addOn;
	*_newImage = image;

	return B_OK;
}
예제 #20
0
BView*
CreateConfigView(entry_ref addon, MailAddonSettings& settings,
	BMailAccountSettings& accountSettings, image_id* image)
{
	BView* (*instantiate_config)(MailAddonSettings& settings,
		BMailAccountSettings& accountSettings);
	BPath path(&addon);
	*image = load_add_on(path.Path());
	if (image < 0)
		return NULL;

	if (get_image_symbol(*image, "instantiate_config_panel", B_SYMBOL_TYPE_TEXT,
		(void **)&instantiate_config) != B_OK) {
		unload_add_on(*image);
		*image = -1;
		return NULL;
	}

	BView* view = (*instantiate_config)(settings, accountSettings);
	return view;
}
예제 #21
0
/* --- functions --- */
static gpointer
_g_module_open (const gchar *file_name,
		gboolean     bind_lazy)
{
  image_id handle;
  
  handle = load_add_on (file_name);
  if (handle < B_OK)
    {
      gchar *msg = g_strdup_printf ("failed to load_add_on(%s): %s",
				    file_name,
				    strerror (handle));
      
      g_module_set_error (msg);
      g_free (msg);
      
      return NULL;
    }
  
  return (gpointer) handle;
}
예제 #22
0
DecorAddOn*
DecorManager::_LoadDecor(BString _path, status_t& error )
{
	if (_path == "Default") {
		error = B_OK;
		return &fDefaultDecor;
	}

	BEntry entry(_path.String(), true);
	if (!entry.Exists()) {
		error = B_ENTRY_NOT_FOUND;
		return NULL;
	}

	BPath path(&entry);
	image_id image = load_add_on(path.Path());
	if (image < 0) {
		error = B_BAD_IMAGE_ID;
		return NULL;
	}

	create_decor_addon*	createFunc;
	if (get_image_symbol(image, "instantiate_decor_addon", B_SYMBOL_TYPE_TEXT,
			(void**)&createFunc) != B_OK) {
		unload_add_on(image);
		error = B_MISSING_SYMBOL;
		return NULL;
	}

	char name[B_FILE_NAME_LENGTH];
	entry.GetName(name);
	DecorAddOn* newDecor = createFunc(image, name);
	if (newDecor == NULL || newDecor->InitCheck() != B_OK) {
		unload_add_on(image);
		error = B_ERROR;
		return NULL;
	}

	return newDecor;
}
예제 #23
0
void
IndexServer::RegisterAddOn(entry_ref ref)
{
	STRACE("RegisterAddOn %s\n", ref.name);

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

	create_index_server_addon* createFunc;

	// Get the instantiation function
	status_t status = get_image_symbol(image, "instantiate_index_server_addon",
		B_SYMBOL_TYPE_TEXT, (void**)&createFunc);
	if (status != B_OK) {
		unload_add_on(image);
		return;
	}

	IndexServerAddOn* addon = createFunc(image, ref.name);
	if (!addon) {
		unload_add_on(image);
		return;
	}
	if (!fAddOnList.AddItem(addon)) {
		unload_add_on(image);
		return;
	}

	for (int i = 0; i < fVolumeWatcherList.CountItems(); i++) {
		VolumeWatcher* watcher = fVolumeWatcherList.ItemAt(i);
		FileAnalyser* analyser = _SetupFileAnalyser(addon, watcher->Volume());
		if (!analyser)
			continue;
		if (!watcher->AddAnalyser(analyser))
			delete analyser;
	}

}
예제 #24
0
status_t
PluginManager::_LoadPlugin(const entry_ref& ref, MediaPlugin** plugin,
	image_id* image)
{
	BPath p(&ref);

	TRACE("PluginManager: _LoadPlugin trying to load %s\n", p.Path());

	image_id id;
	id = load_add_on(p.Path());
	if (id < 0) {
		printf("PluginManager: Error, load_add_on(): %s\n", strerror(id));
		return B_ERROR;
	}
		
	MediaPlugin* (*instantiate_plugin_func)();
	
	if (get_image_symbol(id, "instantiate_plugin", B_SYMBOL_TYPE_TEXT,
			(void**)&instantiate_plugin_func) < B_OK) {
		printf("PluginManager: Error, _LoadPlugin can't find "
			"instantiate_plugin in %s\n", p.Path());
		unload_add_on(id);
		return B_ERROR;
	}
	
	MediaPlugin *pl;
	
	pl = (*instantiate_plugin_func)();
	if (pl == NULL) {
		printf("PluginManager: Error, _LoadPlugin instantiate_plugin in %s "
			"returned NULL\n", p.Path());
		unload_add_on(id);
		return B_ERROR;
	}
	
	*plugin = pl;
	*image = id;
	return B_OK;
}
예제 #25
0
main(int argc, char **argv) {
char *path, *symname;
image_id img;
int32 n = 0;
volatile int32 symnamelen, symtype;
void *symloc;

if (argc != 2) { printf("more args, bozo\n"); exit(1); }

path = (void *) malloc((size_t) 2048);
symname = (void *) malloc((size_t) 2048);

if (!getcwd(path, 2048)) { printf("aiee!\n"); exit(1); }
if (!strcat(path, "/"))  {printf("naah.\n"); exit (1); }
/*printf("%s\n",path);*/

if ('/' != argv[1][0]) {
	if (!strcat(path, argv[1])) { printf("feh1\n"); exit(1); }
} else {
	if (!strcpy(path, argv[1])) { printf("gah!\n"); exit(1); }
}
/*printf("%s\n",path);*/

img = load_add_on(path);
if (B_ERROR == img) {printf("Couldn't load_add_on() %s.\n", path); exit(2); }

symnamelen=2047;

while (B_BAD_INDEX != get_nth_image_symbol(img, n++, symname, &symnamelen,
                        &symtype, &symloc)) {
	printf("%s |%s |GLOB %Lx | \n", symname,
         ((B_SYMBOL_TYPE_ANY == symtype) || (B_SYMBOL_TYPE_TEXT == symtype)) ? "FUNC" : "VAR ", symloc);
	symnamelen=2047;
}
printf("number of symbols: %d\n", n);
if (B_ERROR == unload_add_on(img)) {printf("err while closing.\n"); exit(3); }
free(path);
return(0);
}
예제 #26
0
status_t
GLRendererRoster::CreateRenderer(const entry_ref& ref)
{
	BEntry entry(&ref, true);
	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;

	BGLRenderer* (*instantiate_renderer)
		(BGLView* view, ulong options, BGLDispatcher* dispatcher);

	status = get_image_symbol(image, "instantiate_gl_renderer",
		B_SYMBOL_TYPE_TEXT, (void**)&instantiate_renderer);
	if (status == B_OK) {
		BGLRenderer* renderer
			= instantiate_renderer(fView, fOptions, new BGLDispatcher());
		if (!renderer) {
			unload_add_on(image);
			return B_UNSUPPORTED;
		}

		if (AddRenderer(renderer, image, &ref, nodeRef.node) != B_OK) {
			renderer->Release();
			// this will delete the renderer
			unload_add_on(image);
		}
		return B_OK;
	}
	unload_add_on(image);

	return status;
}
bool
CatalogAddOnInfo::MakeSureItsLoaded()
{
	if (!fIsEmbedded && fAddOnImage < B_OK) {
		// add-on has not been loaded yet, so we try to load it:
		BString fullAddOnPath(fPath);
		fullAddOnPath << "/" << fName;
		fAddOnImage = load_add_on(fullAddOnPath.String());
		if (fAddOnImage >= B_OK) {
			get_image_symbol(fAddOnImage, "instantiate_catalog",
				B_SYMBOL_TYPE_TEXT, (void**)&fInstantiateFunc);
			get_image_symbol(fAddOnImage, "create_catalog",
				B_SYMBOL_TYPE_TEXT, (void**)&fCreateFunc);
			get_image_symbol(fAddOnImage, "get_available_languages",
				B_SYMBOL_TYPE_TEXT, (void**)&fLanguagesFunc);
		} else
			return false;
	} else if (fIsEmbedded) {
		// The built-in catalog still has to provide this function
		fLanguagesFunc = default_catalog_get_available_languages;
	}
	return true;
}
예제 #28
0
static void *
xmlModulePlatformOpen(const char *name)
{
    return (void *) load_add_on(name);
}
/*
iterate over add-on-folders and collect information about each
catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
*/
status_t
LocaleRosterData::_InitializeCatalogAddOns()
{
	BAutolock lock(fLock);
	if (!lock.IsLocked())
		return B_ERROR;

	// add info about embedded default catalog:
	CatalogAddOnInfo* defaultCatalogAddOnInfo
		= new(std::nothrow) CatalogAddOnInfo("Default", "",
			DefaultCatalog::kDefaultCatalogAddOnPriority);
	if (!defaultCatalogAddOnInfo)
		return B_NO_MEMORY;

	defaultCatalogAddOnInfo->fInstantiateFunc = DefaultCatalog::Instantiate;
	defaultCatalogAddOnInfo->fCreateFunc = DefaultCatalog::Create;
	fCatalogAddOnInfos.AddItem((void*)defaultCatalogAddOnInfo);

	directory_which folders[] = {
		B_USER_ADDONS_DIRECTORY,
		B_COMMON_ADDONS_DIRECTORY,
		B_SYSTEM_ADDONS_DIRECTORY,
	};
	BPath addOnPath;
	BDirectory addOnFolder;
	char buf[4096];
	status_t err;
	for (uint32 f = 0; f < sizeof(folders) / sizeof(directory_which); ++f) {
		find_directory(folders[f], &addOnPath);
		BString addOnFolderName(addOnPath.Path());
		addOnFolderName << "/locale/catalogs";

		system_info info;
		if (get_system_info(&info) == B_OK
				&& (info.abi & B_HAIKU_ABI_MAJOR)
				!= (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR)) {
			switch (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR) {
				case B_HAIKU_ABI_GCC_2:
					addOnFolderName << "/gcc2";
					break;
				case B_HAIKU_ABI_GCC_4:
					addOnFolderName << "/gcc4";
					break;
			}
		}


		err = addOnFolder.SetTo(addOnFolderName.String());
		if (err != B_OK)
			continue;

		// scan through all the folder's entries for catalog add-ons:
		int32 count;
		int8 priority;
		entry_ref eref;
		BNode node;
		BEntry entry;
		dirent* dent;
		while ((count = addOnFolder.GetNextDirents((dirent*)buf, 4096)) > 0) {
			dent = (dirent*)buf;
			while (count-- > 0) {
				if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")
						&& strcmp(dent->d_name, "gcc2")
						&& strcmp(dent->d_name, "gcc4")) {
					// we have found (what should be) a catalog-add-on:
					eref.device = dent->d_pdev;
					eref.directory = dent->d_pino;
					eref.set_name(dent->d_name);
					entry.SetTo(&eref, true);
						// traverse through any links to get to the real thang!
					node.SetTo(&entry);
					priority = -1;
					if (node.ReadAttr(kPriorityAttr, B_INT8_TYPE, 0,
						&priority, sizeof(int8)) <= 0) {
						// add-on has no priority-attribute yet, so we load it
						// to fetch the priority from the corresponding
						// symbol...
						BString fullAddOnPath(addOnFolderName);
						fullAddOnPath << "/" << dent->d_name;
						image_id image = load_add_on(fullAddOnPath.String());
						if (image >= B_OK) {
							uint8* prioPtr;
							if (get_image_symbol(image, "gCatalogAddOnPriority",
								B_SYMBOL_TYPE_DATA,
								(void**)&prioPtr) == B_OK) {
								priority = *prioPtr;
								node.WriteAttr(kPriorityAttr, B_INT8_TYPE, 0,
									&priority, sizeof(int8));
							}
							unload_add_on(image);
						}
					}

					if (priority >= 0) {
						// add-ons with priority < 0 will be ignored
						CatalogAddOnInfo* addOnInfo
							= new(std::nothrow) CatalogAddOnInfo(dent->d_name,
								addOnFolderName, priority);
						if (addOnInfo)
							fCatalogAddOnInfos.AddItem((void*)addOnInfo);
					}
				}
				// Bump the dirent-pointer by length of the dirent just handled:
				dent = (dirent*)((char*)dent + dent->d_reclen);
			}
		}
	}
	fCatalogAddOnInfos.SortItems(CompareInfos);

	return B_OK;
}
예제 #30
0
파일: os.c 프로젝트: FLYKingdom/vlc
/**
 * Load a dynamically linked library using a system dependent method.
 *
 * \param p_this vlc object
 * \param psz_file library file
 * \param p_handle the module handle returned
 * \return 0 on success as well as the module handle.
 */
int module_Load( vlc_object_t *p_this, const char *psz_file,
                 module_handle_t *p_handle )
{
    module_handle_t handle;

#if defined(HAVE_DL_BEOS)
    handle = load_add_on( psz_file );
    if( handle < 0 )
    {
        msg_Warn( p_this, "cannot load module `%s'", psz_file );
        return -1;
    }

#elif defined(HAVE_DL_WINDOWS)
    wchar_t psz_wfile[MAX_PATH];
    MultiByteToWideChar( CP_UTF8, 0, psz_file, -1, psz_wfile, MAX_PATH );

#ifndef UNDER_CE
    /* FIXME: this is not thread-safe -- Courmisch */
    UINT mode = SetErrorMode (SEM_FAILCRITICALERRORS);
    SetErrorMode (mode|SEM_FAILCRITICALERRORS);
#endif

    handle = LoadLibraryW( psz_wfile );

#ifndef UNDER_CE
    SetErrorMode (mode);
#endif

    if( handle == NULL )
    {
        char *psz_err = GetWindowsError();
        msg_Warn( p_this, "cannot load module `%s' (%s)", psz_file, psz_err );
        free( psz_err );
        return -1;
    }

#elif defined(HAVE_DL_DLOPEN)

# if defined (RTLD_NOW)
    const int flags = RTLD_NOW;
# elif defined (DL_LAZY)
    const int flags = DL_LAZY;
# else
    const int flags = 0;
# endif
    char *path = ToLocale( psz_file );

    handle = dlopen( path, flags );
    if( handle == NULL )
    {
        msg_Warn( p_this, "cannot load module `%s' (%s)", path, dlerror() );
        LocaleFree( path );
        return -1;
    }
    LocaleFree( path );

#elif defined(HAVE_DL_SHL_LOAD)
    handle = shl_load( psz_file, BIND_IMMEDIATE | BIND_NONFATAL, NULL );
    if( handle == NULL )
    {
        msg_Warn( p_this, "cannot load module `%s' (%m)", psz_file );
        return -1;
    }

#else
#   error "Something is wrong in modules.c"

#endif

    *p_handle = handle;
    return 0;
}