Logo Search packages:      
Sourcecode: kmess version File versions  Download package

void P2PApplication::gotDataPreparation ( const P2PMessage message  )  [private]

Called when the data preparation message is received

Definition at line 566 of file p2papplication.cpp.

References sendP2PAck().

Referenced by gotMessage().

{
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: Got the data preparation message" << endl;
#endif


  // Only if the user starts the invitation,
  // the other contact should send a data preparation message
  if(! isUserStartedApp())
  {
    kdWarning() << "P2PApplication: P2P message can't be handled, "
                << "unexpected data preparation message (contact=" << contactHandle_ << ")." << endl;

    // Got an data-preparation message, but didn't expect it.
    shouldSendAck_ = true;  // ASSERT in sendP2PAck would fail otherwise
    sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
    endApplication( i18n("The transfer failed.  The contact sent bad data, or KMess doesn't support it.") );
    return;
  }


#ifdef KMESSTEST
  ASSERT( shouldSendAck_ );
  ASSERT( waitingState_ == P2P_WAIT_FOR_PREPARE );
#endif


  // The userStarted3_UserPrepares() method should call
  // sendDataPreparationAck() or sendCancelMessage()
  // to reset "userShouldAcknowledge_"
  shouldSendAck_         = true;
  userShouldAcknowledge_ = true;


  // Dispatch to the derived class
  userStarted3_UserPrepares();


  // ACK still wasn't sent yet, determine now what to send:
  if(userShouldAcknowledge_)
  {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Data preparation failed, sending reject" << endl;
#endif

    // Derived class still didn't acknowledge or cancel at all
    // (both disable userShouldAcknowledge_). This shouldn't occur!

    // Reject the data-preparation message
    sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
    endApplication( i18n("The transfer failed.  Data preparation failed.") );
    return;
  }


  // Little API trick:
  // If the user didn't acknowledge,
  // but we no longer have to send an ack any more (sendDataPreparationAck() doesn't send it!),
  // it must have been sendCancelMessage(CANCEL_SESSION) calling sendP2PAck(P2PMessage::MSN_FLAG_ERROR).
  if(! shouldSendAck_)
  {
    // No error message here, assume your derived class already displayed something.
    endApplication();
    return;
  }


  // User did acknowledge, we can send the *actual* ACK now.
  // sendDataPreparationAck() only sets a boolean, so we can do the actual stuff here
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: Data preparation successful, sending ACK" << endl;
#endif

  sendP2PAck();


  // If data preparation was successful, wait for the data to arrive
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: Waiting for file data to arrive..." << endl;
#endif

  waitingState_ = P2P_WAIT_FOR_FILE_DATA;
  waitingTimer_->start(30000, true); // 30 sec
}


Generated by  Doxygen 1.6.0   Back to index