コード例 #1
0
	void ManagerConnection::setState(State newState) {
		if (this->state == newState)
			return;

		LOG_DEBUG_DATA(status[state] << " => " << status[newState]);

		switch (newState) {
		case DISCONNECTED: {
			this->reader.stop();
			ManagerResponsesHandler::stop();
		}
			break;
		case CONNECTED: {
			if (state == DISCONNECTED) {
				this->reader.start(socket, this);
				ManagerResponsesHandler::start();
			} else {
				this->reader.stop();
				ManagerResponsesHandler::stop();
			}
		}
			break;
		case AUTHENTICATED: {

		}
			break;
		}
		this->state = newState;
	}
コード例 #2
0
    void ManagerConnection::setState(State newState) {
        if (this->state == newState)
            return;

        std::stringstream transition;
        transition << status[state] << " => " << status[newState];
        LOG_DEBUG_DATA(transition.str());

        switch (state) { //from state..
            case DISCONNECTED:
                if (newState != CONNECTED) {
                    throw new Exception(transition.str());
                }
                //transition to connected
                LOG_INFO_STR("CONNECTED");
                this->reader.start(socket, this);
                ManagerResponsesHandler::start();
                break;
            case CONNECTED:
                if (newState == DISCONNECTED) {
                    //to disconnected
                    LOG_INFO_STR("DISCONNECTED");
                    ManagerResponsesHandler::stop();
                    this->reader.stop();
                } else {
                    //to authenticated
                    LOG_INFO_STR("AUTHENTICATED");
                }
                break;
            case AUTHENTICATED:
                if (newState == CONNECTED) {
                    // to connected, i.e. logoff
                    LOG_INFO_STR("CONNECTED:=DEAUTHENTICATED");
                } else {
                    //to disconnected
                    LOG_INFO_STR("DISCONNECTED");
                    //logoff()¿?
                    setState(CONNECTED);
                    setState(DISCONNECTED);
                }
                break;
        }

        this->state = newState;
    }