예제 #1
0
void gs_vertexbuffer_flush(gs_vertbuffer_t *vb)
{
    size_t i;

    if (!vb->dynamic) {
        blog(LOG_ERROR, "vertex buffer is not dynamic");
        goto failed;
    }

    if (!update_buffer(GL_ARRAY_BUFFER, vb->vertex_buffer,
                       vb->data->points,
                       vb->data->num * sizeof(struct vec3)))
        goto failed;

    if (vb->normal_buffer) {
        if (!update_buffer(GL_ARRAY_BUFFER, vb->normal_buffer,
                           vb->data->normals,
                           vb->data->num * sizeof(struct vec3)))
            goto failed;
    }

    if (vb->tangent_buffer) {
        if (!update_buffer(GL_ARRAY_BUFFER, vb->tangent_buffer,
                           vb->data->tangents,
                           vb->data->num * sizeof(struct vec3)))
            goto failed;
    }

    if (vb->color_buffer) {
        if (!update_buffer(GL_ARRAY_BUFFER, vb->color_buffer,
                           vb->data->colors,
                           vb->data->num * sizeof(uint32_t)))
            goto failed;
    }

    for (i = 0; i < vb->data->num_tex; i++) {
        GLuint buffer = vb->uv_buffers.array[i];
        struct gs_tvertarray *tv = vb->data->tvarray+i;
        size_t size = vb->data->num * tv->width * sizeof(float);

        if (!update_buffer(GL_ARRAY_BUFFER, buffer, tv->array, size))
            goto failed;
    }

    return;

failed:
    blog(LOG_ERROR, "gs_vertexbuffer_flush (GL) failed");
}
예제 #2
0
bool Insert::J2B(char* filename) {
    ifstream infile(filename);

    if (!infile) {
        cout << "The file with the path \"" << filename << "\" is not exit. Please input again." << endl;
        return false;
    }

    while (!infile.eof()) {
        char json_obj[1000];
        infile.getline(json_obj, 1000);

        row_count++;

        if (row_count == 1 && json_obj[0] != '[' || row_count == 2 && json_obj[0] != '{') {
            cout << "This file isn't a json format file. Please insert correct file." << endl;
            return false;
        }
        else if (json_obj[0] != '[' && json_obj[0] != ']') {
            J2B_json_obj(json_obj);
        }
        update_buffer();
    }
    infile.close();
    return true;
}
예제 #3
0
void update_double_time() {
  time_t temp = time(NULL);

  temp = temp - 5*60*60;
  update_buffer(recife_buffer+1, localtime(&temp)); // TODO: beware! pointer arithmetics!
  
  temp = temp + 5*60*60 + 6*60*60;
  update_buffer(taipei_buffer+1, localtime(&temp)); // TODO: beware! pointer arithmetics!
    
  // Display this time on the TextLayer
  text_layer_set_text(recife_text_layer, recife_buffer);  
  text_layer_set_text(taipei_text_layer, taipei_buffer);  
  
  //TBTR
  snprintf(battery_level_buffer, sizeof(battery_level_buffer), "%d%%", battery_level);
  text_layer_set_text(battery_label_text_layer, battery_level_buffer);  
}
예제 #4
0
 InputIterator& operator++() {
     assert(m_source);
     assert(m_buffer);
     assert(m_iter);
     ++m_iter;
     if (m_iter == m_buffer->end<TItem>()) {
         update_buffer();
     }
     return *this;
 }
