
Rebuilding the Demo Host Software
Additional Procedures
A-19
The main thread sets the text of the "myText" text widget and creates the
new thread. But the new thread is not allowed to call the "getText()"
method of the w["myText"] object. It can get around this limitation by
calling a method "display.syncExec()" or "display.asyncExec()" and
specify a thread-like code within it to access the widget:
w["myText"].setText( "lovely" );
new java.lang.Thread( new java.lang.Runnable() {
run: function() {
var myTextContents;
display.syncExec(
new java.lang.Runnable() {
run: function() {
myTextContents = w["myText"].getText();
}
}
);
print( "Hello " + myTextCo " world" );
}
} ).start();
The new thread now makes a blocking call to the display.syncExec()
method that creates yet another thread, but now one that is allowed to
read the widget. The newest thread reads the contents of the text widget,
stores it in the second thread's local variable, "myTextContents", and
exits. Then the second thread continues and goes on to print the contents
of its local variable, "myTextContents", knowing that it has been set to
reflect the contents of the widgets that it couldn't access directly.
We use display.asyncExec() a couple places in Main.js. One such
example is the fileio thread. The main thread in Main.js spawns a new
thread to be a fileio server upon connection to the target. The new thread
calls fileio.recvCmd() and fileio.dispatchCmd( cmd ) methods in a loop.
The later one can be (and often is) a write request from the target—the
target wants to write data to a file or text on the console. If you look at
Fileio.js, you will see that the function that implements write also calls a
method "showWriteInfo( filename, newFileSize )". This method is by
default a dummy function, but the fileio thread in Main.js sets this method
to update the file size textboxes on the screen. And this is where
display.asyncExec() comes to play:
Fileio's showWriteInfo is effectively a callback, called from another
thread, and is set to update some widgets on the screen. We know that
is not allowed, so in Main.js' fileio thread we set the callback not to be a
simple update of the text, but we wrap it around display.asyncExec() and
it all works.
Summary of Contents for TMS320DM6437
Page 1: ...TMS320DM6437 DVDP Getting Started Guide Literature Number SPRUEV6 July 2007 ...
Page 20: ...2 8 ...
Page 34: ...3 14 ...
Page 40: ...4 6 ...
Page 63: ......