Handling Callback Methods

Context

When an application is registered to listen to the LLCP-link status, CLlcpProvider calls the MLlcpLinkListener::LlcpRemoteFound() method when two NFC-enabled devices with LLCP support are placed together and the MLlcpLinkListener::LlcpRemoteLost() method when the devices are separated. When the MLlcpLinkListener::LlcpRemoteFound() method is called, the data transfer is possible between the local and the remote devices.

Steps

  • Create a connection-object between the local and remote devices to send the "Hello World!" ASCII text.

    1. The following code snippet illustrates how CMyOwnLlcpApplication::LlcpRemoteFound is implemented:

      // CMyOwnLlcpApplication::LlcpRemoteFound()
      // From MLlcpLinkListener
      // -----------------------------------------------------------------------------
      //
      void CMyOwnLlcpApplication::LlcpRemoteFound()
          {
          TInt error = KErrNone;
          MLlcpConnOrientedTransporter* conn = NULL;
          
          // Notify the UI
          iLLcpEventUpdater->DrawLlcpRemoteFound();
          
          if ( !iLocalConnection )
              {
              // Create the  MLlcpConnOrientedTransporter object.
              TRAP( error, conn = iLlcp->CreateConnOrientedTransporterL( KInterestingSsap ) );
              
              if ( error == KErrNone )
                  {
                  // Create a wrapper for the connection. 
                  TRAP( error, iLocalConnection = COwnLlcpConnection::NewL( conn ) );
                  
                  if ( error != KErrNone )
                      {
                      delete conn;
                      }
                  }
              }
          }
      // -----------------------------------------------------------------------------
      // End of CMyOwnLlcpApplication::LlcpRemoteFound()
      
      

      Note: CLlcpProvider does not deallocate any memory block related to the MLlcpConnOrientedTransporter object. Clients can remove the MLlcpConnOrientedTransporter object at any time.

    2. The following code snippet illustrates how the CMyOwnLlcpApplication::LlcpRemoteLost method is implemented. When this method is called, the data transfer between the local and the remote devices stops, and all existing MLlcpConnOrientedTransporter objects are removed.

      // CMyOwnLlcpApplication::LlcpRemoteLost()
      // From MLlcpLinkListener
      // -----------------------------------------------------------------------------
      //
      void CMyOwnLlcpApplication::LlcpRemoteLost()
          {    
          Cleanup();
          
          // Notify the UI.
          iLLcpEventUpdater->DrawLlcpRemoteLost();
          }
      // -----------------------------------------------------------------------------
      // End of CMyOwnLlcpApplication::LlcpRemoteLost()