Ejemplo n.º 1
0
/**
 * Check that we aren't stuck waiting, while loading or playing...
 */
bool SoundPlayer::healthCheck()
{
	DEBUG("SoundPlayer::healthCheck(%s, %llu ms)", getStateName(), currentTime() - m_lastPlayingTime);
	if (!m_filePath.empty() &&		// we are supposed to play something
		(	(m_state == eState_Connecting && m_lastPlayingTime + cConnectDelay < currentTime()) ||	// but we can't connect, or
			(m_state == eState_PlayPending && m_lastPlayingTime + cLoadDelay < currentTime())   ||	// we can't load the file, or
			(m_state == eState_Playing && m_lastPlayingTime + cPlayDelay < currentTime())))			// we can't play the file
	{
		if (m_fakeBackupRingtoneCount == 0)
		{	// log failure, when it first happens
			CRITICAL("SoundPlayer::healthCheck(%s): can't play '%s' as %s for %llu ms", getStateName(),
					m_filePath.c_str(), m_streamClass.c_str(), currentTime() - m_lastPlayingTime);
			m_retries++;	// we failed to play. Remember this, so that we won't recycle this player.
		}
		if (m_audioStreamClass == kAudioStreamRingtone || m_audioStreamClass == kAudioStreamAlarm)
		{	// back ringtone for ringtones & alarms
			if (m_fakeBackupRingtoneCount == 0)
				WARNING("SoundPlayer::healthCheck: using backup ringtone using alert notifications!");
			// Don't use alarm & ringtone sinks, because they trigger a ringtone vibration, which we are faking here!
			if ((m_fakeBackupRingtoneCount++ % 5) < 3)
				SoundPlayerPool::instance()->playFeedback("sysmgr_notification", "palerts");	// let's hope audiod & pulse are ok!
		}
		else if (m_audioStreamClass == kAudioStreamNotification)
		{
			WARNING("SoundPlayer::healthCheck: using default notification instead!");
			stop();
			SoundPlayerPool::instance()->playFeedback("sysmgr_alert", "palerts");	// let's hope audiod & pulse are ok!
		}
		else if (m_audioStreamClass == kAudioStreamCalendar)
		{
			WARNING("SoundPlayer::healthCheck: using default notification instead!");
			stop();
			SoundPlayerPool::instance()->playFeedback("sysmgr_alert", "pcalendar");	// let's hope audiod & pulse are ok!
		}
		else if (m_audioStreamClass == kAudioStreamAlert)
		{
			WARNING("SoundPlayer::healthCheck: using default alert instead!");
			stop();
			SoundPlayerPool::instance()->playFeedback("sysmgr_alert", "palerts");	// let's hope audiod & pulse are ok!
		}
	}
	else if (m_state == eState_Closing && m_lastPlayingTime + cCloseDelay < currentTime())
	{
		WARNING("SoundPlayer::healthCheck(%s): can't close for %llu ms. Declaring SoundPlayer object dead.", getStateName(), currentTime() - m_lastPlayingTime);
		setState(eState_Dead);
	}
	else
	{
		m_fakeBackupRingtoneCount = 0;
	}

	return true;	// return true to repeat
}
Ejemplo n.º 2
0
void log_state(state s, enum role_t r) {
  if (log_level < TRACE) return;
  int line_size = (num_nodes()) * 9 + 6;
  char line[line_size];
  draw_base_graph(line, line_size);

  int meidx = graph_index(my_id(), r);

  line[meidx] = getStateName(s.state)[2];

  printf("GRAPH: %s STATE %s %s %ld %ld %ld dead %ld\n", line, getRole(r), getStateName(s.state), s.ticket, s.slot, s.value, s.deadline);
}
Ejemplo n.º 3
0
/**
 * Takes a PCB pointer and prints out the contents of the PCB
 * @param PCB_p pointer referencing the PCB to print
 */