예제 #5
0
void glt_stream_server_t::OnDisplay() {

	build_trans_matrix();
    
    if (draw_data)
		draw_data();

	glFlush();

	update_buffer();

}
예제 #6
0
RC Row_ts::access(txn_man * txn, TsType type, row_t * row) {
	RC rc;
	ts_t ts = txn->get_ts();
	if (g_central_man)
		glob_manager.lock_row(_row);
	else
		pthread_mutex_lock( latch );
	if (type == R_REQ) {
		if (ts < wts) {
			rc = Abort;
		} else if (ts > min_pts) {
			// insert the req into the read request queue
			buffer_req(R_REQ, txn, NULL);
			txn->ts_ready = false;
			rc = WAIT;
		} else {
			// return the value.
			txn->cur_row->copy(_row);
			if (rts < ts)
				rts = ts;
			rc = RCOK;
		}
	} else if (type == P_REQ) {
		if (ts < rts) {
			rc = Abort;
		} else {
#if TS_TWR
			buffer_req(P_REQ, txn, NULL);
			rc = RCOK;
#else 
			if (ts < wts) {
				rc = Abort;
			} else {
				buffer_req(P_REQ, txn, NULL);
				rc = RCOK;
			}
#endif
		}
	} else if (type == W_REQ) {
		// write requests are always accepted.
		rc = RCOK;
#if TS_TWR
		// according to TWR, this write is already stale, ignore. 
		if (ts < wts) {
			TsReqEntry * req = debuffer_req(P_REQ, txn);
			assert(req != NULL);
			update_buffer();
			return_req_entry(req);
			row->free_row();
			mem_allocator.free(row, sizeof(row_t));
			goto final;
		}
예제 #7
0
파일: x931_rng.cpp 프로젝트: Jesse-V/botan
/*
* Reset V and the cipher key with new values
*/
void ANSI_X931_RNG::rekey()
   {
   const size_t BLOCK_SIZE = m_cipher->block_size();

   if(m_prng->is_seeded())
      {
      m_cipher->set_key(m_prng->random_vec(m_cipher->maximum_keylength()));

      if(m_V.size() != BLOCK_SIZE)
         m_V.resize(BLOCK_SIZE);
      m_prng->randomize(m_V.data(), m_V.size());

      update_buffer();
      }
   }
예제 #8
0
void indexbuffer_flush(indexbuffer_t ib)
{
	if (!ib->dynamic) {
		blog(LOG_ERROR, "Index buffer is not dynamic");
		goto fail;
	}

	if (!update_buffer(GL_ARRAY_BUFFER, ib->buffer, ib->data, ib->size))
		goto fail;

	return;

fail:
	blog(LOG_ERROR, "indexbuffer_flush (GL) failed");
}
예제 #9
0
/*************************************************
* Add entropy to internal state                  *
*************************************************/
void ANSI_X931_RNG::add_randomness(const byte data[], u32bit length)
   {
   prng->add_entropy(data, length);

   if(is_seeded())
      {
      SecureVector<byte> key(cipher->MAXIMUM_KEYLENGTH);
      prng->randomize(key, key.size());
      cipher->set_key(key, key.size());

      prng->randomize(V, V.size());

      update_buffer();
      }
   }
예제 #10
0
/**
* Reset V and the cipher key with new values
*/
void ANSI_X931_RNG::rekey()
   {
   if(prng->is_seeded())
      {
      SecureVector<byte> key(cipher->MAXIMUM_KEYLENGTH);
      prng->randomize(key, key.size());
      cipher->set_key(key, key.size());

      if(V.size() != cipher->BLOCK_SIZE)
         V.create(cipher->BLOCK_SIZE);
      prng->randomize(V, V.size());

      update_buffer();
      }
   }
예제 #11
0
int jack_callback (jack_nframes_t nframes, void *arg)
{
    jack_default_audio_sample_t *in, *outL, *outR;
    
    in = jack_port_get_buffer (input_port, nframes);
    outL = jack_port_get_buffer (output_portL, nframes);
    outR = jack_port_get_buffer (output_portR, nframes);

    update_buffer(in);
    //int start_idx = buffer_size - delay_samples;
    for(int i=0; i < nframes; i++)
    {
        outL[i] = buffer[i];
        outR[i] = buffer[i];
    }
    //memcpy (out, in, nframes * sizeof (jack_default_audio_sample_t));
    return 0;
}
예제 #12
0
/**
* Generate a buffer of random bytes
*/
void ANSI_X931_RNG::randomize(byte out[], u32bit length)
   {
   if(!is_seeded())
      throw PRNG_Unseeded(name());

   while(length)
      {
      if(position == R.size())
         update_buffer();

      const u32bit copied = std::min(length, R.size() - position);

      copy_mem(out, R + position, copied);
      out += copied;
      length -= copied;
      position += copied;
      }
   }
예제 #13
0
void Game::teleport(int chunk_x, int chunk_y, int x, int y)
{
    main_char.set_x(x);
    main_char.set_y(y);
    main_char.set_chunk(IntPoint(chunk_y, chunk_x));
    update_buffer(main_char.get_chunk());
    unsigned int delta_x = chunk_x - main_char.get_chunk().col;
    unsigned int delta_y = chunk_y - main_char.get_chunk().row;
    if(delta_x > 1 || delta_y > 1)
    {
        //chunk_map.serialize_all();
        chunk_map.populate_initial(main_char.get_chunk(), world_map.get_map());
    }
    else
    {
        update_chunk_map(IntPoint(delta_y, delta_x));
    }

}
예제 #14
0
sprite_t*
sen_sprite_new(const char* name,
               const char* texture_name)
{
 // _logfi("+sprite %s, texture=%s", (name ? name : "autoName"), texture_name);
  struct_malloc(sprite_t, self);
  sen_node_init(self, name, 0);
  self->tex = sen_textures_get(texture_name);
  sen_assert(self->tex);
  self->program = sen_shaders_get("sprite");
  sen_assert(self->program);
  self->quad = vertex_buffer_new("a_pos:4f,a_tex_coords:2f,a_color:4f");

  //update_quad(self);
  update_buffer(self);

  ((node_t*)self)->vt = &sprite_interface;

  return self;
}
예제 #15
0
static void update_halftone(halftone_screen *halftone)
{
  int x, y, i;
  XWindowAttributes attrs;

  XGetWindowAttributes(halftone->dpy, halftone->window, &attrs);

  /* Make sure we have a valid buffer */
  update_buffer(halftone, &attrs);
  
  /* Make sure all dot attributes (spacing, width, height, etc) are correct */
  update_dot_attributes(halftone, &attrs);
  
  /* Move gravity points */
  for (i = 0; i < halftone->gravity_point_count; i++)
  {
    halftone->gravity_point_x_inc[i] = 
      (halftone->gravity_point_x[i] >= 1 || halftone->gravity_point_x[i] <= 0 ?
       -halftone->gravity_point_x_inc[i] : 
       halftone->gravity_point_x_inc[i]);
    halftone->gravity_point_y_inc[i] = 
      (halftone->gravity_point_y[i] >= 1 || halftone->gravity_point_y[i] <= 0 ?
       -halftone->gravity_point_y_inc[i] : 
       halftone->gravity_point_y_inc[i]);

    halftone->gravity_point_x[i] += halftone->gravity_point_x_inc[i];
    halftone->gravity_point_y[i] += halftone->gravity_point_y_inc[i];
  }

  /* Update gravity in each dot .*/
  for (x = 0; x < halftone->dots_width; x++)
    for (y = 0; y < halftone->dots_height; y++)
    {
      double gravity = calculate_gravity(halftone, x, y);

      halftone->dots[x + y * halftone->dots_width] = (gravity > 1 ? 1 : (gravity < 0 ? 0 : gravity));
    }
}
예제 #16
0
파일: x931_rng.cpp 프로젝트: Jesse-V/botan
void ANSI_X931_RNG::randomize(byte out[], size_t length)
   {
   if(!is_seeded())
      {
      reseed(BOTAN_RNG_RESEED_POLL_BITS);

      if(!is_seeded())
         throw PRNG_Unseeded(name());
      }

   while(length)
      {
      if(m_R_pos == m_R.size())
         update_buffer();

      const size_t copied = std::min<size_t>(length, m_R.size() - m_R_pos);

      copy_mem(out, &m_R[m_R_pos], copied);
      out += copied;
      length -= copied;
      m_R_pos += copied;
      }
   }
예제 #17
0
파일: row_mvcc.cpp 프로젝트: apavlo/DBx1000
RC Row_mvcc::access(txn_man * txn, TsType type, row_t * row) {
	RC rc = RCOK;
	ts_t ts = txn->get_ts();
uint64_t t1 = get_sys_clock();
	if (g_central_man)
		glob_manager->lock_row(_row);
	else
		while (!ATOM_CAS(blatch, false, true))
			PAUSE
		//pthread_mutex_lock( latch );
uint64_t t2 = get_sys_clock();
INC_STATS(txn->get_thd_id(), debug4, t2 - t1);

#if DEBUG_CC
	for (uint32_t i = 0; i < _req_len; i++)
		if (_requests[i].valid) {
			assert(_requests[i].ts > _latest_wts);
			if (_exists_prewrite)
				assert(_prewrite_ts < _requests[i].ts);
		}
#endif
	if (type == R_REQ) {
		if (ts < _oldest_wts)
			// the version was already recycled... This should be very rare
			rc = Abort;
		else if (ts > _latest_wts) {
			if (_exists_prewrite && _prewrite_ts < ts)
			{
				// exists a pending prewrite request before the current read. should wait.
				rc = WAIT;
				buffer_req(R_REQ, txn, false);
				txn->ts_ready = false;
			} else { 
				// should just read
				rc = RCOK;
				txn->cur_row = _latest_row;
				if (ts > _max_served_rts)
					_max_served_rts = ts;
			}
		} else {
			rc = RCOK;
			// ts is between _oldest_wts and _latest_wts, should find the correct version
			uint32_t the_ts = 0;
		   	uint32_t the_i = _his_len;
	   		for (uint32_t i = 0; i < _his_len; i++) {
		   		if (_write_history[i].valid 
					&& _write_history[i].ts < ts 
			   		&& _write_history[i].ts > the_ts) 
	   			{
		   			the_ts = _write_history[i].ts;
			  		the_i = i;
				}
			}
			if (the_i == _his_len) 
				txn->cur_row = _row;
   			else 
	   			txn->cur_row = _write_history[the_i].row;
		}
	} else if (type == P_REQ) {
		if (ts < _latest_wts || ts < _max_served_rts || (_exists_prewrite && _prewrite_ts > ts))
			rc = Abort;
		else if (_exists_prewrite) {  // _prewrite_ts < ts
			rc = WAIT;
			buffer_req(P_REQ, txn, false);
			txn->ts_ready = false;
		} else {
			rc = RCOK;
			row_t * res_row = reserveRow(ts, txn);
			assert(res_row);
			res_row->copy(_latest_row);
			txn->cur_row = res_row;
		}
	} else if (type == W_REQ) {
		rc = RCOK;
		assert(ts > _latest_wts);
		assert(row == _write_history[_prewrite_his_id].row);
		_write_history[_prewrite_his_id].valid = true;
		_write_history[_prewrite_his_id].ts = ts;
		_latest_wts = ts;
		_latest_row = row;
		_exists_prewrite = false;
		_num_versions ++;
		update_buffer(txn, W_REQ);
	} else if (type == XP_REQ) {
		assert(row == _write_history[_prewrite_his_id].row);
		_write_history[_prewrite_his_id].valid = false;
		_write_history[_prewrite_his_id].reserved = false;
		_exists_prewrite = false;
		update_buffer(txn, XP_REQ);
	} else 
		assert(false);
INC_STATS(txn->get_thd_id(), debug3, get_sys_clock() - t2);
	if (g_central_man)
		glob_manager->release_row(_row);
	else
		blatch = false;
		//pthread_mutex_unlock( latch );	
		
	return rc;
}
예제 #18
0
int main(int argc, char **argv) {
	char buf[32];
	char *bin_path, *ptr;
	struct pru_data	pru;
	int fd;

#ifndef DEBUG
	if (fork() != 0) {
		return 0;
	}
#endif
	tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
	prussdrv_init();
	if (prussdrv_open(PRU_EVTOUT_0)) {
		fprintf(stderr, "Cannot setup PRU_EVTOUT_0.\n");
		return -EINVAL;
	}
	prussdrv_pruintc_init(&pruss_intc_initdata);

	prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, (void *) &pru.prumem);
	if (pru.prumem == NULL) {
		fprintf(stderr, "Cannot map PRU0 memory buffer.\n");
		return -ENOMEM;
	}


	/* Create the FIFO if it does not exist */
	umask(0);
	mknod(FIFO_FILE, S_IFIFO|0666, 0);

	fd = open(FIFO_FILE, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "Cannot open FIFO.\n");
		return -EINVAL;
	}

	pru.prumem[RUN_FLAG_IDX] = 1; /* startup */
	bin_path = strdup(argv[0]);

	ptr = strrchr(bin_path, '/');
	*ptr = '\0';

	chdir(bin_path);
	prussdrv_exec_program(0, "pru0_nixie.bin");

	blank_vfd(&pru);
	signal(SIGINT, shutdown_clock);
	signal(SIGTERM, shutdown_clock);

	while (running) {	
		if (read(fd, buf, sizeof(buf) - 1) > 0) {
			update_buffer((const char *) &buf, &pru);
			trigger_update(&pru);
		}
		usleep(msecs(10));
	}
	close(fd);

	pru.prumem[RUN_FLAG_IDX] = 0;
	trigger_update(&pru);
#ifdef DEBUG
	fprintf(stdout, "Waiting for PRU core to shutdown..\n");
#endif
	prussdrv_pru_wait_event(PRU_EVTOUT_0);
	prussdrv_pru_clear_event(PRU0_ARM_INTERRUPT);

	prussdrv_pru_disable(0);
	prussdrv_exit();

	if (bin_path) {
		free(bin_path);
	}

	return 0;
}
예제 #19
0
void
sen_sprite_render(void* _self)
{
  sprite_t *self = (sprite_t *)_self;
  vec4* bbox;
  const vec4* vp;
  node_t* cam_node;
  const mat4* mv;
  vec4* v;
  int use_cam;


  sen_assert(_self);

  if ( ((node_t*)self)->color.a < F_EPSILON ) return;

  update_buffer(self);


  bbox = & ( ((node_t*) self)->bbox );
  vp = sen_view_get_viewport();

  //const mat4* mv = sen_node_model(sen_camera());

  cam_node = (node_t* ) sen_camera();
  mv = &(cam_node->model);

  v = (vec4*)self->quad->vertices->items;
  use_cam = v->z < 0.9 && v->z > -0.9 ;

  if (use_cam) {
    float sx,sy,vw,vh;

    sx =  mv->data[12];
    sy =  mv->data[13];

    vw = (vp->z - vp->x) / 2.0f ;
    vh = (vp->w - vp->y) / 2.0f ;
    //if (bbox->x > 250) {
    //_logfi("%.f %.f %.f %.f", vp->x, vp->y, vp->z, vp->w);
    //_logfi("%.f %.f %.f %.f", bbox->x, bbox->y, bbox->z, bbox->w);
    //_logfi("--------------------------------------------");
    //}

    if (bbox->z+ sx< -vw  ||
        bbox->x+ sx>  vw  ||
        bbox->w+ sy< -vh  ||
        bbox->y+ sy>  vh  )
    {
      //_logfi("NO");
      return;
    }
  }

  sen_render_push_buffer(self->quad, self->tex, NULL, self->program, ((node_t*)self)->blend);
  /*
  int status  = ((node_t*)self)->updated;

  if (status & SEN_NODE_UPDATE_INVALIDATE_BUFFER) {
   // _logfi("invalidate %s", ((object_t*)self)->name );
    vertex_buffer_invalidate(self->quad);
    ((node_t*)self)->updated &= ~SEN_NODE_UPDATE_INVALIDATE_BUFFER;
  }

  if ( status & (SEN_NODE_UPDATE_BBOX | SEN_NODE_UPDATE_COLOR )) {
    update_quad(self);
  //  status |= (SEN_NODE_UPDATE_MODEL);
  }
*/
  /*
  update_buffer(self);

  sen_texture_bind(self->tex);
  mat4 mvp;
 // mat4_set_identity(mvp.data);
  camera_t* cam = sen_camera();

  //mat4_multiply2(sen_node_model(self), & cam->view_proj, &mvp);
  //mat4_set_identity(&mvp);
  sen_shader_use(self->program);
  {
    sen_uniform_1iN(self->program, "u_tex0", 0);
    //sen_uniform_m4fN(self->program, "u_mvp",  mvp.data);
    sen_uniform_m4fN(self->program, "u_mvp",  cam->view_proj.data);
    vertex_buffer_render( self->quad, GL_TRIANGLES);
  }
  */
}
예제 #20
0
 explicit InputIterator(TSource& source) :
     m_source(&source) {
     update_buffer();
 }
