예제 #1
0
파일: circle.c 프로젝트: china-vo/pgSphere
  Datum  spherecircle_in(PG_FUNCTION_ARGS)
  {
    SCIRCLE  * c  = ( SCIRCLE * ) MALLOC ( sizeof ( SCIRCLE ) ) ;
    char     * s  = PG_GETARG_CSTRING(0);
    double lng, lat, radius ;

    void sphere_yyparse( void );

    init_buffer ( s );
    sphere_yyparse();
    if ( get_circle( &lng, &lat, &radius ) ){
      c->center.lng  = lng;
      c->center.lat  = lat;
      c->radius      = radius;
      reset_buffer();
      /*
        It's important to allow circles with radius 90deg!!      
      */
      if ( FPgt(c->radius,PIH) ){
        FREE( c );
        c = NULL;
        elog ( ERROR , "spherecircle_in: radius must be not greater than 90 degrees" );
      } else if ( FPeq(c->radius,PIH) ){
        // set "exact" 90 degrees
        c->radius = PIH;
      }
      spoint_check ( &c->center );
    } else {
      reset_buffer();
      FREE( c );
      c = NULL;
      elog ( ERROR , "spherecircle_in: parse error" );
    }
    PG_RETURN_POINTER( c );
  }
예제 #2
0
파일: euler.c 프로젝트: china-vo/pgSphere
  Datum  spheretrans_in(PG_FUNCTION_ARGS)
  {
    SEuler   * se   = ( SEuler * ) MALLOC ( sizeof ( SEuler ) ) ;
    char      *  c  = PG_GETARG_CSTRING(0);
    unsigned char etype[3];
    int            i;

    void sphere_yyparse( void );

    init_buffer ( c );
    sphere_yyparse();

    if ( get_euler ( &se->phi, &se->theta, &se->psi, etype ) ){

      for ( i=0; i<3; i++ ){
        switch ( i ){
          case 0:  se->phi_a   = etype[i] ; break;
          case 1:  se->theta_a = etype[i] ; break;
          case 2:  se->psi_a   = etype[i] ; break;
        }
      }
      spheretrans_check(se);
    } else {
      reset_buffer();
      FREE( se );
      se = NULL;
      elog ( ERROR , "spheretrans_in: parse error" );
    }
    reset_buffer();
    PG_RETURN_POINTER( se );
  }
예제 #3
0
파일: point.c 프로젝트: akorotkov/pgsphere
Datum
spherepoint_in(PG_FUNCTION_ARGS)
{
	SPoint	   *sp = (SPoint *) palloc(sizeof(SPoint));
	char	   *c = PG_GETARG_CSTRING(0);
	double		lng,
				lat;

	void		sphere_yyparse(void);

	init_buffer(c);
	sphere_yyparse();
	if (get_point(&lng, &lat))
	{
		sp->lng = lng;
		sp->lat = lat;
		spoint_check(sp);
	}
	else
	{
		reset_buffer();
		pfree(sp);
		sp = NULL;
		elog(ERROR, "spherepoint_in: parse error");
	}
	reset_buffer();
	PG_RETURN_POINTER(sp);
}
예제 #4
0
파일: polygon.c 프로젝트: mnullmei/pgsphere
  Datum  spherepoly_in(PG_FUNCTION_ARGS)
  {
    SPOLY * poly ;
    char  * c  = PG_GETARG_CSTRING(0);
    static int32  i, nelem;

    void sphere_yyparse( void );
    init_buffer ( c );
    sphere_yyparse() ;

    nelem = get_path_count( ) ;
    if ( nelem > 2 ){
      SPoint arr[nelem];
      for ( i = 0; i<nelem ; i++ ){
         get_path_elem ( i , &arr[i].lng , &arr[i].lat );
      }
      poly  = spherepoly_from_array ( &arr[0], nelem );
    } else {
      reset_buffer();
      elog ( ERROR , "spherepoly_in: more than two points needed" );
      PG_RETURN_NULL();
    }
    reset_buffer();

    PG_RETURN_POINTER( poly );
  }
