コード例 #1
0
ファイル: protocol.c プロジェクト: zmanda/amanda
/*
 * event callback that receives a packet
 */
static void
recvpkt_callback(
    void *		cookie,
    pkt_t *		pkt,
    security_status_t	status)
{
    proto_t *p = cookie;

    assert(p != NULL);

    switch (status) {
    case S_OK:
	state_machine(p, PA_RCVDATA, pkt);
	break;
    case S_TIMEOUT:
	state_machine(p, PA_TIMEOUT, NULL);
	break;
    case S_ERROR:
	state_machine(p, PA_ABORT, NULL);
	break;
    default:
	assert(0);
	break;
    }
}
コード例 #2
0
ファイル: link_layer.c プロジェクト: joaoDavidGB/RCOM
/*
  Verifica se a frame está correta segundo o seu tipo ("type")
*/
int verifyFrame(char * frame, int length, char * type) {
    int i=0;
    int j=0;
    estado = START;
    char BBC2 = 0;
    for(i = 0; i < length; i++) {

        //printf("verifyFrame %s[%d]: %x \n", type, i, frame[i]);

        if (type != "I0" && type != "I1") {
            if (length != 5) {
                info->lostPack++;
                printf("frame do tipo %s com tamanho irregular = %d \n", type, length);
                return 0;
            }
            state_machine(estado, frame[i], type);

        }
        else {
            if (i < 4 || (i == (length-1))) {
                state_machine(estado, frame[i], type);
            }
            else if (i == (length - 2)) {
                if (frame[i] != BBC2) {
                    info->lostPack++;
                    //printf("\n\n\n\nBCC2 devia ser 0x%02x, mas é 0x%02x\n\n\n\n\n", BBC2, frame[i]);
                    return 0;
                }
            }
            else {
                BBC2 = BBC2^frame[i];
                info->dados[j] = frame[i];
                j++;
                info->lengthDados = j;
            }
        }

    }

    if (estado == STOP2) {
        estado = START;
        return 1;
    }
    else {
        info->lostPack++;
        estado = START;
        return 0;
    }
}
コード例 #3
0
ファイル: protocol.c プロジェクト: zmanda/amanda
/*
 * This is a callback for security_connect.  After the security layer
 * has initiated a connection to the given host, this will be called
 * with a security_handle_t.
 *
 * On error, the security_status_t arg will reflect errors which can
 * be had via security_geterror on the handle.
 */
static void
connect_callback(
    void *cookie)
{
    proto_t *p = cookie;

    assert(p != NULL);
    if (p->event_handle) {
	event_release(p->event_handle);
	p->event_handle = 0;
    }

    proto_debug(1, _("protocol: connect_callback: p %p\n"), p);

    switch (p->status) {
    case S_OK:
	state_machine(p, PA_START, NULL);
	break;

    case S_TIMEOUT:
	security_seterror(p->security_handle, _("timeout during connect"));
	/* FALLTHROUGH */

    case S_ERROR:
	/*
	 * For timeouts or errors, retry a few times, waiting CONNECT_WAIT
	 * seconds between each attempt.  If they all fail, just return
	 * an error back to the caller.
	 */
	if (--p->connecttries == 0) {
	    state_machine(p, PA_ABORT, NULL);
	} else {
	    proto_debug(1, _("protocol: connect_callback: p %p: retrying %s\n"),
			    p, p->hostname);
	    security_close(p->security_handle);
	    /* XXX overload p->security handle to hold the event handle */
	    p->security_handle =
		(security_handle_t *)event_create(CONNECT_WAIT, EV_TIME,
		connect_wait_callback, p);
	    event_activate((event_handle_t *) p->security_handle);
	}
	break;

    default:
	assert(0);
	break;
    }
}
コード例 #4
0
ファイル: run_elevator.c プロジェクト: andrehy/Heislab
void run_elevator(){
  
  // Elevator is started and state is unknown.
  
  // Initialize timer.
  timer = clock();
  
  current_state = UNDEF; 
  initialize_elevator();
  
  // Elevator is now at some floor and ready for orders.
  while(1){
    
    // Handles io-signals, (sets/clears lights etc.)
    io_signals();
    
    // Calls the state machine switch function.
    state_machine();
    
    // If ... exit the main loop and terminate the program.
    if (elev_get_button_signal(BUTTON_CALL_UP,0) && current_state == EMERGENCY){
      elev_set_speed(0);
      break;
    }
  }

  initialize_elevator();
}
コード例 #5
0
ファイル: power_button_x86.c プロジェクト: thehobn/ec
void power_button_task(void)
{
	uint64_t t;
	uint64_t tsleep;

	while (1) {
		t = get_time().val;

		/* Update state machine */
		CPRINTS("PB task %d = %s", pwrbtn_state,
			state_names[pwrbtn_state]);

		state_machine(t);

		/* Sleep until our next timeout */
		tsleep = -1;
		if (tnext_state && tnext_state < tsleep)
			tsleep = tnext_state;
		t = get_time().val;
		if (tsleep > t) {
			unsigned d = tsleep == -1 ? -1 : (unsigned)(tsleep - t);
			/*
			 * (Yes, the conversion from uint64_t to unsigned could
			 * theoretically overflow if we wanted to sleep for
			 * more than 2^32 us, but our timeouts are small enough
			 * that can't happen - and even if it did, we'd just go
			 * back to sleep after deciding that we woke up too
			 * early.)
			 */
			CPRINTS("PB task %d = %s, wait %d", pwrbtn_state,
			state_names[pwrbtn_state], d);
			task_wait_event(d);
		}
	}
}
コード例 #6
0
ファイル: nrf_drv_twi.c プロジェクト: BlueSkyGjj/nRF52
/**
 * @brief Function for prepering shortcut register.
 *
 * @param[in] p_instance      TWI.
 */
