Beispiel #1
0
int
xmmsc_ipc_io_in_callback (xmmsc_ipc_t *ipc)
{
	bool disco = false;

	x_return_val_if_fail (ipc, false);
	x_return_val_if_fail (!ipc->disconnect, false);

	while (!disco) {
		if (!ipc->read_msg)
			ipc->read_msg = xmms_ipc_msg_alloc ();

		if (xmms_ipc_msg_read_transport (ipc->read_msg, ipc->transport, &disco)) {
			xmms_ipc_msg_t *msg = ipc->read_msg;

			/* must unset read_msg here,
			   because exec_msg can cause reentrancy */
			ipc->read_msg = NULL;

			xmmsc_ipc_exec_msg (ipc, msg);

		} else {

			break;
		}
	}

	if (disco)
		xmmsc_ipc_disconnect (ipc);

	return !disco;
}
Beispiel #2
0
xPointer x_bytes_unref_to_data(xBytes *bytes, xSize *size)
{
    xPointer result;

    x_return_val_if_fail(bytes != NULL, NULL);
    x_return_val_if_fail(size != NULL, NULL);

    /*
     * Optimal path: if this is was the last reference, then we can return
     * the data from this xBytes without copying.
     */
    result = try_steal_and_unref(bytes, free, size);
    if (result == NULL)
    {
        /*
         * Copy: Non malloc (or compatible) allocater, or static memory,
         * so we have to copy, and then unref.
         */
        result = memdup(bytes->data, bytes->size);
        *size = bytes->size;
        x_bytes_unref(bytes);
    }

    return result;
}
Beispiel #3
0
int
xmmsc_ipc_io_out_callback (xmmsc_ipc_t *ipc)
{
	bool disco = false;

	x_return_val_if_fail (ipc, false);
	x_return_val_if_fail (!ipc->disconnect, false);

	while (!x_queue_is_empty (ipc->out_msg)) {
		xmms_ipc_msg_t *msg = x_queue_peek_head (ipc->out_msg);
		if (xmms_ipc_msg_write_transport (msg, ipc->transport, &disco)) {
			x_queue_pop_head (ipc->out_msg);
			xmms_ipc_msg_destroy (msg);
		} else {
			break;
		}
	}

	if (disco) {
		xmmsc_ipc_disconnect (ipc);
	} else {
		if (ipc->need_out_callback)
			ipc->need_out_callback (xmmsc_ipc_io_out (ipc),
			                        ipc->need_out_data);
	}

	return !disco;
}
Beispiel #4
0
xBytes* x_bytes_new_from_bytes(xBytes *bytes, xSize offset, xSize length)
{
    /* Note that length may be 0. */
    x_return_val_if_fail(bytes != NULL, NULL);
    x_return_val_if_fail(offset <= bytes->size, NULL);
    x_return_val_if_fail(offset + length <= bytes->size, NULL);

    return x_bytes_new_with_free_func((xChar*)bytes->data + offset, length, x_bytes_unref, x_bytes_ref(bytes));
}
Beispiel #5
0
xBoolean x_bytes_equal(xConstPointer bytes1, xConstPointer bytes2)
{
    const xBytes *b1 = bytes1;
    const xBytes *b2 = bytes2;

    x_return_val_if_fail(bytes1 != NULL, FALSE);
    x_return_val_if_fail(bytes2 != NULL, FALSE);

    return b1->size == b2->size && memcmp(b1->data, b2->data, b1->size) == 0;
}
Beispiel #6
0
xInt32 x_serialport_read(xSerialPort *port, xUInt8 *buffer, xInt32 count)
{
	x_return_val_if_fail(port, -1);
	x_return_val_if_fail(buffer, -1);
	x_return_val_if_fail(count > 0, -1);

	if (!x_serialport_is_open(port))
		return -1;
	return x_serialport_platform_read(port->platform, buffer, count);
}
Beispiel #7
0
/**
 * Try to read message from transport into msg.
 *
 * @returns TRUE if message is fully read.
 */
