ExgMgr.h
declares the exchange manager API. For more information on the exchange manager, see the chapter "Beaming (Infrared Communication)" in the Palm OS Programmer's Companion.
ExgAskResultType
enum defines possible values for the result
field of the
sysAppLaunchCmdExgAskUser
launch code parameter block.
typedef enum {
    exgAskDialog,
    exgAskOk,
    exgAskCancel }
ExgAskResultType;
exgAskDialog
|
The exchange manager should display the exchange dialog to prompt the user to confirm the receipt of data. See ExgDoDialog .
|
exgAskOk
| Accept the data. |
exgAskCancel
| Reject the data. |
ExgGoToType
structure defines information that is passed to the
sysAppLaunchCmdGoto
launch command, after an item is received. The ExgGoToPtr
type points to a ExgGoToType
structure.
typedef struct {
    UInt16 dbCardNo;
    LocalID dbID;
    UInt16 recordNum;
    UInt32 uniqueID;
    UInt32 matchCustom;
} ExgGoToType;
typedef ExgGoToType * ExgGoToPtr;
ExgSocketType
structure defines an exchange manager socket. The ExgSocketPtr
type points to a ExgSocketType
structure.
typedef struct ExgSocketType {
    UInt16 libraryRef;
    UInt32 socketRef;
    UInt32 target;
    UInt32 count;
    UInt32 length;
    UInt32 time;
    UInt32 appData;
    UInt32 goToCreator;
    ExgGoToType goToParams;
    UInt16 localMode:1;
    UInt16 packetMode:1;
    UInt16 noGoTo:1;
    UInt16 noStatus:1;
    UInt16 reserved:12;
    Char *description;
    Char *type;
    Char *name;
} ExgSocketType;
typedef ExgSocketType* ExgSocketPtr;
count
, time
, appData
, or type
fields; however, it may do so in the future. When you are sending data, it is recommended that you provide values for all of these fields, but you should not rely on receiving values for them.
noGoTo
and noStatus
flags are only defined if 3.5 New Feature Set is present.
Err ExgAccept (ExgSocketPtr socketP)
sysAppLaunchCmdExgReceiveData
. The application is passed socketP
as a parameter. It should pass this parameter to ExgAccept
to accept the connection and then call ExgReceive
one or more times to receive the data.
ExgReceive
Err ExgDBRead (ExgDBReadProcPtr readProcP, ExgDBDeleteProcPtr deleteProcP, void* userDataP, LocalID* dbIDP, UInt16 cardNo, Boolean* needResetP, Boolean keepDates)
  |
-> |
A pointer to a function that you supply that reads in the database and passes it to ExgDBRead . See ReadProc for details. |
  |
-> |
A pointer to a function that is called if a database with an identical name already exists on the device, so you can erase it before ExgDBRead stores the received database. See DeleteProc for details. |
  |
-> |
A pointer to any data you want to pass to either the readProcP or deleteProcP functions. |
  |
<- |
The ID of the database that ExgDBRead created on the local device. |
  |
<- |
The number of the card on which the database was stored by ExgDBRead . |
  |
<- |
Set to true by ExgDBRead if the dmHdrAttrResetAfterInstall attribute bit is set in the received database. |
  |
