Developer

API Reference

IBTOPPServer

Brew Release
Brew MP 1.0.2
See Also
Description

This interface enables the server role of Object Push profile as defined by the Bluetooth SIG.
Application must provide a security level, the server name, and a bitmap of supported formats when enabling OPP server. Once enabled, OPP server is ready to accept connection requests from potential OPP clients.
When responding to a connection request, application must indicate whether or both Push and Pull operations are allowed. If both operations are disallowed, the connection would not get established. Each OPP server object is designed to handle only one connection at a time.
Once a connection is set up, client can send Push request, or Pull request. While client can push multiple types of objects, the only object it can pull from server is the server's default object which, by Bluetooth OPP specification, is a vCard.
Also, by specification, there can be only one operation at a time.

Usage

Usage example:



 
   ===== To create an IBTOPPServer object, see instruction in class header file
 
 
   ===== To register signal
   // first create the signals;
   // for example, use ISignalCBFactory_CreateSignal()
   // then register the signals:
   IBTOPPServer_OnEventNotify (piBTOPPSrv, piSignal);
 
 
   ===== To enable OPP server:
   IBTOPPServer_Enable (piBTOPPSrv, AEEBT_SEC_NONE, "V-Card Only",
                        (AEEBT_OBEX_FORMAT_VCARD_2_1 |
                         AEEBT_OBEX_FORMAT_VCARD_3_0));
 

   ===== To retrieve and handle events when Event signal is triggered:
   while (IBTOPPServer_GetEvent (piBTOPPSrv, &eventData) != AEE_ENOMORE)
   {
      IFilePort1* piTempFile;

      switch (eventData.cEvent)
      {
         case AEEBTOPPSVR_EV_ENABLED:
         case AEEBTOPPSVR_EV_DISABLED:
            // check eventData.cResult to see if it was successful
            break;

         case AEEBTOPPSVR_EV_CONNECT_REQ:
            // eventData.bdAddr tells who the client is
            // prompt user "OPP conn req from JohnsPhone.
            // Accept push? Accept pull?"
            // say, user allows Pull but disallows Push:
            IBTOPPServer_AcceptConnection (piBTOPPSrv, FALSE, TRUE);
            break;
 
         case AEEBTOPPSVR_EV_PULL_REQ:
            // prompt user "Give JohnsPhone your business card?"
            if (FALSE == bUserAccept)
            {
               IBTOPPServer_AcceptPull (piBTOPPSrv, NULL, 0, NULL, 
                                        "text/x-vcard", 0);
            }
            else
            {
               FSStat stat;
               int nLen = IFileSystem1_Stat (piFileSys, 
                                             pszFileName, // business card file
                                             &stat, sizeof(FSStat));
               IFileSystem1_Open (piFileSys, AEECLSID_FilePort1,
                                  pszFileName, FS_CAP_RDONLY, 
                                  (void**) &piTempFile);
               if (NULL != piTempFile)
               {
                  if (TEMP_BUF_SIZE < nLen)
                  {
                     IBTOPPServer_AcceptPullFromPort (
                        piBTOPPSrv, 
                        (IPort1*)piTempFile,
                        stat.dwSize, 
                        DEFAULT_OBJ_NAME,
                        "text/x-vcard",
                        100); // 100 = at least 100 bytes sent
                              // between 2 consecutive progress reports
                  }
                  else
                  {
                     IFilePort1_Read (piTempFile, tempBuf, 
                                      TEMP_BUF_SIZE, &nLen); 
                     IBTOPPServer_AcceptPull (
                        piBTOPPSrv, 
                        tempBuf,
                        nLen,
                        DEFAULT_OBJ_NAME,
                        "text/x-vcard",
                        0); // don't care since it's not much data
                  }
                  IFilePort1_Release (piTempFile);
               }
            }
            break;
 
         case AEEBTOPPSVR_EV_PUSH_REQ:
            int nLen = eventData.objInfo.uObjNameLen;
            int nTypeLen = eventData.objInfo.uTypeStrLen;
            _wchar_t* pwName = MALLOC (sizeof(_wchar_t) * nLen);
            char* pszType = MALLOC (nTypeLen);
            if (NULL != pwName)
            {
               IBTOPPServer_GetObjectName (piBTOPPSrv, pwName, nLen, &nLen);
            }
            if (NULL != pszType)
            {
               IBTOPPServer_GetObjectType (piBTOPPSrv, pszType, nTypeLen, 
                                           &nTypeLen);
               // perhaps app can verify whether the contents of the object
               // conform to this MIME type, or decide whether it would accept
               // objects of this MIME type
            }

            // say the object name is "john_smith.vcf"
            // prompt user "Accept john_smith.vcf from JohnsPhone?"
            if (FALSE == bUserAccept)
            {
               IBTOPPServer_AcceptPush (piBTOPPSrv, 0, 0);
            }
            else if (TEMP_BUF_SIZE < eventData.objInfo.nBytes)
            {
               // open an IPort1 object; we use IFileSystem1 in this example
               IFileSystem1_Open (piFileSys, AEECLSID_FilePort1,
                                  pszFileName,
                                  FS_CAP_CREATE FS_CAP_RDWR, 
                                  (void**) &piTempFile);
               // pszFileName may be something like "fs:/rxFile/johnSmith.vcf"
               if (NULL != piTempFile)
               {
                  IBTOPPServer_AcceptPushIntoPort (
                     piBTOPPSrv, 
                     (IPort1*) piTempFile,
                     1000); // at least 1000 bytes received
                            // between 2 consecutive progress reports
                  IFilePort1_Release (piTempFile);
               }
            }
            else // use a temp buf for short data
            {
               IBTOPPServer_AcceptPush (
                  piBTOPPSrv, 
                  eventData.objInfo.nBytes,
                  0); // don't care since it's not much data
            }
            break;

         case AEEBTOPPSVR_EV_PULL_RSP_COMPLETE:
            // check eventData.cResult to see if it was successful
            // eventData.uBytes tells how much data was sent
            break;

         case AEEBTOPPSVR_EV_PUSH_RSP_COMPLETE:
            // check eventData.cResult to see if it was successful
            // eventData.uBytes tells how much data was received
            IBTOPPServer_GetPushedData (
               0, // start from 1st byte
               piBTOPPSrv, 
               pTempBuf,
               TEMP_BUF_SIZE,
               &nReqSize);
            break;

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

         case AEEBTOPPSVR_EV_EVENT_Q_OVERFLOW:
            // eventData.nDroppedEvents tells how many events got dropped
            // since previous GetEvent()
            break;
      }
   }
   ISignalCtl_Enable (piSignalCtl); // re-enable signal
 
 
   ===== When done with OPP server:
   IBTOPPServer_ForceDisconnect (piBTOPPSrv);
   IBTOPPServer_Disable (piBTOPPSrv);
   IBTOPPServer_Release (piBTOPPSrv);

   

  • Follow