static void __int_xmms_cmd_remove (xmms_object_t *object, xmms_object_cmd_arg_t *arg) { xmmsv_t *t; if (xmmsv_list_get_size (arg->args) != 1) { XMMS_DBG ("Wrong number of arguments to remove (%d)", xmmsv_list_get_size (arg->args)); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Wrong number of arguments to remove"); return; } const char * argval0; if (!xmmsv_list_get (arg->args, 0, &t)) { XMMS_DBG ("Missing arg 0 in remove"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 0 in remove"); return; } if (!xmmsv_get_string (t, &argval0)) { XMMS_DBG ("Error parsing arg 0 in remove"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 0 in remove"); return; } xmms_bindata_client_remove ((xmms_bindata_t *) object, argval0, &arg->error); arg->retval = xmmsv_new_none (); }
static gboolean type_and_msg_to_arg (xmmsv_type_t expected_type, xmmsv_t *argument_list, xmms_object_cmd_arg_t *arg, gint i) { xmmsv_t *arg_value; xmmsv_type_t actual_type; if (argument_list && xmmsv_list_get (argument_list, i, &arg_value)) { xmmsv_ref (arg_value); } else { arg_value = xmmsv_new_none (); } actual_type = xmmsv_get_type (arg_value); if (actual_type != expected_type) { XMMS_DBG ("Expected type %i, but got type %i", expected_type, actual_type); xmmsv_unref (arg_value); return FALSE; } else { arg->values[i] = arg_value; return TRUE; } }
static void __int_xmms_cmd_rehash (xmms_object_t *object, xmms_object_cmd_arg_t *arg) { xmmsv_t *t; if (xmmsv_list_get_size (arg->args) != 1) { XMMS_DBG ("Wrong number of arguments to rehash (%d)", xmmsv_list_get_size (arg->args)); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Wrong number of arguments to rehash"); return; } gint32 argval0; if (!xmmsv_list_get (arg->args, 0, &t)) { XMMS_DBG ("Missing arg 0 in rehash"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 0 in rehash"); return; } if (!xmmsv_get_int (t, &argval0)) { XMMS_DBG ("Error parsing arg 0 in rehash"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 0 in rehash"); return; } xmms_medialib_client_rehash ((xmms_medialib_t *) object, argval0, &arg->error); arg->retval = xmmsv_new_none (); }
static void __int_xmms_cmd_set_property_int (xmms_object_t *object, xmms_object_cmd_arg_t *arg) { xmmsv_t *t; if (xmmsv_list_get_size (arg->args) != 4) { XMMS_DBG ("Wrong number of arguments to set_property_int (%d)", xmmsv_list_get_size (arg->args)); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Wrong number of arguments to set_property_int"); return; } gint32 argval0; const char * argval1; const char * argval2; gint32 argval3; if (!xmmsv_list_get (arg->args, 0, &t)) { XMMS_DBG ("Missing arg 0 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 0 in set_property_int"); return; } if (!xmmsv_get_int (t, &argval0)) { XMMS_DBG ("Error parsing arg 0 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 0 in set_property_int"); return; } if (!xmmsv_list_get (arg->args, 1, &t)) { XMMS_DBG ("Missing arg 1 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 1 in set_property_int"); return; } if (!xmmsv_get_string (t, &argval1)) { XMMS_DBG ("Error parsing arg 1 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 1 in set_property_int"); return; } if (!xmmsv_list_get (arg->args, 2, &t)) { XMMS_DBG ("Missing arg 2 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 2 in set_property_int"); return; } if (!xmmsv_get_string (t, &argval2)) { XMMS_DBG ("Error parsing arg 2 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 2 in set_property_int"); return; } if (!xmmsv_list_get (arg->args, 3, &t)) { XMMS_DBG ("Missing arg 3 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 3 in set_property_int"); return; } if (!xmmsv_get_int (t, &argval3)) { XMMS_DBG ("Error parsing arg 3 in set_property_int"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 3 in set_property_int"); return; } xmms_medialib_client_set_property_int ((xmms_medialib_t *) object, argval0, argval1, argval2, argval3, &arg->error); arg->retval = xmmsv_new_none (); }
/** * Return a new value object which is a deep copy of the input value * * @param val #xmmsv_t to copy. * @return 1 the address to the new copy of the value. */ xmmsv_t * xmmsv_copy (xmmsv_t *val) { xmmsv_t *cur_val = NULL; xmmsv_type_t type; int64_t i; const char *s; float f; x_return_val_if_fail (val, 0); type = xmmsv_get_type (val); switch (type) { case XMMSV_TYPE_DICT: cur_val = duplicate_dict_value (val); break; case XMMSV_TYPE_LIST: cur_val = duplicate_list_value (val); break; case XMMSV_TYPE_INT64: xmmsv_get_int (val, &i); cur_val = xmmsv_new_int (i); break; case XMMSV_TYPE_FLOAT: xmmsv_get_float (val, &f); cur_val = xmmsv_new_float (f); break; case XMMSV_TYPE_STRING: xmmsv_get_string (val, &s); cur_val = xmmsv_new_string (s); break; case XMMSV_TYPE_ERROR: xmmsv_get_error (val, &s); cur_val = xmmsv_new_error (s); break; case XMMSV_TYPE_COLL: cur_val = duplicate_coll_value (val); break; case XMMSV_TYPE_BIN: cur_val = xmmsv_new_bin (val->value.bin.data, val->value.bin.len); break; case XMMSV_TYPE_BITBUFFER: cur_val = xmmsv_new_bitbuffer (); xmmsv_bitbuffer_put_data (cur_val, val->value.bit.buf, val->value.bit.len / 8); xmmsv_bitbuffer_goto (cur_val, xmmsv_bitbuffer_pos (val)); break; default: cur_val = xmmsv_new_none (); break; } assert (cur_val); return cur_val; }
static void __int_xmms_cmd_sync (xmms_object_t *object, xmms_object_cmd_arg_t *arg) { if (xmmsv_list_get_size (arg->args) != 0) { XMMS_DBG ("Wrong number of arguments to sync (%d)", xmmsv_list_get_size (arg->args)); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Wrong number of arguments to sync"); return; } xmms_coll_sync_client_sync ((xmms_coll_sync_t *) object, &arg->error); arg->retval = xmmsv_new_none (); }
void xmms_object_emit_f (xmms_object_t *object, guint32 signalid, xmmsv_type_t type, ...) { va_list ap; xmmsv_t *arg; va_start (ap, type); switch (type) { case XMMSV_TYPE_NONE: arg = xmmsv_new_none (); break; case XMMSV_TYPE_INT32: arg = xmmsv_new_int (va_arg (ap, gint32)); break; case XMMSV_TYPE_STRING: arg = xmmsv_new_string (va_arg (ap, gchar *)); break; case XMMSV_TYPE_DICT: arg = xmms_create_xmmsv_dict (va_arg (ap, GTree *)); break; case XMMSV_TYPE_END: default: XMMS_DBG ("OBJECT: trying to emit value of unsupported type (%d)!", (int)type); g_assert_not_reached (); break; } va_end (ap); xmms_object_emit (object, signalid, arg); /* In all cases above, we created a new xmmsv_t, which we * now destroy. * In some cases, those xmmsv_t's are created from GLib objects, * such as GTrees. Here we must not destroy those GLib objects, * because the caller wants to do that. However, the xmmsv_t's * don't hold onto those GLib objects, so unreffing the * xmmsv_t doesn't kill the GLib object. */ xmmsv_unref (arg); }
static xmmsv_t * create_data (int type, const char *data, uint32_t len) { switch (type) { case JSON_STRING: return xmmsv_new_string (data); case JSON_INT: return xmmsv_new_int (atoi(data)); case JSON_FLOAT: return xmmsv_new_float (strtof (data, NULL)); case JSON_NULL: return xmmsv_new_none (); case JSON_TRUE: return xmmsv_new_int (1); case JSON_FALSE: return xmmsv_new_int (0); default: return xmmsv_new_error ("Unknown data type."); } }
static xmmsv_t * args_to_dict (gchar **argv, gint argc) { xmmsv_t *dict; gint i; dict = xmmsv_new_dict (); if (!dict) { return NULL; } for (i = 0; i < argc; i++) { gchar **tuple; xmmsv_t *val; /* Split the string into arg and value. */ tuple = g_strsplit (argv[i], "=", 2); if (tuple[0] && tuple[1]) { val = xmmsv_new_string (tuple[1]); } else if (tuple[0]) { val = xmmsv_new_none (); } else { g_strfreev (tuple); continue; /* Empty tuple, means empty string. */ } if (!val) { xmmsv_unref (dict); return NULL; } xmmsv_dict_set (dict, tuple[0], val); g_strfreev (tuple); xmmsv_unref (val); } return dict; }
static void __int_xmms_cmd_move_entry (xmms_object_t *object, xmms_object_cmd_arg_t *arg) { xmmsv_t *t; if (xmmsv_list_get_size (arg->args) != 2) { XMMS_DBG ("Wrong number of arguments to move_entry (%d)", xmmsv_list_get_size (arg->args)); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Wrong number of arguments to move_entry"); return; } gint32 argval0; const char * argval1; if (!xmmsv_list_get (arg->args, 0, &t)) { XMMS_DBG ("Missing arg 0 in move_entry"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 0 in move_entry"); return; } if (!xmmsv_get_int (t, &argval0)) { XMMS_DBG ("Error parsing arg 0 in move_entry"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 0 in move_entry"); return; } if (!xmmsv_list_get (arg->args, 1, &t)) { XMMS_DBG ("Missing arg 1 in move_entry"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Missing arg 1 in move_entry"); return; } if (!xmmsv_get_string (t, &argval1)) { XMMS_DBG ("Error parsing arg 1 in move_entry"); xmms_error_set (&arg->error, XMMS_ERROR_INVAL, "Error parsing arg 1 in move_entry"); return; } xmms_medialib_client_move_entry ((xmms_medialib_t *) object, argval0, argval1, &arg->error); arg->retval = xmmsv_new_none (); }
void xmms_xform_auxdata_barrier (xmms_xform_t *xform) { xmmsv_t *val = xmmsv_new_none (); xmms_xform_auxdata_set_val (xform, NULL, val); }
static bool _internal_get_from_bb_value_of_type_alloc (xmmsv_t *bb, xmmsv_type_t type, xmmsv_t **val) { int32_t i; uint32_t len; char *s; xmmsv_coll_t *c; unsigned char *d; switch (type) { case XMMSV_TYPE_ERROR: if (!_internal_get_from_bb_error_alloc (bb, &s, &len)) { return false; } *val = xmmsv_new_error (s); free (s); break; case XMMSV_TYPE_INT32: if (!_internal_get_from_bb_int32 (bb, &i)) { return false; } *val = xmmsv_new_int (i); break; case XMMSV_TYPE_STRING: if (!_internal_get_from_bb_string_alloc (bb, &s, &len)) { return false; } *val = xmmsv_new_string (s); free (s); break; case XMMSV_TYPE_DICT: if (!xmmsc_deserialize_dict (bb, val)) { return false; } break; case XMMSV_TYPE_LIST : if (!xmmsc_deserialize_list (bb, val)) { return false; } break; case XMMSV_TYPE_COLL: if (!_internal_get_from_bb_collection_alloc (bb, &c)) { return false; } *val = xmmsv_new_coll (c); xmmsv_coll_unref (c); break; case XMMSV_TYPE_BIN: if (!_internal_get_from_bb_bin_alloc (bb, &d, &len)) { return false; } *val = xmmsv_new_bin (d, len); free (d); break; case XMMSV_TYPE_NONE: *val = xmmsv_new_none (); break; default: x_internal_error ("Got message of unknown type!"); return false; } return true; }
static gpointer xmms_output_monitor_volume_thread (gpointer data) { xmms_output_t *output = data; xmms_volume_map_t old, cur; if (!xmms_output_plugin_method_volume_get_available (output->plugin)) { return NULL; } xmms_volume_map_init (&old); xmms_volume_map_init (&cur); while (output->monitor_volume_running) { cur.num_channels = 0; cur.status = xmms_output_plugin_method_volume_get (output->plugin, output, NULL, NULL, &cur.num_channels); if (cur.status) { /* check for sane values */ if (cur.num_channels < 1 || cur.num_channels > VOLUME_MAX_CHANNELS) { cur.status = FALSE; } else { cur.names = g_renew (const gchar *, cur.names, cur.num_channels); cur.values = g_renew (guint, cur.values, cur.num_channels); } } if (cur.status) { cur.status = xmms_output_plugin_method_volume_get (output->plugin, output, cur.names, cur.values, &cur.num_channels); } /* we failed at getting volume for one of the two maps or * we succeeded both times and they differ -> changed */ if ((cur.status ^ old.status) || (cur.status && old.status && !xmms_volume_map_equal (&old, &cur))) { /* emit the broadcast */ if (cur.status) { xmms_object_emit (XMMS_OBJECT (output), XMMS_IPC_SIGNAL_PLAYBACK_VOLUME_CHANGED, xmms_volume_map_to_dict (&cur)); } else { /** @todo When bug 691 is solved, emit an error here */ xmms_object_emit (XMMS_OBJECT (output), XMMS_IPC_SIGNAL_PLAYBACK_VOLUME_CHANGED, xmmsv_new_none ()); } } xmms_volume_map_copy (&cur, &old); g_usleep (G_USEC_PER_SEC); } xmms_volume_map_free (&old); xmms_volume_map_free (&cur); return NULL; }
/* Converts the temporary value returned by result_to_xmmsv into the real value */ static xmmsv_t * aggregate_data (xmmsv_t *value, aggregate_function_t aggr_func) { const random_data_t *random_data; const avg_data_t *avg_data; const set_data_t *set_data; gconstpointer data; xmmsv_t *ret; guint len; ret = NULL; data = NULL; if (value != NULL && xmmsv_is_type (value, XMMSV_TYPE_BIN)) xmmsv_get_bin (value, (const guchar **) &data, &len); switch (aggr_func) { case AGGREGATE_FIRST: case AGGREGATE_MIN: case AGGREGATE_MAX: case AGGREGATE_SUM: if (value != NULL) { ret = xmmsv_ref (value); } else { ret = xmmsv_new_none (); } break; case AGGREGATE_LIST: if (value != NULL) { ret = xmmsv_ref (value); } else { ret = xmmsv_new_list (); } break; case AGGREGATE_RANDOM: random_data = data; if (random_data != NULL) { ret = random_data->data; } else { ret = xmmsv_new_none (); } break; case AGGREGATE_SET: set_data = data; if (set_data != NULL) { g_hash_table_destroy (set_data->ht); ret = set_data->list; } else { ret = xmmsv_new_list (); } break; case AGGREGATE_AVG: avg_data = data; if (avg_data != NULL) { ret = xmmsv_new_float (avg_data->n ? avg_data->sum * 1.0 / avg_data->n : 0); } else { ret = xmmsv_new_none (); } break; default: g_assert_not_reached (); } if (value != NULL) { xmmsv_unref (value); } return ret; }