예제 #5
0
lcb_error_t lcb_connection_reset_buffers(lcb_connection_t conn)
{
    if (reset_buffer(&conn->input, conn->instance->config.rbufsize) != LCB_SUCCESS) {
        return LCB_CLIENT_ENOMEM;
    }
    if (reset_buffer(&conn->output, conn->instance->config.wbufsize) != LCB_SUCCESS) {
        return LCB_CLIENT_ENOMEM;
    }
    return LCB_SUCCESS;
}
예제 #6
0
파일: parser.c 프로젝트: jlepere/fillit
int		parse_file(t_tetrim *t, int fd, char *data)
{
	char		last;
	t_buffer	*buffer;
	int			i;

	i = 0;
	buffer = create_buffer();
	while ((read(fd, data, 1)) > 0)
	{
		if ((i == 20 || i == 21) && (last == '\n' &&
					data[0] == '\n' && parse_buffer(buffer, t, 0)))
			return (-1);
		else if ((i == 20 || i == 21) && last == '\n' &&
				data[0] == '\n' && (t = t->next) != NULL)
		{
			buffer = reset_buffer(buffer);
			i = 0;
		}
		add_buffer(buffer, data[0]);
		last = data[0];
		i++;
	}
	if ((i != 21 && i != 20) || (parse_buffer(buffer, t, 1) || close(fd)))
		return (-1);
	free(buffer);
	return (0);
}
예제 #7
0
파일: lexer.cpp 프로젝트: nilium/rusalka-vm
bool lexer::tokenize()
{
  _next_line = _line = 1;
  _next_column = _column = 1;

  _current_char = _next_char = '\0';
  _next_char_cached = false;

  for (; next() != '\0';) {
    whitespace();

    _line = _next_line;
    _column = _next_column;

    if (current() == '\0') {
      break;
    }

    emit_result const test = string();
    switch (test) {
    case no_match:
      emit(token_kind::error); // fallthrough
    case digest_failure:
      return false;
    case good:
      break;
    }

    reset_buffer();
  }

  return true;
}
예제 #8
0
void camera_init_buffer(buffer_arr_t *pbuf)
{
	print_debug("enter %s", __func__);
	memset(pbuf->buffers, 0x00, sizeof(camera_frame_buf) * MAX_FRAME_NR);
	pbuf->buf_count = 0;
	reset_buffer(pbuf->buffers, MAX_FRAME_NR);
}
//this function sets up the global dictionary in the flash and sets the pointers to the same.
static int set_up_data_segment ()
{
	int j=0;
	char * Flash_ptr;
	//here = data_segment;
	//latest = 0;
	//*TOIP(data_segment) = 0;
	//data_set(0,global_dictionary);
	Global_Dict=&GlobalDict;
	Global_Dict->here=global_dictionary;
	Global_Dict->latest=0;
	*TOIP(global_dictionary) = 0;
	for (j = 0; j < 1024; j++)
	Global_Dict->here[j] = 0xff;
	Flash_ptr = (char *) (global_dictionary);
	//FCTL3 = FWKEY;                            // Clear Lock bit
	//FCTL1 = FWKEY+ERASE;                      // Set Erase bit
	*Flash_ptr = 0; 
	//FCTL1 = FWKEY+ERASE;
	Flash_ptr = (char *) (global_dictionary+512); 
	*Flash_ptr = 0;   
	Global_Dict->vtid=-1;
	Global_Dict->Next=0;
	vt_cur_node=Global_Dict;
	reset_buffer();
	return 0;
}
예제 #10
0
int				completion_search_path(t_comp *comp)
{
	t_env		*env;
	t_env_list	*path;
	char		**paths;

	env = &get_shell_data()->env;
	if (!(path = ft_getenv(env->env_list, "PATH")))
		return (0);
	if (!(paths = ft_strsplit(path->value, ':')))
		return (MALLOC_FAIL);
	if (ft_tab_len(paths) > MAX_PATH_COMPONENTS)
	{
		ft_dprintf(STDERR_FILENO, "42sh: Max path components reached");
		reset_buffer(&get_shell_data()->input);
		ft_free_string_tab(&paths);
		return (1);
	}
	if ((comp->matches = open_path_dirs(comp, paths)) == NULL
			&& comp->nb_matches == -1)
	{
		ft_free_string_tab(&paths);
		return (MALLOC_FAIL);
	}
	ft_free_string_tab(&paths);
	return (0);
}
예제 #11
0
파일: http_reply.cpp 프로젝트: dedok/t2h
bool http_reply::add_content(char const * content, std::size_t content_size) 
{
	if (!content || content_size == 0) 
		return false;	
	
	try 
	{
		add_crlf(); 
		std::size_t const prev_buf_size = buf_ref_.size();
		std::size_t new_buf_size = prev_buf_size + content_size;
		
		if (enable_buf_realocation_)
			buf_ref_.resize(new_buf_size);
		
		for (std::size_t it = prev_buf_size, it_ = 0; 
			it < new_buf_size && it_ < content_size; 
			++it, ++it_) 
		{
			buf_ref_.at(it) = content[it_];
		}
	} 
	catch (std::exception const &) 
	{
		reset_buffer();
		return false;	
	} 
	return true;
}	
예제 #12
0
// TODO: Get this thing to be able to setup ANY of the UART channels somehow!!
void config_uart(unsigned long baudRate) {
    
    // Make sure our buffers start empty:
    reset_buffer();

    // Configure RX pin:
    // Set R7 as an input. I don't think this is needed for uart.. but let's 
    // just be sure.
    //TRISBBITS rxPinU1 = TRISBbits.TRISB7;
    TRISBbits.TRISB7 = 1;

    OSCCONbits.IOLOCK = 0;  // unlock the peripheral Control Register Lock

    // Configure RX pin:
    RPINR18bits.U1RXR = 7;  // Map UART1 RX peripheral to RP7
//    RPINR18bits.U1RXR = 26;  // Map UART1 RX peripheral to RP26 (also, RG7)

    // Configure TX pin:
    RPOR3bits.RP6R = 3;     // Map RP6 pin to UART1 TX
    OSCCONbits.IOLOCK = 1;  // relock the peripheral Control Register Lock

    // Set baud rate:
    U1BRG = (((FCY)/(4 * baudRate)) - 1);
    
    // Set interrupt priorities:
    // (Honestly, not sure exactly what this is doing...)
    IPC3bits.U1TXIP2 = 1; //Set Uart TX Interrupt Priority
    IPC3bits.U1TXIP1 = 0;
    IPC3bits.U1TXIP0 = 0;
    IPC2bits.U1RXIP2 = 1; //Set Uart RX Interrupt Priority
    IPC2bits.U1RXIP1 = 0;
    IPC2bits.U1RXIP0 = 0;
    
    U1TXREG = 0; // Ensure that we start with an empty TX buffer
    
    U1STA = 0; // Clear the UxSTA register (for tx1 and rx1 only)
    U1STAbits.URXISEL = 0; // Configure when the TX interrupt will fire
    
    // Enable UART for 8-bit data:
    U1MODE = 0; // Clear the UxMode register (for tx1 and rx1 only)
    //U1MODEbits.RTSMD = 1; // RTS pin bit is in simplex mode not flow control mode
    U1MODEbits.BRGH = 1; // 1 = low speed
    U1MODEbits.UARTEN = 1; // Actually enable the UART module (MUST be done before UTXEN is set)
    
    U1STAbits.UTXEN = 1; // enable transmit
    IEC0bits.U1TXIE = 1; // enable transmit interrupt
    IEC0bits.U1RXIE = 1; // enable receive interrupt
    
    // Clear the flags for both interrupts:
    IFS0bits.U1TXIF = 0; 
    IFS0bits.U1RXIF = 0; 
    
    // Configure the buffer pointers:
    U1TXCharPtr = &txBufU1[0];
    U1RXCharPtr = &rxBufU1[0];
    
    __delay_ms(100);
    printf("\n\nUART should be working at 115200 baud now!\r\n");
}
예제 #13
0
void etna_cmd_stream_finish(struct etna_cmd_stream *stream)
{
	struct etna_cmd_stream_priv *priv = etna_cmd_stream_priv(stream);

	flush(stream);
	etna_pipe_wait(priv->pipe, priv->last_timestamp, 5000);
	reset_buffer(stream);
}
예제 #14
0
파일: player.c 프로젝트: ayoucai/cmus
static void __producer_stop(void)
{
	if (producer_status == PS_PLAYING || producer_status == PS_PAUSED) {
		ip_close(ip);
		__producer_status_update(PS_STOPPED);
		reset_buffer();
	}
}
예제 #15
0
Session::~Session()
{
    reset_buffer();
    if (m_sockfd > 0)
    {
        close(m_sockfd);
    }
}
예제 #16
0
static void flush(struct etna_cmd_stream *stream, int in_fence_fd,
		  int *out_fence_fd)
{
	struct etna_cmd_stream_priv *priv = etna_cmd_stream_priv(stream);
	int ret, id = priv->pipe->id;
	struct etna_gpu *gpu = priv->pipe->gpu;

	struct drm_etnaviv_gem_submit req = {
		.pipe = gpu->core,
		.exec_state = id,
		.bos = VOID2U64(priv->submit.bos),
		.nr_bos = priv->submit.nr_bos,
		.relocs = VOID2U64(priv->submit.relocs),
		.nr_relocs = priv->submit.nr_relocs,
		.stream = VOID2U64(stream->buffer),
		.stream_size = stream->offset * 4, /* in bytes */
	};

	if (in_fence_fd != -1) {
		req.flags |= ETNA_SUBMIT_FENCE_FD_IN | ETNA_SUBMIT_NO_IMPLICIT;
		req.fence_fd = in_fence_fd;
	}

	if (out_fence_fd)
		req.flags |= ETNA_SUBMIT_FENCE_FD_OUT;

	/*
	 * Pass the complete submit structure only if flags are set. Otherwise,
	 * only pass the fields up to, but not including the flags field for
	 * backwards compatiblity with older kernels.
	 */
	ret = drmCommandWriteRead(gpu->dev->fd, DRM_ETNAVIV_GEM_SUBMIT,
			&req, req.flags ? sizeof(req) :
			offsetof(struct drm_etnaviv_gem_submit, flags));

	if (ret)
		ERROR_MSG("submit failed: %d (%s)", ret, strerror(errno));
	else
		priv->last_timestamp = req.fence;

	for (uint32_t i = 0; i < priv->nr_bos; i++) {
		struct etna_bo *bo = priv->bos[i];

		bo->current_stream = NULL;
		etna_bo_del(bo);
	}

	if (out_fence_fd)
		*out_fence_fd = req.fence_fd;
}