static void txrx_shorts_set_task_start(volatile nrf_drv_twi_t const * const p_instance)
{
    uint32_t short_mask;
    volatile transfer_t * p_transfer = &(m_cb[p_instance->instance_id].transfer);

    nrf_twi_shorts_clear(p_instance->p_reg,
                         NRF_TWI_SHORTS_BB_SUSPEND_MASK | NRF_TWI_SHORTS_BB_STOP_MASK);

    // if the last one and no pending transfer prepare to wait for stopped event
    if (((p_transfer->count + 1) == p_transfer->length) && p_transfer->xfer_pending == false)
    {
        short_mask = NRF_TWI_SHORTS_BB_STOP_MASK;

        p_transfer->end_event = NRF_TWI_EVENTS_STOPPED;
        nrf_twi_event_clear(p_instance->p_reg, p_transfer->end_event);

        if (m_handlers[p_instance->instance_id])
        {
            nrf_twi_int_disable(p_instance->p_reg, p_transfer->end_int);
            p_transfer->end_int   = NRF_TWI_INT_STOPPED_MASK;
            nrf_twi_int_enable(p_instance->p_reg, p_transfer->end_int);
        }

        state_machine(p_instance, TO_STOP);
    }
    else
    {
        short_mask = NRF_TWI_SHORTS_BB_SUSPEND_MASK;
    }

    nrf_twi_shorts_set(p_instance->p_reg, short_mask);
    nrf_twi_tasks_t prev_task = p_transfer->task;
    p_transfer->task = NRF_TWI_TASKS_RESUME;
    nrf_twi_task_set(p_instance->p_reg, prev_task);
}
コード例 #7
0
ファイル: aistatemachine.cpp プロジェクト: nebadon2025/replex
// State Machine Thread main loop.
void AIEngine::threadloop(void)
{
  queued_type::iterator queued_element, end;
  {
	engine_state_type_wat engine_state_w(mEngineState);
	end = engine_state_w->list.end();
	queued_element = engine_state_w->list.begin();
	if (queued_element == end)
	{
	  // Nothing to do. Wait till something is added to the queue again.
	  engine_state_w->waiting = true;
	  engine_state_w.wait();
	  engine_state_w->waiting = false;
	  return;
	}
  }
  do
  {
	AIStateMachine& state_machine(queued_element->statemachine());
	state_machine.multiplex(AIStateMachine::normal_run);
	bool active = state_machine.active(this);		// This locks mState shortly, so it must be called before locking mEngineState because add() locks mEngineState while holding mState.
	engine_state_type_wat engine_state_w(mEngineState);
	if (!active)
	{
	  Dout(dc::statemachine(state_machine.mSMDebug), "Erasing state machine [" << (void*)&state_machine << "] from " << mName);
	  engine_state_w->list.erase(queued_element++);
	}
	else
	{
	  ++queued_element;
	}
  }
  while (queued_element != end);
}
コード例 #8
0
ファイル: aistatemachine.cpp プロジェクト: nebadon2025/replex
// MAIN-THREAD
void AIEngine::mainloop(void)
{
  queued_type::iterator queued_element, end;
  {
	engine_state_type_wat engine_state_w(mEngineState);
	end = engine_state_w->list.end();
	queued_element = engine_state_w->list.begin();
  }
  U64 total_clocks = 0;
#if STATE_MACHINE_PROFILING
  queued_type::value_type slowest_element(NULL);
  AIStateMachine::StateTimerRoot::TimeData slowest_timer;
#endif
  while (queued_element != end)
  {
	AIStateMachine& state_machine(queued_element->statemachine());
	AIStateMachine::StateTimerBase::TimeData time_data;
	if (!state_machine.sleep(get_clock_count()))
	{
		AIStateMachine::StateTimerRoot timer(state_machine.getName());
		state_machine.multiplex(AIStateMachine::normal_run);
		time_data = timer.GetTimerData();
	}
	if (U64 delta = time_data.GetDuration())
	{
		state_machine.add(delta);
		total_clocks += delta;
#if STATE_MACHINE_PROFILING
		if (delta > slowest_timer.GetDuration())
		{
			slowest_element = *queued_element;
			slowest_timer = time_data;
		}
#endif
	}

	bool active = state_machine.active(this);		// This locks mState shortly, so it must be called before locking mEngineState because add() locks mEngineState while holding mState.
	engine_state_type_wat engine_state_w(mEngineState);
	if (!active)
	{
	  Dout(dc::statemachine(state_machine.mSMDebug), "Erasing state machine [" << (void*)&state_machine << "] from " << mName);
	  engine_state_w->list.erase(queued_element++);
	}
	else
	{
	  ++queued_element;
	}
	if (total_clocks >= sMaxCount)
	{
#if STATE_MACHINE_PROFILING
		print_statemachine_diagnostics(total_clocks, slowest_timer, slowest_element);
#endif
	  Dout(dc::statemachine, "Sorting " << engine_state_w->list.size() << " state machines.");
	  engine_state_w->list.sort(QueueElementComp());
	  break;
	}
  }
}
コード例 #9
0
static
void
data_callback(
    globus_xio_handle_t                 handle,
    globus_result_t                     result,
    globus_byte_t *                     buffer,
    globus_size_t                       len,
    globus_size_t                       nbytes,
    globus_xio_data_descriptor_t        data_desc,
    void *                              user_arg)
{
    globus_l_timeout_info_t *           info = user_arg;

    globus_mutex_lock(&lock);
    if (result != GLOBUS_SUCCESS)
    {
        if (info->state == info->timeout_state &&
            info->expect_timeout &&
            result_is_timeout(result))
        {
            /* hit expected result */
            info->expect_timeout = GLOBUS_FALSE;

            result = GLOBUS_SUCCESS;
        }

        info->state = GLOBUS_XIO_OPERATION_TYPE_CLOSE;
    }
    else
    {
        globus_assert(info->state == GLOBUS_XIO_OPERATION_TYPE_READ ||
                      info->state == GLOBUS_XIO_OPERATION_TYPE_WRITE);

        if (info->state == GLOBUS_XIO_OPERATION_TYPE_READ &&
            info->server != NULL)
        {
            info->state = GLOBUS_XIO_OPERATION_TYPE_WRITE;
        }
        else if (info->state == GLOBUS_XIO_OPERATION_TYPE_WRITE &&
                 info->server != NULL)
        {
            info->state = GLOBUS_XIO_OPERATION_TYPE_CLOSE;
        }
        else if (info->state == GLOBUS_XIO_OPERATION_TYPE_WRITE)
        {
            info->state = GLOBUS_XIO_OPERATION_TYPE_READ;
        }
        else
        {
            info->state = GLOBUS_XIO_OPERATION_TYPE_WRITE;
        }
    }
    info->result = result;
    globus_mutex_unlock(&lock);
    state_machine(info);
}
コード例 #10
0
/* ************************************************** */
void tx(call_t *c, packet_t *packet) {
    struct nodedata *nodedata = get_node_private_data(c);
    
    das_insert(nodedata->packets, (void *) packet);

    if (nodedata->state == STATE_IDLE) {
        nodedata->clock = get_time();  
        state_machine(c,NULL);
    } 
}
コード例 #11
0
ファイル: prot_emsi.c プロジェクト: askovpen/binkleyforce
int emsi_send_emsidat(s_emsi *local_emsi)
{
	s_tx_emsidat d;
	
	memset(&d, '\0', sizeof(s_tx_emsidat));
	
	d.caller = state.caller;
	d.local_emsi = local_emsi;
	
	return state_machine(st_tx_emsidat, &d) ? 1 : 0;
}
コード例 #12
0
ファイル: prot_emsi.c プロジェクト: askovpen/binkleyforce
int emsi_recv_emsidat(s_emsi *remote_emsi)
{
	s_rx_emsidat d;
	
	memset(&d, '\0', sizeof(s_rx_emsidat));
	
	d.caller = state.caller;
	d.remote_emsi = remote_emsi;
	
	return state_machine(st_rx_emsidat, &d) ? 1 : 0;
}
コード例 #13
0
/**@brief Generic function for handling TWI interrupt
 *
 * @param[in]  p_reg         Pointer to instance register structure.
 * @param[in]  instance_id   Index of instance.
 */
