1 #include <string> 2 3 #include <scx/FileInfo.h> 4 using namespace scx; 5 6 #include "ctx.h" 7 8 static const char* const PLUGIN_ROOT = "/lib/mous/"; 9 10 Context ctx; 11 Context()12Context::Context() 13 { 14 // check plugin path then load it 15 FileInfo dir_info(std::string(CMAKE_INSTALL_PREFIX) + PLUGIN_ROOT); 16 const std::string pluginDir(dir_info.AbsFilePath()); 17 if (!dir_info.Exists() 18 || dir_info.Type() != FileType::Directory 19 || pluginDir.empty()) { 20 printf("bad plugin directory!\n"); 21 exit(EXIT_FAILURE); 22 } 23 pluginManager.LoadPluginDir(pluginDir); 24 25 // get plugin agents and check if we have enough 26 decoderPlugins = pluginManager.PluginAgents(PluginType::Decoder); 27 encoderPlugins = pluginManager.PluginAgents(PluginType::Encoder); 28 outputPlugins = pluginManager.PluginAgents(PluginType::Renderer); 29 sheetParserPlugins = pluginManager.PluginAgents(PluginType::SheetParser); 30 tagParserPlugins = pluginManager.PluginAgents(PluginType::TagParser); 31 if (decoderPlugins.empty() || outputPlugins.empty()) { 32 printf("need more plugins!\n"); 33 exit(EXIT_FAILURE); 34 } 35 36 // setup media loader 37 loader.RegisterSheetParserPlugin(sheetParserPlugins); 38 loader.RegisterTagParserPlugin(tagParserPlugins); 39 // setup parser factory 40 tagParserFactory.RegisterTagParserPlugin(tagParserPlugins); 41 // setup conv factory 42 convertTaskFactory.RegisterDecoderPlugin(decoderPlugins); 43 convertTaskFactory.RegisterEncoderPlugin(encoderPlugins); 44 } 45 ~Context()46Context::~Context() 47 { 48 convertTaskFactory.UnregisterAll(); 49 tagParserFactory.UnregisterAll(); 50 loader.UnregisterAll(); 51 pluginManager.UnloadAll(); 52 } 53 54