コード例 #1
0
int main (void) {
        state_t vec1, vec2, vec3;
        binding_t b;
        int i;
       
        srand(time(NULL));
        fprintf(stdout, "--- Debut\n");
       
        /* Creation du vecteur */
        vec1 = create_state();
        vec2 = create_state();
        vec3 = create_state();
       
        /* Remplissage */
        for (i=0; i<15; i++) {
                b.id = i;
                b.place = (int) rand() % 40;
                add_binding(&vec1, b);
                add_binding(&vec3, b);
        }
       
        /* Remplissage */
        for (i=0; i<15; i++) {
                b.id = i;
                b.place = (int) rand() % 40;
                add_binding(&vec2, b);
        }
       
        print_state(vec1);
        print_state(vec2);

        /* Suppression */
        for (i=0; i<10; i++) {
                int r = (int) rand() % 15;
                fprintf(stdout,"Suppression du %d\n",r);
                erase_binding(&vec1, find_binding(vec1,r));
                erase_binding(&vec3, find_binding(vec3,r));
        }

        /* Suppression */
        for (i=0; i<10; i++) {
                int r = (int) rand() % 15;
                fprintf(stdout,"Suppression du %d\n",r);
                erase_binding(&vec2, find_binding(vec2,r));
        }

        print_state(vec1);
        print_state(vec2);
       
        /* Comparaison */
        if (compare_states(&vec1, &vec2)) { fprintf(stdout, "VEC1 = VEC2\n"); } else { fprintf(stdout, "VEC1 != VEC2\n"); }
        if (compare_states(&vec1, &vec3)) { fprintf(stdout, "VEC1 = VEC3\n"); } else { fprintf(stdout, "VEC1 != VEC3\n"); }

        return 1;
}
コード例 #2
0
void read_counts(Tree &T, Counts &data, std::string fname, long nalpha) {
  int i;
  unsigned int j;
  long id;
  State sta, sta2;
  std::string str;
  std::vector<long> d;

  // The number of letters is fixed to 4 in read_fasta.
  if (nalpha != 4) {
    std::cout << "Reading counts only implemented for 4 letters." << std::endl;
  }

  // reads in the alignment. The data is in _orbits and _couts.
  read_alignment(fname);

  // Now we fill in the Counts structure.
  data.nalpha = 4;
  data.nspecies = g_numSpecies;
  data.nstates = 1;

  // calculate the power:
  for (i=0; i < data.nspecies; i++) {
    data.nstates = data.nstates*data.nalpha;
  }

  // Creates a state of a given dimension
  create_state(sta, data.nspecies, data.nalpha);
  create_state(sta2, data.nspecies, data.nalpha);

  // Matches the species in the fasta with the ones in the tree.
  if (!match_species(T, g_nameSpecies, g_numSpecies, d)) {
    throw std::length_error( "Could not match species in tree with species in fasta." );
  }

  // Stores the counts in the Counts structure.
  data.c.resize(data.nstates);
  data.N = 0;
  for (j=0; j < _orbitals.size(); j++) {
    str = transform_adn_chain_val_to_string(_orbitals[j]);
    string2state(str, sta);
    permute_state(d, sta, sta2);
    id = state2index(sta2);
    data.c[id] = (double) _counts[j];
    data.N = data.N + data.c[id];
  }

  // Stores the species names
  data.species.resize(data.nspecies);
  for (i=0; i < T.nleaves; i++) {
    data.species[i] = T.names[i];
  }
}
コード例 #3
0
// Prints out the data in the Counts
void print_counts(Counts &data, std::ostream &s) {
  unsigned int i;
  State sta;
  std::string str;
  create_state(sta, data.nspecies, data.nalpha);

  s << "species:  ";
  for (i=0; i < data.species.size(); i++) {
    s << data.species[i] << "  ";
  }
  s << std::endl;
  s << "nalpha:   " << data.nalpha << std::endl;
  s << "nspecies: " << data.nspecies << std::endl;
  s << "nstates:  " << data.nstates << std::endl;
  s << "total:    " << data.N << std::endl;
  s << "counts:   " << std::endl;
  for (i=0; i < data.c.size(); i++) {
    if (data.c[i] > 0) {
      index2state(i, sta);
      state2string(sta, str);
      s << "  " << str << ": " << data.c[i] << std::endl;
    }
  }
  s << std::endl;
}
コード例 #4
0
ファイル: lua_state.hpp プロジェクト: dr520/moon_net
	lua_state(lua_State* state = nullptr)
		:_state(state), _release(state == nullptr)
	{
		if (nullptr == _state)
		{
			create_state();
		}
	}