void toString(PCB_p pcb_p) {
    printf("contents: ");

    printf("State: %s  ", getStateName(pcb_p->state));
    printf("PID: %d  ", pcb_p->pid);
    printf("PC: %d  ", pcb_p->PC);

    // prints the register files associated with this PCB
    printf("Reg Files:  ");
    if (pcb_p->reg_file) {
        int i;
        for (i = 0; i < NUMREGS; i++) {
            printf("REG%d: %d  ", i, pcb_p->reg_file[i]);
        }
        printf("  ");
    } else {
        printf("\t\tNONE\n\n");
    }

    // if there exists a following pcb, print out the next address
    if (pcb_p->next_pcb) {
        PCB_p next = pcb_p->next_pcb;
        printf("Next Struct Address: %d  ", next->address_space);
    } else {
    // otherwise print nothing
        printf("Next Struct Address: NULL  ");
    }

    printf("Priority: %d  ", pcb_p->Priority);
    printf("Address Space: %d\n\n  ", pcb_p->address_space);
}
Ejemplo n.º 4
0
/**
 * Destructor: Stop anything we have going & disconnect proxy listener
 */
SoundPlayer::~SoundPlayer()
{
	PRINTF_BLUE("SoundPlayer::~SoundPlayer(%s)", getStateName());
	if (m_state == eState_PlayPending || m_state == eState_Playing)
		stop();

	if (m_player.get()) {
		m_player->removeMediaPlayerChangeListener(m_mediaPlayerChangeListener);
		m_player.reset((media::MediaPlayer*) 0);
	}
	
	// Important: Make sure to call this before the service handle destuction
	if (m_mediaPlayerChangeListener.get())
		m_mediaPlayerChangeListener.reset((media::MediaPlayerChangeListener*)0);

	if (m_serviceHandle) {
		LSError lserror;
		LSErrorInit(&lserror);
		if (!LSUnregisterPalmService(m_serviceHandle, &lserror)) {
	        LSErrorPrint (&lserror, stderr);
	        LSErrorFree (&lserror);
		}

		m_serviceHandle = 0;
	}
}
Ejemplo n.º 5
0
/**
 * Takes a PCB pointer and prints out the contents of the PCB
 * @param PCB_p pointer referencing the PCB to print
 */
void toString(PCB_p pcb_p) {   
    printf("contents: ");
    printf("State: %s  ", getStateName(pcb_p->state));
    printf("PID: %d  ", pcb_p->pid);
    printf("PC: %d  ", pcb_p->PC);
    printf("Priority: %d  ", pcb_p->Priority);
    printf("Address Space: %u\n\n", pcb_p->address_space);
}
Ejemplo n.º 6
0
void MapTile::setState( byte newState )
{
	if (state_ == newState)
		return;

	if (state_ == DEADBEEF)
		return;

	char error[1024];
	switch (newState) {
	case NONE:
		state_ = newState;
		return;
	case LOADING:
		if (state_ == NONE) {
			state_ = newState;
			return;
		}		
		sprintf_s(error, "Loading <= %s %d", getStateName(), this); 
		throw std::exception(error);
	case NEW_DATA:
		if (state_ == LOADING) {
			state_ = newState;
			return;
		}
		sprintf_s(error, "NewData <= %s %d", getStateName(), this); 
		throw std::exception(error);
	case READY:
		if (state_ == NEW_DATA) {
			state_ = newState;
			return;
		}
		sprintf_s(error, "Ready <= %s %d", getStateName(), this); 
		throw std::exception(error);
	case CANCEL:
		if (state_ == LOADING) {
			state_ = newState;
			return;
		}
		sprintf_s(error, "Cancel <= %s %d", getStateName(), this); 
		throw std::exception(error);
	case DEADBEEF:
		state_ = newState;
		return;
	}
}
Ejemplo n.º 7
0
/*
 * Prints contents of the passed PCB to the passed file.  
 */
void printToFile(FILE *outfile, PCB_p pcb_p) {
    fprintf(outfile, "contents: ");
    fprintf(outfile, "State: %s  ", getStateName(pcb_p->state));
    fprintf(outfile, "PID: %d  ", pcb_p->pid);
    fprintf(outfile, "PC: %u  ", pcb_p->PC);
    fprintf(outfile, "Priority: %d  ", pcb_p->Priority);
    fprintf(outfile, "Address Space: %u\n\n", pcb_p->address_space);
}
Ejemplo n.º 8
0
// getStateObjFx
CMenuFxObj CGameState::getStateObjFx()
{
	if ( m_menuFx )
	{
		return m_menuFx->getObj( getStateName(m_state) );
	}
	return CMenuFxObj();
}
Ejemplo n.º 9
0
// setFxStateVisible
// show/hide state on flash
void CGameState::setFxStateVisible( EGameState state, bool b )
{
	if ( m_menuFx )
	{
		CMenuFxObj menuObj = m_menuFx->getObj( getStateName(state) );
		menuObj.setVisible( b );
		menuObj.gotoFrame(0, true);
	}
}
Ejemplo n.º 10
0
/**
 * Errors occur asynchronously.  If an error occurs, this will be called.
 */
