![]() |
![]() |
![]() |
Spread RPC - Reference Manual | ![]() |
---|---|---|---|---|
typedef SPRpcValue; enum SPRpcTypeValue; SPRpcValue* sp_rpc_value_new (void); void sp_rpc_value_ref (SPRpcValue *value); void sp_rpc_value_unref (SPRpcValue *value); void sp_rpc_value_set_type (SPRpcValue *value, SPRpcTypeValue type); SPRpcTypeValue sp_rpc_value_get_type (SPRpcValue *value); gdouble sp_rpc_value_get_number (SPRpcValue *value); void sp_rpc_value_set_number (SPRpcValue *value, gdouble v_number); void sp_rpc_value_set_boolean (SPRpcValue *value, gboolean v_boolean); gboolean sp_rpc_value_get_boolean (SPRpcValue *value); void sp_rpc_value_set_string (SPRpcValue *value, gchar *v_string); void sp_rpc_value_set_string_printf (SPRpcValue *value, gchar *format, ...); gchar* sp_rpc_value_get_string (SPRpcValue *value); guint sp_rpc_value_array_length (SPRpcValue *varray); SPRpcValue* sp_rpc_value_array_get (SPRpcValue *varray, guint id); gint sp_rpc_value_array_get_id_by_value (SPRpcValue *varray, SPRpcValue *v); void sp_rpc_value_array_set (SPRpcValue *varray, SPRpcValue *v); void sp_rpc_value_array_set_new (SPRpcValue *varray, SPRpcValue **v); void sp_rpc_value_array_set_before (SPRpcValue *varray, SPRpcValue *v, SPRpcValue *sibling); void sp_rpc_value_array_set_before_new (SPRpcValue *varray, SPRpcValue **v, SPRpcValue *sibling); void sp_rpc_value_array_set_position (SPRpcValue *varray, SPRpcValue *v, gint position); void sp_rpc_value_array_set_position_new (SPRpcValue *varray, SPRpcValue **v, gint position); void sp_rpc_value_array_remove (SPRpcValue *varray, SPRpcValue *v); void sp_rpc_value_array_remove_by_id (SPRpcValue *varray, guint id); gboolean sp_rpc_value_struct_has_key (SPRpcValue *vstruct, const gchar *key); SPRpcValue* sp_rpc_value_struct_get_key (SPRpcValue *vstruct, const gchar *key); const gchar* sp_rpc_value_struct_get_key_by_value (SPRpcValue *vstruct, SPRpcValue *v); gchar** sp_rpc_value_struct_get_keys (SPRpcValue *vstruct, guint *length); void sp_rpc_value_struct_set_key (SPRpcValue *vstruct, const gchar *key, SPRpcValue *v); void sp_rpc_value_struct_set_key_new (SPRpcValue *vstruct, const gchar *key, SPRpcValue **v); void sp_rpc_value_struct_remove_key (SPRpcValue *vstruct, const gchar *key); void sp_rpc_value_struct_iter_init (SPRpcValue *vstruct, SPRpcIter *iter); gboolean sp_rpc_value_struct_iter_next (SPRpcIter *iter, gchar **key, SPRpcValue **value); void sp_rpc_value_struct_iter_remove (SPRpcIter *iter);
typedef enum { SP_RPC_TYPE_NULL, SP_RPC_TYPE_NUMBER, SP_RPC_TYPE_BOOLEAN, SP_RPC_TYPE_STRING, SP_RPC_TYPE_ARRAY, SP_RPC_TYPE_STRUCT } SPRpcTypeValue;
The types for a SPRpcValue
SPRpcValue* sp_rpc_value_new (void);
Creates a new SPRpcValue with type SP_RPC_TYPE_NULL.
Returns : |
a new SPRpcValue with a reference count of 1 |
void sp_rpc_value_ref (SPRpcValue *value);
Increases the reference count of a SPRpcValue.
|
a SPRpcValue |
void sp_rpc_value_unref (SPRpcValue *value);
Decreases the reference count of a SPRpcValue. When its reference count drops to 0, the SPRpcValue is finalized.
|
a SPRpcValue |
void sp_rpc_value_set_type (SPRpcValue *value, SPRpcTypeValue type);
Changes the type of a SPRpcValue. It removes the previous value of the SPRpcValue.
|
a SPRpcValue |
|
the type |
SPRpcTypeValue sp_rpc_value_get_type (SPRpcValue *value);
Returns the type of a SPRpcValue
|
a SPRpcValue |
Returns : |
the type of the SPRpcValue |
gdouble sp_rpc_value_get_number (SPRpcValue *value);
Returns the value of SPRpcValue if its type is SP_RPC_TYPE_NUMBER.
|
a SPRpcValue |
Returns : |
the value of the SPRpcValue |
void sp_rpc_value_set_number (SPRpcValue *value, gdouble v_number);
Sets the v_number
into a SPRpcValue if its type is SP_RPC_TYPE_NUMBER.
|
a SPRpcValue |
|
the number of the SPRpcValue |
void sp_rpc_value_set_boolean (SPRpcValue *value, gboolean v_boolean);
Sets a boolean value into a SPRpcValue if its type is SP_RPC_TYPE_BOOLEAN.
|
a SPRpcValue |
|
a boolean value |
gboolean sp_rpc_value_get_boolean (SPRpcValue *value);
Returns the value of SPRpcValue if its type is SP_RPC_TYPE_BOOLEAN.
|
a SPRpcValue |
Returns : |
the value of the SPRpcValue |
void sp_rpc_value_set_string (SPRpcValue *value, gchar *v_string);
Sets a string into a SPRpcValue if its type is SP_RPC_TYPE_STRING.
|
a SPRpcValue |
|
a string |
void sp_rpc_value_set_string_printf (SPRpcValue *value, gchar *format, ...);
Sets a string from a format string into a SPRpcValue if its type is SP_RPC_TYPE_STRING.
|
a SPRpcValue |
|
a format string |
|
arguments of the format string |
gchar* sp_rpc_value_get_string (SPRpcValue *value);
Returns the value of SPRpcValue if its type is SP_RPC_TYPE_STRING.
This string must be freed with g_free()
.
|
a SPRpcValue |
Returns : |
a new allocated string |
guint sp_rpc_value_array_length (SPRpcValue *varray);
Returns the number of items of an array if the varray
is a
SP_RPC_TYPE_ARRAY.
|
a SPRpcValue |
Returns : |
the number of items of an array |
SPRpcValue* sp_rpc_value_array_get (SPRpcValue *varray, guint id);
Returns an item of an array if the varray
is a SP_RPC_TYPE_ARRAY.
|
a SPRpcValue |
|
the position of the item |
Returns : |
a SPRpcValue in the position id |
gint sp_rpc_value_array_get_id_by_value (SPRpcValue *varray, SPRpcValue *v);
Returns the position of the value v
into the varray
or -1 if it is not
into the array.
|
a SPRpcValue |
|
a SPRpcValue |
Returns : |
the position of the value v into the array, or -1 |
void sp_rpc_value_array_set (SPRpcValue *varray, SPRpcValue *v);
Inserts a new value into the varray
. The count references of the value
will be increased.
|
a SPRpcValue |
|
a SPRpcValue |
void sp_rpc_value_array_set_new (SPRpcValue *varray, SPRpcValue **v);
Creates and inserts a value into an varray.
|
a SPRpcValue |
|
the location of a SPRpcValue |
void sp_rpc_value_array_set_before (SPRpcValue *varray, SPRpcValue *v, SPRpcValue *sibling);
Inserts a new value into the array before the given position.
|
a SPRpcValue |
|
a SPRpcValue |
|
the array item before which the new value is inserted or NULL to insert at the end of the array; |
void sp_rpc_value_array_set_before_new (SPRpcValue *varray, SPRpcValue **v, SPRpcValue *sibling);
Creates and inserts a new value into the array before the given position.
|
a SPRpcValue |
|
the location of a SPRpcValue |
|
the array item before which the new value is inserted or NULL to insert at the end of the array; |
void sp_rpc_value_array_set_position (SPRpcValue *varray, SPRpcValue *v, gint position);
Inserts a new value into the varray
at the given position.
|
a SPRpcValue |
|
a SPRpcValue |
|
the position to insert the element. If this is negative, or is larger than the number of elements in the array, the new element is added on to the end of the array. |
void sp_rpc_value_array_set_position_new (SPRpcValue *varray, SPRpcValue **v, gint position);
Creates and inserts a new value into the array at the given position.
|
a SPRpcValue |
|
the location of a SPRpcValue |
|
the position to insert the element. If this is negative, or is larger than the number of elements in the array, the new element is added on to the end of the array. |
void sp_rpc_value_array_remove (SPRpcValue *varray, SPRpcValue *v);
Removes a value from the array and decreases its reference count.
|
a SPRpcValue |
|
a SPRpcValue |
void sp_rpc_value_array_remove_by_id (SPRpcValue *varray, guint id);
Removes a value by its position from the array and decreases its reference count.
|
a SPRpcValue |
|
the position |
gboolean sp_rpc_value_struct_has_key (SPRpcValue *vstruct, const gchar *key);
Looks whether the struct has the key key
.
|
a SPRpcValue |
|
the key |
Returns : |
TRUE if key is a part of the struct, FALSE otherwise. |
SPRpcValue* sp_rpc_value_struct_get_key (SPRpcValue *vstruct, const gchar *key);
returns the value of a key
|
a SPRpcValue |
|
the key |
Returns : |
the value of a key |
const gchar* sp_rpc_value_struct_get_key_by_value (SPRpcValue *vstruct, SPRpcValue *v);
Returns the key of a value, or NULL if the value v
is not into the
struct. The string is internal and you should not free it.
|
a SPRpcValue |
|
a SPRpcValue |
Returns : |
the key of a value |
gchar** sp_rpc_value_struct_get_keys (SPRpcValue *vstruct, guint *length);
creates an array of the keys of a struct. Use g_strfreev()
after the usage.
|
a SPRpcValue |
|
the location of the length of the array of keys, or NULL |
Returns : |
a new allocated array of the keys |
void sp_rpc_value_struct_set_key (SPRpcValue *vstruct, const gchar *key, SPRpcValue *v);
Inserts a new key and value into a struct.
If the key already exists into the struct, its current value is replaced with the new value and the old value will be unreferenced.
The count reference of the v
will be increased.
|
a SPRpcValue |
|
the key of the new struct |
|
a SPRpcValue |
void sp_rpc_value_struct_set_key_new (SPRpcValue *vstruct, const gchar *key, SPRpcValue **v);
Creates and inserts a new key and value into a struct.
Read how the sp_rpc_value_struct_set_key()
works.
|
a SPRpcValue |
|
the key of the new struct |
|
the location of the new SPRpcValue |
void sp_rpc_value_struct_remove_key (SPRpcValue *vstruct, const gchar *key);
Removes a key and its associated value from a struct. The count reference of the value will be decreased.
|
a SPRpcValue |
|
the key |
void sp_rpc_value_struct_iter_init (SPRpcValue *vstruct, SPRpcIter *iter);
Initializes a key/value pair iterator and associates it with the vstruct. Modifying the struct after calling this function invalidates the returned iterator.
gchar *key; SPRpcValue *value; SPRpcIter iter; sp_rpc_value_struct_iter_init(vstruct, &iter); while (sp_rpc_value_struct_iter_next(&iter, &key, &value)) { /* do something with key and value */ }
|
a SPRpcValue |
|
an unitialized SPRpcIter |
gboolean sp_rpc_value_struct_iter_next (SPRpcIter *iter, gchar **key, SPRpcValue **value);
Advances iter and retrieves the key and/or value that are now pointed to as a result of this advancement. If FALSE is returned, key and value are not set, and the iterator becomes invalid.
|
an initialized SPRpcIter |
|
a location for the key, or NULL |
|
the location for the value, or NULL |
Returns : |
FALSE if the end of struct has been reached |
void sp_rpc_value_struct_iter_remove (SPRpcIter *iter);
Removes the key/value pair currently pointed to by the iterator from its
associated SPRpcValue. Can only be called after
sp_rpc_value_struct_iter_next()
returned TRUE, and cannot be called more
than once for the same key/value pair.
The count reference of the removed value will be decreased.
|
an initialized SPRpcIter |