EnvSupportLib.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "EnvSupportLib.hpp"
  14. #include "Exceptions.hpp"
  15. #include "HPCCConfigSupport.hpp"
  16. EnvSupportLib::EnvSupportLib(const std::string &libName, EnvironmentMgr *pEnvMgr) : m_libName(libName), m_libHandle(nullptr)
  17. {
  18. if (m_libName.empty())
  19. {
  20. std::string msg = "Error missing library name";
  21. throw (ParseException(msg));
  22. }
  23. m_libHandle = dlopen(m_libName.c_str(), RTLD_LAZY);
  24. if (m_libHandle == nullptr)
  25. {
  26. std::string msg = "Error opening support library " + libName + ", error = " + dlerror();
  27. throw (ParseException(msg));
  28. }
  29. getHPCCSupportLib_t getInstanceProc = (getHPCCSupportLib_t)dlsym(m_libHandle, "getInstance");
  30. if (getInstanceProc != nullptr)
  31. {
  32. m_pSupportLib = getInstanceProc(pEnvMgr);;
  33. }
  34. else
  35. {
  36. std::string msg = "Error getting getInstance function " + libName + ", error = " + dlerror();
  37. throw (ParseException(msg));
  38. }
  39. }
  40. EnvSupportLib::~EnvSupportLib()
  41. {
  42. if (m_libHandle != nullptr)
  43. {
  44. dlclose(m_libHandle);
  45. m_libHandle = nullptr;
  46. }
  47. }
  48. void EnvSupportLib::processEvent(const std::string &event, const std::shared_ptr<SchemaItem> &pSchema, const std::shared_ptr<EnvironmentNode> &pEventNode, Status &status) const
  49. {
  50. m_pSupportLib->processEvent(event, pSchema, pEventNode, status);
  51. }
  52. void EnvSupportLib::validate(const std::shared_ptr<SchemaItem> &pSchema, const std::shared_ptr<EnvironmentNode> &pEnvironment, Status &status) const
  53. {
  54. m_pSupportLib->validate(pSchema, pEnvironment, status);
  55. }