void SoundPlayer::errorChanged()
{
	if (!VERIFY(m_player))
		return;
    if (m_player->getError() != NO_ERROR)
    {
    	CRITICAL("SoundPlayer::errorChanged(%s): %d", getStateName(), m_player->getError());
    	onError();
    }
}
Ejemplo n.º 11
0
/**
 * Errors occur asynchronously.  If an error occurs, this will be called.
 */
void SoundPlayer::extendedErrorChanged()
{
	if (!VERIFY(m_player))
		return;
    if (!m_player->getExtendedError().empty())
    {
    	CRITICAL("SoundPlayer::extendedErrorChanged(%s): '%s'", getStateName(), m_player->getExtendedError().c_str());
    	onError();
    }
}
Ejemplo n.º 12
0
/**
 * The object we are playing was changed.
 */
void SoundPlayer::sourceChanged()
{
	if (!VERIFY(m_player))
		return;
	PRINTF_BLUE("SoundPlayer::sourceChanged(%s): '%s'", getStateName(), m_player->getSource().c_str());
	if (m_player->getSource().empty() && m_state == eState_Closing)
	{
		setState(eState_Connected);
		checkForNextStep();
	}
}
Ejemplo n.º 13
0
    void raiseFatalFromInvalidState(const EventExecuter &eventExecuter, const InvalidStateError &ex)
    {
        auto state = chila::lib::misc::deref(boost::get_error_info<ErrorInfo::ModState>(ex));

        eventExecuter.template execute<Event>
            CHILA_CONNECTIONTOOLS_LIB_OTHER__EV_FATAL_ARGS
            (
                "Invalid state: '" + getStateName(state) + "'",
                chila::lib::misc::deref(boost::get_error_info<boost::throw_function>(ex)),
                chila::lib::misc::deref(boost::get_error_info<boost::throw_file>(ex)),
                chila::lib::misc::deref(boost::get_error_info<boost::throw_line>(ex))
            );
    }
Ejemplo n.º 14
0
/**
 * Playback is moving
 */
void SoundPlayer::currentTimeChanged()
{
	if (VERIFY(m_player))
	{
		PRINTF_BOLD("SoundPlayer::currentTimeChanged(%s): %f sec", getStateName(), m_player->getCurrentTime());
		if (m_state == eState_PlayPending || m_state == eState_Playing)
		{
			setState(eState_Playing);
			m_lastPlayingTime = currentTime();
			if (!m_repeat && m_duration > 0 && m_player->getCurrentTime() >= m_duration)
				stop();
		}
	}
}
Ejemplo n.º 15
0
void CGameState::setFxAllStateVisible( EGameState ignoreState, bool b )
{
	if ( m_menuFx )
	{
		for ( int i = 0; i < CGameState::StateCount; i++ )
		{
			if ( i == ignoreState )
				continue;

			CMenuFxObj menuObj = m_menuFx->getObj( getStateName( (EGameState)i) );			
			menuObj.setVisible( b );				
			menuObj.gotoFrame(0, b);				
		}
	}
}
Ejemplo n.º 16
0
/**
 * The end of the stream has been reached (i.e. we played the entire stream).
 */
void SoundPlayer::eosChanged()
{
    if (VERIFY(m_player) && m_player->getEos()) {
    	PRINTF_BLUE("SoundPlayer::eosChanged(%s): EOS", getStateName());
    	if (m_state == eState_PlayPending || m_state == eState_Playing)
    	{
			if (m_repeat)
			{
				m_player->seek(0);
				m_player->play();
			}
			else
				stop();
    	}
    }
}
Ejemplo n.º 17
0
/**
 * Client side cancel point. Also used internally.
 */