bool
xmms_ipc_msg_read_transport (xmms_ipc_msg_t *msg,
                             xmms_ipc_transport_t *transport,
                             bool *disconnected)
{
	char buf[512];
	unsigned int ret, len, rlen;

	x_return_val_if_fail (msg, false);
	x_return_val_if_fail (transport, false);

	while (true) {
		len = XMMS_IPC_MSG_HEAD_LEN;

		if (msg->xfered >= XMMS_IPC_MSG_HEAD_LEN) {
			len += xmms_ipc_msg_get_length (msg);

			if (msg->xfered == len) {
				return true;
			}
		}

		x_return_val_if_fail (msg->xfered < len, false);

		rlen = len - msg->xfered;
		if (rlen > sizeof (buf))
			rlen = sizeof (buf);

		ret = xmms_ipc_transport_read (transport, buf, rlen);

		if (ret == SOCKET_ERROR) {
			if (xmms_socket_error_recoverable ()) {
				return false;
			}

			if (disconnected) {
				*disconnected = true;
			}

			return false;
		} else if (ret == 0) {
			if (disconnected) {
				*disconnected = true;
			}

			return false;
		} else {
			xmmsv_bitbuffer_goto (msg->bb, msg->xfered * 8);
			xmmsv_bitbuffer_put_data (msg->bb, (unsigned char *) buf, ret);
			msg->xfered += ret;
			xmmsv_bitbuffer_goto (msg->bb, XMMS_IPC_MSG_HEAD_LEN * 8);
		}
	}
}
Beispiel #8
0
xBoolean x_serialport_set_write_buffer_size(xSerialPort *port, xInt32 value)
{
	x_return_val_if_fail(port, FALSE);
	x_return_val_if_fail(value > 0, FALSE);

	if (x_serialport_is_open(port))
		return FALSE;

	port->write_buffer_size = value;
	return TRUE;
}
Beispiel #9
0
xBoolean x_serialport_set_port_name(xSerialPort *port, const xChar *value)
{
	x_return_val_if_fail(port, FALSE);
	x_return_val_if_fail(value, FALSE);

	if (x_serialport_is_open(port))
		return FALSE;

	port->port_name = x_string_assign(port->port_name, value);
	return TRUE;
}
Beispiel #10
0
static int
xmms_ipc_tcp_write (xmms_ipc_transport_t *ipct, char *buffer, int len)
{
	xmms_socket_t fd;
	x_return_val_if_fail (ipct, -1);
	x_return_val_if_fail (buffer, -1);

	fd = ipct->fd;

	return send (fd, buffer, len, 0);

}
Beispiel #11
0
bool
xmmsc_ipc_connect (xmmsc_ipc_t *ipc, char *path)
{
	x_return_val_if_fail (ipc, false);
	x_return_val_if_fail (path, false);

	ipc->transport = xmms_ipc_client_init (path);
	if (!ipc->transport) {
		ipc->error = strdup ("Could not init client!");
		return false;
	}
	return true;
}
Beispiel #12
0
static int
xmms_ipc_tcp_read (xmms_ipc_transport_t *ipct, char *buffer, int len)
{
	xmms_socket_t fd;
	int ret;
	x_return_val_if_fail (ipct, -1);
	x_return_val_if_fail (buffer, -1);

	fd = ipct->fd;

	ret =  recv (fd, buffer, len, 0);

	return ret;
}
Beispiel #13
0
xInt x_bytes_compare(xConstPointer bytes1, xConstPointer bytes2)
{
    const xBytes *b1 = bytes1;
    const xBytes *b2 = bytes2;
    xInt ret;

    x_return_val_if_fail(bytes1 != NULL, 0);
    x_return_val_if_fail(bytes2 != NULL, 0);

    ret = memcmp(b1->data, b2->data, MIN(b1->size, b2->size));
    if (ret == 0 && b1->size != b2->size)
        ret = b1->size < b2->size ? -1 : 1;
    return ret;
}
Beispiel #14
0
/**
 * Remove the value at a given index from the idlist.
 * @param coll  The collection to update.
 * @param index The index at which to remove the value.
 * @return  TRUE on success, false otherwise.
 */
