metamod/mlist.cpp
branchB-work
changeset 130 4bfb3f26c519
parent 128 a6c7b16a6b92
child 133 fbe73f167e7d
     1.1 --- a/metamod/mlist.cpp	Tue Mar 08 10:09:50 2005 +0000
     1.2 +++ b/metamod/mlist.cpp	Tue Jul 12 22:18:15 2005 +0000
     1.3 @@ -62,6 +62,25 @@
     1.4  	endlist=0;
     1.5  }
     1.6  
     1.7 +// Find a plugin based on the plugin handle.
     1.8 +// meta_errno values:
     1.9 +//  - ME_ARGUMENT	invalid pindex
    1.10 +//  - ME_NOTFOUND	couldn't find a matching plugin
    1.11 +MPlugin *MPluginList::find(DLHANDLE handle)
    1.12 +{
    1.13 +	int i;
    1.14 +
    1.15 +	if(!handle)
    1.16 +		RETURN_ERRNO(NULL, ME_ARGUMENT);
    1.17 +	for(i=0; i < endlist; i++) {
    1.18 +		if(plist[i].status < PL_VALID)
    1.19 +			continue;
    1.20 +		if(plist[i].handle == handle)
    1.21 +			return(&plist[i]);
    1.22 +	}
    1.23 +	RETURN_ERRNO(NULL, ME_NOTFOUND);
    1.24 +}
    1.25 +
    1.26  // Find a plugin based on the plugin index #.
    1.27  // meta_errno values:
    1.28  //  - ME_ARGUMENT	invalid pindex
    1.29 @@ -221,6 +240,63 @@
    1.30  		RETURN_ERRNO(NULL, ME_NOTFOUND);
    1.31  }
    1.32  
    1.33 +MPlugin * MPluginList::plugin_addload(plid_t plid, const char *fname, PLUG_LOADTIME now)
    1.34 +{
    1.35 +	MPlugin pl_temp;
    1.36 +	MPlugin *pl_found, *pl_added, *pl_loader;
    1.37 +
    1.38 +	if ( !(pl_loader=find(plid)) )
    1.39 +	{
    1.40 +		META_DEBUG(1, ("Couldn't find plugin that gave this loading request!"));
    1.41 +		RETURN_ERRNO(NULL, ME_BADREQ);
    1.42 +	}
    1.43 +
    1.44 +	memset(&pl_temp, 0, sizeof(pl_temp));
    1.45 +
    1.46 +	if (!pl_temp.plugin_parseline(fname, pl_loader->index))
    1.47 +	{
    1.48 +		RETURN_ERRNO(NULL, ME_NOTFOUND);
    1.49 +	}
    1.50 +
    1.51 +	if (pl_temp.resolve() != mTRUE)
    1.52 +	{
    1.53 +		META_DEBUG(1, ("Couldn't resolve given path into a file: %s", pl_temp.file));
    1.54 +		RETURN_ERRNO(NULL, ME_NOTFOUND);
    1.55 +	}
    1.56 +
    1.57 +	if ( (pl_found=find(pl_temp.pathname)) )
    1.58 +	{
    1.59 +		META_DEBUG(1, ("Plugin '%s' already in current list; file=%s desc='%s'", 
    1.60 +				pl_temp.file, pl_found->file, pl_found->desc));
    1.61 +		RETURN_ERRNO(NULL, ME_ALREADY);
    1.62 +	}
    1.63 +
    1.64 +	if (!(pl_added=add(&pl_temp)))
    1.65 +	{
    1.66 +		META_DEBUG(1, ("Couldn't add plugin '%s' to list; see log", pl_temp.desc));
    1.67 +		return NULL;
    1.68 +	}
    1.69 +
    1.70 +	pl_added->action = PA_LOAD;
    1.71 +	if (!pl_added->load(now))
    1.72 +	{
    1.73 +		if (meta_errno==ME_NOTALLOWED || meta_errno==ME_DELAYED)
    1.74 +		{
    1.75 +			META_DEBUG(1, ("Plugin '%s' couldn't attach; only allowed %s", 
    1.76 +					pl_added->desc, pl_added->str_loadable(SL_ALLOWED)));
    1.77 +			pl_added->clear();
    1.78 +		} else if (pl_added->status == PL_OPENED) {
    1.79 +			META_DEBUG(1, ("Opened plugin '%s', but failed to attach; see log", pl_added->desc));
    1.80 +		} else {
    1.81 +			META_DEBUG(1, ("Couldn't load plugin '%s'; see log", pl_added->desc));
    1.82 +		}
    1.83 +		return NULL;
    1.84 +	}
    1.85 +
    1.86 +	META_DEBUG(1, ("Loaded plugin '%s' successfully", pl_added->desc));
    1.87 +	meta_errno = ME_NOERROR;
    1.88 +	return pl_added;
    1.89 +}
    1.90  
    1.91  // Add a plugin to the list.
    1.92  // meta_errno values:
    1.93 @@ -597,7 +673,7 @@
    1.94  				if(iplug->source==PS_INI && iplug->status >= PL_RUNNING) {
    1.95  					META_DEBUG(1, ("Unloading plugin '%s'", iplug->desc));
    1.96  					iplug->action=PA_UNLOAD;
    1.97 -					if(iplug->unload(now, PNL_INI_DELETED))
    1.98 +					if(iplug->unload(now, PNL_INI_DELETED, PNL_INI_DELETED))
    1.99  						nunloaded++;
   1.100  					else if(meta_errno==ME_DELAYED)
   1.101  						ndelayed++;