diff options
Diffstat (limited to 'source/Core/PluginManager.cpp')
| -rw-r--r-- | source/Core/PluginManager.cpp | 105 | 
1 files changed, 105 insertions, 0 deletions
diff --git a/source/Core/PluginManager.cpp b/source/Core/PluginManager.cpp index 7a2d3772e6c3..813cec227525 100644 --- a/source/Core/PluginManager.cpp +++ b/source/Core/PluginManager.cpp @@ -854,6 +854,111 @@ PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString      return NULL;  } +#pragma mark SystemRuntime + + +struct SystemRuntimeInstance +{ +    SystemRuntimeInstance() : +        name(), +        description(), +        create_callback(NULL) +    { +    } + +    ConstString name; +    std::string description; +    SystemRuntimeCreateInstance create_callback; +}; + +typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances; + +static Mutex & +GetSystemRuntimeMutex () +{ +    static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); +    return g_instances_mutex; +} + +static SystemRuntimeInstances & +GetSystemRuntimeInstances () +{ +    static SystemRuntimeInstances g_instances; +    return g_instances; +} + +bool +PluginManager::RegisterPlugin +( +    const ConstString &name, +    const char *description, +    SystemRuntimeCreateInstance create_callback +) +{ +    if (create_callback) +    { +        SystemRuntimeInstance instance; +        assert ((bool)name); +        instance.name = name; +        if (description && description[0]) +            instance.description = description; +        instance.create_callback = create_callback; +        Mutex::Locker locker (GetSystemRuntimeMutex ()); +        GetSystemRuntimeInstances ().push_back (instance); +    } +    return false; +} + +bool +PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback) +{ +    if (create_callback) +    { +        Mutex::Locker locker (GetSystemRuntimeMutex ()); +        SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); +         +        SystemRuntimeInstances::iterator pos, end = instances.end(); +        for (pos = instances.begin(); pos != end; ++ pos) +        { +            if (pos->create_callback == create_callback) +            { +                instances.erase(pos); +                return true; +            } +        } +    } +    return false; +} + +SystemRuntimeCreateInstance +PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx) +{ +    Mutex::Locker locker (GetSystemRuntimeMutex ()); +    SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); +    if (idx < instances.size()) +        return instances[idx].create_callback; +    return NULL; +} + +SystemRuntimeCreateInstance +PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &name) +{ +    if (name) +    { +        Mutex::Locker locker (GetSystemRuntimeMutex ()); +        SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); +         +        SystemRuntimeInstances::iterator pos, end = instances.end(); +        for (pos = instances.begin(); pos != end; ++ pos) +        { +            if (name == pos->name) +                return pos->create_callback; +        } +    } +    return NULL; +} + +  #pragma mark ObjectFile  struct ObjectFileInstance  | 