void etna_cmd_stream_flush(struct etna_cmd_stream *stream)
{
	flush(stream, -1, NULL);
	reset_buffer(stream);
}
예제 #17
0
int Session::on_close()
{
    logdbg("session close:%s, pid:%d\n",
           get_string_ip().c_str(), g_pid);
    reset_buffer();
    close(m_sockfd);
    m_sockfd = -1;

    return 0;
}
예제 #18
0
static void
receive_frame( int fd, void *user_data ) {
  UNUSED( fd );

  ether_device *device = user_data;
  assert( device != NULL );

  if ( !device->status.up ) {
    return;
  }

  if ( get_max_packet_buffers_length( device->recv_queue ) <= get_packet_buffers_length( device->recv_queue ) ) {
    warn( "Receive queue is full ( device = %s, usage = %u/%u ).", device->name,
          get_packet_buffers_length( device->recv_queue ), get_max_packet_buffers_length( device->recv_queue ) );
    return;
  }

  unsigned int count = 0;
  const unsigned int max_queue_length = get_max_packet_buffers_length( device->recv_queue );
  const unsigned int max_loop_count = max_queue_length < 256 ? max_queue_length : 256;
  while ( count < max_loop_count ) {
    buffer *frame = get_buffer_from_free_buffers( device->recv_queue );
    if ( frame == NULL ) {
      warn( "Failed to retrieve a receive buffer ( device = %s, queue usage = %u/%u ).", device->name,
            get_packet_buffers_length( device->recv_queue ), max_queue_length );
      frame = device->recv_buffer; // Use recv_buffer as a trash.
    }
    append_back_buffer( frame, device->mtu );

    ssize_t length = recv( device->fd, frame->data, frame->length, MSG_DONTWAIT );
    assert( length != 0 );
    if ( length < 0 ) {
      if ( frame != device->recv_buffer ) {
        mark_packet_buffer_as_used( device->recv_queue, frame );
      }
      if ( ( errno == EINTR ) || ( errno == EAGAIN ) || ( errno == EWOULDBLOCK ) || ( errno == ENETDOWN ) ) {
        break;
      }
      char error_string[ ERROR_STRING_SIZE ];
      error( "Receive error ( device = %s, errno = %s [%d] ).",
             device->name, safe_strerror_r( errno, error_string, sizeof( error_string ) ), errno );
      break;
    }
    if ( frame != device->recv_buffer ) {
      frame->length = ( size_t ) length;
      enqueue_packet_buffer( device->recv_queue, frame );
    }
    else {
      reset_buffer( frame );
    }
    count++;
  }

  handle_received_frames( device );
}
예제 #19
0
파일: player.c 프로젝트: jmerdich/cmus
static void _consumer_handle_eof(void)
{
	struct track_info *ti;

	if (ip_is_remote(ip)) {
		_producer_stop();
		_consumer_drain_and_stop();
		player_error("lost connection");
		return;
	}

	if (player_info.ti)
		player_info.ti->play_count++;

	if (player_repeat_current) {
		if (player_cont) {
			ip_seek(ip, 0);
			reset_buffer();
		} else {
			_producer_stop();
			_consumer_drain_and_stop();
			_player_status_changed();
		}
		return;
	}

	if (get_next(&ti) == 0) {
		_producer_unload();
		ip = ip_new(ti->filename);
		_producer_status_update(PS_STOPPED);
		/* PS_STOPPED, CS_PLAYING */
		if (player_cont) {
			_producer_play();
			if (producer_status == PS_UNLOADED) {
				_consumer_stop();
				track_info_unref(ti);
				file_changed(NULL);
			} else {
				/* PS_PLAYING */
				file_changed(ti);
				if (!change_sf(0))
					_prebuffer();
			}
		} else {
			_consumer_drain_and_stop();
			file_changed(ti);
		}
	} else {
		_producer_unload();
		_consumer_drain_and_stop();
		file_changed(NULL);
	}
	_player_status_changed();
}
예제 #20
0
/*
 * Function: Read a byte from the file buffer
 * Parameters:  file - open file descriptor to the target
 * Return: Byte read
 */