void SoundPlayer::stop()
{
	PRINTF_BLUE("SoundPlayer::stop(%s)", getStateName());
	if (m_state == eState_PlayPending || m_state == eState_Playing)
	{
		if (VERIFY(m_player))
		{
			m_player->pause();
			m_player->unload();
		}
		setState(eState_Closing);
	}
	else
	{	// not sure why we were not playing: don't take chance...
		WARNING("SoundPlayer::stop(%s): unexpected stop request. Declaring SoundPlayer object dead.", getStateName());
		setState(eState_Dead);
	}
	m_filePath.clear();
	m_streamClass.clear();
	m_lastPlayingTime = currentTime();
	m_fakeBackupRingtoneCount = 0;
	if (m_activityID)
	{
	    gchar *  request = g_strdup_printf("{\"id\":\"com.palm.sysmgr.soundplayer.%i\"}", m_activityID);

	    LSError lserror;
	    LSErrorInit(&lserror);
	    bool activityStartRequestSuccess = LSCall(getServiceHandle(), "palm://com.palm.power/com/palm/power/activityEnd", request, NULL, NULL, NULL, &lserror);
	    if (!activityStartRequestSuccess)
	    {
	        CRITICAL("SoundPlayer::stop: activity '%s' End failed", request);
	        LSErrorPrint (&lserror, stderr);
	        LSErrorFree (&lserror);
	    }
	    else
	    	DEBUG("SoundPlayer::stop: ended activity '%s'...", request);

	    g_free(request);
	    m_activityID = 0;
	}
}
Ejemplo n.º 18
0
/**
 * Ajoute une action à la règle en cours d'édition (variable gloable lastRule)
 * \param device capteur concerné
 * \param state état du field du device
 * \param field champ du capteur concerné
 */
void addAction(char *device, char *state, char *field) {
	Action *action = malloc(sizeof(Action));
	action->device = getDeviceIndex(device);
	action->state = getState(state);
	action->field = getFieldIndex(field);
	action->next = NULL;
    
	Action *lastAction = getLastAction(lastRule);
    
	if(lastAction == NULL)
	{
		lastRule->actions = action;
	}
	else
	{
		lastAction->next = action;
	}

	if(DEBUG_MODE == 1)
    {
        printf("New action added : %s -> %s\n", device, getStateName(getState(state)));
    }
}
Ejemplo n.º 19
0
/**
 * Connect to mediaserver using lunaservice.
 */