__STATIC_INLINE void nrf_drv_twi_int_handler(NRF_TWI_Type * p_reg, uint32_t instance_id)
{
    volatile transfer_t * p_transfer = &(m_cb[instance_id].transfer);
    sm_evt_t sm_event;

    bool error_occured   = nrf_twi_event_check(p_reg, NRF_TWI_EVENTS_ERROR);
    bool end_evt_occured = nrf_twi_event_check(p_reg, p_transfer->end_event);

    nrf_twi_event_clear(p_reg, NRF_TWI_EVENTS_ERROR);
    nrf_twi_event_clear(p_reg, NRF_TWI_EVENTS_TXDSENT);
    nrf_twi_event_clear(p_reg, NRF_TWI_EVENTS_RXDREADY);
    nrf_twi_event_clear(p_reg, NRF_TWI_EVENTS_STOPPED);

    if (error_occured || end_evt_occured)
    {
        if (error_occured)
        {
            sm_event = ON_ERROR;
        }
        else
        {
            sm_event = p_transfer->is_tx ? TX_DONE : RX_DONE;
        }
        state_machine(m_instances[instance_id], sm_event);

        if (p_transfer->error_condition)
        {
            p_transfer->transfer_in_progress = false;
            nrf_drv_twi_evt_t evt =
            {
                .type               = NRF_DRV_TWI_ERROR,
                .p_data    = p_transfer->p_data,
                .length    = p_transfer->count,
                // Driver uses shortcuts, so NRF_TWI_ERROR_OVERRUN_NACK will not take place.
                .error_src = (nrf_twi_error_source_get(p_reg) &
                             NRF_TWI_ERROR_ADDRESS_NACK) ? NRF_TWI_ERROR_ADDRESS_NACK
                             : NRF_TWI_ERROR_DATA_NACK,
            };
            m_handlers[instance_id](&evt);
        }
        else if (p_transfer->count >= p_transfer->length)
        {
            p_transfer->transfer_in_progress = false;
            nrf_drv_twi_evt_t evt =
            {
                .type   = p_transfer->is_tx ? NRF_DRV_TWI_TX_DONE : NRF_DRV_TWI_RX_DONE,
                .p_data = p_transfer->p_data,
                .length = p_transfer->count,
            };
            m_handlers[instance_id](&evt);
        }
    }
コード例 #14
0
ファイル: automata-demo.c プロジェクト: mueschm/CompilerKit
int main (int argc, char ** argv)
{
    CompilerKitFSM* fsm;
    // Initialize GObject type system.
    // Allow us to query the types of an object.
    // Only needs to be called once, Test suite already calls it and is not necessary there.
    g_type_init();

    fsm = state_machine();
    /*print_states(fsm);*/
    match_string(fsm);
    g_object_unref (fsm); // Decreases the reference count by 1, if count becomes 0, then free memeory.
}
コード例 #15
0
ファイル: tls_server.cpp プロジェクト: BenjaminSchiborr/safe
/*
* Perform a server-side TLS handshake
*/
void TLS_Server::do_handshake()
   {
   while(true)
      {
      if(active && !state)
         break;

      state_machine();

      if(!active && !state)
         throw TLS_Exception(HANDSHAKE_FAILURE, "TLS_Server: Handshake failed");
      }
   }
コード例 #16
0
ファイル: mkdep-toc2.c プロジェクト: slavas490/v8-juice
/*
 * Generate dependencies for one file.
 */
void do_depend(const char * filename, const char * command)
{
    int mapsize;
    int pagesizem1 = getpagesize()-1;
    int fd;
    struct stat st;
    char * map;

    fd = open(filename, O_RDONLY);
    if (fd < 0) {
        fprintf(stderr,"cannot open file: %s\n",filename);
        return;
    }

    fstat(fd, &st);
    if (st.st_size == 0) {
        fprintf(stderr,"%s is empty\n",filename);
        close(fd);
        return;
    }

    mapsize = st.st_size;
    mapsize = (mapsize+pagesizem1) & ~pagesizem1;
    map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
    if ((long) map == -1) {
        fprintf(stderr,"mmap failed\n");
        close(fd);
        return;
    }
    if ((unsigned long) map % sizeof(unsigned long) != 0)
    {
        fprintf(stderr, "do_depend: map not aligned\n");
        exit(1);
    }

    hasdep = 0;
    state_machine(map, map+st.st_size);
    if (hasdep) {
        puts(command);
        if (*command)
            define_precious(filename);
    }
    else
    {
        // Create empty target to avoid "no rule to create ..." when we delete/rename a file:
        printf("%s:\n", filename);
    }

    munmap(map, mapsize);
    close(fd);
}
コード例 #17
0
int
main (int argc, char **argv)
{
  GError *error = NULL;
  GOptionContext *context;
  char **l;

  context = g_option_context_new ("- Carrick/ConnMan 3G connection wizard");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  if (!g_option_context_parse (context, &argc, &argv, &error)) {
    g_printerr ("option parsing failed: %s\n", error->message);
    exit (1);
  }

  connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
  if (connection == NULL) {
    g_printerr ("Cannot connect to DBus: %s\n", error->message);
    g_error_free (error);
    exit (1);
  }

  if (service_paths) {
    for (l = service_paths; *l; l++) {
      GggService *service;

      service = ggg_service_new (connection, *l);
      if (service)
        services = g_list_prepend (services, service);
    }
  }

  if (add_fake) {
    services = g_list_prepend (services, ggg_service_new_fake ("Fake Device 1", FALSE));
    services = g_list_prepend (services, ggg_service_new_fake ("Fake Device 2", TRUE));
  }

  /* Scan connman for services if none were found */
  if (services == NULL)
    find_services ();

  gtk_window_set_default_icon_name ("network-wireless");

  state = STATE_START;
  state_machine ();

  show_network_panel ();

  return 0;
}
コード例 #18
0
void main(void)
{
	unsigned char n;


	restart_hw();				// Hardware zuruecksetzen

	for (n=0;n<50;n++) {		// Warten bis Bus stabil, nach Busspannungswiederkehr
		TR0=0;					// Timer 0 anhalten
		TH0=eeprom[ADDRTAB+1];	// Timer 0 setzen mit phys. Adr. damit Geräte unterschiedlich beginnen zu senden
		TL0=eeprom[ADDRTAB+2];
		TF0=0;					// Überlauf-Flag zurücksetzen
		TR0=1;					// Timer 0 starten
		while(!TF0);
	}
	restart_app();				// Anwendungsspezifische Einstellungen zuruecksetzen


	do  {
		if(APPLICATION_RUN) {	// nur wenn run-mode gesetzt

			state_machine(g_objno);
		}

		if(tel_arrived) process_tel();		// empfangenes Telegramm abarbeiten

		if(RTCCON>=0x80) delay_timer();		// Realtime clock Ueberlauf


		// Watchdog!
		  EA = 0;
		  // feed the watchdog
		  WFEED1 = 0xA5;
		  WFEED2 = 0x5A;
		  // restore interrupts
		  EA=1;

		// Abfrage Programmier-Taster
		TASTER=1;					// Pin als Eingang schalten um Taster abzufragen
		if(!TASTER) {				// Taster gedrückt
			for(n=0;n<100;n++) {}	// Entprell-Zeit
			while(!TASTER);			// warten bis Taster losgelassen
			status60^=0x81;			// Prog-Bit und Parity-Bit im system_state toggeln
		}
		TASTER=!(status60 & 0x01);	// LED entsprechend Prog-Bit schalten (low=LED an)
		for(n=0;n<100;n++) {}		// falls Hauptroutine keine Zeit verbraucht, der LED etwas Zeit geben, damit sie auch leuchten kann
  } while(1);
}
コード例 #19
0
ファイル: main.c プロジェクト: Vanganesha/oufffteam
// Timer interrupt => sample time
void __attribute__((__interrupt__)) _T1Interrupt(void)
{
	unsigned char i;
	WriteTimer1(0);		//reset timer's value
	IFS0bits.T1IF = 0; 	//clear the interrupt flag
	if (current_state == TSOP40_16) // end of read turn
	{
		for (i=0 ; i<16 ; i++)
		{
			polar_response[i]=receive_flag[i];
			receive_flag[i]=0;
		}
		COMPUTE_FLAG = ON;
	}
	state_machine();
}
コード例 #20
0
ファイル: mkdep.c プロジェクト: hugh712/Jollen
/*
 * Generate dependencies for one file.
 */
void do_depend(const char * filename, const char * command)
{
	int mapsize;
	int pagesizem1 = getpagesize()-1;
	int fd;
	struct stat st;
	char * map;

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		perror(filename);
		return;
	}

	fstat(fd, &st);
	if (st.st_size == 0) {
		fprintf(stderr,"%s is empty\n",filename);
		close(fd);
		return;
	}

	mapsize = st.st_size;
	mapsize = (mapsize+pagesizem1) & ~pagesizem1;
	map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
	if ((long) map == -1) {
		perror("mkdep: mmap");
		close(fd);
		return;
	}
	if ((unsigned long) map % sizeof(unsigned long) != 0)
	{
		fprintf(stderr, "do_depend: map not aligned\n");
		exit(1);
	}

	hasdep = 0;
	clear_config();
	state_machine(map, map+st.st_size);
	if (hasdep) {
		puts(command);
		if (*command)
			define_precious(filename);
	}

	munmap(map, mapsize);
	close(fd);
}
コード例 #21
0
ファイル: mqtt-demo.c プロジェクト: 1847123212/contiki
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(mqtt_demo_process, ev, data)
{

  PROCESS_BEGIN();

  printf("MQTT Demo Process\n");

  if(init_config() != 1) {
    PROCESS_EXIT();
  }

  update_config();

  def_rt_rssi = 0x8000000;
  uip_icmp6_echo_reply_callback_add(&echo_reply_notification,
                                    echo_reply_handler);
  etimer_set(&echo_request_timer, conf.def_rt_ping_interval);

	PUBLISH_TRIGGER->configure(SENSORS_ACTIVE, 1);

  /* Main loop */
  while(1) {

    PROCESS_YIELD();

    if(ev == sensors_event && data == PUBLISH_TRIGGER) {
      if(state == STATE_ERROR) {
        connect_attempt = 1;
        state = STATE_REGISTERED;
      }
    }

    if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) ||
       ev == PROCESS_EVENT_POLL ||
       (ev == sensors_event && data == PUBLISH_TRIGGER && PUBLISH_TRIGGER->value(BUTTON_SENSOR_VALUE_STATE) == 0)) {
      state_machine();
    }

    if(ev == PROCESS_EVENT_TIMER && data == &echo_request_timer) {
      ping_parent();
      etimer_set(&echo_request_timer, conf.def_rt_ping_interval);
    }
  }

  PROCESS_END();
}
コード例 #22
0
ファイル: tls_server.cpp プロジェクト: BenjaminSchiborr/safe
/*
* Read from a TLS connection
*/
size_t TLS_Server::read(byte out[], size_t length)
   {
   if(!active)
      throw Internal_Error("TLS_Server::read called while closed");

   writer.flush();

   while(read_buf.size() == 0)
      {
      state_machine();
      if(active == false)
         break;
      }

   size_t got = std::min<size_t>(read_buf.size(), length);
   read_buf.read(out, got);
   return got;
   }
