bool CMetaplugPropsDlg::EmbedCheck(CString& NonFreePlugs)
{
	CFFEngine&	eng = theApp.GetEngine();
	// stop engine before accessing FreeFrame instance directly via GetFFPlugin
	STOP_ENGINE(eng);
	int	plugs = eng.GetPluginCount();
	for (int PlugIdx = 0; PlugIdx < plugs; PlugIdx++) {
		CFFPluginEx&	pr = eng.GetPlugin(PlugIdx);
		bool	CanEmbed = FALSE;	// assume failure
		PlugExtendedInfoStruct	peis;
		if (pr.GetFFPlugin().GetExtendedInfo(peis)) {
			CString	About(peis.About);
			if (About.Find(_T("Pete Warden")) >= 0)	// case-sensitive
				CanEmbed = TRUE;
			else {
				About.MakeLower();
				if (About.Find(_T("copyleft")) >= 0)	// NOT case-sensitive
					CanEmbed = TRUE;
			}
		}
		if (!CanEmbed) {
			CString	PluginPath(pr.GetPath());
			LPCTSTR	DllName = PathFindFileName(PluginPath);
			if (NonFreePlugs.Find(DllName) < 0)	// eliminate duplicates
				NonFreePlugs += CString("\n") + DllName;
		}
	}
	return(NonFreePlugs.IsEmpty() != 0);
}
Example #2
0
Pothos::BlockRegistry::BlockRegistry(const std::string &path, const Callable &factory)
{
    //check the path
    if (path.empty() or path.front() != '/')
    {
        poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Invalid path: %s", path);
        return;
    }

    //parse the path
    PluginPath fullPath;
    try
    {
        fullPath = PluginPath("/blocks").join(path.substr(1));
    }
    catch (const PluginPathError &)
    {
        poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Invalid path: %s", path);
        return;
    }

    //check the factory
    if (factory.type(-1) == typeid(Block*) or factory.type(-1) == typeid(Topology*))
    {
        //register
        PluginRegistry::add(fullPath, factory);
    }

    //otherwise report the error
    else
    {
        poco_error_f1(Poco::Logger::get("Pothos.BlockRegistry"), "Bad Factory, must return Block* or Topology*: %s", factory.toString());
    }
}
void MathPluginManagement::EnumeratePlugins()
{
    dirent* de;
    DIR* dp;

    MathPluginFiles.clear();
    MathPluginDisplayNames.clear();

    errno = 0;
    dp = opendir( INDI_MATH_PLUGINS_DIRECTORY );
    if (dp)
    {
        while (true)
        {
            void *Handle;
            std::string PluginPath(INDI_MATH_PLUGINS_DIRECTORY "/");

            errno = 0;
            de = readdir( dp );
            if (de == NULL)
                break;
            if (0 == strcmp(de->d_name, "."))
                continue;
            if (0 == strcmp(de->d_name, ".."))
                continue;

            // Try to load the plugin
            PluginPath.append(de->d_name);
            Handle = dlopen(PluginPath.c_str(), RTLD_NOW);
            if (NULL == Handle)
            {
                IDLog("EnumeratePlugins - cannot load plugin %s error %s\n", PluginPath.c_str(), dlerror());
                continue;
            }

            // Try to get the plugin display name
            typedef const char* GetDisplayName_t();
            GetDisplayName_t* GetDisplayNamePtr = (GetDisplayName_t*)dlsym(Handle, "GetDisplayName");
            if (NULL == GetDisplayNamePtr)
            {
                IDLog("EnumeratePlugins - cannot get plugin %s DisplayName error %s\n", PluginPath.c_str(), dlerror());
                continue;
            }
            IDLog("EnumeratePlugins - found plugin %s\n", GetDisplayNamePtr());

            MathPluginDisplayNames.push_back(GetDisplayNamePtr());
            MathPluginFiles.push_back( PluginPath );
            dlclose(Handle);
        }
        closedir( dp );
    }
    else
    {
        IDLog("EnumeratePlugins - Failed to open %s error %s\n", INDI_MATH_PLUGINS_DIRECTORY, strerror(errno) );
    }
}
Example #4
0
void Pothos::ManagedClass::unload(const std::string &classPath)
{
    //extract the managed class from the plugin tree
    auto plugin = PluginRegistry::get(PluginPath("/managed").join(classPath));
    auto &managedCls = plugin.getObject().extract<ManagedClass>();

    //unload conversion constructors
    for (const auto &constructor : managedCls.getConstructors())
    {
        if (constructor.getNumArgs() != 1) continue;
        Pothos::PluginRegistry::remove(
            Poco::format("/object/convert/constructors/%s_to_%s",
            typeToPluginPath(constructor.type(0)),
            typeToPluginPath(constructor.type(-1)))
        );
    }

    //then unload the managed class
    Pothos::PluginRegistry::remove(PluginPath("/managed").join(classPath));
}
Example #5
0
void PluginManager::setPluginPaths(const QStringList &paths)
{
    foreach (const QString &path, paths) {
        const QDir dir(path);
        if (!dir.exists())
            continue;
        m_paths.push_back(PluginPath(dir));
    }

    // also register path in widgetpluginmanager
    MetaInfo::setPluginPaths(paths);
}
Example #6
0
Pothos::ManagedClass &Pothos::ManagedClass::commit(const std::string &classPath)
{
    //register conversions for constructors that take one argument
    for (const auto &constructor : this->getConstructors())
    {
        if (constructor.getNumArgs() != 1) continue;
        Pothos::PluginRegistry::add(
            Poco::format("/object/convert/constructors/%s_to_%s",
            typeToPluginPath(constructor.type(0)),
            typeToPluginPath(constructor.type(-1))),
            constructor
        );
    }

    PluginRegistry::add(
        PluginPath("/managed").join(classPath),
        dynamic_cast<ManagedClass &>(*this));
    return *this;
}
Example #7
0
Pothos::PluginPath Pothos::PluginPath::join(const std::string &subPath) const
{
    const std::string joiner = (_path == "/")? "": "/"; //dont join with only root /
    return PluginPath(this->toString() + joiner + subPath);
}
void MathPluginManagement::ProcessSwitchProperties(Telescope* pTelescope, const char *name, ISState *states, char *names[], int n)
{
    DEBUGFDEVICE(pTelescope->getDeviceName(), INDI::Logger::DBG_DEBUG, "ProcessSwitchProperties - name(%s)", name);
    if (strcmp(name, AlignmentSubsystemMathPluginsV.name) == 0)
    {
        int CurrentPlugin = IUFindOnSwitchIndex(&AlignmentSubsystemMathPluginsV);
        IUUpdateSwitch(&AlignmentSubsystemMathPluginsV, states, names, n);
        AlignmentSubsystemMathPluginsV.s = IPS_OK; // Assume OK for the time being
        int NewPlugin  = IUFindOnSwitchIndex(&AlignmentSubsystemMathPluginsV);
        if (NewPlugin != CurrentPlugin)
        {
            // New plugin requested
            // Unload old plugin if required
            if (0 != CurrentPlugin)
            {
                typedef void Destroy_t(MathPlugin *);
                Destroy_t* Destroy = (Destroy_t*)dlsym(LoadedMathPluginHandle, "Destroy");
                if (NULL != Destroy)
                {
                    Destroy(pLoadedMathPlugin);
                    pLoadedMathPlugin = NULL;
                    if (0 == dlclose(LoadedMathPluginHandle))
                    {
                        LoadedMathPluginHandle = NULL;

                    }
                    else
                    {
                        IDLog("MathPluginManagement - dlclose failed on loaded plugin - %s\n", dlerror());
                        AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                    }
                }
                else
                {
                    IDLog("MathPluginManagement - cannot get Destroy function - %s\n", dlerror());
                    AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                }
            }
            // Load the requested plugin if required
            if (0 != NewPlugin)
            {
                std::string PluginPath(MathPluginFiles[NewPlugin - 1]);
                if (NULL != (LoadedMathPluginHandle = dlopen(PluginPath.c_str(), RTLD_NOW)))
                {
                    typedef MathPlugin* Create_t();
                    Create_t* Create = (Create_t*)dlsym(LoadedMathPluginHandle, "Create");
                    if (NULL != Create)
                    {
                        pLoadedMathPlugin = Create();
                        IUSaveText(&AlignmentSubsystemCurrentMathPlugin, PluginPath.c_str());
                    }
                    else
                    {
                        IDLog("MathPluginManagement - cannot get Create function - %s\n", dlerror());
                        AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                    }
                }
                else
                {
                    IDLog("MathPluginManagement - cannot load plugin %s error %s\n", PluginPath.c_str(), dlerror());
                    AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                }
            }
            else
            {
                // It is in built plugin just set up the pointers
                pLoadedMathPlugin = &BuiltInPlugin;
            }
        }

        //  Update client
        IDSetSwitch(&AlignmentSubsystemMathPluginsV, NULL);
    }
    else if (strcmp(name, AlignmentSubsystemMathPluginInitialiseV.name) == 0)
    {
        AlignmentSubsystemMathPluginInitialiseV.s = IPS_OK;
        IUResetSwitch(&AlignmentSubsystemMathPluginInitialiseV);
        //  Update client display
        IDSetSwitch(&AlignmentSubsystemMathPluginInitialiseV, NULL);

        // Initialise or reinitialise the current math plugin
        Initialise(CurrentInMemoryDatabase);
    }
    else if (strcmp(name, AlignmentSubsystemActiveV.name) == 0)
    {
        AlignmentSubsystemActiveV.s=IPS_OK;
        if (0 == IUUpdateSwitch(&AlignmentSubsystemActiveV, states, names, n))
            //  Update client
            IDSetSwitch(&AlignmentSubsystemActiveV, NULL);
    }
}
Example #9
0
bool StateGraphViewerPanel::Create(wxWindow *Parent,
                                   ContextNotifier &WithNotifier,
                                   ActionRecord &WithRecording,
                                   ActionReplayFrame &WithReplay,
                                   wxWindowID ID,
                                   wxPoint const &Position,
                                   wxSize const &Size)
{
  if (!wxPanel::Create(Parent, ID, Position, Size))
    return false;
  
  Notifier = &WithNotifier;
  Recording = &WithRecording;
  
  // Enable vfs access to request information about the state.
  auto const ThisAddr = reinterpret_cast<uintptr_t>(this);
  auto const CallbackProto = std::string{"seec"} + std::to_string(ThisAddr);
  
  CallbackFS = new seec::CallbackFSHandler(CallbackProto);
  
  CallbackFS->addCallback("notify_hover",
    std::function<void (std::string const &)>{
      [this] (std::string const &NodeID) -> void {
        this->OnMouseOver(NodeID);
      }
    });
  
  CallbackFS->addCallback("notify_contextmenu",
    std::function<void (std::string const &)>{
      [this] (std::string const &Foo) -> void {
        this->RaiseContextMenu();
      }
    });
  
  CallbackFS->addCallback("log_debug",
    std::function<void (std::string const &)>{
      [] (std::string const &Message) -> void {
        wxLogDebug("%s", wxString{Message});
      }
    });

  Bind(wxEVT_CONTEXT_MENU,
       &StateGraphViewerPanel::OnContextMenu, this);
  Bind(SEEC_EV_MOUSE_OVER_DISPLAYABLE,
       &StateGraphViewerPanel::OnMouseOverDisplayable, this);

  wxFileSystem::AddHandler(CallbackFS);
  
  // Get our resources from ICU.
  UErrorCode Status = U_ZERO_ERROR;
  auto Resources = seec::getResource("TraceViewer",
                                     getLocale(),
                                     Status,
                                     "StateGraphViewer");
  
  if (!U_SUCCESS(Status))
    return false;
  
  auto Sizer = new wxBoxSizer(wxVERTICAL);
  
  // Setup the webview.
  WebView = wxWebView::New(this, wxID_ANY);
  if (!WebView) {
    wxLogDebug("wxWebView::New failed.");
    return false;
  }
  
  WebView->RegisterHandler(wxSharedPtr<wxWebViewHandler>
                                      (new wxWebViewFSHandler("icurb")));
  WebView->RegisterHandler(wxSharedPtr<wxWebViewHandler>
                                      (new wxWebViewFSHandler(CallbackProto)));
  
  Sizer->Add(WebView, wxSizerFlags(1).Expand());
  SetSizerAndFit(Sizer);
  
  // Find the dot executable.
  PathToDot = getPathForDotExecutable();
  
  if (!PathToDot.empty())
  {
    // Determine the path to Graphviz's libraries, based on the location of dot.
    llvm::SmallString<256> PluginPath (PathToDot);
    
    llvm::sys::path::remove_filename(PluginPath);    // */bin/dot -> */bin
    llvm::sys::path::remove_filename(PluginPath);    // */bin    -> *
    llvm::sys::path::append(PluginPath, "lib");      // *      -> */lib
    
    PathToGraphvizLibraries = "DYLD_LIBRARY_PATH=";
    PathToGraphvizLibraries += PluginPath.str();
    
    llvm::sys::path::append(PluginPath, "graphviz"); // */lib -> */lib/graphviz
    
    PathToGraphvizPlugins = "GVBINDIR=";
    PathToGraphvizPlugins += PluginPath.str();
    
    // Setup the layout handler.
    {
      std::lock_guard<std::mutex> LockLayoutHandler (LayoutHandlerMutex);
      LayoutHandler.reset(new seec::cm::graph::LayoutHandler());
      LayoutHandler->addBuiltinLayoutEngines();
    }

    // After the webpage is loaded, setup the initial ColourScheme.
    WebView->Bind(wxEVT_WEBVIEW_LOADED,
      std::function<void (wxWebViewEvent &)>{
        [this] (wxWebViewEvent &Event) -> void {
          setupColourScheme(
            *wxGetApp().getColourSchemeSettings().getColourScheme());
          Event.Skip();
        }});

    // Load the webpage.
    auto const WebViewURL =
      std::string{"icurb://TraceViewer/StateGraphViewer/WebViewHTML#"}
      + CallbackProto;
    
    WebView->LoadURL(WebViewURL);
    
    // Wire up our event handlers.
    Bind(SEEC_EV_GRAPH_RENDERED, &StateGraphViewerPanel::OnGraphRendered, this);
    
    // Register for context notifications.
    Notifier->callbackAdd([this] (ContextEvent const &Ev) -> void {
      this->handleContextEvent(Ev); });

    // Handle future changes to the ColourScheme.
    wxGetApp().getColourSchemeSettings().addListener(
      [this] (ColourSchemeSettings const &Settings) {
        setupColourScheme(*Settings.getColourScheme());
      });

    // Handle UAR replay.
    WithReplay.RegisterHandler("StateGraphViewer.MouseOverValue",
                               {{"address", "type"}},
      seec::make_function(this, &StateGraphViewerPanel::replayMouseOverValue));
  }
  else {
    // If the user navigates to a link, open it in the default browser.
    WebView->Bind(wxEVT_WEBVIEW_NAVIGATING,
      std::function<void (wxWebViewEvent &)>{
        [] (wxWebViewEvent &Event) -> void {
          if (Event.GetURL().StartsWith("http")) {
            wxLaunchDefaultBrowser(Event.GetURL());
            Event.Veto();
          }
          else
            Event.Skip();
        }});
    
    std::string const WebViewURL =
      "icurb://TraceViewer/StateGraphViewer/StateGraphViewerNoGraphviz.html";
    
    // Load the webpage explaining that dot is required.
    WebView->LoadURL(WebViewURL);
  }
  
  // Create the worker thread that will perform our graph generation.
  WorkerThread = std::thread{
    [this] () { this->workerTaskLoop(); }};

  return true;
}