예제 #21
0
static nss_status_t
getbyuid(ad_backend_ptr be, void *a)
{
	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
	char			searchfilter[ADUTILS_MAXHEXBINSID + 14];
	char			*sidprefix = NULL;
	idmap_rid_t		rid;
	char			cbinsid[ADUTILS_MAXHEXBINSID + 1];
	char			*winname = NULL, *windomain = NULL;
	int			is_user, is_wuser;
	gid_t			gid;
	idmap_stat		idmaprc;
	int			ret, try_idmap;
	nss_status_t		stat;

	be->db_type = NSS_AD_DB_PASSWD_BYUID;

	stat = (nss_status_t)NSS_NOTFOUND;

	/* nss_ad does not support non ephemeral uids */
	if (argp->key.uid <= MAXUID)
		goto out;

	/* Map the given UID to a SID using the idmap service */
	if (idmap_get_u2w_mapping(&argp->key.uid, NULL, 0,
	    1, NULL, &sidprefix, &rid, &winname, &windomain,
	    NULL, NULL) != 0) {
		RESET_ERRNO();
		goto out;
	}

	/*
	 * NULL winname implies a local SID or unresolvable SID both of
	 * which cannot be used to generated passwd(4) entry
	 */
	if (winname == NULL)
		goto out;

	/* If this is not a Well-Known SID try AD lookup */
	if (windomain != NULL && strcasecmp(windomain, WK_DOMAIN) != 0) {
		if (adutils_txtsid2hexbinsid(sidprefix, &rid,
		    &cbinsid[0], sizeof (cbinsid)) != 0)
			goto out;

		ret = snprintf(searchfilter, sizeof (searchfilter),
		    _F_GETPWUID, cbinsid);
		if (ret >= sizeof (searchfilter) || ret < 0)
			goto out;

		stat = _nss_ad_lookup(be, argp, _PASSWD, searchfilter,
		    windomain, &try_idmap);

		if (!try_idmap)
			goto out;
	}

	/* Map winname to primary gid using idmap service */
	is_user = 0;
	is_wuser = -1;
	idmaprc = idmap_get_w2u_mapping(NULL, NULL,
	    winname, windomain, 0, &is_user, &is_wuser, &gid,
	    NULL, NULL, NULL);

	if (idmaprc != IDMAP_SUCCESS) {
		RESET_ERRNO();
		goto out;
	}

	/* Create passwd(4) style string */
	if (update_buffer(be, argp, winname, windomain,
	    argp->key.uid, gid, "", "", "") < 0)
		goto out;

	/* Marshall the data, sanitize the return status and return */
	stat = _nss_ad_marshall_data(be, argp);
	stat = _nss_ad_sanitize_status(be, argp, stat);

out:
	idmap_free(sidprefix);
	idmap_free(winname);
	idmap_free(windomain);
	return (stat);
}
예제 #22
0
static void *
halftone_init (Display *dpy, Window window)
{
  int x, y, i;
  int count;
  int spacing;
  double factor;
  double min_mass;
  double max_mass;
  double min_speed;
  double max_speed;
  XGCValues gc_values;
  XWindowAttributes attrs;
  halftone_screen *halftone;

  halftone = (halftone_screen *) calloc (1, sizeof(halftone_screen));

  halftone->dpy = dpy;
  halftone->window = window;

  //halftone->delay = get_integer_resource (dpy, "delay", "Integer");
  //halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);
  halftone->delay = delay;
  halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);

  halftone->gc = XCreateGC (halftone->dpy, halftone->window, 0, &gc_values);

  halftone->buffer_width = -1;
  halftone->buffer_height = -1;
  halftone->dots = NULL;

  /* Read command line arguments and set all settings. */ 
  //count = get_integer_resource (dpy, "count", "Count");
  count = count_;
  halftone->gravity_point_count = count < 1 ? DEFAULT_COUNT : count; 

  //spacing = get_integer_resource (dpy, "spacing", "Integer");
  spacing = spacing_;
  halftone->spacing = spacing < 1 ? DEFAULT_SPACING : spacing; 

  //factor = get_float_resource (dpy, "sizeFactor", "Double");
  factor = sizeFactor;
  halftone->max_dot_size = 
    (factor < 0 ? DEFAULT_SIZE_FACTOR : factor) * halftone->spacing; 

  //min_mass = get_float_resource (dpy, "minMass", "Double");
  min_mass = minMass;
  min_mass = min_mass < 0 ? DEFAULT_MIN_MASS : min_mass;

  //max_mass = get_float_resource (dpy, "maxMass", "Double");
  max_mass = maxMass;
  max_mass = max_mass < 0 ? DEFAULT_MAX_MASS : max_mass;
  max_mass = max_mass < min_mass ? min_mass : max_mass;

  //min_speed = get_float_resource (dpy, "minSpeed", "Double");
  min_speed = minSpeed;
  min_speed = min_speed < 0 ? DEFAULT_MIN_SPEED : min_speed;

  //max_speed = get_float_resource (dpy, "maxSpeed", "Double");
  max_speed = maxSpeed;
  max_speed = max_speed < 0 ? DEFAULT_MAX_SPEED : max_speed;
  max_speed = max_speed < min_speed ? min_speed : max_speed;


  /* Set up the moving gravity points. */
  halftone->gravity_point_x = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_y = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_mass = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_x_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double));
  halftone->gravity_point_y_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double));

  for (i = 0; i < halftone->gravity_point_count; i++)
  {
    halftone->gravity_point_x[i] = frand(1);
    halftone->gravity_point_y[i] = frand(1);
    halftone->gravity_point_mass[i] = min_mass + (max_mass - min_mass) * frand(1);
    halftone->gravity_point_x_inc[i] = min_speed + (max_speed - min_speed) * frand(1);
    halftone->gravity_point_y_inc[i] = min_speed + (max_speed - min_speed) * frand(1);
  }


  /* Set up the dots. */
  XGetWindowAttributes(halftone->dpy, halftone->window, &attrs);  

  //halftone->ncolors = get_integer_resource (dpy, "colors", "Colors");
  halftone->ncolors = colors;
  if (halftone->ncolors < 4) halftone->ncolors = 4;
  halftone->colors = (XColor *) calloc(halftone->ncolors, sizeof(XColor));
  make_smooth_colormap (attrs.screen, attrs.visual, attrs.colormap,
                        halftone->colors, &halftone->ncolors,
                        True, 0, False);
  halftone->color0 = 0;
  halftone->color1 = halftone->ncolors / 2;
  //halftone->cycle_speed = get_integer_resource (dpy, "cycleSpeed", "CycleSpeed");
  halftone->cycle_speed = cycleSpeed;
  halftone->color_tick = 0;

  update_buffer(halftone, &attrs);
  update_dot_attributes(halftone, &attrs);

  for (x = 0; x < halftone->dots_width; x++)
    for (y = 0; y < halftone->dots_height; y++)
    {
	halftone->dots[x + y * halftone->dots_width] = 0;
    }

  return halftone;
}
예제 #23
0
static nss_status_t
getbyname(ad_backend_ptr be, void *a)
{
	nss_XbyY_args_t	*argp = (nss_XbyY_args_t *)a;
	char		*searchfilter;
	char		name[SEARCHFILTERLEN];
	char		*dname;
	int		filterlen, namelen;
	int		flag;
	nss_status_t	stat;
	idmap_stat	idmaprc;
	uid_t		uid;
	gid_t		gid;
	int		is_user, is_wuser, try_idmap;

	be->db_type = NSS_AD_DB_PASSWD_BYNAME;

	/* Sanitize name so that it can be used in our LDAP filter */
	if (_ldap_filter_name(name, argp->key.name, sizeof (name)) != 0)
		return ((nss_status_t)NSS_NOTFOUND);

	if ((dname = strchr(name, '@')) == NULL)
		return ((nss_status_t)NSS_NOTFOUND);

	*dname = '\0';
	dname++;

	/*
	 * Map the given name to UID using idmap service. If idmap
	 * call fails then this will save us doing AD discovery and
	 * AD lookup here.
	 */
	flag = (strcasecmp(dname, WK_DOMAIN) == 0) ?
	    IDMAP_REQ_FLG_WK_OR_LOCAL_SIDS_ONLY : 0;
	is_wuser = -1;
	is_user = 1;
	if (idmap_get_w2u_mapping(NULL, NULL, name,
	    dname, flag, &is_user, &is_wuser, &be->uid, NULL,
	    NULL, NULL) != IDMAP_SUCCESS) {
		RESET_ERRNO();
		return ((nss_status_t)NSS_NOTFOUND);
	}

	/* If this is not a Well-Known SID then try AD lookup. */
	if (strcasecmp(dname, WK_DOMAIN) != 0) {
		/* Assemble filter using the given name */
		namelen = strlen(name);
		filterlen = snprintf(NULL, 0, _F_GETPWNAM, namelen, name) + 1;
		if ((searchfilter = (char *)malloc(filterlen)) == NULL)
			return ((nss_status_t)NSS_NOTFOUND);
		(void) snprintf(searchfilter, filterlen, _F_GETPWNAM,
		    namelen, name);
		stat = _nss_ad_lookup(be, argp, _PASSWD, searchfilter,
		    dname, &try_idmap);
		free(searchfilter);

		if (!try_idmap)
			return (stat);

	}

	/*
	 * Either this is a Well-Known SID or AD lookup failed. Map
	 * the given name to GID using idmap service and construct
	 * the passwd entry.
	 */
	is_wuser = -1;
	is_user = 0; /* Map name to primary gid */
	idmaprc = idmap_get_w2u_mapping(NULL, NULL, name, dname,
	    flag, &is_user, &is_wuser, &gid, NULL, NULL, NULL);
	if (idmaprc != IDMAP_SUCCESS) {
		RESET_ERRNO();
		return ((nss_status_t)NSS_NOTFOUND);
	}

	/* Create passwd(4) style string */
	if (update_buffer(be, argp, name, dname,
	    be->uid, gid, "", "", "") < 0)
		return ((nss_status_t)NSS_NOTFOUND);

	/* Marshall the data, sanitize the return status and return */
	stat = _nss_ad_marshall_data(be, argp);
	return (_nss_ad_sanitize_status(be, argp, stat));
}
예제 #24
0
/*
 * _nss_ad_passwd2str is the data marshaling method for the passwd getXbyY
 * (e.g., getbyuid(), getbyname(), getpwent()) backend processes. This method is
 * called after a successful AD search has been performed. This method will
 * parse the AD search values into the file format.
 * e.g.
 *
 * blue@whale:x:123456:10:Blue Whale:/:
 *
 */