コード例 #23
0
static
void
open_close_callback(
    globus_xio_handle_t                 handle,
    globus_result_t                     result,
    void *                              user_arg)
{
    globus_l_timeout_info_t *           info = user_arg;

    globus_mutex_lock(&lock);
    if (result != GLOBUS_SUCCESS)
    {
        if (info->state == info->timeout_state &&
            info->expect_timeout &&
            result_is_timeout(result))
        {
            /* hit expected result */
            info->expect_timeout = GLOBUS_FALSE;

            result = GLOBUS_SUCCESS;
        }

        info->state = GLOBUS_XIO_OPERATION_TYPE_FINISHED;
    }
    else
    {
        if (info->state == GLOBUS_XIO_OPERATION_TYPE_OPEN &&
            info->server != NULL)
        {
            info->state = GLOBUS_XIO_OPERATION_TYPE_READ;
        }
        else if (info->state == GLOBUS_XIO_OPERATION_TYPE_OPEN)
        {
            info->state = GLOBUS_XIO_OPERATION_TYPE_WRITE;
        }
        else
        {
            info->state = GLOBUS_XIO_OPERATION_TYPE_FINISHED;
        }
    }
    info->result = result;
    globus_mutex_unlock(&lock);
    state_machine(info);
}
コード例 #24
0
ファイル: main.c プロジェクト: laszuba/binary_watch
int main(void) {

	init();

	// delay for at least one second at boot to allow the RTC to stabilize
	startup_blink();

	// Set an interesting time for testing
	my_time.secs  = 0;
	my_time.mins  = 0b00101010;
	my_time.hours = 0b00010101;

	// Globally enable interrupts
	sei();

	while (TRUE) {
		state_machine();
	}

	return 0;
}
コード例 #25
0
ファイル: accelerate.cpp プロジェクト: danpoe/cbmc
void acceleratet::insert_automaton(trace_automatont &automaton)
{
  symbolt state_sym=make_symbol("trace_automaton::state",
      unsigned_poly_type());
  symbolt next_state_sym=make_symbol("trace_automaton::next_state",
      unsigned_poly_type());
  symbol_exprt state=state_sym.symbol_expr();
  symbol_exprt next_state=next_state_sym.symbol_expr();

  trace_automatont::sym_mapt transitions;
  state_sett accept_states;

  automaton.get_transitions(transitions);
  automaton.accept_states(accept_states);

  std::cout
    << "Inserting trace automaton with "
    << automaton.num_states() << " states, "
    << accept_states.size() << " accepting states and "
    << transitions.size() << " transitions\n";

  // Declare the variables we'll use to encode the state machine.
  goto_programt::targett t=program.instructions.begin();
  decl(state, t, from_integer(automaton.init_state(), state.type()));
  decl(next_state, t);

  // Now for each program location that appears as a symbol in the
  // trace automaton, add the appropriate code to drive the state
  // machine.
  for(const auto &sym : automaton.alphabet)
  {
    scratch_programt state_machine(symbol_table);
    trace_automatont::sym_range_pairt p=transitions.equal_range(sym);

    build_state_machine(p.first, p.second, accept_states, state, next_state,
        state_machine);

    program.insert_before_swap(sym, state_machine);
  }
}
コード例 #26
0
static
void
accept_callback(
    globus_xio_server_t                 server,
    globus_xio_handle_t                 server_handle,
    globus_result_t                     result,
    void *                              user_arg)
{
    globus_l_timeout_info_t *           info = user_arg;

    globus_mutex_lock(&lock);
    if (result != GLOBUS_SUCCESS)
    {
        if (info->timeout_state == info->state &&
            info->expect_timeout &&
            result_is_timeout(result))
        {
            /* hit expected result */
            info->expect_timeout = GLOBUS_FALSE;

            result = GLOBUS_SUCCESS;
        }
        else
        {
            fprintf(stderr, "Unexpected accept failure\n");
        }

        info->state = GLOBUS_XIO_OPERATION_TYPE_FINISHED;
    }
    else
    {
        info->state = GLOBUS_XIO_OPERATION_TYPE_OPEN;
    }
    info->handle = server_handle;
    info->result = result;
    globus_mutex_unlock(&lock);
    state_machine(info);
}
コード例 #27
0
int main(void)
{
	haveString = 0;	// Initialize haveString to false
	InitUSART6();	// Initialize USART
	
	// Setup SysTick
	ticks = 0;
	lastTicks = 0;
	SystemCoreClockUpdate();

	InitBuffer(&receive_buff);	// Initialize receive buffer to '+'
	InitBuffer(&send_buff);		// Initialize send buffer to '+'
	STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);	// Initialize Push Button

	// Configure so 1 tick = 1ms or 1000tick = 1 second
	if (SysTick_Config(SystemCoreClock / 1000))
		while (1);
	
	while(1)
	{
		state_machine();
	}
}
コード例 #28
0
ファイル: main.c プロジェクト: quark-mcu/qmsi
int main(void)
{
	bool do_soc_sleep, sleep_ready;
	int current_state = 0;
	QM_PRINTF("Starting: Sleep multicore %s\n", MYNAME);

#if !QM_SENSOR
	sensor_activation();
#endif
	init_mailbox();

	while (current_state < 5) {
		clk_sys_udelay(DELAY_1_SECOND);
		state_machine(current_state, &sleep_ready, &do_soc_sleep);

		/*
		 * In that order, we can force the race condition when both
		 * request sleep.
		 */
		if (do_soc_sleep) {
			request_soc_sleep();
			current_state++;
		} else if (mbox_cb_fired) {
			mbox_cb_fired = false;

			qm_mbox_ch_read(mbox_rx, &rx_data);
			if (rx_data.ctrl == SLEEP_REQ) {
				soc_sleep_requested(sleep_ready);
				current_state++;
			}
		}
	}

	QM_PRINTF("Finished: Sleep multicore %s\n", MYNAME);
	return 0;
}
コード例 #29
0
void ms_bitrate_controller_process_rtcp(MSBitrateController *obj, mblk_t *rtcp){
	if (ms_qos_analyzer_process_rtcp(obj->analyzer,rtcp)){
		state_machine(obj);
	}
}
コード例 #30
0
ファイル: mqtt-client.c プロジェクト: zzeekk/cc26xx-st2
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(mqtt_client_process, ev, data)
{

    PROCESS_BEGIN();

    printf("CC26XX MQTT Client Process\n");

    conf = &cc26xx_web_demo_config.mqtt_config;
    if(init_config() != 1) {
        PROCESS_EXIT();
    }

    register_http_post_handlers();

    def_rt_rssi = 0x8000000;
    uip_icmp6_echo_reply_callback_add(&echo_reply_notification,
                                      echo_reply_handler);
    etimer_set(&echo_request_timer, conf->def_rt_ping_interval);

    /* Main loop */
    while(1) {

        PROCESS_YIELD();

        if(ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER) {
            if(state == MQTT_CLIENT_STATE_ERROR) {
                connect_attempt = 1;
                state = MQTT_CLIENT_STATE_REGISTERED;
            }
        }

        if(ev == httpd_simple_event_new_config) {
            /*
             * Schedule next pass in a while. When HTTPD sends us this event, it is
             * also in the process of sending the config page. Wait a little before
             * reconnecting, so as to not cause congestion.
             */
            etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL);
        }

        if(ev == cc26xx_web_demo_config_loaded_event) {
            update_config();
        }

        if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) ||
                ev == PROCESS_EVENT_POLL ||
                ev == cc26xx_web_demo_publish_event ||
                (ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER)) {
            state_machine();
        }

        if(ev == PROCESS_EVENT_TIMER && data == &echo_request_timer) {
            ping_parent();
            etimer_set(&echo_request_timer, conf->def_rt_ping_interval);
        }

        if(ev == cc26xx_web_demo_load_config_defaults) {
            init_config();
            etimer_set(&publish_periodic_timer, NEW_CONFIG_WAIT_INTERVAL);
        }
    }

    PROCESS_END();
}