You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovtKernelContext.cpp 2.4KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*********************************************************************
  2. * Software License Agreement (AGPL-3 License)
  3. *
  4. * OpenViBE SDK Test Software
  5. * Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
  6. * Copyright (C) Inria, 2015-2017,V1.0
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program.
  19. * If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <iostream>
  22. #include "ovtKernelContext.h"
  23. namespace OpenViBE {
  24. namespace Test {
  25. bool ctx::initialize()
  26. {
  27. #if defined TARGET_OS_Windows
  28. const CString kernelFile = Directories::getLibDir() + "/openvibe-kernel.dll";
  29. #elif defined TARGET_OS_Linux
  30. const CString kernelFile = Directories::getLibDir() + "/libopenvibe-kernel.so";
  31. #elif defined TARGET_OS_MacOS
  32. const CString kernelFile = Directories::getLibDir() + "/libopenvibe-kernel.dylib";
  33. #endif
  34. CString error;
  35. if (!m_KernelLoader.load(kernelFile, &error))
  36. {
  37. std::cerr << "ERROR: impossible to load kernel from file located at: " << kernelFile << std::endl;
  38. std::cerr << "ERROR: kernel error: " << error << std::endl;
  39. return false;
  40. }
  41. m_KernelLoader.initialize();
  42. Kernel::IKernelDesc* kernelDesc{ nullptr };
  43. m_KernelLoader.getKernelDesc(kernelDesc);
  44. if (!kernelDesc)
  45. {
  46. std::cerr << "ERROR: impossible to retrieve kernel descriptor " << std::endl;
  47. return false;
  48. }
  49. const CString configFile = CString(Directories::getDataDir() + "/kernel/openvibe.conf");
  50. Kernel::IKernelContext* ctx = kernelDesc->createKernel("test-kernel", configFile);
  51. if (!ctx)
  52. {
  53. std::cerr << "ERROR: impossible to create kernel context " << std::endl;
  54. return false;
  55. }
  56. ctx->initialize();
  57. m_Context = ctx;
  58. return true;
  59. }
  60. bool ctx::uninitialize()
  61. {
  62. if (m_Context)
  63. {
  64. Kernel::IKernelDesc* kernelDesc{ nullptr };
  65. m_KernelLoader.getKernelDesc(kernelDesc);
  66. kernelDesc->releaseKernel(m_Context);
  67. m_Context = nullptr;
  68. }
  69. m_KernelLoader.uninitialize();
  70. m_KernelLoader.unload();
  71. return true;
  72. }
  73. } // namespace Test
  74. } // namespace OpenViBE