Ejemplo n.º 1
0
void XMPPStream::onAuthReply (const XMLChunk & chunk) {
	if (chunk.name() == "success"){
		finishOp (XMO_Authenticate, NoError);
		return;
	}
	finishOp (XMO_Authenticate, error::AuthError);
}
Ejemplo n.º 2
0
void XMPPStream::onXmlStreamStateChange () {
	XMLStreamDecoder::State s = mXmlStreamDecoder.state();
	if (s == XMLStreamDecoder::XS_ReadXmlBegin) return; // ignore
	if (s == XMLStreamDecoder::XS_ReadOpener) {
		if (mState == XMS_StartInitializing) {
			if (!decodeStreamInit()) {
				finishOp (XMO_StartInitialize, mError);
				return;
			}
			mState = XMS_Initialized;
			finishOp (XMO_StartInitialize, NoError);
			return;
		} else
		if (mState == XMS_RespondInitializing) {
			if (!decodeStreamInit()){
				finishOp (XMO_RespondInitialize, mError);
				return;
			}
			sendStreamInit();
			mState = XMS_Initialized;
			finishOp (XMO_RespondInitialize, NoError);
		} else {
			onChannelError (error::BadProtocol);
		}
	}
	if (s == XMLStreamDecoder::XS_Closed) {
		mState = XMS_End;
		if (mClosed)
			xcall (mClosed);
	}
}
Ejemplo n.º 3
0
void XMPPStream::onStartTlsReply (const XMLChunk & chunk) {
	if (chunk.name() == "proceed"){
		finishOp (XMO_RequestTls, NoError);
		return;
	}
	Log (LogWarning) << LOGID << "Could not request TLS: " << chunk << std::endl;
	finishOp (XMO_RequestTls, error::NotSupported);
}
Ejemplo n.º 4
0
void XMPPStream::onXmlChunkRead (const XMLChunk & chunk) {
	if (mNextChunkHandler){
		mNextChunkHandler (chunk);
		mNextChunkHandler.clear();
		return;
	}

	if (chunk.name() == "stream:features") {
		if (mReceivedFeatures) {
			Log (LogWarning) << LOGID << "Double receive features!" << std::endl;
		}
		mFeatures         = chunk;
		mReceivedFeatures = true;
		finishOp (XMO_WaitFeatures, NoError);
		return;
	} else
	if (chunk.name() == "iq") {
		xmpp::Iq iq;
		bool suc = iq.decode(chunk);
		if (!suc) {
			Log (LogWarning) << LOGID << "Could not decode " << chunk << std::endl;
			return;
		}
		String id = chunk.getAttribute("id");
		if (id.empty()){
			Log (LogWarning) << LOGID << "Received empty id in iq" << std::endl;
		}

		OpenIqMap::iterator i = mOpenIqs.find (id);
		if (i != mOpenIqs.end()){
			IqResultCallback cb = i->second;
			mOpenIqs.erase(i); // make this behaviour selectable?
			if (cb){
				notifyAsync (cb, NoError, iq, chunk);
			} else {
				Log (LogInfo) << LOGID << "Ignoring iq reply as there is no callback set (id=" << iq.id << ")" << std::endl;
			}
		} else {
			if (mIncomingIq) {
				notifyAsync (mIncomingIq, iq, chunk);
			} else {
				Log (LogWarning) << LOGID << "No iq handler set!" << std::endl;
			}
		}
	} else
	if (chunk.name() == "message") {
		xmpp::Message m;
		bool suc = m.decode(chunk);
		if (!suc) {
			Log (LogWarning) << LOGID << "Could not decode message " << chunk << std::endl;
			return;
		}
		notifyAsync (mIncomingMessage, m, chunk);
	} else
	if (chunk.name() == "presence") {
		xmpp::PresenceInfo p;
		bool suc = p.decode(chunk);
		if (!suc) {
			Log (LogWarning) << LOGID << "Could not decode presence " << chunk << std::endl;
			return;
		}
		notifyAsync (mIncomingPresence, p, chunk);
	} else
	if (chunk.name() == "stream:error"){
		String text = chunk.getChild("text").text();
		if (mIncomingStreamError){
			notifyAsync (mIncomingStreamError, text, chunk);
		} else {
			Log (LogWarning) << LOGID << "Discarding incoming stream error, no delegate " << text << std::endl;
		}
	} else {
		Log (LogWarning) << LOGID << "Unknown chunk type " << chunk << std::endl;
	}
}
bool mitk::CoordinateSupplier::ExecuteAction(Action* action, mitk::StateEvent const* stateEvent)
{
    bool ok = false;

    const PositionEvent* posEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());

    PointOperation* doOp=NULL;
    if(posEvent!=NULL)
    {
      ScalarType timeInMS = 0;
      if(stateEvent->GetEvent()->GetSender()!=NULL)
      {
        timeInMS = stateEvent->GetEvent()->GetSender()->GetTime();
      }
      else
      {
        itkWarningMacro(<<"StateEvent::GetSender()==NULL - setting timeInMS to 0");
      }

      switch (action->GetActionId())
      {
        case AcNEWPOINT:
        {
          if (m_Destination == NULL)
            return false;
          m_OldPoint = posEvent->GetWorldPosition();

          doOp = new mitk::PointOperation(OpADD, timeInMS, m_OldPoint, 0);
          //Undo
          if (m_UndoEnabled)
          {
            PointOperation* undoOp = new PointOperation(OpDELETE, m_OldPoint, 0);
            OperationEvent *operationEvent = new OperationEvent( m_Destination, doOp, undoOp );
            m_UndoController->SetOperationEvent(operationEvent);
          }
          //execute the Operation
          m_Destination->ExecuteOperation(doOp);

          if (!m_UndoEnabled)
            delete doOp;

          ok = true;
          break;
        }
        case AcINITMOVEMENT:
        {
          if (m_Destination == NULL)
            return false;
          //move the point to the coordinate //not used, cause same to MovePoint... check xml-file
          mitk::Point3D movePoint = posEvent->GetWorldPosition();

          mitk::PointOperation doPointOp(OpMOVE, timeInMS, movePoint, 0);
          //execute the Operation
          m_Destination->ExecuteOperation(&doPointOp);
          ok = true;
          break;
        }
        case AcMOVEPOINT:
        case AcMOVE:
        {
          mitk::Point3D movePoint = posEvent->GetWorldPosition();
          m_CurrentPoint = movePoint;
          if (m_Destination == NULL)
            return false;
          mitk::PointOperation doPointOp(OpMOVE, timeInMS, movePoint, 0);
          //execute the Operation
          m_Destination->ExecuteOperation(&doPointOp);
          ok = true;
          break;
        }
        case AcFINISHMOVEMENT:
        {
          if (m_Destination == NULL)
            return false;
          /*finishes a Movement from the coordinate supplier:
          gets the lastpoint from the undolist and writes an undo-operation so
          that the movement of the coordinatesupplier is undoable.*/
          mitk::Point3D movePoint = posEvent->GetWorldPosition();
          mitk::Point3D oldMovePoint; oldMovePoint.Fill(0);

          doOp = new mitk::PointOperation(OpMOVE, timeInMS, movePoint, 0);
          PointOperation finishOp(OpTERMINATE, movePoint, 0);
          if (m_UndoEnabled )
          {
            //get the last Position from the UndoList
            OperationEvent *lastOperationEvent = m_UndoController->GetLastOfType(m_Destination, OpMOVE);
            if (lastOperationEvent != NULL)
            {
              PointOperation* lastOp = dynamic_cast<PointOperation *>(lastOperationEvent->GetOperation());
              if (lastOp != NULL)
              {
                oldMovePoint = lastOp->GetPoint();
              }
            }
            PointOperation* undoOp = new PointOperation(OpMOVE, timeInMS, oldMovePoint, 0, "Move slices");
            OperationEvent *operationEvent = new OperationEvent(m_Destination, doOp, undoOp, "Move slices");
            m_UndoController->SetOperationEvent(operationEvent);
          }
          //execute the Operation
          m_Destination->ExecuteOperation(doOp);

          if (!m_UndoEnabled)
            delete doOp;

          m_Destination->ExecuteOperation(&finishOp);
          ok = true;

          break;
        }
        default:
          ok = false;
          break;
      }
      return ok;
    }