OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <!-- |
| 4 Copyright (c) 2010 The Native Client SDK Authors. All rights reserved. |
| 5 Use of this source code is governed by a BSD-style license that can be |
| 6 found in the LICENSE file. |
| 7 --> |
| 8 <head> |
| 9 <title>Duality!</title> |
| 10 |
| 11 <script type="text/javascript"> |
| 12 // Global application objects. |
| 13 proc_one = null; |
| 14 proc_two = null; |
| 15 |
| 16 // Indicates the shared state of the two application objects. |
| 17 shared_object = 'UNINITIALIZED'; |
| 18 |
| 19 // Indicates whether our nacls have loaded. |
| 20 status_one_text = 'NO-STATUS'; |
| 21 status_two_text = 'NO-STATUS'; |
| 22 |
| 23 |
| 24 // Updates the status field for |process| to indicate that it has loaded |
| 25 // successfully. |
| 26 function moduleDidLoad(process) { |
| 27 if(process == 1) { |
| 28 proc_one = document.getElementById('process_one'); |
| 29 } else { |
| 30 proc_two = document.getElementById('process_two'); |
| 31 } |
| 32 |
| 33 updateStatus('LOADED', process); |
| 34 } |
| 35 |
| 36 // If the page loads before the Native Client module loads, then set the |
| 37 // status message indicating that the module is still loading. Otherwise, |
| 38 // do not change the status message. |
| 39 // TODO(mlinck) populate |
| 40 function pageDidLoad() { |
| 41 if (proc_one == null) { |
| 42 updateStatus('LOADING...', 1); |
| 43 } else { |
| 44 updateStatus('LOADED', 1); |
| 45 } |
| 46 |
| 47 if (proc_two == null) { |
| 48 updateStatus('LOADING...', 2); |
| 49 } else { |
| 50 updateStatus('LOADED', 2); |
| 51 } |
| 52 } |
| 53 |
| 54 // Tells |process| to read from the global status. |
| 55 function readGlobal(process) { |
| 56 var proc; |
| 57 |
| 58 if(process == 1) { |
| 59 proc = proc_one; |
| 60 } else { |
| 61 proc = proc_two; |
| 62 } |
| 63 |
| 64 alert("Process " + process + " says " + proc.say_hello()); |
| 65 } |
| 66 |
| 67 // Tells |process| to write to the global status. |
| 68 function writeGlobal(process) { |
| 69 var proc; |
| 70 |
| 71 if(process == 1) { |
| 72 proc = proc_one; |
| 73 } else { |
| 74 proc = proc_two; |
| 75 } |
| 76 |
| 77 alert("Process " + process + " says " + proc.SayHello()); |
| 78 } |
| 79 |
| 80 // Tells |process| to read |user_string| from its input. |
| 81 function readInput(user_string, process) { |
| 82 alert("Reading input " + user_string + " into process: " + process); |
| 83 } |
| 84 |
| 85 // figures out which status field is to be updated and then updates it. |
| 86 function updateStatus(message, process) { |
| 87 var status_field; |
| 88 |
| 89 if (process == 1) { |
| 90 status_field = document.getElementById('status_one_field'); |
| 91 } else { |
| 92 status_field = document.getElementById('status_two_field'); |
| 93 } |
| 94 |
| 95 |
| 96 if (status_field) { |
| 97 status_field.innerHTML = message; |
| 98 } else { |
| 99 // alert("updatestatus could not find status field"); |
| 100 } |
| 101 } |
| 102 </script> |
| 103 </head> |
| 104 <body onload="pageDidLoad()"> |
| 105 <!-- First draw the content... --> |
| 106 <h1>Example of Shared Memory and Events</h1> |
| 107 <p> |
| 108 If this module is working, you should be able to enter text in either |
| 109 text field. Each text field is controlled by a separate NaCl process |
| 110 so there are actually 2 processes running concurrently. Editing either |
| 111 textfield and clicking "Write", writes the content to a shared object. |
| 112 "Read" reads the state of the shared object into the process. The point |
| 113 of this page is to illustrate inter-process communication and event |
| 114 handling in NaCl. |
| 115 </p> |
| 116 |
| 117 |
| 118 |
| 119 <h3>Process 1 Controls</h3> |
| 120 <input type="text" size="15" id="process_1_textfield" |
| 121 value="#undef" onchange="readInput(this.value, 1)" /> |
| 122 |
| 123 <button onclick="readGlobal(1)">Read</button> |
| 124 <button onclick="writeGlobal(1)">Write</button> |
| 125 |
| 126 |
| 127 <h3>Process 2 Controls</h3> |
| 128 <input type="text" size="15" id="process_2_textfield" |
| 129 value="#undef" onchange="readInput(this.value, 2)" /> |
| 130 |
| 131 <button onclick="readGlobal(2)">Read</button> |
| 132 <button onclick="writeGlobal(2)">Write</button> |
| 133 |
| 134 |
| 135 |
| 136 <h3>Global State (No Process)</h3> |
| 137 <div id="global_state_field">UNINITALIZED</div> |
| 138 |
| 139 |
| 140 <!-- ... then load modules --> |
| 141 <embed name="nacl_module_one" |
| 142 id="process_one" |
| 143 width=0 |
| 144 height=0 |
| 145 type="application/x-nacl-srpc"/> |
| 146 |
| 147 <script type="text/javascript"> |
| 148 var nexes = 'x86-32: duality_x86_32.nexe\n' |
| 149 + 'x86-64: duality_x86_64.nexe\n' |
| 150 + 'ARM: duality_arm.nexe '; |
| 151 |
| 152 document.getElementById('process_one').nexes = nexes; |
| 153 |
| 154 moduleDidLoad(1); |
| 155 </script> |
| 156 |
| 157 <embed name="nacl_module_two" |
| 158 id="process_two" |
| 159 width=0 |
| 160 height=0 |
| 161 type="application/x-nacl-srpc"/> |
| 162 |
| 163 <script type="text/javascript"> |
| 164 var nexes = 'x86-32: duality_x86_32.nexe\n' |
| 165 + 'x86-64: duality_x86_64.nexe\n' |
| 166 + 'ARM: duality_arm.nexe '; |
| 167 |
| 168 document.getElementById('process_two').nexes = nexes; |
| 169 |
| 170 moduleDidLoad(2); |
| 171 </script> |
| 172 |
| 173 <h2>Status</h2> |
| 174 Have our NaCl Modules loaded? |
| 175 <br><br> |
| 176 Module 1: |
| 177 <div id="status_one_field">UNINITIALIZED</div> |
| 178 <br> |
| 179 Module 2: |
| 180 <div id="status_two_field">UNINITIALIZED</div> |
| 181 </body> |
| 182 </html> |
OLD | NEW |