Paul,
You have found the trickiest part of coding for the exchange manager. Your
app can be called with sysAppLaunchCMDExgReceiveData when it is open or
when it is closed. If your app is already open, you can reference global
variables from this call. So if you store the open database reference in a
global, you can simply reference that global in this call. If your app is
not open, you cannot reference the global at all since it does not exist.
In that case, you need to open the database in the call (you know it is not
already open because your app is not open). So the most important thing to
know is whether your app is currently running or not. You can do this with
the following code (taken from addressbook address.c):
case sysAppLaunchCmdExgReceiveData:
{
DmOpenRef dbP;
// if our app is not active, we need to open the database
// the subcall flag is used here since this call can be made without
launching the app
if (!(launchFlags & sysAppLaunchFlagSubCall))
{
dbP = DmOpenDatabaseByTypeCreator (addrDBType, sysFileCAddress,
dmModeReadWrite);
}
else
dbP = AddrDB; // AddrDB is a global variable from this app
if (dbP != NULL)
{
error = AddrReceiveData(dbP, (ExgSocketPtr) cmdPBP);
if (!(launchFlags & sysAppLaunchFlagSubCall))
error = DmCloseDatabase(dbP); // close the database if we
opened it
}
}
break;
Also note that any function you call from this code must not reference
global variables. Any such data should be passed as parameters to the
functions called.
---Gavin
>Date: 24 May 1999 21:47:11 -0700
>From: Paul Gargan <[EMAIL PROTECTED]>
>Subject: Opening databases during Sub-Call?
>I'm trying to implement rudimentary support for beaming using the Exchange
>Manager. In my PilotMain I evaluate the launch command and act
accordingly.
>When I catch sysAppLaunchCmdExgReceiveData I need to open my database to
>store the incoming data. Chances are it's open already - at the moment I'm
>testing using loopback so it's guaranteed to be open already.
>But I need to get a reference to it, so I call
DmOpenDatabaseByTypeCreator,
>passing it dmModeReadWrite as the mode to open it in.
>For some reason it's failing - returning a NULL DmOpenRef. Calling
>DmGetLastErr reports 0x216, which seems to correspond to
>dmErrAlreadyOpenForWrites (dmErrorClass | 22).
>2. If I must open it exclusively, is there any way of getting a DmOpenRef
to
>the already open database, ie the "main" instance?
>3. When exiting from PilotMain after handling
sysAppLaunchCmdExgReceiveData,
>should I close the database? I'd imagine so, if I've opened it twice so to
>speak, but at the moment I can only open it once!