metamod/mlist.cpp
changeset 248 f72386298cba
parent 247 2b1bf332bf41
     1.1 --- a/metamod/mlist.cpp	Fri Feb 18 20:52:34 2005 +0000
     1.2 +++ b/metamod/mlist.cpp	Tue Aug 23 20:31:28 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,64 @@
    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 +
    1.89 +	return pl_added;
    1.90 +}
    1.91  
    1.92  // Add a plugin to the list.
    1.93  // meta_errno values:
    1.94 @@ -259,7 +336,9 @@
    1.95  	// copy source
    1.96  	iplug->source=padd->source;
    1.97  	// copy status
    1.98 -	iplug->status=padd->status;
    1.99 +	iplug->status=padd->status;	
   1.100 +	//copy other things
   1.101 +	iplug->source_plugin_index = padd->source_plugin_index;
   1.102  
   1.103  	return(iplug);
   1.104  }
   1.105 @@ -519,12 +598,12 @@
   1.106  			META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->desc);
   1.107  		else
   1.108  			META_CONS("Couldn't load plugin '%s'; see log", pl_added->desc);
   1.109 -		show();
   1.110 +		show(0);
   1.111  		// meta_errno should be already set in load()
   1.112  		return(mFALSE);
   1.113  	}
   1.114  	META_CONS("Loaded plugin '%s' successfully", pl_added->desc);
   1.115 -	show();
   1.116 +	show(0);
   1.117  	return(mTRUE);
   1.118  }
   1.119  
   1.120 @@ -597,7 +676,7 @@
   1.121  				if(iplug->source==PS_INI && iplug->status >= PL_RUNNING) {
   1.122  					META_DEBUG(1, ("Unloading plugin '%s'", iplug->desc));
   1.123  					iplug->action=PA_UNLOAD;
   1.124 -					if(iplug->unload(now, PNL_INI_DELETED))
   1.125 +					if(iplug->unload(now, PNL_INI_DELETED, PNL_INI_DELETED))
   1.126  						nunloaded++;
   1.127  					else if(meta_errno==ME_DELAYED)
   1.128  						ndelayed++;
   1.129 @@ -663,12 +742,16 @@
   1.130  // List plugins and information about them in a formatted table.
   1.131  // meta_errno values:
   1.132  //  - none
   1.133 -void MPluginList::show() {
   1.134 +void MPluginList::show(int source_index) {
   1.135  	int i, n=0, r=0;
   1.136  	MPlugin *pl;
   1.137  	char desc[15+1], file[16+1], vers[7+1];		// plus 1 for term null
   1.138  
   1.139 -	META_CONS("Currently loaded plugins:");
   1.140 +	if (source_index <= 0)
   1.141 +		META_CONS("Currently loaded plugins:");
   1.142 +	else
   1.143 +		META_CONS("Child plugins:");
   1.144 +
   1.145  	META_CONS("  %*s  %-*s  %-4s %-4s  %-*s  v%-*s  %-3s  %-5s %-5s",
   1.146  			WIDTH_MAX_PLUGINS, "",
   1.147  			sizeof(desc)-1, "description",
   1.148 @@ -679,6 +762,8 @@
   1.149  		pl=&plist[i];
   1.150  		if(pl->status < PL_VALID)
   1.151  			continue;
   1.152 +		if ((source_index > 0) && (pl->source_plugin_index != source_index))
   1.153 +			continue;
   1.154  		STRNCPY(desc, pl->desc, sizeof(desc));
   1.155  		STRNCPY(file, pl->file, sizeof(file));
   1.156  		if(pl->info && pl->info->version) STRNCPY(vers, pl->info->version, sizeof(vers));
   1.157 @@ -723,3 +808,37 @@
   1.158  	}
   1.159  	META_CLIENT(pEntity, "%d plugins", n);
   1.160  }
   1.161 +
   1.162 +mBOOL MPluginList::found_child_plugins(int source_index)
   1.163 +{
   1.164 +	int i;
   1.165 +
   1.166 +	if (source_index <= 0)
   1.167 +		return mFALSE;
   1.168 +
   1.169 +	for (i=0; i<endlist; i++)
   1.170 +	{
   1.171 +		if (plist[i].status < PL_VALID)
   1.172 +			continue;
   1.173 +		if (plist[i].source_plugin_index == source_index)
   1.174 +			return mTRUE;
   1.175 +	}
   1.176 +
   1.177 +	return mFALSE;
   1.178 +}
   1.179 +
   1.180 +void MPluginList::clear_source_plugin_index(int source_index)
   1.181 +{
   1.182 +	int i;
   1.183 +
   1.184 +	if (source_index <= 0)
   1.185 +		return;
   1.186 +
   1.187 +	for (i=0; i<endlist; i++)
   1.188 +	{
   1.189 +		if (plist[i].status < PL_VALID)
   1.190 +			continue;
   1.191 +		if (plist[i].source_plugin_index == source_index)
   1.192 +			plist[i].source_plugin_index = -1;
   1.193 +	}
   1.194 +}