Source code of Windows XP (NT5)
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.8 KiB

  1. /*
  2. master.js
  3. Starts "harness.js" to manage a distributed build
  4. This script must be very responsive to Exec calls -
  5. we don't want to hang the UI at all.
  6. It uses MsgQueue to communicate with Harness. This lets
  7. us easily avoid waiting for harness when it is communicating
  8. with remote machines.
  9. */
  10. Include('types.js');
  11. Include('utils.js');
  12. Include('MsgQueue.js');
  13. var g_HarnessQueue;
  14. var g_fUpdatePublicData = false;
  15. var g_nHarnessTimeout = 8000;
  16. var g_nUpdateTimeout = 2000;
  17. var ERROR = 'error';
  18. var HARNESS_SYNCS = ['HarnessThreadReady','HarnessThreadFailed'];
  19. function master_js::OnScriptError(strFile, nLine, nChar, strText, sCode, strSource, strDescription)
  20. {
  21. return CommonOnScriptError("master_js", strFile, nLine, nChar, strText, sCode, strSource, strDescription);
  22. }
  23. function master_js::ScriptMain()
  24. {
  25. var nEvent;
  26. LogMsg('ScriptMain()');
  27. CommonVersionCheck(/* $DROPVERSION: */ "V(########) F(!!!!!!!!!!!!!!)" /* $ */);
  28. PrivateData.fnExecScript = MasterRemoteExec;
  29. g_HarnessQueue = new MsgQueue('harness');
  30. ResetSync(HARNESS_SYNCS.toString());
  31. SpawnScript('harness.js', g_HarnessQueue);
  32. var nWait = WaitForMultipleSyncs(HARNESS_SYNCS.toString(), false, g_nHarnessTimeout);
  33. if (nWait == 1)
  34. {
  35. SignalThreadSync('MasterThreadReady');
  36. do
  37. {
  38. nEvent = g_HarnessQueue.WaitForMsgAndDispatch('MasterThreadExit', MasterMsgProc, g_nUpdateTimeout);
  39. if (g_fUpdatePublicData)
  40. {
  41. g_fUpdatePublicData = false;
  42. NotifyUpdatePublicData();
  43. }
  44. } while (nEvent != 1);
  45. LogMsg('ScriptMain() EXIT');
  46. return;
  47. }
  48. else
  49. LogMsg('master::failed to launch mode script nWait is ' + nWait);
  50. SignalThreadSync('MasterThreadFailed');
  51. LogMsg('ScriptMain() EXIT');
  52. }
  53. // MTScript.Remote
  54. function MasterMsgProc(queue, params)
  55. {
  56. OLogMsg('MasterMsgProc ! ' + params);
  57. }
  58. function MasterRemoteExec(cmd, params)
  59. {
  60. LogMsg('MasterRemoteExec :' + cmd + ", params is: " + params);
  61. var vRet = 'ok';
  62. var msg;
  63. // debugger;
  64. switch (cmd)
  65. {
  66. case 'msgtest':
  67. MsgTest();
  68. break;
  69. case 'terminate':
  70. msg = g_HarnessQueue.SendMessage('harnessexit', 0);
  71. g_HarnessQueue.WaitForMsg(msg);
  72. break;
  73. case 'abort':
  74. LogMsg("asking harness to abort, then waiting");
  75. msg = g_HarnessQueue.SendMessage('abort', 0);
  76. g_HarnessQueue.WaitForMsg(msg);
  77. break;
  78. case 'remote':
  79. LogMsg("Sending 'remote' cmd to harness, then waiting");
  80. msg = g_HarnessQueue.SendMessage('remote', params);
  81. g_HarnessQueue.WaitForMsg(msg);
  82. vRet = msg.vReplyValue;
  83. break;
  84. default:
  85. g_HarnessQueue.SendMessage(cmd, params);
  86. break;
  87. }
  88. LogMsg('master::MasterRemoteExec returns: ' + vRet);
  89. return vRet;
  90. }
  91. function master_js::OnProcessEvent(pid, evt, param)
  92. {
  93. LogMsg('OnProcessEvent('+pid+', '+evt+', '+param+') received!');
  94. }
  95. function NotifyUpdatePublicData()
  96. {
  97. JAssert(false);
  98. var buildindex = 0;
  99. EnsureArray(PrivateData.objEnviron, 'Machine');
  100. var aMachine = PrivateData.objEnviron.Machine;
  101. var strStatus = 'idle';
  102. for (i = 0; i < aMachine.length; ++i)
  103. {
  104. var mach = PublicData.aBuild[buildindex].hMachine[aMachine[i].Name];
  105. }
  106. NotifyScript('UpdatePublicData', 0);
  107. }
  108. function MsgTest()
  109. {
  110. LogMsg('Message test!');
  111. JAssert(false);
  112. var msgs = new Array();
  113. for(var i = 0; i < 10; ++i)
  114. {
  115. LogMsg('Sending message #' + (i + 1));
  116. msgs[i] = g_HarnessQueue.SendMessage('test', 'Message #' + (i + 1));
  117. }
  118. for(i = 10; i > 0; --i)
  119. {
  120. LogMsg('Waiting for message #' + i);
  121. g_HarnessQueue.WaitForMsg(msgs[i - 1]);
  122. }
  123. }