PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/mythtv/libs/libmythfreemheg/Root.cpp

http://github.com/MythTV/mythtv
C++ | 144 lines | 89 code | 19 blank | 36 comment | 9 complexity | a25ff460be639b7ccffe619b3a0468b1 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, MIT, GPL-2.0, LGPL-2.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. /* Root.cpp
  2. Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  14. Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  15. */
  16. #include "Root.h"
  17. #include "ParseNode.h"
  18. #include "BaseClasses.h"
  19. #include "Ingredients.h"
  20. #include "Engine.h"
  21. #include "Logging.h"
  22. // Initialise the root class from the parse tree.
  23. void MHRoot::Initialise(MHParseNode *p, MHEngine *engine)
  24. {
  25. MHParseNode *pArg = p->GetArgN(0); // The first argument should be present.
  26. // Extract the field.
  27. m_ObjectReference.Initialise(pArg, engine);
  28. }
  29. // Print the contents, in this case just the object reference.
  30. void MHRoot::PrintMe(FILE *fd, int nTabs) const
  31. {
  32. m_ObjectReference.PrintMe(fd, nTabs);
  33. fprintf(fd, "\n");
  34. }
  35. // An action was attempted on an object of a class which doesn't support this.
  36. void MHRoot::InvalidAction(const char *actionName)
  37. {
  38. MHLOG(MHLogWarning, QString("WARN Action \"%1\" is not understood by class \"%2\"").arg(actionName).arg(ClassName()));
  39. throw "Invalid Action";
  40. }
  41. // Preparation - sets up the run-time representation. Sets m_fAvailable and generates IsAvailable event.
  42. void MHRoot::Preparation(MHEngine *engine)
  43. {
  44. if (m_fAvailable)
  45. {
  46. return; // Already prepared
  47. }
  48. // Retrieve object
  49. // Set the internal attributes.
  50. m_fAvailable = true;
  51. engine->EventTriggered(this, EventIsAvailable);
  52. // When the content becomes available generate EventContentAvailable. This is not
  53. // generated if an object has no Content.
  54. ContentPreparation(engine);
  55. }
  56. // Activation - starts running the object. Sets m_fRunning and generates IsRunning event.
  57. void MHRoot::Activation(MHEngine *engine)
  58. {
  59. if (m_fRunning)
  60. {
  61. return; // Already running.
  62. }
  63. if (! m_fAvailable)
  64. {
  65. Preparation(engine); // Prepare it if that hasn't already been done.
  66. }
  67. // The subclasses are responsible for setting m_fRunning and generating IsRunning.
  68. }
  69. // Deactivation - stops running the object. Clears m_fRunning
  70. void MHRoot::Deactivation(MHEngine *engine)
  71. {
  72. if (! m_fRunning)
  73. {
  74. return; // Already stopped.
  75. }
  76. m_fRunning = false;
  77. engine->EventTriggered(this, EventIsStopped);
  78. }
  79. // Destruction - deletes the run-time representation. Clears m_fAvailable.
  80. void MHRoot::Destruction(MHEngine *engine)
  81. {
  82. if (! m_fAvailable)
  83. {
  84. return; // Already destroyed or never prepared.
  85. }
  86. if (m_fRunning)
  87. {
  88. Deactivation(engine); // Deactivate it if it's still running.
  89. }
  90. // We're supposed to wait until it's stopped here.
  91. m_fAvailable = false;
  92. engine->EventTriggered(this, EventIsDeleted);
  93. }
  94. // Return this object if it matches.
  95. MHRoot *MHRoot::FindByObjectNo(int n)
  96. {
  97. if (n == m_ObjectReference.m_nObjectNo)
  98. {
  99. return this;
  100. }
  101. return nullptr;
  102. }
  103. void MHGetAvailabilityStatus::Initialise(MHParseNode *p, MHEngine *engine)
  104. {
  105. MHElemAction::Initialise(p, engine);
  106. m_ResultVar.Initialise(p->GetArgN(1), engine);
  107. }
  108. void MHGetAvailabilityStatus::Perform(MHEngine *engine)
  109. {
  110. // This is a special case. If the object does not exist we set the result to false.
  111. MHObjectRef target;
  112. m_Target.GetValue(target, engine); // Get the target
  113. MHRoot *pObject = engine->FindObject(target, false);
  114. bool fResult = false; // Default result.
  115. if (pObject)
  116. {
  117. fResult = pObject->GetAvailabilityStatus();
  118. }
  119. engine->FindObject(m_ResultVar)->SetVariableValue(fResult);
  120. }