-> |
Specify true to retain the creation, modification, and last backup dates as set in the received database header. Specify false to reset these dates to the current date. |
errNone
if successful; otherwise, returns one of the data manager error codes (dmErr...
) or a callback-specific error code (if the readProcP
function returns an error, it is also returned by ExgDBRead
).
readProcP
is called multiple times by ExgDBRead
. Each time, ExgDBRead
passes in sizeP
the number of bytes it expects to receive in the next chunk that the read callback function is to return in dataP
. It's important for the read callback function to set the number of bytes (in sizeP
) that it actually placed in dataP
, if it's not the same as what ExgDBRead
expected. ExgDBRead
stops calling the read callback function after it receives the entire database (it knows when it's got it all based on the header information).
ExgDBWrite
Err ExgDBWrite (ExgDBWriteProcPtr writeProcP, void* userDataP, const char* nameP, LocalID dbID, UInt16 cardNo)
  |
-> |
A pointer to a function that you supply that writes out the database identified by dbID . See WriteProc for details. |
  |
-> |
A pointer to any data you want to pass to the writeProcP function. |
  |
-> |
A pointer to the name of the database that you want ExgDBWrite to read and pass to writeProcP . |
  |
-> |
The id of the database that you want ExgDBWrite to read and pass to writeProcP . If you don't supply an ID, then nameP is used to search for the database by name. |
  |
-> |
The number of the card on which to look for the database identified by nameP . |
errNone
if successful; otherwise, returns one of the data manager error codes (dmErr...
) or a callback-specific error code (if the writeProcP
function returns an error, it is also returned by ExgDBWrite
).
writeProcP
parameter points to a function that you supply and that is called by ExgDBWrite
to write out a database. For example, you might use this function to call exchange manager functions to beam the database to another unit.
ExgDBWrite
. In the sizeP
parameter, ExgDBWrite
passes the number of bytes in dataP
. Due to transport errors, timeouts, or other problems, you may not be able to successfully send all this data. If the write callback function didn't handle it all, it's important that it set in sizeP
the number of bytes that it did handle successfully. ExgDBWrite
stops calling the write callback function after you write out the entire database (it knows when you've done it all based on the header information and number of bytes you return in sizeP
each time).
ExgDBRead
Err ExgDisconnect(ExgSocketPtr socketP, Err error)
  |
-> |
Pointer to the socket structure identifying the connection to terminate. |
  |
-> |
Any application error that occurred. |
error
parameter, pass any error that occurs during the application loop, including errors returned from other exchange manager functions. This ensures that the connection is shut down knowing that it failed rather than succeeded.
errNone
return value means that the item was delivered to the destination successfully. It does not mean that the user on the other end actually kept the data.
ExgDisconnect
is used for sending and receiving. When receiving, the application can insert its creator ID into the goToCreator
field in the socket structure and add other goto information. After the application returns from the sysAppLaunchCmdExgReceiveData
call, the system will launch the application with a standard sysAppLaunchCmdGoto
launch code built from the information in the socket header gotoParams
field.
ExgPut
,
ExgReceive
,
ExgSend
Boolean ExgDoDialog (ExgSocketPtr socketP, ExgDialogInfoType *infoP, Err *errP)
  |
-> |
Pointer to the socket structure identifying the connection. You can obtain this pointer from the sysAppLaunchCmdExgAskUser launch code parameter block. |
  |
<-> |
A pointer to an ExgDialogInfoType structure (see the "Comment" section below). |
  |
<- |
errNone if no error, or the error code if an error occurred. Currently, no errors are returned. |
true
if the user clicks the OK button on the dialog, or false
otherwise.
sysAppLaunchCmdExgAskUser
launch code or if you return exgAskDialog
from the launch code handler. When the exchange manager calls ExgDoDialog
, the dialog only displays a message similar to "Do you want to accept `John Doe' into AddressBook?" and allows the user to accept or reject the data. If the user clicks OK, the data should be received as an unfiled record.
sysAppLaunchCmdExgAskUser
to call ExgDoDialog
explicitly, and pass it a pointer to an ExgDialogInfoType
structure. The ExgDialogInfoType
structure is defined as follows:
typedef struct {
    UInt16 version;
    DmOpenRef db;
    UInt16 categoryIndex;
} ExgDialogInfoType;
  |
-> |
Set this field to 0 to specify version 0 of this structure. |
  |
-> |
Pointer to an open database that defines the categories the dialog should display. |
  |
<- |
Index of the category in which the user wants to file the incoming data. |
db
is valid, the function extracts the category information from the specified database and displays it in a pop-up list. Upon return, the categoryIndex
field contains the index of the category the user selected, or dmUnfiledCategory
if the user did not select a category.
ExgDoDialog
is successful, your application is responsible for retaining the value returned in categoryIndex
and using it to file the incoming data as a record in that category. One way to do this is to store the categoryIndex
in the socket's appData
field (see
ExgSocketType
) and then extract it from the socket in your response to the launch code
sysAppLaunchCmdExgReceiveData
. For example:
if (cmd == sysAppLaunchCmdExgReceiveData) {
    UInt16 categoryID =
    (ExgSocketPtr)cmdPBP->appData;
    /* other declarations */
/* Receive the data, and create a new record
    using the received data. indexNew is the
    index of this record. */
    if (categoryID){
    UInt16 attr;
    Err err;
    err = DmRecordInfo(dbP, indexNew, &attr,
    NULL, NULL);
    // Set the category to the one the user
    // specified, and mark the record dirty.
    if ((attr & dmRecAttrCategoryMask) !=
    categoryID) {
    attr &= ~dmRecAttrCategoryMask;
    attr |= categoryID | dmRecAttrDirty;
    err = DmSetRecordInfo(dbP, indexNew,
    &attr, NULL);
    }
    }
}
ExgDoDialog
.
ExgDoDialog
, you must set the result
field of the sysAppLaunchCmdExgAskUser
launch code's parameter block to either exgAskOk
(upon success) or exgAskCancel
(upon failure) to prevent the system from displaying the dialog a second time.
Err ExgPut (ExgSocketPtr socketP)
  |
-> |
Pointer to the socket structure containing connection information and information identifying the object to send. |
ExgSocketType
structure containing information about the data to send and the destination application. All unused fields in the structure must be zeroed.
ExgSend
, to begin sending data, or ExgDisconnect
, to disconnect. You may need to call ExgSend
multiple times to send all the data.
ExgDisconnect
,
ExgSend
UInt32 ExgReceive (ExgSocketPtr socketP, void *bufP, const UInt32 bufLen, Err * err)
  |
-> |
Pointer to the socket structure. |
  |
-> |
Pointer to the buffer to receive the data. |
  |
-> |
Number of bytes to receive. |
  |
<- |
Pointer to an error code result. |
err
. The error code exgErrUserCancel
is returned if the user cancels the operation.
ExgAccept
. After receiving the data, call ExgDisconnect
to terminate the connection.
ExgAccept
,
ExgDisconnect
Err ExgRegisterData (const UInt32 creatorID, const UInt16 id, const Char * const dataTypesP)
  |
-> |
Creator ID of the registering application. |
  |
-> |
Registry ID identifying the type of the items being registered. Specify exgRegExtensionID or exgRegTypeID . |
  |
-> |
Pointer to a tab-delimited, null-terminated string listing the items to register. (Use /t for the tab character.) These include file extensions or MIME types. To unregister, pass a NULL value. |
errNone
if successful, otherwise, one of the data manager error codes (dmErr
...).
exgRegExtensionID
to register to receive data that has a filename with a particular extension. For example, if your application wants to receive files with a .TXT extension, it could register like this:
ExgRegisterData(myCreator, exgRegExtensionID, "TXT");
ExgRegisterData(myCreator, exgRegExtensionID, "TXT/tDOC");
exgRegTypeID
to register to receive data with a specific MIME type. For example, if your application wants to receive "setext" text files, it could register like this:
ExgRegisterData(myCreator, exgRegTypeID,
"text/x-setext");
NULL
and will not match "setext." However, applications may choose to register for a type anyway because this limitation may be removed in the future.
NULL
value.
UInt32 ExgSend (ExgSocketPtr socketP, const void * const bufP, const UInt32 bufLen, Err * err)
  |
-> |
Pointer to the socket structure. |
  |
-> |
Pointer to the data to send. |
  |
-> |
Number of bytes to send. |
  |
<- |
Pointer to an error code result. |
bufLen
. An error code is returned in the address indicated by err
. The error code exgErrUserCancel
is returned if the user cancels the operation.
ExgPut
. After sending the data, call ExgDisconnect
to terminate the connection.
ExgDisconnect
,
ExgPut
ExgDBRead
and
ExgDBWrite
).
Boolean DeleteProc (const char* nameP, UInt16 version, UInt16 cardNo, LocalID dbID, void* userDataP)
  |
