dmppythonutils.h 1.8 KB
/**************************************************************************
* file:              dmppythonutils.h

* Author:            wanzhongping
* Date:              2021-02-20 16:20:53
* Email:             zhongpingw@chinadci.com
* copyright:         广州城市信息研究所有限公司
***************************************************************************/

#ifndef __dmppythonutils_h__
#define __dmppythonutils_h__

#define BOOST_BIND_GLOBAL_PLACEHOLDERS
#include <boost/python.hpp>
#include "dmpconfig.h"
#include <boost/dll/shared_library.hpp>
#include "dmap_server.h"
#include "../dmpserverinterface.h"
#include <string>
#include <vector>

class SERVER_EXPORT DmpPythonUtils
{
  public:
    DmpPythonUtils();
    ~DmpPythonUtils();

    void InitServerPython( DmpServerInterface *iface );
    bool StartServerPlugin( std::string package_name );
    void ExitPython();
    bool LoadPlugin(const std::string &package_name);
    std::vector<std::string> PluginList();
    bool RunString(const std::string &command, bool single = true);
    bool EvalString(const std::string &command, std::string &result);
    std::string GetPluginMetadata(const std::string &pluginName, const std::string &function);

    bool IsEnabled();
    
    std::vector<std::string> ExtraPluginsPaths() const;
    std::string PythonPath() const;
    std::string PluginsPath() const;
    std::string HomePythonPath() const;
    std::string HomePluginsPath() const;

protected:
    void Init();
    bool CheckSystemImports();
    void UninstallErrorHook();

    boost::python::object main_module_;
    boost::python::object main_namespace_;

    bool python_enabled_ = false;

    //! cleanup Python context
    void Finish();
  
private:
    bool error_hook_installed_ = false;
    
};
#endif //__dmppythonutils_h__