On Fri, 21 Apr 2000 15:03:24 -0700, <[EMAIL PROTECTED]> wrote:

>Hi there,
>     I've been racking my brain trying to get a ReadProc which will work when
>receiving a database which has been sent via ExgDBWrite.  Does anyone have
>any suggestions where I might find some sample code for a viable ReadProc?
>Thanks,
>                             Chris Gilmore


I just happen to have some.  I also have a vague recollection of having seen some more 
authorative sample code on the Web somewhere, but at the moment, can't find it.

Note that the following is actually C++ code, though it could clearly just as easily 
be plain C.  showError() is a trivial error-reporting function, not shown.

If some expert out there sees anything wrong with the code or comments here, we would 
all appreciate comment.



//  FUNCTION:       receiveBeam
//
//  The application has been launched in order to respond to Exchange
//  Manager input (beamed data).  It should be a database for our app,
//  which we will duly receive and write out.
//
void
receiveBeam(ExgSocketType* pSocket, UInt16 launchFlags)
{
     //  There's a launchFlags bit that tells us whether we were already
     //  active at the time the beam came in. We can't receive a
     //  database under those circumstances, as it will very likely land
     //  on top of the currently open database.  But also note that,
     //  when that flag *isn't* set, our global variables are not
     //  available.
     //
     if (launchFlags & sysAppLaunchFlagSubCall) {
         showError("Can't receive a database when application is running");
         return;
     }
     ASSERT(pSocket != NULL);

     //  ExgDBRead does essentially everything.
     //
     LocalID whoCaresWhatDBID;
     Boolean noDontReset;
     if (ExgDBRead(
             exgReadProc,        
             exgDeleteProc,
             pSocket,
             &whoCaresWhatDBID,
             0,                  // Card number
             &noDontReset,           
             true) != 0)
     {
         showError("Failed to create beamed database");
     }
}

//  Function:       exgReadProc
//
//  The ReadProc for receiveBeam.  See documentation of ExgDBRead.
//
Err
exgReadProc(void* pData, UInt32* pSize, void* pUserData)
{
     ExgSocketType* pSocket = static_cast<ExgSocketType*>(pUserData);
     Err e;
     *pSize = ExgReceive(pSocket, pData, *pSize, &e);
     return e;
}

//  Function:       exgDeleteProc
//
//  The DeleteProc for receiveBeam.  See documentation of ExgDBRead.
//
//  In contrast to exgReadProc, there's room in this function for the
//  exercise of some intelligence.  We forgo that opportunity and
//  simply do our best to delete the existing database.
//
Boolean
exgDeleteProc(const char* /*pName*/, UInt16 /*version*/, UInt16 cardNo,
     LocalID dbID, void* /*pUserData*/)
{
     if (DmDeleteDatabase(cardNo, dbID) == 0)
         return true;
     else {
         showError("Unable to delete existing database");
         return false;
     }
}


--Greg Lutz


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to