{"id":852,"date":"2016-04-12T14:14:08","date_gmt":"2016-04-12T12:14:08","guid":{"rendered":"https:\/\/iww.inria.fr\/sed-sophia\/?p=852"},"modified":"2018-01-15T09:09:00","modified_gmt":"2018-01-15T08:09:00","slug":"dtk-plugins-tricks","status":"publish","type":"post","link":"https:\/\/iww.inria.fr\/sed-sophia\/dtk-plugins-tricks\/","title":{"rendered":"dtk plugins tricks"},"content":{"rendered":"<p>In this post, we are going to explore two tricks around plugins: <em>auto-loading<\/em> and <em>application private plugins<\/em>.<br \/>\n<!--more--><\/p>\n<h4>auto-loading<\/h4>\n<p>dtk plugins path is usually set in a <em>.config\/inria\/dtk-LAYER-NAME.ini<\/em> file (in linux) in order to be loaded at runtime. Let&#8217;s take the layer <strong>dtk-discrete-geometry<\/strong> for demonstration. For this layer, my <em>dtk-discrete-geometry.ini<\/em> file is:<\/p>\n<pre style=\"color: #bebebe;background-color: #262626\">[discrete-geometry]\r\nplugins=\/home\/tcabel\/Devel\/dtk-plugins-discrete-geometry\/build\/lib64\r\n<\/pre>\n<p>the default action when you initialize a layer is to scan all files in the plugins directory define in this <em>.ini<\/em> file and load them if they are plugins of the layer being initialized.<br \/>\nHowever, you may have some plugins that cannot work together (for example two plugins compiled with different versions of VTK). In this situation, you can choose to only load the plugins you need. Here is how you do these two options:<\/p>\n<ul>\n<li><strong> default way: <\/strong>\n<pre style=\"color: #bebebe;background-color: #262626\"><span style=\"color: #add8e6\">\/\/ <\/span><span style=\"color: #add8e6\">dtk-discrete-geometry\r\n <\/span><span style=\"color: #98fb98\">dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">pluginManager<\/span>::initialize();\r\n\r\n mesh_view = <span style=\"color: #98fb98\">dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">meshView<\/span>::pluginFactory().create(<span style=\"color: #87cefa\">\"dtkMeshViewVTKCatalyst\"<\/span>);<\/pre>\n<\/li>\n<li><strong> no auto-load<\/strong>\n<pre style=\"color: #bebebe;background-color: #262626\"> <span style=\"color: #add8e6\">\/\/<\/span><span style=\"color: #add8e6\">dtk-discrete-geometry\r\n <\/span><span style=\"color: #98fb98\">dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">pluginManager<\/span>::setAutoLoading(<span style=\"color: #98fb98\">false<\/span>);\r\n <span style=\"color: #98fb98\">dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">pluginManager<\/span>::initialize();\r\n\r\n <span style=\"color: #98fb98\">dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">meshView<\/span>::pluginManager().loadFromName(<span style=\"color: #87cefa\">\"dtkMeshViewVTKCatalyst\"<\/span>);\r\n mesh_view = <span style=\"color: #98fb98\">dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">meshView<\/span>::pluginFactory().create(<span style=\"color: #87cefa\">\"dtkMeshViewVTKCatalyst\"<\/span>);<\/pre>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4>private plugins<\/h4>\n<p>Another usefull functionality that you may need is to use plugins specific for your application: <strong>private plugins<\/strong>. In order to use this kind of plugins do the three following steps.<\/p>\n<ol>\n<li>First add a new file <strong>dtkTracesPluginsConfig.in<\/strong> in your application plugins source directory as this:\n<pre style=\"color: #bebebe;background-color: #262626\"><span style=\"color: #7fffd4\">#pragma<\/span> once\r\n<span style=\"color: #7fffd4\">#define<\/span> <span style=\"color: #40e0d0;font-weight: bold\">DTKTRACES_PLUGINS_PATH<\/span> <span style=\"color: #87cefa\">\"@CMAKE_BINARY_DIR@\/lib\"<\/span>\r\n<\/pre>\n<p>As you guessed &#8220;@CMAKE_BINARY_DIR@\/lib&#8221; is the directory where the plugins will be compiled.\n<\/li>\n<li>Then, edit your <strong>CMakeLists.txt<\/strong> to include this config file\n<pre style=\"color: #bebebe;background-color: #262626\"><span style=\"color: #7fffd4;font-weight: bold\">configure_file<\/span>(plugins\/dtkTracesPluginsConfig.in dtkTracesPluginsConfig.h)<\/pre>\n<\/li>\n<li>To finish, when you initialize your plugins, use this pre-processing variable:\n<pre style=\"color: #bebebe;background-color: #262626\"><span style=\"color: #7fffd4\">#include<\/span> <span style=\"color: #87cefa\">\"dtkTracesPluginsConfig.h\"<\/span>\r\n[...]\r\n\r\n<span style=\"color: #98fb98\"> dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">pluginManager<\/span>::initialize();\r\n<span style=\"color: #98fb98\"> dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">mesher<\/span>::pluginManager().initialize(DTKTRACES_PLUGINS_PATH);\r\n<span style=\"color: #98fb98\"> dtkDiscreteGeometry<\/span>::<span style=\"color: #98fb98\">meshPartitionner<\/span>::pluginManager().initialize(DTKTRACES_PLUGINS_PATH);\r\n<\/pre>\n<\/li>\n<\/ol>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>In this post, we are going to explore two tricks around plugins: auto-loading and application private plugins.<\/p>\n<p> <a class=\"continue-reading-link\" href=\"https:\/\/iww.inria.fr\/sed-sophia\/dtk-plugins-tricks\/\"><span>Continue reading<\/span><i class=\"crycon-right-dir\"><\/i><\/a> <\/p>\n","protected":false},"author":2085,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[29,30],"tags":[59,43,45],"class_list":["post-852","post","type-post","status-publish","format-standard","hentry","category-development-in-the-inria-teams","category-shared-development","tag-c","tag-dtk","tag-trick"],"_links":{"self":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/users\/2085"}],"replies":[{"embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/comments?post=852"}],"version-history":[{"count":29,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/852\/revisions"}],"predecessor-version":[{"id":899,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/posts\/852\/revisions\/899"}],"wp:attachment":[{"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/media?parent=852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/categories?post=852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iww.inria.fr\/sed-sophia\/wp-json\/wp\/v2\/tags?post=852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}