char read_char(FILE* file) {
	if (bytes_in_buffer != CHUNK_SIZE && read_ptr >= bytes_in_buffer) {
		eof = 1;
		return 0xff;
	}

	if (read_ptr == CHUNK_SIZE) {
		reset_buffer(file);
	}

	return read_buffer[read_ptr++];
}
예제 #21
0
int Session::on_read_event()
{
    int ret;
    while (true)
    {
        if (!m_has_head)
        {
            ret = read_head();
            if (ret < 0)
            {
                return -1;
            }
            if (ret == SESSION_RET_NO_DATA)
            {
                return 0;
            }
            if (m_msg_type == MSG_HEART_BEAT)
            {
                if (g_is_master)
                {
                    update_active_time();
                }
                else
                {
                    struct commu_msg msg;
                    msg.ip = get_cli_addr();
                    msg.msg = MSG_HEART_BEAT;
                    notify_master(msg);
                }
                continue;
            }
            m_has_head = true;
            m_buff = (u_char *)glb_mempool()->get(m_msg_len);
        }
        int n_read = readn(m_sockfd, &m_buff[m_n_read], m_msg_len - m_n_read);
        if (n_read < 0)
        {
            logerr("socket broken\n");
            m_msg_len = 0;
            m_has_head = false;
            return -1;
        }
        m_n_read += n_read;
        if (m_n_read == m_msg_len)
        {
            write_msg(m_buff, m_msg_len);
            reset_buffer();
        }
    }
    return 0;

}
예제 #22
0
파일: esp8266.c 프로젝트: JiuchengXu/shit
s8 set_echo(s8 on)
{
	reset_buffer();
	
	sprintf(temp, "ATE%d\r\n", on);
	bus_send_string(temp);
	
	msleep(200);
	
	bus_recieve_string(output);
	
	return str_include(output, "OK");
}
예제 #23
0
/* Reads any base64-encoded certificates present in fp and adds them to store.
 * Returns TRUE if any certificates were successfully imported.
 */
