Пример #1
0
int
_spi_iomsg_write(resmgr_context_t *ctp, io_msg_t *msg, spi_ocb_t *ocb)
{
	spi_msg_t	*spimsg = (spi_msg_t *)msg;
    uint8_t		*buf;
    int			nbytes, msglen, status;
	SPIDEV		*drvhdl = (SPIDEV *)ocb->hdr.attr;
	spi_dev_t	*dev = drvhdl->hdl;
	uint16_t	chip = spimsg->device & SPI_DEV_ID_MASK;

	/* check if message buffer is too short */
	nbytes = spimsg->xlen;

    if (nbytes <= 0) {
        _IO_SET_WRITE_NBYTES(ctp, 0);
        return _RESMGR_NPARTS(0);
    }

	msglen = nbytes + sizeof(spi_msg_t);

	if (msglen > ctp->msg_max_size) {
		if (dev->buflen < msglen) {
			dev->buflen = msglen;
			if (dev->buf)
				free(dev->buf);
			if ((dev->buf = malloc(dev->buflen)) == NULL) {
				dev->buflen = 0;
				return ENOMEM;
			}
		}

		status = resmgr_msgread(ctp, dev->buf, msglen, 0);
		if (status < 0)
			return errno;
		if (status < msglen)
			return EFAULT;

		buf = dev->buf;
	}
	else
		buf = (uint8_t *)msg;

	if (chip == SPI_DEV_ID_NONE)
		chip = ocb->chip;

	buf = dev->funcs->xfer(drvhdl, _SPI_DEV_WRITE(chip), buf + sizeof(spi_msg_t), &nbytes);

	if (nbytes == 0)
		return EAGAIN;

	if (nbytes > 0) {
		_IO_SET_WRITE_NBYTES(ctp, nbytes);
		return _RESMGR_NPARTS(0);
	}

	return EIO;
}
int io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
    int     status;    

    if ((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK)
        return (status);

    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
        return(ENOSYS);

    /* set up the number of bytes (returned by client's write()) */

    _IO_SET_WRITE_NBYTES (ctp, msg->i.nbytes);   

    /*
     *  Reread the data from the sender's message buffer.
     *  We're not assuming that all of the data fit into the
     *  resource manager library's receive buffer.
     */
    
    resmgr_msgread(ctp, buffer, min(msg->i.nbytes, 4095), sizeof(msg->i));    
    buffer[min(msg->i.nbytes, 4095)] = '\0'; /* just in case the text is not NULL terminated */
    ocb->offset = 0;
    attr.nbytes = strlen (buffer)+1;
    printf("%s\n", buffer);  

    if (msg->i.nbytes > 0)
        ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

    return (_RESMGR_NPARTS (0));
}
Пример #3
0
int io_write(resmgr_context_t *ctp, io_write_t *msg, iofunc_ocb_t *ocb)
{
	LOCK(resource_mutex);
	printf("IO write activated\n");

	// set data to return
	_IO_SET_WRITE_NBYTES(ctp, msg->i.nbytes);

	int nBytes = msg->i.nbytes + 1;

	char *buf = (char *)malloc(nBytes * sizeof(char));
	if (!buf)
		RETURN_UNLOCK(ENOMEM, resource_mutex);

	resmgr_msgread(ctp, buf, nBytes, sizeof(msg->i));
	buf[msg->i.nbytes] = '\0';
	printf("Received %d bytes = \"%s\"\n", msg->i.nbytes, buf);

	int rcvid = fifo_rem_blocked_id(fifoHandler);
	if(rcvid != -1)
	{
		printf("Found blocked id, sending string '%s' with %i bytes\n", buf, nBytes);
		MsgReply(rcvid, nBytes, buf, nBytes);
		free(buf);
		RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex);
	}

	fifo_add_string(fifoHandler, buf);
	free(buf);

	RETURN_UNLOCK(_RESMGR_NPARTS(0), resource_mutex);
}
Пример #4
0
int
io_console_write(resmgr_context_t *ctp, io_write_t *msg, iofunc_ocb_t *ocb) {
	int		n;
	int		off;
	int		len;
	int		ret;
	int		cnt;
	int		status;
	int		nonblock;
	char	*cptr;

	ret = EOK;
	cptr = (char *) (sizeof(msg->i) + (char *)&msg->i);
	off = 0;
	len = msg->i.nbytes;
	
	// Is device open for write?
	if((status = iofunc_write_verify(ctp, msg, ocb, &nonblock)) != EOK)
		return status;

	// No special xtypes
	if((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
		return(EINVAL);
	
	while(off < len) {
		
		/* Limit write to max payload, NULL terminate the string,
		 * and figure out how many ints we're writing.
		 */
		n = min(len - off,  _SLOG_MAXSIZE - _SLOG_HDRINTS*sizeof(int) - 1);
		cptr[n] = '\0';
		cnt = n/sizeof(int) +1;

		/* put it in the log */
		ret = _io_write_log(ctp, msg, ocb, cnt, 1);
		if(ret != EOK)
			break;
	
		off += n;

		//skip the MsgRead() if we're done.
		if (off == len)
			break;
		
		ret = MsgRead(ctp->rcvid, cptr, n, off + sizeof(msg->i));
		if(ret <= 0) 
			break;
	}

	_IO_SET_WRITE_NBYTES(ctp, off);
	return(ret);
}
Пример #5
0
int io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb){
    char    *buf;

    /* set up the number of bytes (returned by client's write()) */
    _IO_SET_WRITE_NBYTES (ctp, msg->i.nbytes);

    buf = (char *) malloc(msg->i.nbytes + 1);
    if (buf == NULL)
        return(ENOMEM);

    /*
     *  Reread the data from the sender's message buffer.
     *  We're not assuming that all of the data fit into the
     *  resource manager library's receive buffer.
     */

    resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(msg->i));
    buf [msg->i.nbytes] = '\0'; /* just in case the text is not NULL terminated */
    printf ("Received %d bytes = '%s'\n", msg -> i.nbytes, buf);

    /* Set the dir var for counter thread according to the command */
    if(!strncmp(buf, "up", 2)){
    	/* Count upwards */
    	pthread_mutex_lock(&lock);
    	counter_dir = DIR_UP;
    	pthread_mutex_unlock(&lock);

    }else if(!strncmp(buf,"down", 4)){
    	/* Count downwards */
    	pthread_mutex_lock(&lock);
    	counter_dir = DIR_DOWN;
    	pthread_mutex_unlock(&lock);

    }else if(!strncmp(buf, "stop", 4)){
    	/* Stop counting */
    	pthread_mutex_lock(&lock);
    	counter_dir = DIR_NONE;
    	pthread_mutex_unlock(&lock);

    }else{
    	// do nothing
    }

    free(buf);

    return (_RESMGR_NPARTS (0));
}
Пример #6
0
int dumper_write(resmgr_context_t *ctp, io_write_t *msg, iofunc_ocb_t *ocb) {
	int				status;
	int				nonblock;
	long			size = max_core_size;
	char			*p, *tmp;
	pid_t pid;

	if((status = iofunc_write_verify(ctp, msg, ocb, &nonblock)) != EOK) {
		return status;
	}

	switch(msg->i.xtype & _IO_XTYPE_MASK) {
	case _IO_XTYPE_NONE:
		break;
	default:
		return EINVAL;
	}

	if(msg->i.nbytes > sizeof ctp->msg - sizeof msg->i) {
		return ENOSPC;
	}

	p = (char *)(&msg->i) + sizeof msg->i;
	p[msg->i.nbytes] = '\0';

	pid = strtol(p, &tmp, 10);

	/* eat whitespace */
	while(*tmp && !ISDIGIT(*tmp))
		tmp++;

	if(*tmp){
		size = strtol(tmp, NULL, 10);
		if(size > max_core_size)
			size = max_core_size;
	}
	
	DeliverNotifies(pid); // send all notifications first, 
                        // since the call to dump might return an error
	if((status = dump(ctp->info.nd, pid, size)) != EOK) {
		return status;
	}

	_IO_SET_WRITE_NBYTES(ctp, msg->i.nbytes);
	return EOK;
}
Пример #7
0
int
io_write( resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
  int status;
  char *buf;

  if((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK )
    return(status);

  if((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
    return(ENOSYS);

  _IO_SET_WRITE_NBYTES(ctp, msg->i.nbytes);

  buf = (char *)malloc(msg->i.nbytes + 1);
  if( buf == NULL)
    return(ENOMEM);

  /*
   * reread the data from the sender's message buffer.
   * We're not assuming that all of the data fit into the 
   * resource manager library's receive buffer.
   */
  if( (status = resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(msg->i))) == -1){ 
    return(ENOSYS);
  }
  fprintf(stderr,"_ics660-drvr:  bytes attemted: %d  bytes received %d\n",msg->i.nbytes,status);
  buf[msg->i.nbytes] = '\0'; //just in case text is not NULL terminated 
  memcpy((int *)ics660->mem1,buf,(size_t)msg->i.nbytes);
  free(buf);

  if(msg->i.nbytes > 0)
    ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

  return(_RESMGR_NPARTS(0));
}
Пример #8
0
int
io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
    int status;
    
    if (optv) {
        printf ("%s:  in io_write\n", progname);
    }

    if ((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK)
        return (status);
        
    // No special xtypes
    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) {
        return(ENOSYS);
    }

    _IO_SET_WRITE_NBYTES (ctp, msg -> i.nbytes);

    if (msg->i.nbytes > 0)
        ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

    return (_RESMGR_NPARTS (0));
}
Пример #9
0
int
io_write (resmgr_context_t *ctp, io_write_t *msg, RESMGR_OCB_T *ocb)
{
    int status;
    int nb;
    
    if (optv) {
        printf ("%s:  in io_write, of %d bytes\n", progname, msg->i.nbytes);
    }

    if ((status = iofunc_write_verify(ctp, msg, ocb, NULL)) != EOK)
        return (status);
        
    // No special xtypes
    if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE) {
        return(ENOSYS);
    }
	
	if( msg->i.nbytes == ctp->info.msglen - (ctp->offset + sizeof(*msg) ))
	{
		/* have all the data */
		char *buf;
		buf = (char *)(msg+1);
		
		nb = write( STDOUT_FILENO , buf, msg->i.nbytes ); // fd 1 is stdout
		if( -1 == nb )
		   return errno;
	} else 
	{
#if 0
		char *buf;
		buf = malloc( msg->i.nbytes );
		if (NULL == buf )
		   return ENOMEM;
		nb = resmgr_msgread(ctp, buf, msg->i.nbytes, sizeof(*msg));
		nb = write(1, buf, nb ); // fd 1 is stdout
		free(buf);
		if( -1 == nb )
		   return errno;
#else		   
		char buf[1000]; // my hardware buffer
        int count, bytes;
        count = 0;
        
        while ( count < msg->i.nbytes )
        {
        	bytes = resmgr_msgread( ctp, buf, 1000, count + sizeof(*msg ));
        	if( bytes == -1 )
        	   return errno;
        	bytes = write( 1, buf, bytes ); // fd 1 is standard out 
        	if( bytes == -1 )
        	{  
        	   if (!count )
        	     return errno;
        	   else 
        	      break;
        	}
        	count += bytes;
        }
        nb = count;
#endif		
	}
    _IO_SET_WRITE_NBYTES (ctp, nb);

    if (msg->i.nbytes > 0)
        ocb->attr->flags |= IOFUNC_ATTR_MTIME | IOFUNC_ATTR_CTIME;

    return (_RESMGR_NPARTS (0));
}