コード例 #5
0
ファイル: srv_dirent_state.c プロジェクト: pombredanne/cliffs
/****************************************************************************
  create handle
****************************************************************************/
BOOL create_dirent_hnd(PCONN_HND parent_hnd, PDENT_HND *hnd, vuser_key *key)
{
	BOOL ret;
	DEBUG(5, ("creating policy handle\n"));
	ret = open_policy_hnd(key, parent_hnd, (PHANDLE*)hnd, 0);
	if (ret)
		ret = create_state(*hnd) != NULL;
	return ret;
}
コード例 #6
0
// Assigns memory and fills the struct StateList from the information in T.
// After this, sl.l containes the states on leaves and sl.h the states on hidden
// nodes. Both states are obtained from the index via the index2state function in state.h.
StateList create_state_list(Tree &T) {
  long i, j;
  State sta;
  StateList sl;
  sl.nalpha = T.nalpha;


  // Initialize the number of hidden states
  sl.nhidden = T.nhidden;
  sl.nsthidden = 1;
  for (i=0; i < sl.nhidden; i++) {
    sl.nsthidden = sl.nsthidden * sl.nalpha;
  }

  // fill in the state list for the hidden nodes.
  sl.h.resize(sl.nsthidden);
  create_state(sta, sl.nhidden, sl.nalpha);
  for (i=0; i < sl.nsthidden; i++) {
    index2state(i, sta);
    sl.h[i].resize(sl.nhidden);
    for(j=0; j < sl.nhidden; j++) {
      sl.h[i][j] = sta.s[j];
    }
  }

  // Initialize the number of leaf states
  sl.nleaves = T.nleaves;
  sl.nstleaves = 1;
  for (i=0; i < sl.nleaves; i++) {
    sl.nstleaves = sl.nstleaves * sl.nalpha;
  }

  // fill in the state list for the leaf nodes.
  sl.l.resize(sl.nstleaves);
  create_state(sta, sl.nleaves, sl.nalpha);
  for (i=0; i < sl.nstleaves; i++) {
    index2state(i, sta);
    sl.l[i].resize(sl.nleaves);
    for(j=0; j < sl.nleaves; j++) {
      sl.l[i][j] = sta.s[j];
    }
  }
  return sl;
}
コード例 #7
0
ファイル: transition_system.c プロジェクト: r2im/pickaxe
void add_trace(TransitionSystem *model, char **activities)
{
	char *activity = *activities++;
	State *state = create_state(activity);
	State *parent = model->pseudo_initial;
	add_child(parent, state);
	add_parent(state, parent);

	parent = state;
	while((activity = *activities++) != NULL)
	{
		state = create_state(activity);
		add_child(parent, state);
		add_parent(state, parent);
		parent = state;
	}
	parent->is_end = 1;
	add_child(parent, &PSEUDO_END);
	add_parent(&PSEUDO_END, parent);
}
コード例 #8
0
ファイル: transpositions.c プロジェクト: gonmf/matilda
/*
Looks up a previously stored state, or generates a new one. No assumptions are
made about whether the board state is in reduced form already. Never fails. If
the memory is full it allocates a new state regardless. If the state is found
and returned it's OpenMP lock is first set. Thread-safe.
RETURNS the state information
*/
tt_stats * tt_lookup_create(
    const board * b,
    bool is_black,
    u64 hash
){
    u32 key = (u32)(hash % ((u64)number_of_buckets));
    omp_lock_t * bucket_lock = is_black ? &b_table_lock : &w_table_lock;
    omp_set_lock(bucket_lock);

    tt_stats * ret = find_state(hash, b, is_black);
    if(ret == NULL) /* doesnt exist */
    {
        if(states_in_use >= max_allocated_states)
        {
            /*
            It is possible in theory for a complex ko to produce a situation
            where freeing the game tree that is not reachable doesn't free any
            states.
            */
            tt_log_status();
            char * s = alloc();
            board_to_string(s, b->p, b->last_played, b->last_eaten);
            flog_warn("tt", s);
            release(s);
            flog_warn("tt", "memory exceeded on root lookup");
        }

        ret = create_state(hash);
        memcpy(ret->p, b->p, TOTAL_BOARD_SIZ);
        ret->last_eaten_passed =
            (b->last_played == PASS) ? PASS : b->last_eaten;
        omp_set_lock(&ret->lock);

        if(is_black)
        {
            ret->next = b_stats_table[key];
            b_stats_table[key] = ret;
        }
        else
        {
            ret->next = w_stats_table[key];
            w_stats_table[key] = ret;
        }
        omp_unset_lock(bucket_lock);
    }
    else /* update */
    {
        omp_set_lock(&ret->lock);
        omp_unset_lock(bucket_lock);
    }

    return ret;
}
コード例 #9
0
ファイル: transition_system.c プロジェクト: r2im/pickaxe
TransitionSystem* create_emtpty_model(void)
{
	TransitionSystem *model = malloc(sizeof(TransitionSystem));
	model->pseudo_initial = create_state("__START__");
	model->states_size = 1;
	model->transitions = NULL;
	model->transition_size = 0;
	model->transitions_bdd = 0;

	model->labels = NULL;
	model->activities_size = 0;

	return model;
}
コード例 #10
0
ファイル: transpositions.c プロジェクト: gonmf/matilda
/*
Looks up a previously stored state, or generates a new one. No assumptions are
made about whether the board state is in reduced form already. If the limit on
states has been met the function returns NULL. If the state is found and
returned it's OpenMP lock is first set. Thread-safe.
RETURNS the state information or NULL
*/
tt_stats * tt_lookup_null(
    const cfg_board * cb,
    bool is_black,
    u64 hash
){
    u32 key = (u32)(hash % ((u64)number_of_buckets));
    omp_lock_t * bucket_lock = is_black ? &b_table_lock : &w_table_lock;
    omp_set_lock(bucket_lock);

    tt_stats * ret = find_state2(hash, cb, is_black);
    if(ret == NULL) /* doesnt exist */
    {
        if(states_in_use >= max_allocated_states)
        {
            omp_unset_lock(bucket_lock);
            return NULL;
        }

        ret = create_state(hash);
        memcpy(ret->p, cb->p, TOTAL_BOARD_SIZ);
        ret->last_eaten_passed =
            (cb->last_played == PASS) ? PASS : cb->last_eaten;
        omp_set_lock(&ret->lock);

        if(is_black)
        {
            ret->next = b_stats_table[key];
            b_stats_table[key] = ret;
        }
        else
        {
            ret->next = w_stats_table[key];
            w_stats_table[key] = ret;
        }
        omp_unset_lock(bucket_lock);
    }
    else /* update */
    {
        omp_set_lock(&ret->lock);
        omp_unset_lock(bucket_lock);
    }

    return ret;
}
コード例 #11
0
void animation_state::create_move() {
	bool
		allocate = (server_animation_state == nullptr),
		change = (!allocate) && (&g_ctx.m_local->GetRefEHandle() != entity_handle),
		reset = (!allocate && !change) && (g_ctx.m_local->m_flSpawnTime() != spawn_time);

	if (change)
		g_csgo.m_memalloc()->Free(server_animation_state);

	if (reset) {
		reset_state(server_animation_state);
		spawn_time = g_ctx.m_local->m_flSpawnTime();
	}

	if (allocate || change) {
		auto state = (c_baseplayeranimationstate *)g_csgo.m_memalloc()->Alloc(sizeof(c_baseplayeranimationstate));

		if (state != nullptr)
			create_state(state, g_ctx.m_local);

		entity_handle = const_cast<CBaseHandle *>(&g_ctx.m_local->GetRefEHandle());
		spawn_time = g_ctx.m_local->m_flSpawnTime();

		server_animation_state = state;
	}

	float server_time = util::server_time();
	if (!g_csgo.m_clientstate()->m_nChokedCommands) {
		float pose_parameters[24];
		AnimationLayer anim_layers[13];

		memcpy(pose_parameters, g_ctx.m_local->m_flPoseParameter(), sizeof(float) * 24);
		memcpy(anim_layers, g_ctx.m_local->get_animlayers(), sizeof(AnimationLayer) * 13);

		update_state(server_animation_state, g_ctx.get_command()->m_viewangles); // this is what causes the legs to be f****d, but i know you guys are retarded enough not to realise OR CARE about it, so im leaving this comment here as a reminder that when im gonna leak this source everyone will realise how stupid you guys are and how you cant solve the most basic shit without breaking even mroe shit. hf crying under your bed you dumb """cheat developers""", i feel bad for whoever bought this cheat, especially the ones that paid $130 for it. talking about money, i dont want to get deep into this because its currently sunday morning 4 am, but either way, dusk/ecralion has told me that he will pay me at the end of the week (2 day late btw, and he hasnt even apologised / brung it up to me), which he for obvious reasons didnt do. one guy purchased the cheat and dusk never even bothered to add him to the users role on our discord (that he deleted lol), i assume because he didnt want me knowing a guy purchased the cheat, and didnt want to pay me. after i asked him if he bought the cheat, then he made him a user on the server. im really sorry for victims that fell for this terrible cheat, i'd do something if i got the money(refund or something), but unfortuantely i didnt get any money because the greedy dickheads kept it for themselves and used me to make 'their' cheat better. this is directed at "ecralion" on uc, and jeffrey which idk his uc name, but yeah, i am signing out as the 12 year old child aka alpha/"524245534435344", which is smarter than 15 year old dusk/ecralion. i dont give the slightest f**k if my rep gets ruined by this, but im not going to be forced to work on a cheat, promise to get paid, and get lied to. peace out.

		memcpy(g_ctx.m_local->m_flPoseParameter(), pose_parameters, sizeof(float) * 24);
		memcpy(g_ctx.m_local->get_animlayers(), anim_layers, sizeof(AnimationLayer) * 13);
	}
}
コード例 #12
0
ファイル: srv_file_state.c プロジェクト: pombredanne/cliffs
/****************************************************************************
  set fileection info
****************************************************************************/
BOOL set_file_info(PFILE_HND hnd, files_struct *fsp)
{
	struct file_state *state;
	state = (struct file_state*)get_policy_state_info(hnd);

	DEBUG(3, ("Setting policy file info: %d %s\n",
				fsp->fd, smbstrA(fsp->fsp_name)));

	if (state == NULL)
	{
		state = create_state(hnd);
	}
	if (state == NULL)
	{
		return False;
	}

	get_file_index(hnd, &fsp->fnum);
	state->fsp = fsp;

	return True;
}
コード例 #13
0
// Gets the counts from the input alignment.
void get_counts(Alignment &align, Counts &data) {
  unsigned int len;
  long i, j, a;
  State st;

  len = align.seq[0].size();
  for(i=0; i < align.nspecies; i++) {
    if (len > align.seq[i].size()) {
      len = align.seq[i].size();
    }
  }

  data.nspecies = align.nspecies;
  data.nalpha = align.nalpha;
  data.N = (double) len;

  data.nstates = 1;
  data.species.resize(data.nspecies);
  for (i=0; i < align.nspecies; i++) {
    data.species[i] = align.name[i];
    data.nstates = data.nstates * data.nalpha;
  }

  // assigns memory for the counts
  data.c.resize(data.nstates);
  for(a=0; a < data.nstates; a++) {
    data.c[a] = 0;
  }

  //ounting ...
  create_state(st, align.nspecies, align.nalpha);
  for(i=0; i < len; i++) {
    for(j=0; j < align.nspecies; j++) {
      st.s[j] = align.seq[j][i];
    }
    a = state2index(st);
    data.c[a] = data.c[a] + 1;
  }
}
コード例 #14
0
ファイル: channel.c プロジェクト: BackupTheBerlios/bonephone
int
_channel_coder_create(cc_id_t id, channel_state_t **ppcs, int is_encoder)
{
        channel_state_t *pcs;
        int (*create_state)(u_char**, uint32_t *len);

        pcs = (channel_state_t*)xmalloc(sizeof(channel_state_t));
        if (pcs == NULL) {
                return FALSE;
        }

        *ppcs = pcs;

        pcs->coder = (uint16_t)CC_ID_TO_IDX(id);
        assert(pcs->coder < CC_NUM_CODERS);

        pcs->units_per_packet = 2;
        pcs->is_encoder       = is_encoder;

        if (is_encoder) {
                create_state = table[pcs->coder].enc_create_state;
		debug_msg("Created encoder: \"%s\"\n", table[pcs->coder].details.name);
        } else {
                create_state = table[pcs->coder].dec_create_state;
		debug_msg("Created decoder: \"%s\"\n", table[pcs->coder].details.name);
        }

        if (create_state) {
                create_state(&pcs->state, &pcs->state_len);
        } else {
                pcs->state     = NULL;
		pcs->state_len = 0;
	}

        return TRUE;
}
コード例 #15
0
ファイル: sprinkle.c プロジェクト: Lachann/gst-plugins-base
int
main (int argc, char *argv[])
{
  GstBus *bus;
  GstElement *filter, *convert, *sink;
  GstCaps *caps;
  gboolean res;
  SprinkleState *state;

  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, TRUE);

  pipeline = gst_pipeline_new ("pipeline");

  /* add the fixed part to the pipeline. Remember that we need a capsfilter
   * after adder so that multiple sources are not racing to negotiate
   * a format */
  adder = gst_element_factory_make ("adder", "adder");
  filter = gst_element_factory_make ("capsfilter", "filter");
  convert = gst_element_factory_make ("audioconvert", "convert");
  sink = gst_element_factory_make ("autoaudiosink", "sink");

  caps = gst_caps_new_simple ("audio/x-raw",
      "format", G_TYPE_STRING, "S16LE",
      "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 44100, NULL);
  g_object_set (filter, "caps", caps, NULL);
  gst_caps_unref (caps);

  gst_bin_add_many (GST_BIN (pipeline), adder, filter, convert, sink, NULL);

  res = gst_element_link_many (adder, filter, convert, sink, NULL);
  g_assert (res);

  /* setup message handling */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
  g_signal_connect (bus, "message::error", (GCallback) message_received,
      pipeline);
  g_signal_connect (bus, "message::warning", (GCallback) message_received,
      pipeline);
  g_signal_connect (bus, "message::eos", (GCallback) eos_message_received,
      pipeline);

  /* we set the pipeline to PLAYING, the pipeline will not yet preroll because
   * there is no source providing data for it yet */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* and add the function that modifies the pipeline every 100ms */
  state = create_state ();
  g_timeout_add (100, (GSourceFunc) do_sprinkle, state);

  /* go to main loop */
  g_main_loop_run (loop);

  gst_element_set_state (pipeline, GST_STATE_NULL);

  free_state (state);
  gst_object_unref (bus);
  gst_object_unref (pipeline);

  return 0;
}
コード例 #16
0
ファイル: normalization.c プロジェクト: SamidhaParoha/BTP
//Input:  A name (type: string) and all characteristics of an FSMD
//Output: An FSMD with proper states and transitions
void createFSMD( char* FSMDname, STMT_LIST *stmts )
{
	FSMD *M;
	TRANSITION_ST *trans;
	STMT *oneStmt;
	int i, j, k;
	int current_state, temp, numtrans;
	
	if(!(flagVar_List))
	{
		M0 = (FSMD*) malloc (sizeof(FSMD));
		M = M0;
	}
	else
	{
		M1 = (FSMD*) malloc (sizeof(FSMD));
		M = M1;
	}
	
	strcpy(M->name, FSMDname);
	
	current_state = 0;
		
	for(i = 0; i < stmts->numStatements; i++)
	{
		oneStmt = stmts->statements[i];
		temp = create_state( oneStmt->stateName, M, current_state );
		
		numtrans = constval(oneStmt->numTransitions);

		M->states[temp].numtrans = numtrans;
		
		//value propagation code start
		M->states[temp].VAPFLAG = FALSE;
				
		M->states[temp].propVector.cond = NULL;
		for(j=0; j < SYMTABSIZE; j++)
		{
			M->states[temp].propVector.value[j] = NULL;
			
			//array start
			M->states[temp].propVector.subVector[j].countValues = 0;
			for(k = 0; k < MAX_ARRAY_VALUES; k++)
			{
				M->states[temp].propVector.subVector[j].arrayValue[k] = NULL;
			}
			//array end
		}
		//value propagation code end
		
		
		if( numtrans == 0 ) 
		{
			M->states[temp].node_type = 1; 
			// state with no outward transition. This is the last state of the fsmd.
			// it has a dummy transition from itself to the start state of the fmsd,
			// with condition = '-' and action = '-'.
		}
		else
			M->states[temp].node_type = 2;
			
		if( current_state == 0 ) 
		{   // This is the start state of the FSMD
			M->states[temp].node_type = 0;
		}
		if( temp == current_state ) 
		{		
			current_state++;
			strcpy(M->states[temp].state_id, oneStmt->stateName);
		}
		
		M->states[temp].translist = NULL;
		for(k = 0; k < numtrans; k++) 
		{
		    // This loop will read the transtions of each state
					
			trans = (TRANSITION_ST *) malloc (sizeof(TRANSITION_ST));
			trans->next = M->states[temp].translist;
			M->states[temp].translist = trans;
			trans->condition = oneStmt->substmts->substmt[k]->condition;

		    generateAssignments(oneStmt->substmts->substmt[k]->assignments, trans);

			trans->outtrans = create_state(oneStmt->substmts->substmt[k]->stateName, M, current_state);
			if(trans->outtrans == current_state) 
			{       
			    current_state++;
				M->states[trans->outtrans].translist = NULL;
				M->states[trans->outtrans].numtrans = 0;
				M->states[trans->outtrans].node_type = 1;
				strcpy(M->states[trans->outtrans].state_id, oneStmt->substmts->substmt[k]->stateName);
			}
		}
	}
	
	M->numstates = current_state;	
}
コード例 #17
0
void DepthStencilStateMgr::init()
{
    depth_stencil_states_[ "default" ] = create_state( get_default_desc() );
}
コード例 #18
0
ファイル: con.c プロジェクト: project8/katcp_devel
int main(int argc, char **argv)
{
  struct state *ss;
  struct child *cx;
  fd_set fsr, fsw;
  char *cmd;
  int i, j, c, mfd, fd, verbose, result, status;
  sigset_t mask_current, mask_previous;
  struct sigaction action_current, action_previous;
  pid_t pid;

  ss = create_state(STDOUT_FILENO);
  if(ss == NULL){
    return 4;
  }

#if 0
  char *app, *parm, *cmd, *copy, *ptr, *servers;
  int verbose, result, status, base, info, reply, timeout, pos, flags, show;
  int xmit, code;
  unsigned int len;
  
  info = 1;
  reply = 1;
  i = j = 1;
  app = argv[0];
  base = (-1);
  timeout = 5;
  pos = (-1);
  k = NULL;
  show = 1;
  parm = NULL;
#endif

  verbose = 1;
  i = j = 1;

  while (i < argc) {
    if (argv[i][0] == '-') {
      c = argv[i][j];
      switch (c) {

        case 'h' :
          usage(argv[0]);
          return 0;

        case 'v' : 
          verbose++;
          j++;
          break;
        case 'q' : 
          verbose = 0;
          j++;
          break;

        case '-' :
          j++;
          break;
        case '\0':
          j = 1;
          i++;
          break;

        default:
          sync_message_katcl(ss->s_up, KATCP_LEVEL_ERROR, KCPCON_NAME, "unknown option -%c", argv[i][j]);
          return 2;
      }
    } else {
#ifdef DEBUG
      fprintf(stderr, "about to start <%s>\n", argv[i]);
#endif
      if(string_launch_child(ss, argv[i]) < 0){
        sync_message_katcl(ss->s_up, KATCP_LEVEL_ERROR, KCPCON_NAME, "unable to start <%s>", argv[i]);
        return 4;
      }
      i++;
    }
  }

  sigprocmask(SIG_SETMASK, NULL, &mask_current);
  sigaddset(&mask_current, SIGCHLD);

  action_current.sa_handler = &handle_child;
  action_current.sa_flags = SA_NOCLDSTOP;
  sigfillset(&(action_current.sa_mask));
  sigaction(SIGCHLD, &action_current, &action_previous);

  sigprocmask(SIG_SETMASK, &mask_current, &mask_previous);

  sigemptyset(&mask_current);
#if 0
  sigaddset(&mask_current, SIGTERM);
#endif

  for(ss->s_finished = 0; ss->s_finished < ss->s_count;){


    mfd = 0;

    FD_ZERO(&fsr);
    FD_ZERO(&fsw);

    if(flushing_katcl(ss->s_up)){
      mfd = fileno_katcl(ss->s_up);
      FD_SET(mfd, &fsw);
    }

    for(i = 0; i < ss->s_count; i++){
      cx = ss->s_vector[i];
      if(cx->c_line){
        fd = fileno_katcl(cx->c_line);
        if(fd > mfd){
          mfd = fd;
        }
        FD_SET(fd, &fsr);
      } 
    }

    result = pselect(mfd + 1, &fsr, &fsw, NULL, NULL, &mask_current);
#ifdef DEBUG
    fprintf(stderr, "select returns %d\n", result);
#endif
    switch(result){
      case -1 :
        switch(errno){
          case EAGAIN :
          case EINTR  :
            continue; /* WARNING */
          default  :
            sync_message_katcl(ss->s_up, KATCP_LEVEL_ERROR, KCPCON_NAME, "select failed: %s", strerror(errno));
            return 4;
        }
        break;
      case  0 :
        sync_message_katcl(ss->s_up, KATCP_LEVEL_ERROR, KCPCON_NAME, "requests timed out despite having no timeout");
        /* could terminate cleanly here, but ... */
        return 4;
    }


    fd = fileno_katcl(ss->s_up);
    if(FD_ISSET(fd, &fsw)){
      result = write_katcl(ss->s_up);
    }

    for(i = 0; i < ss->s_count; i++){
      cx = ss->s_vector[i];
      if(cx->c_line){
        fd = fileno_katcl(cx->c_line);

        if(FD_ISSET(fd, &fsr)){ /* get things */
          result = read_katcl(cx->c_line);
          if(result){
            if(result < 0){
              sync_message_katcl(ss->s_up, KATCP_LEVEL_ERROR, KCPCON_NAME, "read failed: %s", strerror(error_katcl(cx->c_line)));
            } else {
              if(cx->c_pid > 0){
                log_message_katcl(ss->s_up, KATCP_LEVEL_DEBUG, KCPCON_NAME, "subordinate job %u ended", cx->c_pid);
              }
            }
            destroy_katcl(cx->c_line, 1);
            cx->c_line = NULL;
            ss->s_finished++;
            continue; /* WARNING */
          }
        }

        while(have_katcl(cx->c_line) > 0){ /* compute */
          cmd = arg_string_katcl(cx->c_line, 0);
          if(cmd){
#ifdef DEBUG
            fprintf(stderr, "reading message <%s ...>\n", cmd);
#endif
            switch(cmd[0]){
              case KATCP_INFORM : 
#if 0
                if(!strcmp(KATCP_VERSION_CONNECT_INFORM, cmd)){
                }
                if(!strcmp(KATCP_VERSION_INFORM, cmd)){
                }
                if(!strcmp(KATCP_BUILD_STATE_INFORM, cmd)){
                }
#endif
                relay_katcl(cx->c_line, ss->s_up);
                break;
            }
          }
        }
      }
    }

    /* the position of this logic is rather intricate */
    if(got_child_signal){
      got_child_signal = 0;
      while((pid = waitpid(WAIT_ANY, &status, WNOHANG)) > 0){
        for(i = 0; i < ss->s_count; i++){
          cx = ss->s_vector[i];
          if(cx->c_pid == pid){

            if (WIFEXITED(status)) {
              result = WEXITSTATUS(status);
              log_message_katcl(ss->s_up, KATCP_LEVEL_DEBUG, KCPCON_NAME, "subordinate job[%u] %u exited with code %d", i, cx->c_pid, result);
              cx->c_status = (result > 4) ? 4 : result;
            } else if (WIFSIGNALED(status)) {
              result = WTERMSIG(status);
              log_message_katcl(ss->s_up, KATCP_LEVEL_WARN, KCPCON_NAME, "subordinate job[%u] %u killed by signal %d", i, cx->c_pid, result);
              cx->c_status = 4;
            } else {
              log_message_katcl(ss->s_up, KATCP_LEVEL_WARN, KCPCON_NAME, "subordinate job[%u] %u return unexpected status %d", i, cx->c_pid, status);
              cx->c_status = 4;
            }

            if(cx->c_status > ss->s_code){
              ss->s_code = cx->c_status;
            }

            cx->c_pid = (-1);
          }
        }
      }
    }
  }

  /* force drain */
  while(write_katcl(ss->s_up) == 0);

  result = ss->s_code;

  destroy_state(ss);

  /* WARNING: pointlessly fussy */
  sigaction(SIGCHLD, &action_previous, NULL);
  sigprocmask(SIG_BLOCK, &mask_previous, NULL);

  return result;
}
コード例 #19
0
ファイル: state_manager.cpp プロジェクト: tomgalvin594/Struct
void State_Manager::update(double delta)
{
    //check if active state requested for change
    unsigned int next_state_id = m_all_states[0]->get_next_state_id();

    if(next_state_id == game_state::null_state)
    {
        //no change, update the active state
        m_all_states[0]->update(delta);
    }
    else
    {
        //change in state required
        unsigned int current_state_id = m_all_states[0]->get_state_id();

        //menu state
        if(current_state_id == game_state::menu)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::quit)
            {
                clear_states();
            }
        }

        //play state
        else if(current_state_id == game_state::play)
        {
            if(next_state_id == game_state::pause_state)
            {
                create_state(game_state::pause_state);
            }
            else if(next_state_id == game_state::game_over)
            {
                create_state(game_state::game_over);
            }
            else if(next_state_id == game_state::level_win)
            {
                create_state(game_state::level_win);
            }
        }

        //pause state
        else if(current_state_id == game_state::pause_state)
        {
            if(next_state_id == game_state::play)
            {
                remove_state();
                m_all_states[0]->reset_next_state_id();
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        //level win state
        else if(current_state_id == game_state::level_win)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        //game over state
        else if(current_state_id == game_state::game_over)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        else
            std::cout << "Undefined state requested\n";
    }

}
コード例 #20
0
static inline void push_state(int id, int parent_id, double cost, 
			      double new_utility, queue state_queue)
{
  state_ptr new_state = create_state(id, parent_id, cost, new_utility);
  insert_into_queue(new_state, state_queue);
}