void CTcpSymbianEngine::Read()
{
   __ASSERT_ALWAYS(EngineState() == EConnected, 
                   User::Panic(KEchoEngine, EReadNotConnected));
   ///if we are already active, that's not a problem.
   if ((EngineState() == EConnected) && (!iEchoRead->IsActive())) {
      iEchoRead->IssueRead();
   } else {
      ERR("Read issued while not connected ot echoread is active");
   }
}
void CTcpSymbianEngine::Query()
{
   DBG("Query");
   //TODO: keep the disconnect reasons somewhere, we can give better
   //indication that way.
   enum isab::Module::ConnectionNotify state = isab::Module::CLEAR;
   enum isab::Module::ConnectionNotifyReason reason = isab::Module::REQUESTED;
   switch(EngineState()){
   case EComplete:                                               break;
   case EConnecting:    state  = isab::Module::CONNECTING;       break;
   case EConnected:     state  = isab::Module::CONNECTED;        break;
   case ETimedOut:      state  = isab::Module::DISCONNECTING;
                        reason = isab::Module::UNSPECIFIED;      break;
   case ELinking:       state  = isab::Module::CONNECTING;       break;
   case ELinkFailed:    state  = isab::Module::DISCONNECTING;
                        reason = isab::Module::TRANSPORT_FAILED; break;
   case ELookingUp:     state  = isab::Module::CONNECTING;       break;
   case ELookUpFailed:  state  = isab::Module::DISCONNECTING;
                        reason = isab::Module::LOOKUP_FAILED;    break;
   case EConnectFailed: state  = isab::Module::DISCONNECTING;
                        reason = isab::Module::NO_RESPONSE;      break;
   case EClosing:       state  = isab::Module::DISCONNECTING;
                        reason = isab::Module::REQUESTED;        break;
   case EBroken:        state  = isab::Module::DISCONNECTING;
                        reason = isab::Module::CHANNEL_FAILED;   break;
   case ESwitching:     state  = isab::Module::CONNECTING;
                        reason = isab::Module::REQUESTED;        break;
   case EClosed:        state  = isab::Module::DISCONNECTING;
                        reason = isab::Module::BY_PEER;   break;
   }
   iConsole.ConnectionNotify(state, reason);
}
void CTcpSymbianEngine::DoCancel()
   // Cancel asychronous requests
{
   DBG("DoCancel");
   iTimer->Cancel();
   // Cancel appropriate request to socket
   //XXX handle bad opens!
   switch (EngineState()){
   case EConnecting:
      DBG("While EConnecting");
      iEchoSocket.CancelConnect();
      break;
   case ELookingUp:
      DBG("While ELookingUp");
      // Cancel look up attempt
      iResolver.Cancel();
      iResolver.Close();
      break;
   case ELinking:
      DBG("While ELinking");
      CloseLinkLayer();
      break;
   case EClosing:
      DBG("While EClosing");
      break;
   default:
      ERR("PANIC KEchoEngine, EBadCancelStatus (%d)", TInt(EBadCancelStatus));
      User::Panic(KEchoEngine, EBadCancelStatus);
      break;
   }
   DBG("DoCancel comnplete");
}
void CTcpSymbianEngine::Write(HBufC8* aData)
{
   if(EngineState() != EConnected || iEchoWrite->IsActive()){
      ERR("EngineState: %d, Echowrite is %sactive", EngineState(), iEchoWrite->IsActive() ? "": "not");
   }
   __ASSERT_ALWAYS(EngineState() == EConnected, 
                   User::Panic(KEchoEngine, EWriteNotConnected));
   __ASSERT_ALWAYS(!iEchoWrite->IsActive(), 
                   User::Panic(KEchoEngine, EWriteActive));
   //we should never get here unless CTcpSymbianEngine is ready for
   //another write.  See assertations above.
   if ((EngineState() == EConnected) && !iEchoWrite->IsActive()){
      iEchoWrite->IssueWrite(aData);
   } else {
      ERR("Write issued while not connected or echowrite is active");
   }
}
Пример #5
0
void Rocket::update(float deltaSec) {
    Projectile::update(deltaSec);

    if (m_aiTask) {
        m_aiTask->update(deltaSec);
        m_boardComputer.update(deltaSec);
    } else {
        components().setEngineState(EngineState(
            glm::vec3(0, 0, -1),
            glm::vec3(0, 0, 0)
            ));
    }
}
void CTcpSymbianEngine::ConnectL()
{
   DBG("ConnectL()");
   if(EngineState() == EComplete){
      iConsole.ConnectionNotify( isab::Module::CONNECTING,
                                 isab::Module::REQUESTED );
      OpenLinkLayerL(); //setactive here
   } else {
      DBG("Do nothing, but handle the next request.");
      if(!IsActive()){ //don't think this is needed
         DBG("Signal OperationComplete");
         iConsole.OperationComplete();
      } else {
         WARN("This was unexpected!");
      }
   }   
}
void CTcpSymbianEngine::Stop(enum TEchoEngineState aState)
{
   enum TEchoEngineState state = EngineState();
   DBG("Stop, Enginestate: %d, aState: %d", state, aState);
   if(state != EComplete){
      iConsole.BlockEvents();
   }
   switch (state){
   case EConnected:
      // Stop live connection
      iEchoRead->Cancel();
      iEchoWrite->Cancel();
      SetEngineState(aState);
      iEchoSocket.Shutdown(RSocket::EImmediate, iStatus);
      SetActive();
      iTimer->After(iTimeOut);
      break;
   case EConnecting:
   case ELookingUp:
   case ELinking:
      // if request to CTcpSymbianEngine, then stop it
      Cancel();
      break;
   case ESwitching:
      SetEngineState(EClosing);
      break;
   case EClosing:
      ///already closing. 
      break;
   case EComplete:
      //all set.
      if(!IsActive()){
         DBG("Signal OperationComplete");
         iConsole.OperationComplete();
         DBG("Signaled OperationComplete");
      }
      break;
   default:
      ERR("PANIC KEchoEngine EBadEngineStopState (%d)", EBadEngineStopState);
      User::Panic(KEchoEngine, EBadEngineStopState);
      break;
   }
}
void CTcpSymbianEngine::ConnectL(const TDesC& aServerName, TUint aPort, 
                                 TInt aIAP, TBool aConsiderWLAN)
{
   DBG("ConnectL(HOST, %u, %d)", aPort, aIAP);
   //see if state is EComplete. used several times below
   const TBool stateComplete = (EngineState() == EComplete);
   //The changeServer variable indicates that we must close the
   //current connection and open a new one.
   const TBool changeServer = !stateComplete && iHostName && 
      (*iHostName != aServerName || iPort != aPort);
   DBG("stateComplete: %d, changeServer: %d", stateComplete, changeServer);
   if(changeServer){
      WARN("Switching server, danger will robinson");
      Stop(ESwitching);
      SetConnectionParamsL(aServerName, aPort, aIAP, aConsiderWLAN);      
   } else {
      DBG("No need to change server");
      if(stateComplete){
         DBG("update params");
         SetConnectionParamsL(aServerName, aPort, aIAP, aConsiderWLAN);
      } 
      ConnectL();
   }
}
void CTcpSymbianEngine::RunL()
{
   DBG("RunL, EngineState: %d, iStatus: %d", EngineState(), iStatus.Int());
   iTimer->Cancel(); // Cancel TimeOut timer before handling completion
   switch(EngineState()){
   case EConnecting:
      // IP connection request
      if (iStatus == KErrNone){
         DBG("Connection completed Ok");
         // Connection completed sucessfully   
         iConsole.ConnectionNotify(isab::Module::CONNECTED,
                                    isab::Module::REQUESTED);
         SetEngineState(EConnected);
         Read(); //Start CTcpSymbianRead Active object
      } else {
         WARN("Unable to connect, removing host from cache.");
         iDNSCache.Remove(*iHostName);
         if (iStatus == KErrCouldNotConnect){
            ResetL(EConnectFailed, isab::Module::NO_RESPONSE);
         } else if (iStatus == KErrTimedOut) {
            ResetL(ETimedOut, isab::Module::NO_RESPONSE);
         } else{
            WARN("EConnectFailed, INTERNAL_ERROR");
            ResetL(EConnectFailed, isab::Module::INTERNAL_ERROR);
            //XXX handle the different cases
         }
      }
      break;
   case ELookingUp:
      iResolver.Close();
      if (iStatus == KErrNone) {
         DBG("Name lookup ok");
         // DNS look up successful
         // Extract domain name and IP address from name record
         class TInetAddr addr = TInetAddr::Cast(iNameEntry().iAddr);
         //cache the ip for later.
         TInt cacheStat = iDNSCache.CacheHost(*iHostName, addr.Address());
         DBG("Host cached with result %d", cacheStat);
         cacheStat = cacheStat;
         // And connect to the IP address
         Connect(addr.Address(), iPort); //setactive here
      } else { //includes KErrTimedOut
         WARN("Lookup failed");
         ResetL(ELookUpFailed, isab::Module::LOOKUP_FAILED);
      }
      break;
   case ELinking:
      if(iStatus == KErrNone){
         DBG("Link layer setup ok");
         OpenSocketL();  //cannot open socket until here. We need RConnection.
         StartLookupL(); //setactive here
      } else { //includes KErrCanceled and KErrTimedOut
         WARN("Link layer setup failed");
         ResetL(ELinkFailed, isab::Module::TRANSPORT_FAILED);
      }
      break;
   case EBroken:
      DBG("Broken");
      ResetL( EngineState(), isab::Module::CHANNEL_FAILED );
      break;
   case EClosing:
      if(iStatus == KErrNone){
         DBG("Closing ok");
         ResetL(EComplete, isab::Module::REQUESTED);
      } else if(iStatus == KErrTimedOut){
         ResetL(ETimedOut);
      } else {
         ResetL(EngineState());
         //XXX ???
      }
      break;
   case ESwitching:
      if(iStatus == KErrNone){
         //the connection has been closed, start a new connection
         //using the values in iHostName, iPort, and iIAP.
         SetEngineState(EComplete);
         ConnectL();
      } else if(iStatus == KErrTimedOut){
         ResetL(ETimedOut);
      } else {
         ResetL(EngineState());
      }
      break;
   case EClosed:
      DBG("Closed");
      ResetL( EngineState(), isab::Module::BY_PEER );
      break;
   default:
      ERR("PANIC KEchoEngine EBadEngineState (%d)", TInt(EBadEngineState));
      User::Panic(KEchoEngine, EBadEngineState);
      break;
   };
   if(!IsActive()){
      DBG("Signal OperationComplete");
      iConsole.OperationComplete();
      DBG("Signaled OperationComplete");
   }
}
TBool CTcpSymbianEngine::IsConnected()
{
   return EngineState() == EConnected;
}