-> |
A pointer to the name of the identical database that already exists. |
  |
-> |
The version of the identical database that already exists. |
  |
-> |
The card number of the identical database that already exists. |
  |
-> |
The database ID of the identical database that already exists. |
  |
-> |
The userDataP parameter passed to ExgDBRead is simply passed on to the delete function. You can use it for application-specific data. |
true
means that this function handled the situation successfully; that is, it deleted, renamed, or moved the database so there would no longer be a conflict with the one that ExgDBRead
is writing. false
means that this function did not handle the situation successfully; in this case, ExgDBRead
exits with no error (same as if the user cancelled the operation).
ExgDBRead
.
Err ReadProc (void* dataP, UInt32* sizeP, void* userDataP)
  |
-> |
A pointer to a buffer where this function should place the database data. |
  |
<-> |
The size of dataP . This value is set by ExgDBRead to the number of bytes it expects to receive in dataP . You must set this value to the number of bytes you return in dataP (if it's not the same). |
  |
-> |
The userDataP parameter passed to ExgDBRead is simply passed on to the read function. You can use it for application-specific data. |
errNone
if there is no error. If this function returns an error, ExgDBRead
deletes the database it was creating, cleans up any memory it allocated, then exits, returning the error passed back from this function.
Err WriteProc (const void* dataP, UInt32* sizeP, void* userDataP)
  |
-> |
A pointer to a buffer containing the database data, placed there by ExgDBWrite . |
  |
<-> |
The number of bytes placed in dataP by ExgDBWrite . If you were unable to write out or send all of the data in this chunk, on exit, you should set sizeP to the number of bytes you did write. |
  |
-> |
The userDataP parameter passed to ExgDBWrite is simply passed on to the write function. You can use it for application-specific data. |
errNone
if there is no error. If this function returns an error, ExgDBWrite
closes the database it was reading, cleans up any memory it allocated, then exits, returning the error passed back from this function.
  |   |