static void
state_initialize_pin (GcrImporter *self, gboolean async)
{
	GP11TokenInfo *info;
	gboolean initialize;
	CK_RV rv;
	
	g_assert (GCR_IS_IMPORTER (self));
	
	/* HACK: Doesn't function when async */
	if (!async) {
		g_return_if_fail (self->pv->slot);
		info = gp11_slot_get_token_info (self->pv->slot);
		g_return_if_fail (info);
	
		initialize = !(info->flags & CKF_USER_PIN_INITIALIZED);
		gp11_token_info_free (info);
		
		if (initialize) {
			rv = hacky_perform_initialize_pin (self->pv->slot);
			if (rv != CKR_OK) {
				g_propagate_error (&self->pv->error, g_error_new (GP11_ERROR, rv, "%s", gp11_message_from_rv (rv)));
				next_state (self, state_failure);
				return;
			} 
		}
	}

	next_state (self, state_open_session);
}
static void
complete_read_buffer (GcrImporter *self, gssize count, GError *error)
{
	g_assert (GCR_IS_IMPORTER (self));
	g_assert (self->pv->buffer);
	
	/* A failure */
	if (count == -1) {
		g_propagate_error (&self->pv->error, error);
		next_state (self, state_failure);
	} else {
	
		g_return_if_fail (count >= 0 && count <= BLOCK);
		g_byte_array_set_size (self->pv->buffer, self->pv->buffer->len - (BLOCK - count));
		
		/* Finished reading */
		if (count == 0) {
			
			/* Optimization, unref input early */
			g_object_unref (self->pv->input);
			self->pv->input = NULL;
			
			next_state (self, state_parse_buffer);
			
		/* Read the next block */
		} else {
			next_state (self, state_read_buffer);
		}
	}
	
}
static void
complete_open_session (GcrImporter *self, GP11Session *session, GError *error)
{
	if (!session) {
		g_propagate_error (&self->pv->error, error);
		next_state (self, state_failure);
	} else {
		self->pv->session = session;
		next_state (self, state_create_object);
	}
}
static void
complete_create_object (GcrImporter *self, GP11Object *object, GError *error)
{
	if (object == NULL) {
		g_propagate_error (&self->pv->error, error);
		next_state (self, state_failure);
		
	} else {
		g_signal_emit (self, signals[IMPORTED], 0, object);
		g_object_unref (object);
		next_state (self, state_create_object);
	}
}
gboolean
gcr_importer_import (GcrImporter *self, GInputStream *input,
                     GCancellable *cancel, GError **error)
{
	g_return_val_if_fail (GCR_IS_IMPORTER (self), FALSE);
	g_return_val_if_fail (G_IS_INPUT_STREAM (input), FALSE);
	g_return_val_if_fail (!error || !*error, FALSE);
	g_return_val_if_fail (!self->pv->processing, FALSE);
	
	cleanup_import_data (self);
	
	self->pv->input = g_object_ref (input);
	if (cancel)
		self->pv->cancel = g_object_ref (cancel);
	self->pv->processing = TRUE;
	self->pv->async = FALSE;
	
	next_state (self, state_read_buffer);
	
	g_assert (!self->pv->processing);
	g_assert (!self->pv->input);
	g_assert (!self->pv->cancel);
	
	if (!self->pv->succeeded) {
		g_propagate_error (error, self->pv->error);
		self->pv->error = NULL;
		return FALSE;
	}
	
	return TRUE;
}
Example #6
0
net_t *sym_gen( net_t *n, rules_t *r )
{
	assert( r != NULL );

	net_t *next_net = malloc( sizeof(net_t) );
	if( next_net == NULL )
		print_error("alloc");

	next_net->cols = n->cols;
	next_net->rows = n->rows;

	next_net->vec = calloc( next_net->rows * next_net->cols, sizeof(unsigned char) );
	if( n->vec == NULL )
		print_error("alloc");
	
	for( int i = 0; i < next_net->rows * next_net->cols; i++ )
	{	
		next_net->vec[i] = next_state( n, i, r );
	}

	free(n->vec);
	free(n);

	return next_net;
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
core_error_e core_operation_base_c::goto_state(
    u32_t state )
    {
    operation_state_m = state;
    
    return next_state();
    }
static void
state_create_object (GcrImporter *self, gboolean async)
{
	GP11Attributes *attrs;
	GP11Object *object;
	GError *error = NULL;
	
	/* No more objects */
	if (g_queue_is_empty (&self->pv->queue)) {
		next_state (self, state_complete);
		
	} else {
		
		/* Pop first one off the list */
		attrs = g_queue_pop_head (&self->pv->queue);
		g_assert (attrs);
		
		gp11_attributes_add_boolean (attrs, CKA_TOKEN, CK_TRUE);
		
		if (async) {
			gp11_session_create_object_async (self->pv->session, attrs, self->pv->cancel, 
			                                  on_create_object, self);
		} else {
			object = gp11_session_create_object_full (self->pv->session, attrs, self->pv->cancel, &error);
			complete_create_object (self, object, error);
		}
	
		gp11_attributes_unref (attrs);
	}
}
Example #9
0
int main(int argc, char *argv[])
{
    cint_t board_a[BOARD_HEIGHT][BOARD_WIDTH] = {
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0 },
        { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 },
        { 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 },
        { 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
    };
    cint_t board_b[BOARD_HEIGHT][BOARD_WIDTH];

    cint_t *origin = (cint_t *) board_a
         , *dest   = (cint_t *) board_b;

    for (;;) {
        next_state(origin, dest);

        system("clear");
        print_board(dest);
        sleep(1);

        cint_t *tmp = origin;
        origin = dest;
        dest = tmp;
    }

    return 0;
}
Example #10
0
    void
    Outro::on_draw()
    {
        if (m_snd_game_exit != NULL)
        {
            if (timer_elapsed() > static_cast<unsigned int>(m_snd_game_exit->length_in_ms) + 100)
            {
                next_state();
            }
        }

        Globals g;

        g.render().DrawTile(0,0, g.values().res_w(), g.values().res_h(), m_img_mainmenu);

        string text1 = g.snd2txt().text();
        string text2 = "";

        if (text1.length() >= 25)
        {
            text2 = text1;
            text1.erase(25, string::npos);
            text2.erase(0, 25);
        }
        g.render().DrawText(500, 400, 1.0, 1.0, 1.0, text1);
        g.render().DrawText(500, 450, 1.0, 1.0, 1.0, text2);
    }
Example #11
0
static gboolean tick(gpointer data)
{
   xcowsay.transition_timeout -= TICK_TIMEOUT;
   if (xcowsay.transition_timeout <= 0) {
      xcowsay.state = next_state(xcowsay.state);
      switch (xcowsay.state) {
      case csLeadIn:
         fprintf(stderr, "Internal Error: Invalid state csLeadIn\n");
         exit(EXIT_FAILURE);
      case csDisplay:
         show_shape(xcowsay.bubble);
         close_when_clicked(xcowsay.bubble);
         xcowsay.transition_timeout = xcowsay.display_time;
         break;
      case csLeadOut:
         hide_shape(xcowsay.bubble);
         xcowsay.transition_timeout = get_int_option("lead_out_time");
         break;
      case csCleanup:
         destroy_shape(xcowsay.cow);
         xcowsay.cow = NULL;
         destroy_shape(xcowsay.bubble);
         xcowsay.bubble = NULL;
         break;
      }
   }
   
   return (xcowsay.state != csCleanup);
}
std::pair<STATUS, boost::asio::const_buffer> start_line_parser::parse_token(boost::asio::const_buffer buffer,
                                                                            size_t max_length,
                                                                            PARSE_OPTION option)
{
  parse_result result = http::parse_token(buffer,
                                          current_length_,
                                          max_length,
                                          get_token_delimiters(option));
  
  if(result.status == OVERFLOW || result.status == INVALID){
    return std::make_pair(result.status, result.result_buffer);
  }

  current_length_ += boost::asio::buffer_size(result.result_buffer);
    
  STATUS return_value = set_token(result.result_buffer, result.status == COMPLETE);

  if(return_value == DATAOVERFLOW || return_value == INVALID){
    return std::make_pair(result.status, result.remaining_buffer);
  }
  else if(result.status == COMPLETE){
    next_state(result.delimiter);
  }
  return std::make_pair(result.status, result.remaining_buffer);
}
Example #13
0
 void
 Outro::on_key_down(UINT keysym)
 {
     if (SDLK_ESCAPE == keysym)
     {
         next_state();
     }
 }
void sscf_estab_req(SSCF_DSC *dsc,void *uu_data,int uu_length)
{
    switch (dsc->state) {
	case sscf_11:
	case sscf_34:
	    next_state(dsc,sscf_22);
	    sscop_estab_req(&dsc->sscop,uu_data,uu_length,1);
	    return;
	case sscf_410:
	    next_state(dsc,sscf_25);
	    sscop_res_req(&dsc->sscop,uu_data,uu_length);
	    return;
	default:
	    break;
    }
    diag(COMPONENT,DIAG_FATAL,"sscf_estab_req invoked in state %s",
      state_name[dsc->state]);
}
static void
state_cancelled (GcrImporter *self, gboolean async)
{
	if (self->pv->cancel && g_cancellable_is_cancelled (self->pv->cancel))
		g_cancellable_cancel (self->pv->cancel);
	if (self->pv->error)
		g_error_free (self->pv->error);
	self->pv->error = g_error_new_literal (GCR_DATA_ERROR, GCR_ERROR_CANCELLED, _("The operation was cancelled"));
	next_state (self, state_failure);
}
static void sscf_rel_conf(void *user_data)
{
    SSCF_DSC *dsc = user_data;

    if (dsc->state != sscf_34)
	diag(COMPONENT,DIAG_FATAL,"sscf_rel_conf in state %s",
	  state_name[dsc->state]);
    next_state(dsc,sscf_11);
    if (dsc->ops->rel_conf) dsc->ops->rel_conf(dsc->user);
}
static void sscf_res_conf(void *user_data)
{
    SSCF_DSC *dsc = user_data;

    if (dsc->state != sscf_25)
	diag(COMPONENT,DIAG_FATAL,"sscf_res_conf in state %s",
	  state_name[dsc->state]);
    next_state(dsc,sscf_410);
    if (dsc->ops->estab_conf) dsc->ops->estab_conf(dsc->user,NULL,0);
}
static void sscf_rel_ind(void *user_data,void *uu_data,int uu_length,int user)
{
    SSCF_DSC *dsc = user_data;

    if (dsc->state == sscf_11 || dsc->state == sscf_34)
	diag(COMPONENT,DIAG_FATAL,"sscf_rel_ind in state %s",
	  state_name[dsc->state]);
    next_state(dsc,sscf_11);
    if (dsc->ops->rel_ind)
	dsc->ops->rel_ind(dsc->user,user ? uu_data : NULL,uu_length);
}
static void
complete_import_prompt (GcrImporter *self, GcrImportDialog *dialog, gint response)
{
	GP11Slot *slot;

	gtk_widget_hide (GTK_WIDGET (dialog));
	self->pv->prompted = TRUE;

	/* No dialog or dialog completed */
	if (response == GTK_RESPONSE_OK) {

		slot = _gcr_import_dialog_get_selected_slot (dialog);
		gcr_importer_set_slot (self, slot);
		next_state (self, state_initialize_pin);
		
	/* The dialog was cancelled or closed */
	} else {
		next_state (self, state_cancelled);
	}
}
static void sscf_estab_ind(void *user_data,void *uu_data,int uu_length)
{
    SSCF_DSC *dsc = user_data;

    if (dsc->state != sscf_11)
	diag(COMPONENT,DIAG_FATAL,"sscf_estab_ind in state %s",
	  state_name[dsc->state]);
    next_state(dsc,sscf_410);
    sscop_estab_resp(&dsc->sscop,NULL,0,1);
    if (dsc->ops->estab_ind) dsc->ops->estab_ind(dsc->user,uu_data,uu_length);
}
Example #21
0
static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer)
{
	if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
		fprintf(stderr, "mode change transfer not completed!\n");
		request_exit(2);
	}

	printf("async cb_mode_changed length=%d actual_length=%d\n",
		transfer->length, transfer->actual_length);
	if (next_state() < 0)
		request_exit(2);
}
Example #22
0
static gboolean
key_pressed_cb (ClutterActor *actor,
                ClutterEvent *event,
                gpointer      user_data)
{
  ClutterState *transitions = CLUTTER_STATE (user_data);

  if (!clutter_timeline_is_playing (clutter_state_get_timeline (transitions)))
    next_state (transitions, NULL);

  return TRUE;
}
Example #23
0
void recoder::send_rec_budget()
{
    while (m_rec_pkt_count < m_max_budget && next_state() == STATE_SEND_BUDGET) {
        guard g(m_lock);
        send_rec_packet();
    }

    dispatch_event(EVENT_BUDGET_SENT);
    inc("forward generations written");
    VLOG(LOG_GEN) << "Recoder " << m_coder << ": Write recoded packets ("
                  << m_rec_pkt_count << " of " << m_max_budget << ")";
}
static void sscf_restart(void *user_data,void *uu_data,int uu_length,int ind)
{
    SSCF_DSC *dsc = user_data;

    if ((!ind && dsc->state != sscf_34) || (ind && (dsc->state == sscf_11 ||
      dsc->state == sscf_34)))
	diag(COMPONENT,DIAG_FATAL,"sscf_restart (ind = %d) in state %s",
	  state_name[dsc->state],ind);
    sscop_estab_resp(&dsc->sscop,NULL,0,1);
    next_state(dsc,sscf_410);
    if (dsc->ops->restart) dsc->ops->restart(dsc->user,uu_data,uu_length,ind);
}
static void sscf_estab_conf(void *user_data,
  void *uu_data,int uu_length)
{
    SSCF_DSC *dsc = user_data;

    if (dsc->state != sscf_22)
	diag(COMPONENT,DIAG_FATAL,"sscf_estab_conf in state %s",
	  state_name[dsc->state]);
    next_state(dsc,sscf_410);
    if (dsc->ops->estab_conf)
	dsc->ops->estab_conf(dsc->user,uu_data,uu_length);
    
}
Example #26
0
int main()
{
    state prev = to_state("00000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000");
    std::size_t steps = 25;

    print_state(prev);
    for (std::size_t i = 0; i < steps; ++i) {
        state curr = next_state(prev);
        print_state(curr);
        prev.swap(curr);
    }
    return 0;
}
Example #27
0
static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer)
{
	unsigned char irqtype = transfer->buffer[0];

	if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
		fprintf(stderr, "irq transfer status %d?\n", transfer->status);
		do_exit = 2;
		libusb_free_transfer(transfer);
		irq_transfer = NULL;
		return;
	}

	printf("IRQ callback %02x\n", irqtype);
	switch (state) {
	case STATE_AWAIT_IRQ_FINGER_DETECTED:
		if (irqtype == 0x01) {
			if (next_state() < 0) {
				do_exit = 2;
				return;
			}
		} else {
			printf("finger-on-sensor detected in wrong state!\n");
		}
		break;
	case STATE_AWAIT_IRQ_FINGER_REMOVED:
		if (irqtype == 0x02) {
			if (next_state() < 0) {
				do_exit = 2;
				return;
			}
		} else {
			printf("finger-on-sensor detected in wrong state!\n");
		}
		break;
	}
	if (libusb_submit_transfer(irq_transfer) < 0)
		do_exit = 2;
}
Example #28
0
void search_cycle(CA *ca, char *graph, UINT starting_state)
{
  UINT actual_state = starting_state;
  int is_new_cycle = 0;

  while (!flags_test(graph, actual_state, STATE_HAS_BEEN_VISITED))
  {
    flags_set(graph, actual_state, STATE_HAS_BEEN_VISITED | STATE_IS_BEING_VISITED);
    actual_state = next_state(ca, actual_state);
  }

  is_new_cycle = flags_test(graph, actual_state, STATE_IS_BEING_VISITED);

  if (is_new_cycle)
  {
    UINT cycle_len = 0;

    while (flags_test(graph, actual_state, STATE_IS_BEING_VISITED))
    {
      flags_unset(graph, actual_state, STATE_IS_BEING_VISITED);

      actual_state = next_state(ca, actual_state);

      cycle_len ++;
    }

    /* printf("len %u seed %u start %u ", cycle_len, actual_state, starting_state); */
    printf("%" UFM  "\n", cycle_len);
    fflush(stdout);
  }

  for  (actual_state = starting_state;
        flags_test(graph, actual_state, STATE_IS_BEING_VISITED);
        actual_state = next_state(ca, actual_state))
  {
     flags_unset(graph, actual_state, STATE_IS_BEING_VISITED);
  }
}
static void 
state_import_prompt (GcrImporter *self, gboolean async)
{
	GcrImportDialog *dialog;
	gboolean prompt;
	gint response;
	
	g_assert (GCR_IS_IMPORTER (self));
	
	/* No need to prompt */
	if (self->pv->prompted == TRUE)
		prompt = FALSE;
	else if (self->pv->behavior == GCR_IMPORTER_PROMPT_ALWAYS)
		prompt = TRUE;
	else if (self->pv->behavior == GCR_IMPORTER_PROMPT_NEVER)
		prompt = FALSE;
	else 
		prompt = self->pv->slot ? FALSE : TRUE;
	
	if (prompt == FALSE) {
		next_state (self, state_initialize_pin);
		
	} else {
		
		dialog = _gcr_import_dialog_new ();

		_gcr_import_dialog_set_primary_text (dialog, _("Import Certificates/Keys"));
		_gcr_import_dialog_hide_password (dialog);
		
		if (self->pv->slot) {
			_gcr_import_dialog_set_selected_slot (dialog, self->pv->slot);
			_gcr_import_dialog_hide_selected_slot (dialog);
		} else {
			_gcr_import_dialog_set_secondary_text (dialog, _("Choose a location to store the imported certificates/keys."));
		}
			
		/* Prompt without blocking main loop */
		if (async) {
			g_signal_connect (dialog, "response", G_CALLBACK (on_prompt_response), self);
			gtk_widget_show (GTK_WIDGET (dialog));
			
		/* Block mainloop */
		} else {
			response = gtk_dialog_run (GTK_DIALOG (dialog));
			complete_import_prompt (self, dialog, response);
			g_object_unref (dialog);
		}
	}
}
Example #30
0
int nfa2dfa() {
    char state[40][40];
    int i = 0;
    int n = 1;
    char next[40];
    int j;
    strcpy(state[0], "0");
    for (i = 0; i < n; i++) {
        for (j = 0; j < NFA_symbols; j++) {
            next_state(next, state[i], j);
            DFAtab[i][j] = state_at(next, state, &n);
        }
    }
    return n;
}