LSPalmService* SoundPlayer::connectToBus()
{
	PRINTF_BLUE("SoundPlayer::connectToBus(%s)", getStateName());
	VERIFY(m_state == eState_Connecting);
	setState(eState_Connecting);

	if (m_serviceHandle)
		return m_serviceHandle;

	bool result = true;
	LSError lserror;
	LSErrorInit(&lserror);

	result = LSRegisterPalmService(NULL, &m_serviceHandle, &lserror);
	if (!result)
	{
		CRITICAL("SoundPlayer::connectToBus: Could not register SoundPlayer");
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
		// Make next health check fail ASAP...
		m_lastPlayingTime = 0;
		return NULL;
	}

	result = LSGmainAttachPalmService (m_serviceHandle, HostBase::instance()->mainLoop(), &lserror);
	if (!result)
	{
		CRITICAL("SoundPlayer::connectToBus: Could not attach SoundPlayer to main loop");
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
		// Make next health check fail ASAP...
		m_lastPlayingTime = 0;
		return NULL;
	}
	return m_serviceHandle;
}
Ejemplo n.º 20
0
static void
setState( tr_handshake * handshake, handshake_state_t state )
{
    dbgmsg( handshake, "setting to state [%s]", getStateName( state ) );
    handshake->state = state;
}
Ejemplo n.º 21
0
ParseStatus gotXSTATE(TAPState tapState) {
    printf("XSTATE(%s)\n", getStateName(tapState));
    return PARSE_SUCCESS;
}
Ejemplo n.º 22
0
//====================UTILITY METHOD================
bool BTFsaManager::isValidStateTransition(BTState destState){

    char buff[100];

    switch(this->state)
    {
    case START:
        if(destState == STANDBY || destState == ADVERTISING)
            return true;
        break;

    case STANDBY:

        if(destState != CONNECTION_MASTER || destState != CONNECTION_SLAVE )
            return true;

        break;

    case SCANNING:

        if(destState != CONNECTION_MASTER || destState != CONNECTION_SLAVE )
            return true;

        break;

    case ADVERTISING:

        if(destState != CONNECTION_MASTER)
            return true;

        break;

    case INITIATING:

        if(destState != CONNECTION_SLAVE )
            return true;

        break;

    case CONNECTION_MASTER:

        if(destState != CONNECTION_SLAVE)
            return true;

        break;

    case CONNECTION_SLAVE:

        if(destState != CONNECTION_MASTER)
            return true;

        break;

    default: throw std::runtime_error("INVALID BT FSA STATE !!");

    }

    sprintf(buff, "Bluetooth FSA INVALID STATE TRANSITION FROM %s TO %s !!", getStateName(state), getStateName(destState));

    std::string errorMessage(buff);

    throw std::logic_error(errorMessage);
}
int getOptModelStateName(emb_optimizer optim, int name_idx, char x_name[], size_t maxlen, size_t *reqlen)
{
	return getStateName(myModel, name_idx, x_name, maxlen, reqlen);
}
Ejemplo n.º 24
0
void Jtag::setTapState(tapState_t state, int pre)
{
  bool tms;
  while(current_state!=state){
    switch(current_state){

    case TEST_LOGIC_RESET:
      switch(state){
      case TEST_LOGIC_RESET:
	tms=true;
	break;
      default:
	tms=false;
	current_state=RUN_TEST_IDLE;
      };
      break;

    case RUN_TEST_IDLE:
      switch(state){
      case RUN_TEST_IDLE:
	tms=false;
	break;
      default:
	tms=true;
	current_state=SELECT_DR_SCAN;
      };
      break;

    case SELECT_DR_SCAN:
      switch(state){
      case CAPTURE_DR:
      case SHIFT_DR:
      case EXIT1_DR:
      case PAUSE_DR:
      case EXIT2_DR:
      case UPDATE_DR:
	tms=false;
	current_state=CAPTURE_DR;
	break;
      default:
	tms=true;
	current_state=SELECT_IR_SCAN;
      };
      break;

    case CAPTURE_DR:
      switch(state){
      case SHIFT_DR:
	tms=false;
	current_state=SHIFT_DR;
	break;
      default:
	tms=true;
	current_state=EXIT1_DR;
      };
      break;

    case SHIFT_DR:
      switch(state){
      case SHIFT_DR:
	tms=false;
	break;
      default:
	tms=true;
	current_state=EXIT1_DR;
      };
      break;

    case EXIT1_DR:
      switch(state){
      case PAUSE_DR:
      case EXIT2_DR:
      case SHIFT_DR:
      case EXIT1_DR:
	tms=false;
	current_state=PAUSE_DR;
	break;
      default:
	tms=true;
	current_state=UPDATE_DR;
      };
      break;

    case PAUSE_DR:
      switch(state){
      case PAUSE_DR:
	tms=false;
	break;
      default:
	tms=true;
	current_state=EXIT2_DR;
      };
      break;

    case EXIT2_DR:
      switch(state){
      case SHIFT_DR:
      case EXIT1_DR:
      case PAUSE_DR:
	tms=false;
	current_state=SHIFT_DR;
	break;
      default:
	tms=true;
	current_state=UPDATE_DR;
      };
      break;

    case UPDATE_DR:
      switch(state){
      case RUN_TEST_IDLE:
	tms=false;
	current_state=RUN_TEST_IDLE;
	break;
      default:
	tms=true;
	current_state=SELECT_DR_SCAN;
      };
      break;

    case SELECT_IR_SCAN:
      switch(state){
      case CAPTURE_IR:
      case SHIFT_IR:
      case EXIT1_IR:
      case PAUSE_IR:
      case EXIT2_IR:
      case UPDATE_IR:
	tms=false;
	current_state=CAPTURE_IR;
	break;
      default:
	tms=true;
	current_state=TEST_LOGIC_RESET;
      };
      break;

    case CAPTURE_IR:
      switch(state){
      case SHIFT_IR:
	tms=false;
	current_state=SHIFT_IR;
	break;
      default:
	tms=true;
	current_state=EXIT1_IR;
      };
      break;

    case SHIFT_IR:
      switch(state){
      case SHIFT_IR:
	tms=false;
	break;
      default:
	tms=true;
	current_state=EXIT1_IR;
      };
      break;

    case EXIT1_IR:
      switch(state){
      case PAUSE_IR:
      case EXIT2_IR:
      case SHIFT_IR:
      case EXIT1_IR:
	tms=false;
	current_state=PAUSE_IR;
	break;
      default:
	tms=true;
	current_state=UPDATE_IR;
      };
      break;

    case PAUSE_IR:
      switch(state){
      case PAUSE_IR:
	tms=false;
	break;
      default:
	tms=true;
	current_state=EXIT2_IR;
      };
      break;

    case EXIT2_IR:
      switch(state){
      case SHIFT_IR:
      case EXIT1_IR:
      case PAUSE_IR:
	tms=false;
	current_state=SHIFT_IR;
	break;
      default:
	tms=true;
	current_state=UPDATE_IR;
      };
      break;

    case UPDATE_IR:
      switch(state){
      case RUN_TEST_IDLE:
	tms=false;
	current_state=RUN_TEST_IDLE;
	break;
      default:
	tms=true;
	current_state=SELECT_DR_SCAN;
      };
      break;

    default:
      tapTestLogicReset();
      tms=true;
    };
    if(fp_dbg)
        fprintf(fp_dbg,"TMS %d: %s\n", tms, getStateName(current_state));
    io->set_tms(tms);
  }
  for(int i=0; i<pre; i++)
    io->set_tms(false);
}
Ejemplo n.º 25
0
/**
 * Client request entry point
 */
