ComponentManager.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <QObject>
  2. #include <QtQml>
  3. #include <qqmlwebchannel.h>
  4. #include "ComponentManager.h"
  5. #include "power/PowerComponent.h"
  6. #include "server/HTTPServer.h"
  7. #include "input/InputComponent.h"
  8. #include "player/PlayerComponent.h"
  9. #include "display/DisplayComponent.h"
  10. #include "system/SystemComponent.h"
  11. #include "system/UpdaterComponent.h"
  12. #include "settings/SettingsComponent.h"
  13. #include "remote/RemoteComponent.h"
  14. #include "server/HTTPServer.h"
  15. #if KONVERGO_OPENELEC
  16. #include "system/openelec/OESystemComponent.h"
  17. #endif
  18. #include "QsLog.h"
  19. ///////////////////////////////////////////////////////////////////////////////////////////////////
  20. ComponentManager::ComponentManager() : QObject(nullptr)
  21. {
  22. }
  23. ///////////////////////////////////////////////////////////////////////////////////////////////////
  24. void ComponentManager::registerComponent(ComponentBase* comp)
  25. {
  26. if (m_components.contains(comp->componentName()))
  27. {
  28. QLOG_ERROR() << "Component" << comp->componentName() << "already registered!";
  29. return;
  30. }
  31. if (comp->componentInitialize())
  32. {
  33. QLOG_INFO() << "Component:" << comp->componentName() << "inited";
  34. m_components[comp->componentName()] = comp;
  35. // define component as property for qml
  36. m_qmlProperyMap.insert(comp->componentName(), QVariant::fromValue(comp));
  37. }
  38. else
  39. {
  40. QLOG_ERROR() << "Failed to init component:" << comp->componentName();
  41. }
  42. }
  43. ///////////////////////////////////////////////////////////////////////////////////////////////////
  44. void ComponentManager::initialize()
  45. {
  46. // then settings, since all other components
  47. // might have some settings
  48. //
  49. registerComponent(&SettingsComponent::Get());
  50. // start our web server
  51. auto server = new HttpServer(this);
  52. server->start();
  53. registerComponent(&InputComponent::Get());
  54. registerComponent(&SystemComponent::Get());
  55. registerComponent(&DisplayComponent::Get());
  56. registerComponent(&UpdaterComponent::Get());
  57. registerComponent(&RemoteComponent::Get());
  58. registerComponent(&PlayerComponent::Get());
  59. registerComponent(&PowerComponent::Get());
  60. #if KONVERGO_OPENELEC
  61. registerComponent(&OESystemComponent::Get());
  62. #endif
  63. for(ComponentBase* component : m_components.values())
  64. component->componentPostInitialize();
  65. }
  66. /////////////////////////////////////////////////////////////////////////////////////////
  67. void ComponentManager::setWebChannel(QWebChannel* webChannel)
  68. {
  69. for(ComponentBase* comp : m_components.values())
  70. {
  71. if (comp->componentExport())
  72. {
  73. QLOG_DEBUG() << "Adding component:" << comp->componentName() << "to webchannel";
  74. webChannel->registerObject(comp->componentName(), comp);
  75. }
  76. }
  77. }