//=========================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//=========================================================================

#include "smtk/plugin/InitializeDefaultPlugins.h"

#include "vtkPVPlugin.h"
#include "vtkPVPluginLoader.h"

#include "vtkPVPluginTracker.h"

#include <string>

@SMTK_PLUGIN_IMPORT_INIT@

namespace
{
bool queryPlugins(const char* name, bool load);

bool loadPlugins(const char* name)
{
  return queryPlugins(name, true);
}

bool searchPlugins(const char* name)
{
  return queryPlugins(name, false);
}
}

namespace smtk
{
namespace extension
{
namespace paraview
{
void initializeDefaultPlugins()
{
  vtkPVPluginLoader::RegisterLoadPluginCallback(loadPlugins);
  vtkPVPluginTracker::SetStaticPluginSearchFunction(searchPlugins);
}

void loadDefaultPlugins()
{
  @SMTK_PLUGIN_IMPORT@
}
}
}
}

namespace
{
bool queryPlugins(const char* name, bool load)
{
  std::string sname = name;

#define queryPlugin(plugin_name)                        \
  if (sname == #plugin_name)                            \
  {                                                     \
    if (load)                                           \
    {                                                   \
      static bool loaded = false;                       \
      if (!loaded)                                      \
      {                                                 \
        loaded = PV_PLUGIN_IMPORT(plugin_name);         \
      }                                                 \
    }                                                   \
    return true;                                        \
  }

@SMTK_PLUGIN_QUERY@

#undef queryPlugin

  return false;
}
}