void SoundPlayer::play(const std::string& filePath, const std::string& streamClass, bool repeat, int duration)
{
	WARNING("SoundPlayer::play(%s): %p: filePath: %s, streamClass: %s, repeat: %d, duration: %d",
			  getStateName(), this, filePath.c_str(), streamClass.c_str(), repeat, duration);

	if (m_state == eState_Dead)
	{
		CRITICAL("SoundPlayer::play(%s): This player can not be reused!", getStateName());
		return;
	}

	if (m_state != eState_Init)
		stop();

	// recycling? move state machine back
	if (m_state == eState_Finished)
		setState(eState_Connected);

	m_filePath = filePath;
	m_streamClass = streamClass;
	m_audioStreamClass = kAudioStreamMedia;

	if (!m_streamClass.empty())
	{
		if (m_streamClass == "ringtones")
			m_audioStreamClass = kAudioStreamRingtone;

		else if (m_streamClass == "alarm")
			m_audioStreamClass = kAudioStreamAlarm;

		else if (m_streamClass == "alerts")
			m_audioStreamClass = kAudioStreamAlert;

		else if (m_streamClass == "notifications")
			m_audioStreamClass = kAudioStreamNotification;

		else if (m_streamClass == "calendar")
			m_audioStreamClass = kAudioStreamCalendar;

		else if (m_streamClass == "media")
			m_audioStreamClass = kAudioStreamMedia;

		else if (m_streamClass == "voicedial")
			m_audioStreamClass = kAudioStreamVoicedial;

		else if (m_streamClass == "flash")
			m_audioStreamClass = kAudioStreamFlash;

		else if (m_streamClass == "navigation")
			m_audioStreamClass = kAudioStreamNavigation;

		else if (m_streamClass == "defaultapp")
			m_audioStreamClass = kAudioStreamDefaultapp;

		else if (m_streamClass == "feedback")
			m_audioStreamClass = kAudioStreamFeedback;

		else
		{
			WARNING("SoundPlayer::play: unrecognized media class '%s' for '%s'. Will use media class.", streamClass.c_str(), filePath.c_str());
			m_audioStreamClass = kAudioStreamMedia;
		}
	}

	m_repeat = repeat;
	m_duration = float(duration) / 1000.f;	// integer ms to float seconds
	checkForNextStep();
}
Ejemplo n.º 26
0
char* getState(PCB_p pcb_p) {
    return getStateName(pcb_p->state);
}
Ejemplo n.º 27
0
/**
 * Ecrit un fichier de règles sur une sortie
 * \param rules les règles à écrire
 * \param output la sortie à utiliser
 */
