Exemplo n.º 1
0
void Volume::setState(int state) {
    char msg[255];
    int oldState = mState;

    if (oldState == state) {
        SLOGW("Duplicate state (%d)\n", state);
        return;
    }

    if ((oldState == Volume::State_Pending) && (state != Volume::State_Idle)) {
        mRetryMount = false;
    }

    mState = state;

    SLOGD("Volume %s state changing %d (%s) -> %d (%s)", mLabel,
         oldState, stateToStr(oldState), mState, stateToStr(mState));
    snprintf(msg, sizeof(msg),
             "Volume %s %s state changed from %d (%s) to %d (%s)", getLabel(),
             getMountpoint(), oldState, stateToStr(oldState), mState,
             stateToStr(mState));

    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeStateChange,
                                         msg, false);
}
Exemplo n.º 2
0
void CharacterController::setState(State desiredState, const char* reason) {
#else
void CharacterController::setState(State desiredState) {
#endif
    if (!_flyingAllowed && desiredState == State::Hover) {
        desiredState = State::InAir;
    }

    if (desiredState != _state) {
#ifdef DEBUG_STATE_CHANGE
        qCDebug(physics) << "CharacterController::setState" << stateToStr(desiredState) << "from" << stateToStr(_state) << "," << reason;
#endif
        if (desiredState == State::Hover && _state != State::Hover) {
            // hover enter
            if (_rigidBody) {
                _rigidBody->setGravity(btVector3(0.0f, 0.0f, 0.0f));
            }
        } else if (_state == State::Hover && desiredState != State::Hover) {
            // hover exit
            if (_rigidBody) {
                _rigidBody->setGravity(DEFAULT_CHARACTER_GRAVITY * _currentUp);
            }
        }
        _state = desiredState;
    }
}

void CharacterController::setLocalBoundingBox(const glm::vec3& corner, const glm::vec3& scale) {
    _boxScale = scale;

    float x = _boxScale.x;
    float z = _boxScale.z;
    float radius = 0.5f * sqrtf(0.5f * (x * x + z * z));
    float halfHeight = 0.5f * _boxScale.y - radius;
    float MIN_HALF_HEIGHT = 0.1f;
    if (halfHeight < MIN_HALF_HEIGHT) {
        halfHeight = MIN_HALF_HEIGHT;
    }

    // compare dimensions
    float radiusDelta = glm::abs(radius - _radius);
    float heightDelta = glm::abs(halfHeight - _halfHeight);
    if (radiusDelta < FLT_EPSILON && heightDelta < FLT_EPSILON) {
        // shape hasn't changed --> nothing to do
    } else {
        if (_dynamicsWorld) {
            // must REMOVE from world prior to shape update
            _pendingFlags |= PENDING_FLAG_REMOVE_FROM_SIMULATION;
        }
        _pendingFlags |= PENDING_FLAG_UPDATE_SHAPE;
        // only need to ADD back when we happen to be enabled
        if (_enabled) {
            _pendingFlags |= PENDING_FLAG_ADD_TO_SIMULATION;
        }
    }

    // it's ok to change offset immediately -- there are no thread safety issues here
    _shapeLocalOffset = corner + 0.5f * _boxScale;
}
Exemplo n.º 3
0
void DirectVolume::udiskSetState(int state,int index,char * mountpoint) {
    char msg[255];
	int mState = 0;
    int oldState = mState;



	if(state == State_Idle){
		oldState = State_Unmounting;
	}
	if(state == State_Unmounting){
		oldState = State_Mounted;
	}
	if(state == State_NoMedia){
		oldState = State_Idle;
	}

    if (oldState == state) {
        SLOGW("Duplicate state (%d)\n", state);
        return;
    }



    if ((oldState == Volume::State_Pending) && (state != Volume::State_Idle)) {
        mRetryMount = false;
    }

    mState = state;

    SLOGD("Volume Udisk%d path %s state changing %d (%s) -> %d (%s)", index,mountpoint,
         oldState, stateToStr(oldState), mState, stateToStr(mState));
    snprintf(msg, sizeof(msg),
             "Volume Udisk%d %s state changed from %d (%s) to %d (%s)", index,
             mountpoint, oldState, stateToStr(oldState), mState,
             stateToStr(mState));

    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeStateChange,
                                         msg, false);
}
void move_group::MoveGroupPickPlaceAction::setPlaceState(MoveGroupState state)
{
  place_state_ = state;
  place_feedback_.state = stateToStr(state);
  place_action_server_->publishFeedback(place_feedback_);
}
Exemplo n.º 5
0
void stateMachine(womim* p_womim) {
    int id;
    MUTEX_LOCK(stateMachineMutex);
    //printf("State = %s, receive message = %s\n", stateToStr(automatonState), msgTypeToStr(p_womim->msg.type));
    switch (automatonState) {
    case OFFLINE_CONNECTION_ATTEMPT:
        switch (p_womim->msg.type) {
        case NAK_INSERT:
        case DISCONNECT_PRED:
        case DISCONNECT_SUCC:
            freeWomim(p_womim);
            nextState(WAIT);
            break;
        case INSERT:
            prec = p_womim->msg.body.insert.sender;
            sendOther(p_womim->msg.body.insert.sender, true, NAK_INSERT, myAddress);
            freeWomim(p_womim);
            break;
        case ACK_INSERT:
            prec = p_womim->msg.body.ackInsert.sender;
            openConnection(prec, true);
            sendOther(prec, true, NEWSUCC, myAddress);
            freeWomim(p_womim);
            nextState(OFFLINE_CONFIRMATION_WAIT);
            break;
        default:
            ERROR_AT_LINE_WITHOUT_ERRNUM(EXIT_FAILURE, __FILE__, __LINE__,
                                         "unexpected case : received message %s in state %s",
                                         msgTypeToStr(p_womim->msg.type), stateToStr(automatonState));
            break;
        }
        break;

    case OFFLINE_CONFIRMATION_WAIT:
        switch (p_womim->msg.type) {
        case NEWSUCC:
        case DISCONNECT_PRED:
        case DISCONNECT_SUCC:
            freeWomim(p_womim);
            nextState(WAIT);
            break;
        case INSERT:
            sendOther(p_womim->msg.body.insert.sender, true, NAK_INSERT, myAddress);
            freeWomim(p_womim);
            break;
        case TRAIN:
            id = (int) p_womim->msg.body.train.stamp.id;
            if (addrIsMember(myAddress, p_womim->msg.body.train.circuit)) {
                p_womim->msg.body.train.stamp.lc++;
            }
            releaseWiw(&(lts[id].w.w_w));
            lts[id].w.len = 0;
            if (firstWagon(&(p_womim->msg)) != NULL ) {
                lts[id].w.w_w.p_wagon = firstWagon(&(p_womim->msg));
                lts[id].w.w_w.p_womim = p_womim;
                lts[id].w.len = (p_womim->msg.len - sizeof(stamp) - sizeof(int)
                                 - sizeof(MType) - sizeof(address));
                // We do not need to lock the p_womim->pfx.mutex as we are the only thread
                // accessing to counter
                p_womim->pfx.counter++;
            }
            lts[id].circuit = p_womim->msg.body.train.circuit;
            lts[id].stamp = p_womim->msg.body.train.stamp;
            sendTrain(succ, false, lts[id]);
            if (isInLts(myAddress, lts)) {
#ifdef INSERTION_TEST
                gettimeofday(&trainDate, NULL);
                timersub(&trainDate, &offlineInitDate, &insertionDuration);
                floatInsertionDuration = ((double) insertionDuration.tv_sec) * 1000
                                         + ((double) insertionDuration.tv_usec) / 1000;
                printf("My insertion duration : %.3lfms\n", floatInsertionDuration);
                printf("number of times automaton has been in state WAIT ; %llu\n", counters.wait_states);
#endif /* INSERTION_TEST */
                lis = p_womim->msg.body.train.stamp.id;
                signalArrival(myAddress, lts[lis].circuit);
                nextState(SEVERAL);
                int rc = sem_post(sem_init_done);
                if (rc)
                    ERROR_AT_LINE(EXIT_FAILURE, errno, __FILE__, __LINE__,
                                  "error in sem_post");
            }
            freeWomim(p_womim);
            break;
        default:
            ERROR_AT_LINE_WITHOUT_ERRNUM(EXIT_FAILURE, __FILE__, __LINE__,
                                         "unexpected case : received message %s in state %s",
                                         msgTypeToStr(p_womim->msg.type), stateToStr(automatonState));
            freeWomim(p_womim);
            break;
        }
        break;

    case WAIT:
        freeWomim(p_womim);
        break;

    case ALONE_INSERT_WAIT:
        switch (p_womim->msg.type) {
        case DISCONNECT_PRED:
        case DISCONNECT_SUCC:
            // May happen in case there are 2 processes on the circuit and one process dies
            // The other process receives DISCONNECT in SEVERAL state and switched to
            // ALONE_INSERT_WAIT state, where it receives the DISCONNECT corresponding
            // to the loss of the second connection
            freeWomim(p_womim);
            break;
        case INSERT:
            MUTEX_LOCK(mutexWagonToSend);
            sendOther(p_womim->msg.body.insert.sender, true, ACK_INSERT, myAddress);
            prec = p_womim->msg.body.insert.sender;
            freeWomim(p_womim);
            nextState(ALONE_CONNECTION_WAIT);
            MUTEX_UNLOCK(mutexWagonToSend);
            break;
        default:
            ERROR_AT_LINE_WITHOUT_ERRNUM(EXIT_FAILURE, __FILE__, __LINE__,
                                         "unexpected case : received message %s in state %s",
                                         msgTypeToStr(p_womim->msg.type), stateToStr(automatonState));
            freeWomim(p_womim);
            break;
        }
        break;

    case ALONE_CONNECTION_WAIT:
        switch (p_womim->msg.type) {
        case DISCONNECT_PRED:
            nextState(ALONE_INSERT_WAIT);
            freeWomim(p_womim);
            break;
        case INSERT:
            // In the PhD-thesis algorithm, we are supposed to do a
            // saveUntilNextstate(p_womim). Sending a NAK_INSERT is more simple.
            sendOther(p_womim->msg.body.insert.sender, true, NAK_INSERT, myAddress);
            freeWomim(p_womim);
            break;
        case NEWSUCC:
            succ = p_womim->msg.body.newSucc.sender;
            int i;
            for (i = 1; i <= ntr; i++) {
                int id = ((lis + i) % ntr);
                (lts[(int) id]).stamp.lc += 1;
                (lts[(int) id]).circuit = myAddress | prec;
                (lts[(int) id]).w.w_w.p_wagon = NULL;
                (lts[(int) id]).w.w_w.p_womim = NULL;
                (lts[(int) id]).w.len = 0;
                sendTrain(succ, false, lts[(int) id]);
            }
            freeWomim(p_womim);
            nextState(SEVERAL);
            break;
        default:
            ERROR_AT_LINE_WITHOUT_ERRNUM(EXIT_FAILURE, __FILE__, __LINE__,
                                         "unexpected case : received message %s in state %s",
                                         msgTypeToStr(p_womim->msg.type), stateToStr(automatonState));
            freeWomim(p_womim);
            break;
        }
        break;

    case SEVERAL:
        switch (p_womim->msg.type) {
        case TRAIN:
            if (addrIsMember(myAddress, p_womim->msg.body.train.circuit)) {
                if (isRecentTrain(p_womim->msg.body.train.stamp, lts, lis)) {
#ifdef INSERTION_TEST
                    if (theLostPrec != 0) {
                        if (recentlyLostMyPred) {
                            gettimeofday(&firstRecentTrainDate, NULL);
                            recentlyLostMyPred = false;
                        }
                        if (!isInLts(theLostPrec,lts)) {
                            gettimeofday(&firstNewCircuitDate, NULL);
                            theLostPrec = 0;

                            timersub(&firstRecentTrainDate, &discoPredDate, &recoveryRecentTrainDuration);
                            timersub(&firstNewCircuitDate, &discoPredDate, &recoveryNewCircuitDuration);

                            floatRecoveryRecentTrainDuration = ((double) recoveryRecentTrainDuration.tv_sec) * 1000
                                                               + ((double) recoveryRecentTrainDuration.tv_usec) / 1000;

                            floatRecoveryNewCircuitDuration = ((double) recoveryNewCircuitDuration.tv_sec) * 1000
                                                              + ((double) recoveryNewCircuitDuration.tv_usec) / 1000;

                            printf("Disconnection pred recovery :\n");
                            printf("\t- First recent train after %.3lfms\n", floatRecoveryRecentTrainDuration);
                            printf("\t- Up-to-date circuit received after %.3lfms\n", floatRecoveryNewCircuitDuration);

                        }
                    }
#endif /* INSERTION_TEST */
                    trainHandling(p_womim);
                    lis = p_womim->msg.body.train.stamp.id;
                    if (succ != 0)
                        sendTrain(succ, false, lts[lis]);
                }
            } else {
                ERROR_AT_LINE_WITHOUT_ERRNUM(EXIT_FAILURE, __FILE__, __LINE__,
                                             "myAddress not in the circuit ==> Suicide");
            }
            freeWomim(p_womim);
            break;
        case INSERT:
            closeConnection(prec, true);
            sendOther(p_womim->msg.body.insert.sender, true, ACK_INSERT, prec);
            prec = p_womim->msg.body.insert.sender;
            addrAppendArrived(&cameProc, prec);
            freeWomim(p_womim);
            break;
        case NEWSUCC:
            if (succ != 0)
                closeConnection(succ, false);
            succ = p_womim->msg.body.newSucc.sender;
            int i;
            for (i = 1; i <= ntr; i++) {
                sendTrain(succ, false, lts[(lis + i) % ntr]);
            }
            freeWomim(p_womim);
            break;
        case DISCONNECT_PRED:
#ifdef INSERTION_TEST
            gettimeofday(&discoPredDate, NULL);
            recentlyLostMyPred = true;
            theLostPrec = prec;
#endif /* INSERTION_TEST */
            MUTEX_LOCK(mutexWagonToSend);
            while (!(addrIsEqual(prec,myAddress))) {
                if (openConnection(prec, true) != (-1)) {
                    sendOther(prec, true, NEWSUCC, myAddress);
                    freeWomim(p_womim);
                    nextState(SEVERAL);
                    MUTEX_UNLOCK(stateMachineMutex);
                    MUTEX_UNLOCK(mutexWagonToSend);
                    return;
                }
                addrAppendGone(&cameProc, &goneProc, prec);
                prec = addrPrec(prec, lts[lis].circuit);
            }
            signalDepartures(goneProc, lts[lis].circuit, true);
            goneProc = 0;
            int aRound;
            for (aRound = 1; aRound <= NR; aRound++) {
                int i;
                for (i = 1; i <= ntr; i++) {
                    int id = (lis + i) % ntr;
                    int round = (lts[id].stamp.round + aRound) % NR;
                    bqueueExtend(wagonsToDeliver, unstableWagons[id][round]);
                    cleanList(unstableWagons[id][round]);
                }
            }
            bqueueEnqueue(wagonsToDeliver, wagonToSend);
            wagonToSend = newWiw();
            freeWomim(p_womim);
#ifdef INSERTION_TEST
            gettimeofday(&firstNewCircuitDate, NULL);
            timersub(&firstNewCircuitDate, &discoPredDate, &recoveryNewCircuitDuration);
            floatRecoveryNewCircuitDuration = ((double) recoveryNewCircuitDuration.tv_sec) * 1000
                                              + ((double) recoveryNewCircuitDuration.tv_usec) / 1000;
            printf("I am alone !\n"
                   "%.3lfms since the DISCONNECT_PRED message\n", floatRecoveryNewCircuitDuration);
#endif /* INSERTION_TEST */
            nextState(ALONE_INSERT_WAIT);
            MUTEX_UNLOCK(stateMachineMutex);
            MUTEX_UNLOCK(mutexWagonToSend);
            pthread_cond_signal(&condWagonToSend);
            break;
        case DISCONNECT_SUCC:
            succ = 0;
            freeWomim(p_womim);
            break;
        default:
            ERROR_AT_LINE_WITHOUT_ERRNUM(EXIT_FAILURE, __FILE__, __LINE__,
                                         "unexpected case : received message %s in state %s",
                                         msgTypeToStr(p_womim->msg.type), stateToStr(automatonState));
            break;
        }
        break;
    default:
        ERROR_AT_LINE_WITHOUT_ERRNUM(EXIT_FAILURE, __FILE__, __LINE__, "Unknown state : %d",
                                     automatonState);
        freeWomim(p_womim);
        break;
    }
    MUTEX_UNLOCK(stateMachineMutex);
}