int
xmmsv_coll_idlist_remove (xmmsv_t *coll, int index)
{
	x_return_val_if_fail (coll, 0);

	return xmmsv_list_remove (coll->value.coll->idlist, index);
}
Beispiel #15
0
int
xmmsc_ipc_io_out (xmmsc_ipc_t *ipc)
{
	x_return_val_if_fail (ipc, false);

	return !x_queue_is_empty (ipc->out_msg) && !ipc->disconnect;
}
Beispiel #16
0
/**
 * Empties the idlist.
 * @param coll  The collection to update.
 * @return  TRUE on success, false otherwise.
 */
int
xmmsv_coll_idlist_clear (xmmsv_t *coll)
{
	x_return_val_if_fail (coll, 0);

	return xmmsv_list_clear (coll->value.coll->idlist);
}
Beispiel #17
0
xmmsv_t *
xmmsv_coll_operands_get (xmmsv_t *coll)
{
	x_return_val_if_fail (coll, NULL);

	return coll->value.coll->operands;
}
Beispiel #18
0
/**
 * Sets the value at the given position in the idlist.
 * @param coll  The collection to update.
 * @param index The position of the value to set.
 * @param val   The new value.
 * @return  TRUE on success, false otherwise.
 */
int
xmmsv_coll_idlist_set_index (xmmsv_t *coll, int index, int64_t val)
{
	x_return_val_if_fail (coll, 0);

	return xmmsv_list_set_int (coll->value.coll->idlist, index, val);
}
Beispiel #19
0
bool
x_queue_is_empty (x_queue_t *queue)
{
	x_return_val_if_fail (queue, true);

	return queue->head == NULL;
}
Beispiel #20
0
void *
x_queue_peek_tail (x_queue_t *queue)
{
	x_return_val_if_fail (queue, NULL);

	return queue->tail ? queue->tail->data : NULL;
}
Beispiel #21
0
/**
 * Return the type of the collection.
 * @param coll  The collection to consider.
 * @return The #xmmsv_coll_type_t of the collection, or -1 if invalid.
 */
xmmsv_coll_type_t
xmmsv_coll_get_type (xmmsv_t *coll)
{
	x_return_val_if_fail (coll, -1);

	return coll->value.coll->type;
}
Beispiel #22
0
/**
 * Append a value to the idlist.
 * @param coll  The collection to update.
 * @param id    The id to append to the idlist.
 * @return  TRUE on success, false otherwise.
 */
int
xmmsv_coll_idlist_append (xmmsv_t *coll, int64_t id)
{
	x_return_val_if_fail (coll, 0);

	return xmmsv_list_append_int (coll->value.coll->idlist, id);
}
Beispiel #23
0
/**
 * Allocate a new collection of the given type.
 * The pointer will have to be deallocated using #xmmsv_coll_unref.
 *
 * @param type the #xmmsv_coll_type_t specifying the type of collection to create.
 * @return a pointer to the newly created collection, or NULL if the type is invalid.
 */