static BOOL import_base64_certs_from_fp(FILE *fp, HCERTSTORE store)
{
    char line[1024];
    BOOL in_cert = FALSE;
    struct DynamicBuffer saved_cert = { 0, 0, NULL };
    int num_certs = 0;

    TRACE("\n");
    while (fgets(line, sizeof(line), fp))
    {
        static const char header[] = "-----BEGIN CERTIFICATE-----";
        static const char trailer[] = "-----END CERTIFICATE-----";

        if (!strncmp(line, header, strlen(header)))
        {
            TRACE("begin new certificate\n");
            in_cert = TRUE;
            reset_buffer(&saved_cert);
        }
        else if (!strncmp(line, trailer, strlen(trailer)))
        {
            DWORD size;

            TRACE("end of certificate, adding cert\n");
            in_cert = FALSE;
            if (CryptStringToBinaryA((char *)saved_cert.data, saved_cert.used,
             CRYPT_STRING_BASE64, NULL, &size, NULL, NULL))
            {
                LPBYTE buf = CryptMemAlloc(size);

                if (buf)
                {
                    CryptStringToBinaryA((char *)saved_cert.data,
                     saved_cert.used, CRYPT_STRING_BASE64, buf, &size, NULL,
                     NULL);
                    if (CertAddEncodedCertificateToStore(store,
                     X509_ASN_ENCODING, buf, size, CERT_STORE_ADD_NEW, NULL))
                        num_certs++;
                    CryptMemFree(buf);
                }
            }
        }
        else if (in_cert)
            add_line_to_buffer(&saved_cert, line);
    }
    CryptMemFree(saved_cert.data);
    TRACE("Read %d certs\n", num_certs);
    return num_certs > 0;
}
예제 #24
0
파일: readgml.c 프로젝트: posix4e/ecolab
int count_vertices()
{
  int result=0;
  char *ptr;
  char line[LINELENGTH];

  reset_buffer();

  while (next_line(line)==0) {
    ptr = strstr(line,"node");
    if (ptr!=NULL) result++;
  }

  return result;
}
예제 #25
0
파일: readgml.c 프로젝트: posix4e/ecolab
void get_degrees(NETWORK *network)
{
  int s,t;
  int vs,vt;
  char *ptr;
  char line[LINELENGTH];

  reset_buffer();

  while (next_line(line)==0) {

    // Find the next edge entry

    ptr = strstr(line,"edge");
    if (ptr==NULL) continue;

    // Read the source and target of the edge

    s = t = -1;

    do {

      ptr = strstr(line,"source");
      if (ptr!=NULL) sscanf(ptr,"source %i",&s);
      ptr = strstr(line,"target");
      if (ptr!=NULL) sscanf(ptr,"target %i",&t);

      // If we see a closing square bracket we are done

      if (strstr(line,"]")!=NULL) break;

    } while (next_line(line)==0);

    // Increment the degrees of the appropriate vertex or vertices

    if ((s>=0)&&(t>=0)) {
      vs = find_vertex(s,network);
      network->vertex[vs].degree++;
      if (network->directed==0) {
	vt = find_vertex(t,network);
	network->vertex[vt].degree++;
      }
    }

  }

  return;
}
예제 #26
0
파일: readgml.c 프로젝트: posix4e/ecolab
int is_directed()
{
  int result=0;
  char *ptr;
  char line[LINELENGTH];

  reset_buffer();

  while (next_line(line)==0) {
    ptr = strstr(line,"directed");
    if (ptr==NULL) continue;
    sscanf(ptr,"directed %i",&result);
    break;
  }

  return result;
}
예제 #27
0
파일: http_reply.cpp 프로젝트: dedok/t2h
bool http_reply::stock_reply(http_reply::status_type status) 
{
	try 
	{
		reset_buffer();
		std::string const content = stock_replies::cast_to_string(status);
		std::size_t const content_size = content.size();
		add_status(status);
		add_header("Content-Length", safe_lexical_cast<std::string>(content_size));
		add_header("Content-Type", "text/html");
		add_content(content.c_str(), content_size);
	} 
	catch (std::exception const & expt) 
	{
		return false;
	}
	return true;
} 
예제 #28
0
//***************************************************
//***************************************************
// Pops the top of the stack
uint8_t Single_buff::pop_top(uint8_t* buff, const uint8_t sz)
{
	// ensure there is even a top
	if(!m_buff_ready)
		return 0;
	
	// ensure the buffer to copy to is big enough
	if(sz < m_buff_sz)
		return 0;
	
	// copy over the buffer	
	m_util.cpy_buff(buff, m_buff_array, m_buff_sz);
		
	// buffer no longer ready
	reset_buffer();
	
	return m_buff_sz;
}
예제 #29
0
파일: player.c 프로젝트: ayoucai/cmus
static void __producer_play(void)
{
	if (producer_status == PS_UNLOADED) {
		struct track_info *ti;

		if (get_next(&ti) == 0) {
			int rc;

			ip = ip_new(ti->filename);
			rc = ip_open(ip);
			if (rc) {
				player_ip_error(rc, "opening file `%s'", ti->filename);
				ip_delete(ip);
				track_info_unref(ti);
				file_changed(NULL);
			} else {
				ip_setup(ip);
				__producer_status_update(PS_PLAYING);
				file_changed(ti);
			}
		}
	} else if (producer_status == PS_PLAYING) {
		if (ip_seek(ip, 0.0) == 0) {
			reset_buffer();
		}
	} else if (producer_status == PS_STOPPED) {
		int rc;

		rc = ip_open(ip);
		if (rc) {
			player_ip_error(rc, "opening file `%s'", ip_get_filename(ip));
			ip_delete(ip);
			__producer_status_update(PS_UNLOADED);
		} else {
			ip_setup(ip);
			__producer_status_update(PS_PLAYING);
		}
	} else if (producer_status == PS_PAUSED) {
		__producer_status_update(PS_PLAYING);
	}
}
예제 #30
0
//***************************************************
//***************************************************
// Add a TUN buffer
uint8_t Single_buff::add_TUN_buffer(uint8_t* buff, const uint8_t sz)
{
	// keep track if we had to remove the frame
	boolean frame_removed = false;

	// ensure the size is less than max
	if(sz < LARGE_BUFF_SZ )
	{
		// reset the buffer
		reset_buffer();
	
		// remove the TUN framing just-in-case
		frame_removed = m_util.remove_TUN_frame(buff);
		
		// only add the TUN packet if it passes
		// the checksum
		if(m_util.verify_checksum(buff))
		{
			// set the size
			if(frame_removed)
				m_buff_sz = sz - 2;
			else
				m_buff_sz = sz;
		
			// copy over the buffer
			m_util.cpy_buff(m_buff_array, buff, m_buff_sz);
	
			// signal that we have a buffer ready
			m_buff_ready = true;
		
			// update the packet_id 
			m_buffer_id++;
		
		}
	}
	else 
		return 0;
		
	return m_buff_sz;
}