
June 1996 Newton Technology Journal
4
Then, when you call the InetGrabLink function in your application,
you pass it the name (symbol) of your callback function. For example:
myApp.TestGrab := func()
begin
myStatusView := InetStatusDisplay(nil, nil, nil);
InetGrabLink(nil, self, 'GrabLinkCallback);
...
end;
This function first calls the InetStatusDisplay function to
create and display the status view. The call to InetGrabLink uses the
default link ID and specifies self (the application frame) as the value of the
clientContext
parameter, and 'GrabLinkCallback (the symbol
for the callback function) as the value of the
clientCallback
parameter.
The GrabLinkCallback function will be called repeatedly while the
system is attempting to grab the link, until either the status is
'connected or an error occurs.
USING THE LINK CONTROLLER INTERFACE
You can use the Link Controller to create and manage a link between a
Newton device and the Internet. The Link Controller can manage a single
link for multiple applications simultaneously. This means that one
application establishes the link and other applications use the same link.
To establish (grab) a link, you call the InetGrabLink function. The
first grab of a link can be expensive in terms of time: typically, the Inet tool
software dials the Newton modem and negotiates the connection to establish
an Internet session. The Inet tool then performs whatever login and
initialization procedures are required, which the user has configured with the
Internet Setup application. All of this can take a substantial amount of time.
Since it can take so much time to grab a new link, Newton Internet
Enabler makes it easy for another application to grab a link that has already
been established by maintaining a reference count of users for each link.
Whenever an application grabs a link, the link controller increments its count
of users of that link. The physical link is dropped only after all users have
released the link (when the count becomes 0).
Most of the link controller functions operate asynchronously. After the
Inet tool initiates the operation, it returns control to your application. When
the operation is complete, or in some cases while the operation is in
progress, the Inet tool notifies you by calling a callback function that you
have provided. You can use your callback functions to monitor the status of
a link and to determine if an operation was successful or not.
While the grab of a link is in progress, the Inet frequently calls your
callback function, providing it with information about the current status of
the link. You can send this status information along to the
InetStatusDisplay function to provide visual feedback to the user
about the connection process.
The following is an example of a typical flow of operations that occur
during an Internet session using Newton Internet Enabler:
1. An application (My_Application) issues a call to the InetGrabLink
function. The link controller dials the modem and begins an Internet
session with an Internet provider.
2. While the grab operation is in process, the Inet tool periodically calls the
callback function that My_Application has defined for grab operations.
This callback function calls the InetStatusDisplay function to
update the on-screen display of the current status of the link.
3. When the grab operation completes, the callback function removes the
status display from the screen.
4. My_Application instantiates and binds one or more endpoints to use
over that link. Each endpoint can use either the TCP or UDP transport
services, and each endpoint can be bound either to initiate an outgoing
connection (connect) or to listen for an incoming connection (listen).
5. My_Application uses its endpoint(s) to perform communications
operations, calling endpoint methods such as Output and
SetInputSpec.
6. Another application (Your_Application) issues a call to the
InetGrabLink function to use the same service provider as
My_Application. The Inet tool returns the same link that it established
in step 1.
7. Your_Application creates and uses endpoint(s) to perform
communications operations.
8. Your_Application finishes its use of the link and calls the
InetReleaseLink function. The link controller decrements its
count of users of the link.
9. A third application (Their_Application) grabs the link, creates endpoints
to use over the link, and releases the link.
10. My_Application finishes its use of the link and calls the
InetReleaseLink function. The link controller decrements its
count of link users. The count becomes 0, so the link is dropped: the
Internet session ends, the modem is hung up, and any resources used
for the link are released.
Grabbing a Link
To get started, you need to establish (grab) a link. To establish a link, you
need to call the InetGrabLink function. You need to provide
InetGrabLink with a link ID, a callback function, and a callback
context frame:
InetGrabLink(linkID, clientContext, clientCallback)
For the link ID, you can tell InetGrabLink to use the default link by
using nil or you can use an identifier returned by the
InetAddNewLinkEntry function as the value of this parameter.
When you specify nil, the system software uses the link ID that has been
established as the default link ID, which is almost always what you want to do.
The InetGrabLink operation can take some time to complete. While
it is in progress, the Inet tool repeatedly calls your callback function to report the
current status of grabbing the link. The Inet tool calls your callback function until
either an error occurs or until the status becomes 'connected.
The status value in your callback is a status frame. This frame contains
the current link status value and (possibly) other information. In your
callback, you can use the InetDisplayStatus function to show the
current status to the user. The next section, “Retrieving and Displaying Link
Status Information,” describes how to display status to the user.
Here is an example of a callback function for the InetGrabLink
function:
myApp.GrabLinkCallback := func(linkID, stat, err)
begin
myLinkID := linkID; // save the link ID
// during grab processing, display status & return
if err = nil and status.linkStatus <> 'connected then
return InetDisplayStatus(linkID, myStatView, stat);
// at this point, either we are connected or we
// got an error, so close the status display
InetDisplayStatus(linkID, myStatView, nil);
Comentários a estes Manuais