Exemplo n.º 1
0
command_stream_t
make_command_stream (int (*get_next_byte) (void *),
		     void *get_next_byte_argument)
{
  /* FIXME: Replace this with your implementation.  You may need to
     add auxiliary functions and otherwise modify the source code.
     You can also use external functions defined in the GNU C Library.  */
  // get_next_byte(get_next_byte_argument);

  command_t *res = checked_malloc(sizeof(command_t) * 128);
  memset(res, 0, 128);
  
  make_commands(get_next_byte_argument, get_next_byte, res);

  commandNode_t node = checked_malloc(sizeof(struct commandNode));
  node->next = NULL;
  commandNode_t cursor = node;

  int i = 0;
  while (res[i] != NULL)
  {
    commandNode_t tmp_node = checked_malloc(sizeof(struct commandNode));
    cursor->next = tmp_node;
    cursor = cursor->next;
    cursor->command = res[i];
    
    i++;
  }
  cursor->next = NULL;

  command_stream_t stream = checked_malloc(sizeof(struct command_stream));
  stream->head = node->next;
  stream->cursor = node->next;
  stream->tail = cursor;

  // error (1, 0, "command reading not yet implemented");
  return stream;
}
Exemplo n.º 2
0
void PluginLoader::loadPlugins(
        iscore::ApplicationRegistrar& registrar,
        const iscore::ApplicationContext& context)
{
    auto folders = pluginsDir();

    // Here, the plug-ins that are effectively loaded.
    std::vector<iscore::Plugin_QtInterface*> availablePlugins;

    // Load static plug-ins
    for(QObject* plugin : QPluginLoader::staticInstances())
    {
        if(auto iscore_plug = dynamic_cast<iscore::Plugin_QtInterface*>(plugin))
            availablePlugins.push_back(iscore_plug);
    }

    QSet<QString> pluginFiles;
#if !defined(ISCORE_STATIC_QT)
    // Load dynamic plug-ins
    for(const QString& pluginsFolder : folders)
    {
        QDir pluginsDir(pluginsFolder);
        for(const QString& fileName : pluginsDir.entryList(QDir::Files))
        {
            auto plug = loadPlugin(pluginsDir.absoluteFilePath(fileName), availablePlugins);

            if(!plug.first.isEmpty())
            {
                pluginFiles.insert(plug.first);
            }

            if(plug.second)
            {
                availablePlugins.push_back(plug.second);
            }
        }
    }
#endif

    // First bring in the plugin objects
    registrar.registerPlugins(
                pluginFiles.toList(),
                availablePlugins);


    // Here, it is important not to collapse all the for-loops
    // because for instance a ApplicationPlugin from plugin B might require the factory
    // from plugin A to be loaded prior.
    // Load all the factories.
    for(iscore::Plugin_QtInterface* plugin : availablePlugins)
    {
        auto facfam_interface = dynamic_cast<FactoryList_QtInterface*> (plugin);

        if(facfam_interface)
        {
            for(auto&& elt : facfam_interface->factoryFamilies())
            {
                registrar.registerFactory(std::move(elt));
            }
        }
    }

    // Load all the application context plugins.
    // We have to order them according to their dependencies
    PluginDependencyGraph graph;
    for(auto plugin : availablePlugins)
    {
        graph.addNode(dynamic_cast<QObject*>(plugin));
    }

    graph.visit([&] (QObject* plugin) {
        auto ctrl_plugin = dynamic_cast<GUIApplicationContextPlugin_QtInterface*> (plugin);
        if(ctrl_plugin)
        {
            auto plug = ctrl_plugin->make_applicationPlugin(context);
            registrar.registerApplicationContextPlugin(plug);
        }
    });

    // Load what the plug-ins have to offer.
    for(auto plugin : availablePlugins)
    {
        auto panel_plugin = dynamic_cast<PanelFactory_QtInterface*> (plugin);
        if(panel_plugin)
        {
            auto panels = panel_plugin->panels();
            for(auto panel : panels)
            {
                registrar.registerPanel(panel);
            }
        }

        auto commands_plugin = dynamic_cast<CommandFactory_QtInterface*> (plugin);
        if(commands_plugin)
        {
            registrar.registerCommands(commands_plugin->make_commands());
        }

        auto factories_plugin = dynamic_cast<FactoryInterface_QtInterface*> (plugin);
        if(factories_plugin)
        {
            for(auto& factory_family : registrar.components().factories)
            {
                for(auto&& new_factory : factories_plugin->factories(context, factory_family.first))
                {
                    factory_family.second->insert(std::move(new_factory));
                }
            }
        }
    }
}