void ftraceRules(Rule *rules, int output)
{
	Rule *r;
	int i=0, j;
	char msg[1024];
    
    printf("\n==========[[ Regles chargees ]]==========\n");
    
	for(r = rules; r != NULL; r = r->next)
	{
		sprintf(msg, "\n\033[31mRule n°%d :\033[00m %s\n", ++i, r->name);        
		write(output, msg, strlen(msg));
        
		// Liste les actions
		Action *ac;
		j=0;
		sprintf(msg, "├── \033[32mActions\033[00m\n");
		write(output, msg, strlen(msg));
		for(ac = r->actions; ac != NULL; ac = ac->next)
		{
			if(ac->next == NULL)
			{
				sprintf(msg, "│\t└── \033[33mAction n°%d : \033[34mDo\033[00m %s\033[34m->\033[00m%s \033[34m=\033[00m %s\n", ++j, getDeviceName(ac->device), getFieldName(ac->field), getStateName(ac->state));
				write(output, msg, strlen(msg));
			}
			else
			{
				sprintf(msg, "│\t├── \033[33mAction n°%d : \033[34mDo\033[00m %s\033[34m->\033[00m%s \033[34m=\033[00m %s\n", ++j, getDeviceName(ac->device), getFieldName(ac->field), getStateName(ac->state));
				write(output, msg, strlen(msg));
			}
		}

		// Liste les alertes
		Alert *al;
		j=0;
		sprintf(msg, "├── \033[32mAlertes\033[00m\n");
		write(output, msg, strlen(msg));
		for(al = r->alerts; al != NULL; al = al->next)
		{
			if(al->next == NULL)
			{
				sprintf(msg, "│\t└── \033[33mAlert n°%d : \033[34mSend \"\033[00m%s\033[34m\" To\033[00m %s\n", ++j, al->message, getRecipientName(al->recipient));
				write(output, msg, strlen(msg));
			}
			else
			{
				sprintf(msg, "│\t├── \033[33mAlert n°%d : \033[34mSend\033[00m \"%s\" \033[34mTo\033[00m %s\n", ++j, al->message, getRecipientName(al->recipient));
				write(output, msg, strlen(msg));
			}
		}

		// Liste les conditions
		Condition *cd;
		j=0;
		sprintf(msg, "└── \033[32mConditions\033[00m\n");
		write(output, msg, strlen(msg));
		for(cd = r->conditions; cd != NULL; cd = cd->next)
		{
			if(cd->next == NULL)
			{
				sprintf(msg, "\t└── \033[33mCondition n°%d : \033[34mWhen\033[00m %s[%d]\033[34m->\033[00m%s %s %f\n", ++j,  getDeviceName(cd->device), cd->device, getFieldName(cd->field), getConditionType(cd->type), cd->value);
				write(output, msg, strlen(msg));
			}
			else
			{
				sprintf(msg, "\t├── \033[33mCondition n°%d : \033[34mWhen\033[00m %s[%d]\033[34m->\033[00m%s %s %f \033[34mAnd\033[00m\n", ++j, getDeviceName(cd->device), cd->device, getFieldName(cd->field), getConditionType(cd->type), cd->value);
				write(output, msg, strlen(msg));
			}
		}
	}
    
    printf("\n=========================================\n");    
}                       
Ejemplo n.º 28
0
static ReadState
canRead( struct tr_peerIo * io, void * arg, size_t * piece )
{
    tr_handshake    * handshake = arg;
    struct evbuffer * inbuf = tr_peerIoGetReadBuffer( io );
    ReadState         ret;
    tr_bool           readyForMore = TRUE;

    assert( tr_isPeerIo( io ) );

    /* no piece data in handshake */
    *piece = 0;

    dbgmsg( handshake, "handling canRead; state is [%s]",
           getStateName( handshake->state ) );

    while( readyForMore )
    {
        switch( handshake->state )
        {
            case AWAITING_HANDSHAKE:
                ret = readHandshake    ( handshake, inbuf ); break;

            case AWAITING_PEER_ID:
                ret = readPeerId       ( handshake, inbuf ); break;

            case AWAITING_YA:
                ret = readYa           ( handshake, inbuf ); break;

            case AWAITING_PAD_A:
                ret = readPadA         ( handshake, inbuf ); break;

            case AWAITING_CRYPTO_PROVIDE:
                ret = readCryptoProvide( handshake, inbuf ); break;

            case AWAITING_PAD_C:
                ret = readPadC         ( handshake, inbuf ); break;

            case AWAITING_IA:
                ret = readIA           ( handshake, inbuf ); break;

            case AWAITING_PAYLOAD_STREAM:
                ret = readPayloadStream( handshake, inbuf ); break;

            case AWAITING_YB:
                ret = readYb           ( handshake, inbuf ); break;

            case AWAITING_VC:
                ret = readVC           ( handshake, inbuf ); break;

            case AWAITING_CRYPTO_SELECT:
                ret = readCryptoSelect ( handshake, inbuf ); break;

            case AWAITING_PAD_D:
                ret = readPadD         ( handshake, inbuf ); break;

            default:
                assert( 0 );
        }

        if( ret != READ_NOW )
            readyForMore = FALSE;
        else if( handshake->state == AWAITING_PAD_C )
            readyForMore = evbuffer_get_length( inbuf ) >= handshake->pad_c_len;
        else if( handshake->state == AWAITING_PAD_D )
            readyForMore = evbuffer_get_length( inbuf ) >= handshake->pad_d_len;
        else if( handshake->state == AWAITING_IA )
            readyForMore = evbuffer_get_length( inbuf ) >= handshake->ia_len;
    }

    return ret;
}
Ejemplo n.º 29
0
/**
 * This simply loads the media source URI and plays it.
 */