static int
_nss_ad_passwd2str(ad_backend_ptr be, nss_XbyY_args_t *argp)
{
	int			nss_result;
	adutils_result_t	*result = be->result;
	const adutils_entry_t	*entry;
	char			**sid_v, *ptr, **pgid_v, *end;
	ulong_t			tmp;
	uint32_t		urid, grid;
	uid_t			uid;
	gid_t			gid;
	idmap_stat		gstat;
	idmap_get_handle_t 	*ig = NULL;
	char			**name_v, **dn_v, *domain = NULL;
	char			**gecos_v, **shell_v;
	char			**homedir_v = NULL, *homedir = NULL;
	char			*NULL_STR = "";

	if (result == NULL)
		return (NSS_STR_PARSE_PARSE);
	entry = adutils_getfirstentry(result);
	nss_result = NSS_STR_PARSE_PARSE;

	/* Create handles for idmap service */
	if (idmap_get_create(&ig) != 0)
		goto result_pwd2str;

	/* Get name */
	name_v = adutils_getattr(entry, _PWD_SAN);
	if (name_v == NULL || name_v[0] == NULL || *name_v[0] == '\0')
		goto result_pwd2str;

	/* Get domain */
	dn_v = adutils_getattr(entry, _PWD_DN);
	if (dn_v == NULL || dn_v[0] == NULL || *dn_v[0] == '\0')
		goto result_pwd2str;
	domain = adutils_dn2dns(dn_v[0]);

	/* Get objectSID (in text format) */
	sid_v = adutils_getattr(entry, _PWD_OBJSID);
	if (sid_v == NULL || sid_v[0] == NULL || *sid_v[0] == '\0')
		goto result_pwd2str;

	/* Break SID into prefix and rid */
	if ((ptr = strrchr(sid_v[0], '-')) == NULL)
		goto result_pwd2str;
	*ptr = '\0';
	end = ++ptr;
	tmp = strtoul(ptr, &end, 10);
	if (end == ptr || tmp > UINT32_MAX)
		goto result_pwd2str;
	urid = (uint32_t)tmp;

	/* We already have uid -- no need to call idmapd */
	if (be->db_type == NSS_AD_DB_PASSWD_BYUID)
		uid = argp->key.uid;
	else
		uid = be->uid;

	/* Get primaryGroupID */
	pgid_v = adutils_getattr(entry, _PWD_PRIMARYGROUPID);
	if (pgid_v == NULL || pgid_v[0] == NULL || *pgid_v[0] == '\0')
		/*
		 * If primaryGroupID is not found then we request
		 * a GID to be mapped to the given user's objectSID
		 * (diagonal mapping) and use this GID as the primary
		 * GID for the entry.
		 */
		grid = urid;
	else {
		end = pgid_v[0];
		tmp = strtoul(pgid_v[0], &end, 10);
		if (end == pgid_v[0] || tmp > UINT32_MAX)
			goto result_pwd2str;
		grid = (uint32_t)tmp;
	}

	/* Map group SID to GID using idmap service */
	if (idmap_get_gidbysid(ig, sid_v[0], grid, 0, &gid, &gstat) != 0)
		goto result_pwd2str;
	if (idmap_get_mappings(ig) != 0 || gstat != 0) {
		RESET_ERRNO();
		goto result_pwd2str;
	}

	/* Get gecos, homedirectory and shell information if available */
	gecos_v = adutils_getattr(entry, _PWD_CN);
	if (gecos_v == NULL || gecos_v[0] == NULL || *gecos_v[0] == '\0')
		gecos_v = &NULL_STR;

	homedir_v = adutils_getattr(entry, _PWD_HOMEDIRECTORY);
	if (homedir_v == NULL || homedir_v[0] == NULL || *homedir_v[0] == '\0')
		homedir = NULL_STR;
	else if ((homedir = process_homedir(homedir_v[0])) == NULL)
		homedir = NULL_STR;

	shell_v = adutils_getattr(entry, _PWD_LOGINSHELL);
	if (shell_v == NULL || shell_v[0] == NULL || *shell_v[0] == '\0')
		shell_v = &NULL_STR;

	if (update_buffer(be, argp, name_v[0], domain, uid, gid,
	    gecos_v[0], homedir, shell_v[0]) < 0)
		nss_result = NSS_STR_PARSE_ERANGE;
	else
		nss_result = NSS_STR_PARSE_SUCCESS;

result_pwd2str:
	idmap_get_destroy(ig);
	(void) adutils_freeresult(&be->result);
	free(domain);
	if (homedir != NULL_STR && homedir_v != NULL &&
	    homedir != homedir_v[0])
		free(homedir);
	return ((int)nss_result);
}
예제 #25
0
파일: functions.c 프로젝트: Goalt/Text_edit
int print_range(int f, int l)
{
    int a = f,b= l, height, widht, i, j, k, count_strochek, tmp;
    char c = 0;
    struct MyString *tmp_string, *tmp2string;
    struct MySymbol *tmp_symbol;
    if (is_redirected == 1)
    {
        write_Strings(stdout);
        return 0;
    }
    clear_terminal();
    if (my_strings_start == NULL)
    {
        set_keypress();
        while (1)
        {
            c = getchar();
            if (c == 'q')
            {
                reset_keypress();
                system("setterm -cursor on");
                putchar('\n');
                return 0;
            }
        }
    }
    tmp_string = my_strings_start;
    ioctl(0, TIOCGWINSZ, &terminal);
    height = terminal.ws_row-1;
    widht = terminal.ws_col;
    /*height = 5;*/
    
    if (f > N)
        return -3;
    if (f == -1)
        a = 1;
    if ((l == -1) || (l > N))
        b = N;
    
    for (i = 0; i < a-1; i++) {tmp_string = tmp_string->next_string;}
    if (is_wrap == 0)
    {
        tmp = N;
        N = b-a+1;
        tmp2string = my_strings_start;
        my_strings_start = tmp_string;
        j = 1;
        a = 1;
        if(update_buffer(a)!= 0)
        {
            free_buffer();
            return exit_force();
        }
        while (1)
        {
            print_buffer(j);
            set_keypress();
            while (1)
            {
                c = getchar();
                if (c == 'q')
                {
                    reset_keypress();
                    printf("\n");
                    free_buffer();
                    N = tmp;
                    my_strings_start = tmp2string;
                    return 0;
                }
                if (c == '>')
                {
                    reset_keypress();
                    clear_terminal();
                    j++;
                    break;
                }
                if ((c == '<') && (j >= 2))
                {
                    reset_keypress();
                    clear_terminal();
                    j--;
                    break;
                }
                if ((c == ' ') && (a + height <= N))
                {
                    reset_keypress();
                    clear_terminal();
                    a = a + height;
                    free_buffer();
                    
                    if(update_buffer(a)!= 0)
                    {
                        free_buffer();
                        return exit_force();
                    }
                    
                    break;
                }
            }
        }
    }
    else
    {
        height -= 2;
        system("setterm -cursor off");
        i = a;
        count_strochek = 1;
        while (i <= b)
        {
            tmp_symbol = tmp_string->first_symbol;
            putchar('@');
            j = 1;
            while (tmp_symbol != NULL)
            {
                if ((j == widht) && (tmp_symbol->next_symbol != NULL))
                {
                    putchar('\n');
                    count_strochek++;
                    if (count_strochek > height)
                    {
                        set_keypress();
			
                        while (1)
                        {
                            c = getchar();
                            if (c == 'q')
                            {
                                reset_keypress();
                                system("setterm -cursor on");
                                printf("\n");
                                return 0;
                            }
                            if (c == ' ')
                            {
                                count_strochek = 1;
                                reset_keypress();
                                clear_terminal();
                                break;
                            }
                        }
                    }
                    j = 0;
                }
                if (tmp_symbol->symbol == '\t')
                {
                    for (k = 0; k < count_ofspaces_intabulation; k++)
                    {
                        if (j == widht)
                        {
                            putchar('\n');
                            count_strochek++;
                            if (count_strochek > height)
                            {
                                set_keypress();
                                
                                while (1)
                                {
                                    c = getchar();
                                    if (c == 'q')
                                    {
                                        reset_keypress();
                                        system("setterm -cursor on");
                                        putchar('\n');
                                        return 0;
                                    }
                                    if (c == ' ')
                                    {
                                        count_strochek = 1;
                                        reset_keypress();
                                        clear_terminal();
                                        break;
                                    }
                                }
                            }
                            j = 0;
                        }
                        putchar(' ');
                        j++;
                    }
                }
                else
                    putchar(tmp_symbol->symbol);
                j++;
                tmp_symbol = tmp_symbol->next_symbol;
            }
            i++;
            count_strochek++;
            if (count_strochek > height)
            {
                set_keypress();
                while (1)
                {
                    c = getchar();
                    if (c == 'q')
                    {
                        reset_keypress();
                        system("setterm -cursor on");
                        printf("\n");
                        return 0;
                    }
                    if (c == ' ')
                    {
                        count_strochek = 1;
                        reset_keypress();
                        clear_terminal();
                        tmp_string = tmp_string->next_string;
                        break;
                    }
                }
                continue;
            }
            tmp_string = tmp_string->next_string;
            putchar('\n');
        }
        set_keypress();
        while (1)
        {
            c = getchar();
            if (c == 'q')
            {
                reset_keypress();
                printf("\n");
                break;
            }
        }
    }
    system("setterm -cursor on");
    return 0;
}
예제 #26
0
int main(int argc, char **argv) {
    char buf[32];
    struct pru_data	pru;
    int fd, rdsize;

#ifndef DEBUG
    if (fork() != 0) {
        return 0;
    }
#endif

    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

    printf("Initializing pruss\n");
    prussdrv_init();
    if (prussdrv_open(PRU_EVTOUT_0)) {
        fprintf(stderr, "Cannot setup PRU_EVTOUT_0.\n");
        return -EINVAL;
    }
    
    printf("Initializing interrupts\n");
    prussdrv_pruintc_init(&pruss_intc_initdata);

    printf("Mapping PRUSS0 RAM\n");
    prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, (void *) &pru.prumem);
    if (pru.prumem == NULL) {
        fprintf(stderr, "Cannot map PRU0 memory buffer.\n");
        return -ENOMEM;
    }


    printf("Creating FIFO\n");
    /* Create the FIFO if it does not exist */
    umask(0);
    mknod(FIFO_FILE, S_IFIFO|0666, 0);

    printf("Opening FIFO\n");
    fd = open(FIFO_FILE, O_RDONLY);
    if (fd < 0) {
        fprintf(stderr, "Cannot open FIFO.\n");
        return -EINVAL;
    }

    pru.prumem[RUN_FLAG_IDX] = 1; /* startup */

    printf("Loading PRU0 program\n");
    prussdrv_exec_program(0, "7seg_spi_test_fifo.bin");

    signal(SIGINT, shutdown_clock);
    signal(SIGTERM, shutdown_clock);

    printf("Entering runloop\n");
    while (running) {	
        if ((rdsize = read(fd, buf, sizeof(buf) - 1)) > 0) {
            update_buffer((const char *) &buf, &pru, rdsize);
        }
        usleep(msecs(10));
    }
    close(fd);

    pru.prumem[RUN_FLAG_IDX] = 0;
    
