Checkpointing the dynamic plugin code.

This is essentially the code from the dynamic-plugin branch except for
some pieces that I have split out into separate, earlier commits.

I'm going to updatre things in this branch going forward.
This commit is contained in:
Robin Sommer 2013-11-26 11:23:25 -08:00
parent 7412470d66
commit 555df1e7ea
43 changed files with 1306 additions and 110 deletions

View file

@ -10,9 +10,9 @@
using namespace plugin;
BifItem::BifItem(const std::string& arg_id, Type arg_type)
BifItem::BifItem(const char* arg_id, Type arg_type)
{
id = copy_string(arg_id.c_str());
id = copy_string(arg_id);
type = arg_type;
}
@ -47,6 +47,9 @@ Plugin::Plugin()
version = -9999;
api_version = -9999;
dynamic = false;
base_dir = 0;
sopath = 0;
extensions = 0;
Manager::RegisterPlugin(this);
}
@ -57,6 +60,14 @@ Plugin::~Plugin()
delete [] name;
delete [] description;
delete [] base_dir;
delete [] sopath;
delete [] extensions;
}
Plugin::Type Plugin::PluginType() const
{
return STANDARD;
}
const char* Plugin::Name() const
@ -66,6 +77,7 @@ const char* Plugin::Name() const
void Plugin::SetName(const char* arg_name)
{
delete [] name;
name = copy_string(arg_name);
}
@ -76,6 +88,7 @@ const char* Plugin::Description() const
void Plugin::SetDescription(const char* arg_description)
{
delete [] description;
description = copy_string(arg_description);
}
@ -99,6 +112,16 @@ bool Plugin::DynamicPlugin() const
return dynamic;
}
const char* Plugin::PluginDirectory() const
{
return base_dir;
}
const char* Plugin::PluginPath() const
{
return sopath;
}
void Plugin::SetAPIVersion(int arg_version)
{
api_version = arg_version;
@ -109,22 +132,26 @@ void Plugin::SetDynamicPlugin(bool arg_dynamic)
dynamic = arg_dynamic;
}
void Plugin::SetPluginLocation(const char* arg_dir, const char* arg_sopath)
{
delete [] base_dir;
delete [] sopath;
base_dir = copy_string(arg_dir);
sopath = copy_string(arg_sopath);
}
void Plugin::InitPreScript()
{
}
void Plugin::InitPostScript()
{
for ( bif_init_func_list::const_iterator f = bif_inits.begin(); f != bif_inits.end(); f++ )
{
bif_init_func_result items = (**f)();
}
for ( bif_init_func_result::const_iterator i = items.begin(); i != items.end(); i++ )
{
BifItem bi((*i).first, (BifItem::Type)(*i).second);
bif_items.push_back(bi);
}
}
void Plugin::InitBifs()
{
for ( bif_init_func_list::const_iterator f = bif_inits.begin(); f != bif_inits.end(); f++ )
(**f)(this);
}
Plugin::bif_item_list Plugin::BifItems() const
@ -143,6 +170,22 @@ Plugin::bif_item_list Plugin::CustomBifItems() const
return bif_item_list();
}
const char* Plugin::FileExtensions() const
{
return extensions ? extensions : "";
}
void Plugin::SetFileExtensions(const char* ext)
{
extensions = copy_string(ext);
}
bool Plugin::LoadFile(const char* file)
{
reporter->InternalError("Plugin::LoadFile not overriden for %s", file);
return false;
}
void Plugin::Done()
{
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
@ -170,11 +213,23 @@ void Plugin::AddComponent(Component* c)
components.sort(component_cmp);
}
void Plugin::AddBifInitFunction(bif_init_func c)
bool Plugin::LoadBroFile(const char* file)
{
add_input_file(file);
return true;
}
void Plugin::__AddBifInitFunction(bif_init_func c)
{
bif_inits.push_back(c);
}
void Plugin::AddBifItem(const char* name, BifItem::Type type)
{
BifItem bi(name, (BifItem::Type)type);
bif_items.push_back(bi);
}
void Plugin::Describe(ODesc* d) const
{
d->Add("Plugin: ");
@ -190,7 +245,7 @@ void Plugin::Describe(ODesc* d) const
{
if ( version > 0 )
{
d->Add(" (version ");
d->Add(" (dynamic, version ");
d->Add(version);
d->Add(")");
}
@ -201,6 +256,18 @@ void Plugin::Describe(ODesc* d) const
else
d->Add(" (built-in)");
switch ( PluginType() ) {
case STANDARD:
break;
case INTERPRETER:
d->Add( " (interpreter plugin)");
break;
default:
reporter->InternalError("unknown plugin type in Plugin::Describe");
}
d->Add("\n");
if ( d->IsShort() )
@ -252,4 +319,46 @@ void Plugin::Describe(ODesc* d) const
}
}
InterpreterPlugin::InterpreterPlugin(int arg_priority)
{
priority = arg_priority;
}
InterpreterPlugin::~InterpreterPlugin()
{
}
int InterpreterPlugin::Priority() const
{
return priority;
}
Plugin::Type InterpreterPlugin::PluginType() const
{
return INTERPRETER;
}
Val* InterpreterPlugin::CallFunction(const Func* func, val_list* args)
{
return 0;
}
bool InterpreterPlugin::QueueEvent(Event* event)
{
return false;
}
void InterpreterPlugin::UpdateNetworkTime(double network_time)
{
}
void InterpreterPlugin::DrainEvents()
{
}
void InterpreterPlugin::DisableInterpreterPlugin() const
{
plugin_mgr->DisableInterpreterPlugin(this);
}