static xmmsv_coll_internal_t*
_xmmsv_coll_new (xmmsv_coll_type_t type)
{
	xmmsv_coll_internal_t *coll;

	x_return_val_if_fail (type <= XMMS_COLLECTION_TYPE_LAST, NULL);

	coll = x_new0 (xmmsv_coll_internal_t, 1);
	if (!coll) {
		x_oom ();
		return NULL;
	}

	coll->type = type;

	coll->idlist = xmmsv_new_list ();
	xmmsv_list_restrict_type (coll->idlist, XMMSV_TYPE_INT64);

	coll->operands = xmmsv_new_list ();
	xmmsv_list_restrict_type (coll->operands, XMMSV_TYPE_COLL);

	coll->attributes = xmmsv_new_dict ();

	return coll;
}
Beispiel #24
0
xBoolean x_serialport_open(xSerialPort *port)
{
	x_return_val_if_fail(port, FALSE);

	if (x_serialport_is_open(port))
		return FALSE;

	if (port->platform != NULL)
		x_serialport_platform_free(port->platform);

	port->platform = x_serialport_platform_new();

	if (!x_serialport_platform_open(port->platform,
		port->port_name->str,
		port->baudrate,
		port->parity,
		port->databits,
		port->stopbits,
		port->read_timeout,
		port->write_timeout,
		port->handshake,
		port->dtr_enable,
		port->rts_enable,
		FALSE,
		'\0'))
		return FALSE;

	x_serialport_platform_set_buffer_sizes(port->platform, 
		port->read_buffer_size, 
		port->write_buffer_size);
	return TRUE;
}
Beispiel #25
0
xmmsv_t *
xmmsv_coll_attributes_get (xmmsv_t *coll)
{
	x_return_val_if_fail (coll, NULL);

	return coll->value.coll->attributes;
}
Beispiel #26
0
/**
 * Returns a collection with a LIMIT operator added
 *
 * @param coll The collection to add the limit operator to
 * @param lim_start The index of the first element to include, or 0 to disable
 * @param lim_len The length of the interval, or 0 to disable
 * @return A new collection with LIMIT operator added
 */
xmmsv_t *
xmmsv_coll_add_limit_operator (xmmsv_t *coll, int lim_start, int lim_len)
{
	xmmsv_t *ret;
	char str[12];

	x_return_val_if_fail (lim_start >= 0 && lim_len >= 0, NULL);

	if (lim_start == 0 && lim_len == 0) {
		return xmmsv_ref (coll);
	}

	ret = xmmsv_new_coll (XMMS_COLLECTION_TYPE_LIMIT);
	xmmsv_coll_add_operand (ret, coll);

	if (lim_start != 0) {
		int count = snprintf (str, sizeof (str), "%i", lim_start);
		if (count > 0 && count < sizeof (str)) {
			xmmsv_coll_attribute_set_string (ret, "start", str);
		} else {
			x_api_warning ("could not set collection limit operator start");
		}
	}

	if (lim_len != 0) {
		int count = snprintf (str, sizeof (str), "%i", lim_len);
		if (count > 0 && count < sizeof (str)) {
			xmmsv_coll_attribute_set_string (ret, "length", str);
		} else {
			x_api_warning ("could not set collection limit operator length");
		}
	}

	return ret;
}
Beispiel #27
0
/**
 * Insert a value at a given position in the idlist.
 * @param coll  The collection to update.
 * @param id    The id to insert in the idlist.
 * @param index The position at which to insert the value.
 * @return  TRUE on success, false otherwise.
 */
int
xmmsv_coll_idlist_insert (xmmsv_t *coll, int index, int64_t id)
{
	x_return_val_if_fail (coll, 0);

	return xmmsv_list_insert_int (coll->value.coll->idlist, index, id);
}
Beispiel #28
0
void *
x_queue_peek_head (x_queue_t *queue)
{
	x_return_val_if_fail (queue, NULL);

	return queue->head ? queue->head->data : NULL;
}
Beispiel #29
0
xConstPointer x_bytes_get_data(xBytes *bytes, xSize *size)
{
    x_return_val_if_fail(bytes != NULL, NULL);
    if (size)
        *size = bytes->size;
    return bytes->data;
}
Beispiel #30
0
/**
 * Get the size of the idlist.
 * @param coll  The collection to update.
 * @return  The size of the idlist.
 */
int
xmmsv_coll_idlist_get_size (xmmsv_t *coll)
{
	x_return_val_if_fail (coll, 0);

	return xmmsv_list_get_size (coll->value.coll->idlist);
}