#ifdef DEBUG
    fprintf(stdout, "Waiting for PRU core to shutdown..\n");
#endif

    prussdrv_pru_wait_event(PRU_EVTOUT_0);
    prussdrv_pru_clear_event(PRU0_ARM_INTERRUPT);

    prussdrv_pru_disable(0);
    prussdrv_exit();

    return 0;
}
예제 #27
0
RC Row_mvcc::access(TxnManager * txn, TsType type, row_t * row) {
	RC rc = RCOK;
	ts_t ts = txn->get_timestamp();
	uint64_t starttime = get_sys_clock();

	if (g_central_man)
		glob_manager.lock_row(_row);
	else
		pthread_mutex_lock( latch );
  if (type == R_REQ) {
		// figure out if ts is in interval(prewrite(x))
		bool conf = conflict(type, ts);
		if ( conf && rreq_len < g_max_read_req) {
			rc = WAIT;
      //txn->wait_starttime = get_sys_clock();
        DEBUG("buf R_REQ %ld %ld\n",txn->get_txn_id(),_row->get_primary_key());
			buffer_req(R_REQ, txn);
			txn->ts_ready = false;
		} else if (conf) { 
			rc = Abort;
			printf("\nshould never happen. rreq_len=%ld", rreq_len);
		} else {
			// return results immediately.
			rc = RCOK;
			MVHisEntry * whis = writehis;
			while (whis != NULL && whis->ts > ts) 
				whis = whis->next;
			row_t * ret = (whis == NULL)? 
				_row : whis->row;
			txn->cur_row = ret;
			insert_history(ts, NULL);
			assert(strstr(_row->get_table_name(), ret->get_table_name()));
		}
	} else if (type == P_REQ) {
		if ( conflict(type, ts) ) {
			rc = Abort;
		} else if (preq_len < g_max_pre_req){
        DEBUG("buf P_REQ %ld %ld\n",txn->get_txn_id(),_row->get_primary_key());
			buffer_req(P_REQ, txn);
			rc = RCOK;
		} else  {
			rc = Abort;
		}
	} else if (type == W_REQ) {
		rc = RCOK;
		// the corresponding prewrite request is debuffered.
		insert_history(ts, row);
        DEBUG("debuf %ld %ld\n",txn->get_txn_id(),_row->get_primary_key());
		MVReqEntry * req = debuffer_req(P_REQ, txn);
		assert(req != NULL);
		return_req_entry(req);
		update_buffer(txn);
	} else if (type == XP_REQ) {
        DEBUG("debuf %ld %ld\n",txn->get_txn_id(),_row->get_primary_key());
		MVReqEntry * req = debuffer_req(P_REQ, txn);
		assert (req != NULL);
		return_req_entry(req);
		update_buffer(txn);
	} else 
		assert(false);
	
	if (rc == RCOK) {
		if (whis_len > g_his_recycle_len || rhis_len > g_his_recycle_len) {
			ts_t t_th = glob_manager.get_min_ts(txn->get_thd_id());
			if (readhistail && readhistail->ts < t_th)
				clear_history(R_REQ, t_th);
			// Here is a tricky bug. The oldest transaction might be 
			// reading an even older version whose timestamp < t_th.
			// But we cannot recycle that version because it is still being used.
			// So the HACK here is to make sure that the first version older than
			// t_th not be recycled.
			if (whis_len > 1 && 
				writehistail->prev->ts < t_th) {
				row_t * latest_row = clear_history(W_REQ, t_th);
				if (latest_row != NULL) {
					assert(_row != latest_row);
					_row->copy(latest_row);
				}
			}
		}
	}
	
	uint64_t timespan = get_sys_clock() - starttime;
	txn->txn_stats.cc_time += timespan;
	txn->txn_stats.cc_time_short += timespan;

	if (g_central_man)
		glob_manager.release_row(_row);
	else
		pthread_mutex_unlock( latch );	
		
	return rc;
}