1
0

ComponentManagerBase.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #include "ComponentManagerBase.h"
  2. #include "foundation/error.h"
  3. #include "nx/nxuri.h"
  4. ComponentManagerBase::ComponentManagerBase()
  5. {
  6. phase=PHASE_INITIALIZE;
  7. service_api=0;
  8. component_sync=0;
  9. }
  10. int ComponentManagerBase::LateLoad(ifc_component *component)
  11. {
  12. int ret;
  13. if (phase >= PHASE_REGISTERED)
  14. {
  15. ret = component->RegisterServices(service_api);
  16. if (ret != NErr_Success)
  17. {
  18. int ret2 = component->Quit(service_api);
  19. if (ret2 == NErr_TryAgain)
  20. {
  21. component_sync->Wait(1);
  22. }
  23. return ret;
  24. }
  25. }
  26. if (phase >= PHASE_LOADING)
  27. {
  28. ret = component->OnLoading(service_api);
  29. if (ret != NErr_Success)
  30. {
  31. int ret2 = component->Quit(service_api);
  32. if (ret2 == NErr_TryAgain)
  33. {
  34. component_sync->Wait(1);
  35. }
  36. return ret;
  37. }
  38. }
  39. if (phase >= PHASE_LOADED)
  40. {
  41. ret = component->OnLoaded(service_api);
  42. if (ret != NErr_Success)
  43. {
  44. int ret2 = component->Quit(service_api);
  45. if (ret2 == NErr_TryAgain)
  46. {
  47. component_sync->Wait(1);
  48. }
  49. return ret;
  50. }
  51. }
  52. return NErr_Success;
  53. }
  54. void ComponentManagerBase::SetServiceAPI(api_service *service_api)
  55. {
  56. this->service_api = service_api;
  57. service_api->QueryInterface(&component_sync);
  58. }
  59. int ComponentManagerBase::Load()
  60. {
  61. if (phase != PHASE_INITIALIZE)
  62. return NErr_Error;
  63. int ret;
  64. /* RegisterServices phase */
  65. for (ComponentList::iterator itr=components.begin();itr!=components.end();)
  66. {
  67. ifc_component *component = *itr;
  68. ComponentList::iterator next=itr;
  69. next++;
  70. ret = component->RegisterServices(service_api);
  71. if (ret != NErr_Success)
  72. {
  73. int ret2 = component->Quit(service_api);
  74. if (ret2 == NErr_TryAgain)
  75. {
  76. component_sync->Wait(1);
  77. }
  78. NXURIRelease(component->component_info.filename);
  79. CloseComponent(component);
  80. components.erase(component);
  81. }
  82. itr=next;
  83. }
  84. phase = PHASE_REGISTERED;
  85. /* OnLoading phase */
  86. for (ComponentList::iterator itr=components.begin();itr!=components.end();)
  87. {
  88. ifc_component *component = *itr;
  89. ComponentList::iterator next=itr;
  90. next++;
  91. ret = component->OnLoading(service_api);
  92. if (ret != NErr_Success)
  93. {
  94. int ret2 = component->Quit(service_api);
  95. if (ret2 == NErr_TryAgain)
  96. {
  97. component_sync->Wait(1);
  98. }
  99. NXURIRelease(component->component_info.filename);
  100. CloseComponent(component);
  101. components.erase(component);
  102. }
  103. itr=next;
  104. }
  105. phase = PHASE_LOADING;
  106. /* OnLoaded phase */
  107. for (ComponentList::iterator itr=components.begin();itr!=components.end();)
  108. {
  109. ifc_component *component = *itr;
  110. ComponentList::iterator next=itr;
  111. next++;
  112. ret = component->OnLoading(service_api);
  113. if (ret != NErr_Success)
  114. {
  115. int ret2 = component->Quit(service_api);
  116. if (ret2 == NErr_TryAgain)
  117. {
  118. component_sync->Wait(1);
  119. }
  120. NXURIRelease(component->component_info.filename);
  121. CloseComponent(component);
  122. components.erase(component);
  123. }
  124. itr=next;
  125. }
  126. phase = PHASE_LOADED;
  127. return NErr_Success;
  128. }