Терминальный проект КиберПлат [open source]
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.

145 lines
3.9KB

  1. /* @file Сервис для организации перехвата вызовов других сервисов. */
  2. // Qt
  3. #include <Common/QtHeadersBegin.h>
  4. #include <QtCore/QString>
  5. #include <QtCore/QGenericArgument>
  6. #include <QtCore/QMetaObject>
  7. #include <Common/QtHeadersEnd.h>
  8. // SDK
  9. #include <SDK/PaymentProcessor/Components.h>
  10. // Модули
  11. #include <Crypt/ICryptEngine.h>
  12. // Проект
  13. #include "DatabaseUtils/IPaymentDatabaseUtils.h"
  14. #include "Services/ServiceNames.h"
  15. #include "Services/HookService.h"
  16. #include "Services/PluginService.h"
  17. #include "Services/PaymentService.h"
  18. namespace PPSDK = SDK::PaymentProcessor;
  19. //---------------------------------------------------------------------------
  20. HookService * HookService::instance(IApplication * aApplication)
  21. {
  22. return static_cast<HookService *>(aApplication->getCore()->getService(CServices::HookService));
  23. }
  24. //---------------------------------------------------------------------------
  25. HookService::HookService(IApplication * aApplication)
  26. : mApplication(aApplication)
  27. {
  28. }
  29. //---------------------------------------------------------------------------
  30. HookService::~HookService()
  31. {
  32. }
  33. //---------------------------------------------------------------------------
  34. bool HookService::initialize()
  35. {
  36. QStringList hookers =
  37. PluginService::instance(mApplication)->getPluginLoader()->getPluginList(QRegExp(QString("%1\\.%2\\..*").arg(PPSDK::Application, PPSDK::CComponents::Hook)));
  38. foreach (const QString & path, hookers)
  39. {
  40. SDK::Plugin::IPlugin * plugin = PluginService::instance(mApplication)->getPluginLoader()->createPlugin(path);
  41. if (plugin)
  42. {
  43. if (plugin->isReady())
  44. {
  45. mHooks << plugin;
  46. }
  47. else
  48. {
  49. PluginService::instance(mApplication)->getPluginLoader()->destroyPlugin(plugin);
  50. }
  51. }
  52. }
  53. return true;
  54. }
  55. //------------------------------------------------------------------------------
  56. void HookService::finishInitialize()
  57. {
  58. }
  59. //---------------------------------------------------------------------------
  60. bool HookService::canShutdown()
  61. {
  62. return true;
  63. }
  64. //---------------------------------------------------------------------------
  65. bool HookService::shutdown()
  66. {
  67. while (!mHooks.isEmpty())
  68. {
  69. PluginService::instance(mApplication)->getPluginLoader()->destroyPlugin(mHooks.first());
  70. mHooks.takeFirst();
  71. }
  72. return true;
  73. }
  74. //---------------------------------------------------------------------------
  75. QString HookService::getName() const
  76. {
  77. return CServices::HookService;
  78. }
  79. //---------------------------------------------------------------------------
  80. const QSet<QString> & HookService::getRequiredServices() const
  81. {
  82. static QSet<QString> requiredServices = QSet<QString>()
  83. << CServices::PluginService;
  84. return requiredServices;
  85. }
  86. //---------------------------------------------------------------------------
  87. QVariantMap HookService::getParameters() const
  88. {
  89. return QVariantMap();
  90. }
  91. //---------------------------------------------------------------------------
  92. void HookService::resetParameters(const QSet<QString> &)
  93. {
  94. }
  95. //---------------------------------------------------------------------------
  96. bool HookService::invokeHook(const QString & aMetodName,
  97. QGenericArgument aVal0,
  98. QGenericArgument aVal1, QGenericArgument aVal2,
  99. QGenericArgument aVal3, QGenericArgument aVal4,
  100. QGenericArgument aVal5, QGenericArgument aVal6,
  101. QGenericArgument aVal7, QGenericArgument aVal8,
  102. QGenericArgument aVal9)
  103. {
  104. bool result = false;
  105. foreach (SDK::Plugin::IPlugin * plugin, mHooks)
  106. {
  107. QObject * pluginObject = dynamic_cast<QObject *> (plugin);
  108. if (pluginObject != nullptr)
  109. {
  110. // Всегда делаем Qt::DirectConnection независимо от того в каком процессе находится объект перехватчик
  111. result = QMetaObject::invokeMethod(pluginObject, aMetodName.toLatin1().data(), Qt::DirectConnection,
  112. aVal0, aVal1, aVal2, aVal3, aVal4, aVal5, aVal6, aVal7, aVal8, aVal9) || result;
  113. }
  114. }
  115. return result;
  116. }