void SoundPlayer::connected() {
	PRINTF_BLUE("SoundPlayer::connected(%s): loading '%s', as '%s'", getStateName(), m_filePath.c_str(), m_streamClass.c_str());
	if (VERIFY(m_state == eState_Connecting))
		setState(eState_Connected);
	checkForNextStep();
}
Ejemplo n.º 30
0
			void handleAjaxRequest(CGIRequest& request,Json::Value& root)
			{
				ISD_LOGGER_TRACE("cgi begin.");
				
				//判断用户的合法性
				string strUid = request.getTrimQueryVal("uid");

				string strErrorMsg;
				int iRet = argsIsIllegal(strUid,strErrorMsg);
				if ( iRet != 0 )
				{
					root["ret"] = 10;
					root["msg"] = strErrorMsg;
					return;
				}
	
				string strWhere;
				bool bFlag = false;
				string strCid = request.getTrimQueryVal("cid",bFlag);
				if (bFlag && !strCid.empty())
				{
					strWhere = "c_cid='" + _cMysqlUtil.EscapeString2(strCid) + "'";
				}
				else
				{
					string strTitle = request.getTrimQueryVal("title",bFlag);
					if (bFlag && !strTitle.empty())
					{
						strWhere = "c_title like '%" + _cMysqlUtil.EscapeString2(strTitle) + "%'";
					}
				}
				
				int iState = atoi(request.getTrimQueryVal("state",bFlag).c_str());
				if (bFlag && iState != -1)
				{
					if (strWhere.empty())
					{
						strWhere = "c_state=" + intToString(iState);
					}
					else
					{
						strWhere += " and c_state=" + intToString(iState);
					}
				}
				
				if (!strWhere.empty())
				{
					strWhere = "and " + strWhere;
				}
				
				int iStartPage = 0;
				int iPage = atoi(request.getQueryVal("p").c_str());					//当前页
				if ( iPage > 0 )
				{
					iStartPage = iPage - 1;
				}
				int iRecordNumberOfPage = atoi(request.getQueryVal("psz").c_str());	//每页结果数
				if ( iRecordNumberOfPage <= 0 || iRecordNumberOfPage > 20)
				{
					iRecordNumberOfPage = 20;
				}
				
				char szSql[MAX_SQL_LENGTH] = {0};
				snprintf(szSql,sizeof(szSql)-1,"select c_cid,c_title,c_date,c_mtime,c_state,c_longpic_num,c_normalpic_num from d_config_system.t_cover where c_uid='%s' %s order by c_mtime desc limit %d,%d;",_cMysqlUtil.EscapeString2(strUid).c_str(),strWhere.c_str(),iStartPage*iRecordNumberOfPage,iRecordNumberOfPage);

				int iIndex = iStartPage*iRecordNumberOfPage;
				MYSQL_EXEC_GET_BEGIN(_cMysqlUtil, szSql, iRet)
				{
					string strCid,strTitle,strDate,strMtime;
					int iState = 0,iLongPicNum = 0,iNormalPicNum = 0;
					unsigned int uiPos = 0;
					GET_STR_COLUMN_VALUE_SCROLL(strCid, uiPos)
					GET_STR_COLUMN_VALUE_SCROLL(strTitle, uiPos)
					GET_STR_COLUMN_VALUE_SCROLL(strDate, uiPos)
					GET_STR_COLUMN_VALUE_SCROLL(strMtime, uiPos)
					GET_INT_COLUMN_VALUE_SCROLL(iState, uiPos)
					GET_INT_COLUMN_VALUE_SCROLL(iLongPicNum, uiPos)
					GET_INT_COLUMN_VALUE_SCROLL(iNormalPicNum, uiPos)
					
					Json::Value json;

					json["no"] = ++iIndex;
					json["cid"] = strCid;
					json["ti"] = strTitle;
					json["d"] = strDate;
					json["m"] = strMtime;
					json["sn"] = getStateName(iState);
					json["ln"] = iLongPicNum;
					json["rn"] = iNormalPicNum;
					
					root["node"].append(json);
				}MYSQL_EXEC_GET_END()