Developer

API Reference

IBTOPPClient

Brew Release
Brew MP 1.0.2
See Also
Description
This interface enables the client role of Object Push profile as defined by the Bluetooth SIG.
To connect to an OPP server, OPP client app needs to provide the Bluetooth address of the server, and a minimum security level to be applied on the connection.
Once a connection is set up, client can send Object Push request, Business Card Pull request, or Business Card Exchange request to server.
Usage

Usage example:



 
   ===== To create an IBTOPPClient object, see instruction in class header file

 
   ===== To register signal
   // first create the signals;
   // for example, use ISignalCBFactory_CreateSignal()
   // then register the signals:
   IBTOPPClient_OnEventNotify (piBTOPPCli, piSignal);
 
 
   ===== To find out what formats the server supports:
   IBTOPPClient_GetServerSupportedFormat (piBTOPPCli, bdAddrOfSrv, 0);


   ===== To get the server's default business card:
   IFilePort1* piTempFile = NULL;
   IFileSystem1_Open (piFileSys, AEECLSID_FilePort1,
                      pMe->pwObjName, // name of server's business card
                      FS_CAP_RDWR FS_CAP_CREATE, 
                      (void**) &piTempFile);
   if (NULL != piTempFile)
   {
      IBTOPPClient_Pull (piBTOPPCli, bdAddrOfSrv,
                         uServerChannel, // retrieved via IBTServiceDiscovery
                         AEEBT_SEC_SM4_LOW, 
                         100, // report every 100 bytes
                         0,   // connection goes down as soon as Pull completes
                         (IPort1*) piTempFile);
      IFilePort1_Release (piTempFile);

      // when PULL_COMPLETE with success, the file should 
      // contain the server's business card
   }


   ===== To push own business card to OPP server:
   // first get your business card into a byte array; 
   // here's an example of how to do that
   char* pszBuf = NULL;
   int nBufSize = 0;
   IvCard* pivCard = GetMyCard();
   if (NULL != pivCard)
   {
      IvObject* pivObject = IvCard_To_IvObject (pivCard);
      IvObjectParser_GetBufferFromIvObject (pIvObjectParser,
                                            pivObject,
                                            pszBuf, nBufSize, &nBufSize);
      pszBuf = MALLOC (nBufSize);
      if (NULL != pszBuf)
      {
         IvObjectParser_GetBufferFromIvObject (pIvObjectParser,
                                               pivObject,
                                               pszBuf, nBufSize, &nBufSize);
      }
   }

   // now push the data from the byte array to server
   if (NULL != pszBuf)
   {
      IBTOPPClient_PushBytes (piBTOPPCli, bdAddrOfSrv, 
                              0, // server channel unknown
                              AEEBT_SEC_SM4_MED,
                              0, // I don't care to know the progress
                              1, // 1 second idle time
                              "text/x-vCard,
                              "James' Business Card",
                              pszBuf, nBufSize);
   }

   ===== To cancel this operation
   IBTOPPClient_Cancel (piBTOPPCli);


   ===== To push a picture to OPP server:
   IFilePort1* piTempFile = NULL;
   IFileSystem1_Open (piFileSys, AEECLSID_FilePort1,
                      pszFileName,
                      FS_CAP_RDONLY, 
                      (void**) &piTempFile);
   if (NULL != piTempFile)
   {
      FSStatEx stat;
      IFilePort1_Stat (piTempFile, &stat);
      IBTOPPClient_Push (piBTOPPCli, bdAddrOfSrv, 
                         0, // server channel unknown
                         AEEBT_SEC_SM4_MED,
                         0, // I don't care to know the progress
                         1, // 1 second idle time
                         "image/jpeg",
                         pszFileName,
                         (IPort1*)piTempFile,
                         stat.qwSize);

      IFilePort1_Release (piTempFile);
   }


   ===== To retrieve and handle events when Event signal is triggered:
   while (IBTOPPClient_GetEvent (piBTOPPCli, &eventData) != AEE_ENOMORE)
   {
      switch (eventData.cEvent)
      {
         case AEEBTOPPCLI_EV_CONNECTED:
         case AEEBTOPPCLI_EV_DISCONNECTED:
            // eventData.connInfo tells who the server is
            break;

         case AEEBTOPPCLI_EV_FORMATS_AVAIL:
            // eventData.cFormats tells what server supports
            break;

         case AEEBTOPPCLI_EV_PULL_COMPLETE:
         case AEEBTOPPCLI_EV_PUSH_COMPLETE:
            // check eventData.cResult to see result of operation
            // eventData.uBytes tells how much data has been sent/received
            break;

         case AEEBTOPPCLI_EV_FORMATS_UNAVAIL:
            // check eventData.cResult to see result of operation
            break;

         case AEEBTOPPCLI_EV_PULL_PROGRESS:
         case AEEBTOPPCLI_EV_PUSH_PROGRESS:
            // eventData.uBytes tells how much data has been sent/received
            break;

         case AEEBTOPPCLI_EV_EVENT_Q_OVERFLOW:
            // eventData.nDroppedEvents tells how many events got dropped
            // since previous GetEvent()
            break;
      }
   }
   ISignalCtl_Enable (piSignalCtl); // re-enable signal
 
   
  • Follow