From: Enlightenment S. <no-...@en...> - 2010-12-04 04:18:43
|
Log: remove some unnecessary azy_value functions, fully document azy_value functions, rename a lot of azy_value functions Author: discomfitor Date: 2010-12-03 20:18:35 -0800 (Fri, 03 Dec 2010) New Revision: 55253 Trac: http://trac.enlightenment.org/e/changeset/55253 Modified: trunk/PROTO/azy/src/bin/azy.c trunk/PROTO/azy/src/bin/main.c trunk/PROTO/azy/src/include/Azy.h trunk/PROTO/azy/src/include/azy_private.h trunk/PROTO/azy/src/lib/azy_content.c trunk/PROTO/azy/src/lib/azy_content_json.c trunk/PROTO/azy/src/lib/azy_content_xml.c trunk/PROTO/azy/src/lib/azy_value.c trunk/PROTO/azy/src/tests/client.c trunk/PROTO/azy/src/tests/unit/t001_content.c Modified: trunk/PROTO/azy/src/bin/azy.c =================================================================== --- trunk/PROTO/azy/src/bin/azy.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/bin/azy.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -90,13 +90,13 @@ c = calloc(1, sizeof(Azy_Model)); EINA_SAFETY_ON_NULL_RETURN_VAL(c, NULL); - c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "int", "int", "int", "0", "azy_value_to_int", "azy_value_int_new", NULL, "%i")); - c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "boolean", "boolean", "Eina_Bool", "EINA_FALSE", "azy_value_to_bool", "azy_value_bool_new", NULL, "%s")); - c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "string", "string", "const char *", "NULL", "azy_value_to_string", "azy_value_string_new", "eina_stringshare_del", "%s")); - c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "double", "double", "double", "0.0", "azy_value_to_double", "azy_value_double_new", NULL, "%.3lf")); - c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "time", "time", "const char *", "NULL", "azy_value_to_string", "azy_value_time_new", "eina_stringshare_del", "%s")); - c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "base64", "base64", "const char *", "NULL", "azy_value_to_base64", "azy_value_base64_new", "eina_stringshare_del", "%s")); - c->types = eina_list_append(c->types, azy_typedef_new(TD_ANY, "any", "any", "Azy_Value *", "NULL", "azy_value_to_value", "azy_value_ref", "azy_value_unref", NULL)); + c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "int", "int", "int", "0", "azy_value_int_get", "azy_value_int_new", NULL, "%i")); + c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "boolean", "boolean", "Eina_Bool", "EINA_FALSE", "azy_value_bool_get", "azy_value_bool_new", NULL, "%s")); + c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "string", "string", "const char *", "NULL", "azy_value_string_get", "azy_value_string_new", "eina_stringshare_del", "%s")); + c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "double", "double", "double", "0.0", "azy_value_double_get", "azy_value_double_new", NULL, "%.3lf")); + c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "time", "time", "const char *", "NULL", "azy_value_string_get", "azy_value_time_new", "eina_stringshare_del", "%s")); + c->types = eina_list_append(c->types, azy_typedef_new(TD_BASE, "base64", "base64", "const char *", "NULL", "azy_value_base64_get", "azy_value_base64_new", "eina_stringshare_del", "%s")); + c->types = eina_list_append(c->types, azy_typedef_new(TD_ANY, "any", "any", "Azy_Value *", "NULL", "azy_value_value_get", "azy_value_ref", "azy_value_unref", NULL)); return c; } Modified: trunk/PROTO/azy/src/bin/main.c =================================================================== --- trunk/PROTO/azy/src/bin/main.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/bin/main.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -243,7 +243,7 @@ EL(3, "return NULL;"); EL(2, "}"); NL; - EL(2, "azy_value_array_append(_array, _item_value);"); + EL(2, "azy_value_array_push(_array, _item_value);"); EL(1, "}"); NL; EL(1, "return _array;"); @@ -1453,7 +1453,7 @@ /* EL(1, "{"); EL(2,"if (!%s(azy_content_retval_get(_content), %s&_retval))", - method->return_type->demarch_name, (!strcmp(method->return_type->demarch_name, "azy_value_to_bool")) ? "(int*)" : ""); + method->return_type->demarch_name, (!strcmp(method->return_type->demarch_name, "azy_value_bool_get")) ? "(int*)" : ""); EL(3, "azy_content_error_faultmsg_set(_error, AZY_CLIENT_ERROR_MARSHALIZER, \"Call return value demarshalization failed.\");"); EL(1, "}"); Modified: trunk/PROTO/azy/src/include/Azy.h =================================================================== --- trunk/PROTO/azy/src/include/Azy.h 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/include/Azy.h 2010-12-04 04:18:35 UTC (rev 55253) @@ -105,7 +105,7 @@ AZY_VALUE_MEMBER, AZY_VALUE_INT, AZY_VALUE_STRING, - AZY_VALUE_BOOLEAN, + AZY_VALUE_BOOL, AZY_VALUE_DOUBLE, AZY_VALUE_TIME, AZY_VALUE_BASE64 @@ -251,30 +251,24 @@ Azy_Value *azy_value_bool_new(Eina_Bool val); Azy_Value *azy_value_double_new(double val); Azy_Value *azy_value_time_new(const char *val); - Eina_Bool azy_value_to_int(Azy_Value *val, - int *nval); - Eina_Bool azy_value_to_string(Azy_Value *val, - const char **nval); - Eina_Bool azy_value_to_base64(Azy_Value *val, - const char **nval); - Eina_Bool azy_value_to_bool(Azy_Value *val, - Eina_Bool *nval); - Eina_Bool azy_value_to_double(Azy_Value *val, + Eina_Bool azy_value_int_get(Azy_Value *val, + int *nval); + Eina_Bool azy_value_string_get(Azy_Value *val, + const char **nval); + Eina_Bool azy_value_base64_get(Azy_Value *val, + const char **nval); + Eina_Bool azy_value_bool_get(Azy_Value *val, + Eina_Bool *nval); + Eina_Bool azy_value_double_get(Azy_Value *val, double *nval); - Eina_Bool azy_value_to_value(Azy_Value *val, + Eina_Bool azy_value_value_get(Azy_Value *val, Azy_Value **nval); Azy_Value_Type azy_value_type_get(Azy_Value *val); - Azy_Value *azy_value_array_new(void); - void azy_value_array_append(Azy_Value *arr, - Azy_Value *val); + Azy_Value *azy_value_array_new(void); + void azy_value_array_push(Azy_Value *arr, + Azy_Value *val); Eina_List *azy_value_children_items_get(Azy_Value *arr); - Azy_Value *azy_value_struct_new(void); - Azy_Value *azy_value_struct_new_from_string(const char *name, - const char *value); - Azy_Value *azy_value_struct_new_from_double(const char *name, - double value); - Azy_Value *azy_value_struct_new_from_int(const char *name, - int value); + Azy_Value *azy_value_struct_new(void); void azy_value_struct_member_set(Azy_Value *str, const char *name, Azy_Value *val); Modified: trunk/PROTO/azy/src/include/azy_private.h =================================================================== --- trunk/PROTO/azy/src/include/azy_private.h 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/include/azy_private.h 2010-12-04 04:18:35 UTC (rev 55253) @@ -232,7 +232,7 @@ extern void _azy_magic_fail(const void *d, Azy_Magic m, Azy_Magic req_m, const char *fname); -Eina_Bool _azy_value_multi_line_get(Azy_Value *v, +Eina_Bool azy_value_multi_line_get_(Azy_Value *v, int max_strlen); int azy_events_type_parse(Azy_Net *net, int type, Modified: trunk/PROTO/azy/src/lib/azy_content.c =================================================================== --- trunk/PROTO/azy/src/lib/azy_content.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/lib/azy_content.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -485,7 +485,7 @@ single_line = EINA_FALSE; else EINA_LIST_FOREACH(content->params, l, v) - if (_azy_value_multi_line_get(v, 25)) + if (azy_value_multi_line_get_(v, 25)) single_line = EINA_FALSE; eina_strbuf_append_printf(string, "%s%s(", buf, content->method ? content->method : "<anonymous>"); Modified: trunk/PROTO/azy/src/lib/azy_content_json.c =================================================================== --- trunk/PROTO/azy/src/lib/azy_content_json.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/lib/azy_content_json.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -47,7 +47,7 @@ case AZY_VALUE_INT: { int int_val = -1; - azy_value_to_int(val, &int_val); + azy_value_int_get(val, &int_val); return cJSON_CreateNumber(int_val); } @@ -55,16 +55,16 @@ case AZY_VALUE_TIME: { const char *str_val; - azy_value_to_string(val, &str_val); + azy_value_string_get(val, &str_val); object = cJSON_CreateString(str_val); eina_stringshare_del(str_val); return object; } - case AZY_VALUE_BOOLEAN: + case AZY_VALUE_BOOL: { Eina_Bool bool_val = -1; - azy_value_to_bool(val, &bool_val); + azy_value_bool_get(val, &bool_val); if (bool_val) return cJSON_CreateTrue(); @@ -75,7 +75,7 @@ case AZY_VALUE_DOUBLE: { double dbl_val = -1; - azy_value_to_double(val, &dbl_val); + azy_value_double_get(val, &dbl_val); return cJSON_CreateNumber(dbl_val); } @@ -119,7 +119,7 @@ uint32_t arr_len = cJSON_GetArraySize(object); for (i = 0; i < arr_len; i++) - azy_value_array_append(arr, azy_value_unserialize_json(cJSON_GetArrayItem(object, i))); + azy_value_array_push(arr, azy_value_unserialize_json(cJSON_GetArrayItem(object, i))); return arr; } Modified: trunk/PROTO/azy/src/lib/azy_content_xml.c =================================================================== --- trunk/PROTO/azy/src/lib/azy_content_xml.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/lib/azy_content_xml.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -196,7 +196,7 @@ case AZY_VALUE_INT: { int int_val = -1; - azy_value_to_int(val, &int_val); + azy_value_int_get(val, &int_val); snprintf(buf, sizeof(buf), "%d", int_val); xmlNewChild(node, NULL, BAD_CAST "int", BAD_CAST buf); break; @@ -205,16 +205,16 @@ case AZY_VALUE_STRING: { const char *str_val; - azy_value_to_string(val, &str_val); + azy_value_string_get(val, &str_val); xmlNewChild(node, NULL, BAD_CAST "string", BAD_CAST str_val); eina_stringshare_del(str_val); break; } - case AZY_VALUE_BOOLEAN: + case AZY_VALUE_BOOL: { Eina_Bool bool_val = -1; - azy_value_to_bool(val, &bool_val); + azy_value_bool_get(val, &bool_val); xmlNewChild(node, NULL, BAD_CAST "boolean", BAD_CAST (bool_val ? "1" : "0")); break; } @@ -222,7 +222,7 @@ case AZY_VALUE_DOUBLE: { double dbl_val = -1; - azy_value_to_double(val, &dbl_val); + azy_value_double_get(val, &dbl_val); snprintf(buf, sizeof(buf), "%g", dbl_val); xmlNewChild(node, NULL, BAD_CAST "double", BAD_CAST buf); break; @@ -231,7 +231,7 @@ case AZY_VALUE_TIME: { const char *str_val; - azy_value_to_string(val, &str_val); + azy_value_string_get(val, &str_val); xmlNewChild(node, NULL, BAD_CAST "dateTime.iso8601", BAD_CAST str_val); eina_stringshare_del(str_val); break; @@ -310,7 +310,7 @@ return NULL; } - azy_value_array_append(arr, elem); + azy_value_array_push(arr, elem); } for_each_node_end() Modified: trunk/PROTO/azy/src/lib/azy_value.c =================================================================== --- trunk/PROTO/azy/src/lib/azy_value.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/lib/azy_value.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -14,7 +14,11 @@ # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif -static Azy_Value * +static Azy_Value *azy_value_new_(void); +static Eina_Bool azy_value_list_multi_line_get_(Azy_Value *v); + +/* allocate a new Azy_Value */ +static inline Azy_Value * azy_value_new_(void) { Azy_Value *v; @@ -27,6 +31,7 @@ return v; } +/* returns EINA_TRUE if a struct/array object requires multiple lines to print */ static Eina_Bool azy_value_list_multi_line_get_(Azy_Value *v) { @@ -57,7 +62,8 @@ return EINA_FALSE; } -static Eina_Bool +/* returns EINA_TRUE if the line requires multiple lines to print */ +Eina_Bool azy_value_multi_line_get_(Azy_Value *val, int max_strlen) { @@ -78,6 +84,14 @@ return EINA_FALSE; } +/** + * @brief Increase the refcount of an existing #Azy_Value + * This function can be used to increase the reference count of @p val, + * effectively copying the struct. Note that only the struct itself has + * its refcount increased, not the members. + * @param val The #Azy_Value to ref (NOT NULL) + * @return The same variable, or #NULL on error + */ Azy_Value * azy_value_ref(Azy_Value *val) { @@ -86,12 +100,18 @@ AZY_MAGIC_FAIL(val, AZY_MAGIC_VALUE); return NULL; } - val->ref++; - return val; } +/** + * @brief Decrease the refcount of an existing #Azy_Value + * This function can be used to decrease the reference count of @p val, + * effectively deleting an instance of the struct. Note that only the + * struct itself has its refcount decreased, not the members. If the refcount + * of an object reaches 0, it and its data are automatically freed. + * @param val The #Azy_Value to ref (NOT NULL) + */ void azy_value_unref(Azy_Value *val) { @@ -119,6 +139,13 @@ } /* base types */ +/** + * @brief Create an #Azy_Value of type #AZY_VALUE_STRING + * This function allocates memory around and stringshares a string into + * an #Azy_Value struct. + * @param val The string + * @return The allocated struct, or #NULL on error + */ Azy_Value * azy_value_string_new(const char *val) { @@ -131,6 +158,13 @@ return v; } +/** + * @brief Create an #Azy_Value of type #AZY_VALUE_INT + * This function allocates memory around an int into + * an #Azy_Value struct. + * @param val The int + * @return The allocated struct, or #NULL on error + */ Azy_Value * azy_value_int_new(int val) { @@ -143,6 +177,13 @@ return v; } +/** + * @brief Create an #Azy_Value of type #AZY_VALUE_BOOL + * This function allocates memory around a boolean value into + * an #Azy_Value struct. + * @param val The boolean value + * @return The allocated struct, or #NULL on error + */ Azy_Value * azy_value_bool_new(Eina_Bool val) { @@ -150,11 +191,18 @@ v = azy_value_new_(); EINA_SAFETY_ON_NULL_RETURN_VAL(v, NULL); - v->type = AZY_VALUE_BOOLEAN; - v->int_val = val; + v->type = AZY_VALUE_BOOL; + v->int_val = !!val; return v; } +/** + * @brief Create an #Azy_Value of type #AZY_VALUE_DOUBLE + * This function allocates memory around a double into + * an #Azy_Value struct. + * @param val The double + * @return The allocated struct, or #NULL on error + */ Azy_Value * azy_value_double_new(double val) { @@ -167,6 +215,13 @@ return v; } +/** + * @brief Create an #Azy_Value of type #AZY_VALUE_TIME + * This function allocates memory around and stringshares a time string into + * an #Azy_Value struct. + * @param val The time string + * @return The allocated struct, or #NULL on error + */ Azy_Value * azy_value_time_new(const char *val) { @@ -179,6 +234,13 @@ return v; } +/** + * @brief Create an #Azy_Value of type #AZY_VALUE_BASE64 + * This function allocates memory around a base64 encoded + * string into an #Azy_Value struct. + * @param val The base64 string + * @return The allocated struct, or #NULL on error + */ Azy_Value * azy_value_base64_new(const char *base64) { @@ -193,8 +255,17 @@ return val; } +/* conversion functions */ +/** + * @brief Retrieve the int value from an #Azy_Value struct of type #AZY_VALUE_INT + * This function gets the int value previously stored in the struct, + * returning success or failure. + * @param val The #Azy_Value (NOT NULL) + * @param nval The pointer to store the int in (NOT NULL) + * @return EINA_TRUE on success, else EINA_FALSE + */ Eina_Bool -azy_value_to_int(Azy_Value *val, +azy_value_int_get(Azy_Value *val, int *nval) { if (!AZY_MAGIC_CHECK(val, AZY_MAGIC_VALUE)) @@ -209,8 +280,18 @@ return EINA_TRUE; } +/** + * @brief Retrieve the string value from an #Azy_Value struct of type + * #AZY_VALUE_STRING, #AZY_VALUE_TIME, or #AZY_VALUE_BASE64 + * This function stringshare_refs the string value previously stored in the struct, + * returning success or failure. It accepts all string type values, and + * will automatically decode base64 strings. + * @param val The #Azy_Value (NOT NULL) + * @param nval The pointer to store the value in (NOT NULL) + * @return EINA_TRUE on success, else EINA_FALSE + */ Eina_Bool -azy_value_to_string(Azy_Value *val, +azy_value_string_get(Azy_Value *val, const char **nval) { if (!AZY_MAGIC_CHECK(val, AZY_MAGIC_VALUE)) @@ -242,8 +323,17 @@ return EINA_TRUE; } +/** + * @brief Retrieve the string value from an #Azy_Value struct of type #AZY_VALUE_BASE64 + * This function stringshare_refs the base64 encoded string previously stored in + * the struct into a new pointer. + * To retrieve the value and decode it in one call, @see azy_value_string_get + * @param val The #Azy_Value (NOT NULL) + * @param nval The pointer to store the value in (NOT NULL) + * @return EINA_TRUE on success, else EINA_FALSE + */ Eina_Bool -azy_value_to_base64(Azy_Value *val, +azy_value_base64_get(Azy_Value *val, const char **nval) { if (!AZY_MAGIC_CHECK(val, AZY_MAGIC_VALUE)) @@ -257,8 +347,16 @@ return EINA_TRUE; } +/** + * @brief Retrieve the int value from an #Azy_Value struct of type #AZY_VALUE_BOOL + * This function gets the bool value previously stored in the struct, + * returning success or failure. + * @param val The #Azy_Value (NOT NULL) + * @param nval The pointer to store the bool in (NOT NULL) + * @return EINA_TRUE on success, else EINA_FALSE + */ Eina_Bool -azy_value_to_bool(Azy_Value *val, +azy_value_bool_get(Azy_Value *val, Eina_Bool *nval) { if (!AZY_MAGIC_CHECK(val, AZY_MAGIC_VALUE)) @@ -266,15 +364,24 @@ AZY_MAGIC_FAIL(val, AZY_MAGIC_VALUE); return EINA_FALSE; } - if ((!nval) || (val->type != AZY_VALUE_BOOLEAN)) + if ((!nval) || (val->type != AZY_VALUE_BOOL)) return EINA_FALSE; *nval = !!val->int_val; return EINA_TRUE; } +/** + * @brief Retrieve the double value from an #Azy_Value struct of type + * #AZY_VALUE_DOUBLE, or #AZY_TYPE_INT + * This function gets the double value previously stored in the struct, + * returning success or failure. + * @param val The #Azy_Value (NOT NULL) + * @param nval The pointer to store the value in (NOT NULL) + * @return EINA_TRUE on success, else EINA_FALSE + */ Eina_Bool -azy_value_to_double(Azy_Value *val, +azy_value_double_get(Azy_Value *val, double *nval) { if (!AZY_MAGIC_CHECK(val, AZY_MAGIC_VALUE)) @@ -292,8 +399,16 @@ return EINA_TRUE; } +/** + * @brief Increases the refcount of an #Azy_Value + * This function increases the refcount of an #Azy_Value, returning + * success or failure. + * @param val The #Azy_Value (NOT NULL) + * @param nval The pointer to store the value in (NOT NULL) + * @return EINA_TRUE on success, else EINA_FALSE + */ Eina_Bool -azy_value_to_value(Azy_Value *val, +azy_value_value_get(Azy_Value *val, Azy_Value **nval) { if (!AZY_MAGIC_CHECK(val, AZY_MAGIC_VALUE)) @@ -309,6 +424,13 @@ return EINA_TRUE; } +/** + * @brief Return the type of an #Azy_Value + * This function is used to return the type of value in + * an #Azy_Value. + * @param val The #Azy_Value struct (NOT NULL) + * @return The #Azy_Value_Type, or -1 on error + */ Azy_Value_Type azy_value_type_get(Azy_Value *val) { @@ -321,6 +443,14 @@ return val->type; } +/** + * @brief Returns the name of the #Azy_Value struct member + * This function returns the name of the struct member that the #Azy_Value + * contains. Note that the name is still owned by the #Azy_Value, but is + * guaranteed to be stringshared. + * @param val The #Azy_Value of type #AZY_VALUE_MEMBER (NOT NULL) + * @return The struct member's name, or #NULL on failure + */ const char * azy_value_struct_member_name_get(Azy_Value *val) { @@ -335,6 +465,14 @@ return val->member_name; } +/** + * @brief Returns the value of the #Azy_Value struct member + * This function returns the value of the struct member that the specified + * #Azy_Value contains. Note that the returned value is still owned by the + * specified #Azy_Value. + * @param val The #Azy_Value of type #AZY_VALUE_MEMBER (NOT NULL) + * @return The struct member's value, or #NULL on failure + */ Azy_Value * azy_value_struct_member_value_get(Azy_Value *val) { @@ -349,6 +487,16 @@ return val->member_value; } +/** + * @brief Returns the #Azy_Value struct member that matches a name + * This function returns the struct member that the specified + * #Azy_Value contains which matches @p name. + * Note that the returned value is still owned by the + * specified #Azy_Value. + * @param val The #Azy_Value of type #AZY_VALUE_STRUCT (NOT NULL) + * @param name The name of the member to return (NOT NULL) + * @return The #Azy_Value of the named struct member, or #NULL on failure + */ Azy_Value * azy_value_struct_member_get(Azy_Value *val, const char *name) @@ -375,6 +523,15 @@ return NULL; } +/** + * @brief Returns a list of the child members of an #Azy_Value + * This function returns the list of struct member that the specified + * #Azy_Value contains. + * Note that the returned values (including the list) are still owned by the + * specified #Azy_Value. + * @param val The #Azy_Value of type #AZY_VALUE_ARRAY or #AZY_VALUE_STRUCT (NOT NULL) + * @return An #Eina_List of #Azy_Value members, or #NULL on failure + */ Eina_List * azy_value_children_items_get(Azy_Value *val) { @@ -390,7 +547,10 @@ } /* composite types */ - +/** + * @brief This function allocates and returns a new #Azy_Value of type AZY_VALUE_STRUCT + * @return The new #Azy_Value struct, or #NULL on failure + */ Azy_Value * azy_value_struct_new(void) { @@ -402,61 +562,11 @@ return v; } +/** + * @brief This function allocates and returns a new #Azy_Value of type AZY_VALUE_ARRAY + * @return The new #Azy_Value array struct, or #NULL on failure + */ Azy_Value * -azy_value_struct_new_from_string(const char *name, const char *value) -{ - Azy_Value *v, *str; - - v = azy_value_new_(); - EINA_SAFETY_ON_NULL_RETURN_VAL(v, NULL); - v->type = AZY_VALUE_STRUCT; - str = azy_value_string_new(value); - if (!str) - { - azy_value_unref(v); - return NULL; - } - azy_value_struct_member_set(v, name, str); - return v; -} - -Azy_Value * -azy_value_struct_new_from_int(const char *name, int value) -{ - Azy_Value *v, *i; - - v = azy_value_new_(); - EINA_SAFETY_ON_NULL_RETURN_VAL(v, NULL); - v->type = AZY_VALUE_STRUCT; - i = azy_value_int_new(value); - if (!i) - { - azy_value_unref(v); - return NULL; - } - azy_value_struct_member_set(v, name, i); - return v; -} - -Azy_Value * -azy_value_struct_new_from_double(const char *name, double value) -{ - Azy_Value *v, *d; - - v = azy_value_new_(); - EINA_SAFETY_ON_NULL_RETURN_VAL(v, NULL); - v->type = AZY_VALUE_STRUCT; - d = azy_value_double_new(value); - if (!d) - { - azy_value_unref(v); - return NULL; - } - azy_value_struct_member_set(v, name, d); - return v; -} - -Azy_Value * azy_value_array_new(void) { Azy_Value *v; @@ -467,8 +577,16 @@ return v; } +/** + * @brief Set a struct member in an #Azy_Value to use a name and a value + * This function sets member with name @p name to @p val. If a previous member + * with @p name exists, unref it and use @p val instead. + * @param struc The #Azy_Value struct to set the member in (NOT NULL) + * @param name The member name (NOT NULL) + * @param val The struct member value (NOT NULL) + */ void -azy_value_struct_member_set(Azy_Value *str, +azy_value_struct_member_set(Azy_Value *struc, const char *name, Azy_Value *val) { @@ -481,18 +599,18 @@ return; } - if (!AZY_MAGIC_CHECK(str, AZY_MAGIC_VALUE)) + if (!AZY_MAGIC_CHECK(struc, AZY_MAGIC_VALUE)) { - AZY_MAGIC_FAIL(str, AZY_MAGIC_VALUE); + AZY_MAGIC_FAIL(struc, AZY_MAGIC_VALUE); return; } EINA_SAFETY_ON_NULL_RETURN(name); - if (str->type != AZY_VALUE_STRUCT) + if (struc->type != AZY_VALUE_STRUCT) return; - EINA_LIST_FOREACH(str->children, l, m) + EINA_LIST_FOREACH(struc->children, l, m) if (!strcmp(m->member_name, name)) { azy_value_unref(m->member_value); @@ -505,12 +623,18 @@ v->type = AZY_VALUE_MEMBER; v->member_name = eina_stringshare_add(name); v->member_value = val; - str->children = eina_list_append(str->children, v); + struc->children = eina_list_append(struc->children, v); } +/** + * @brief Add a value to an array + * This function adds @p val to array @p arr. + * @param arr The array (NOT NULL) + * @param val The value to add (NOT NULL) + */ void -azy_value_array_append(Azy_Value *arr, - Azy_Value *val) +azy_value_array_push(Azy_Value *arr, + Azy_Value *val) { if (!AZY_MAGIC_CHECK(val, AZY_MAGIC_VALUE)) { @@ -526,10 +650,21 @@ arr->children = eina_list_append(arr->children, val); } +/** + * @brief Check if an #Azy_Value is an RPC error + * This function checks to see if @p val is an RPC error + * with a faultcode and faultstring, returning both if + * it is. + * Note that the faultstring returned is still owned by @p val. + * @param val The #Azy_Value to check + * @param errcode Pointer to store a faultcode in + * @param errmsg Pointer to store a faultmsg in + * @return EINA_FALSE if @p val is not an error value, else EINA_TRUE + */ Eina_Bool azy_value_retval_is_error(Azy_Value *val, - int *errcode, - const char **errmsg) + int *errcode, + const char **errmsg) { Azy_Value *c, *s; @@ -555,17 +690,27 @@ return EINA_TRUE; } +/** + * @brief Dump a value's contents into a string + * This function appends the values in @p v into #Eina_Strbuf @p string, + * indenting @p indent spaces. It calls itself recursively, dumping all sub-values + * into @p string as well. + * Note that base64 values are NOT decoded when dumping. + * @param v The value to dump (NOT NULL) + * @param string The #Eina_Strbuf to append to (NOT NULL) + * @param indent The number of spaces to indent + */ void azy_value_dump(Azy_Value *v, - Eina_Strbuf *string, - unsigned int indent) + Eina_Strbuf *string, + unsigned int indent) { Eina_List *l; Azy_Value *val; char buf[256]; - if (!v) - return; + EINA_SAFETY_ON_NULL_RETURN(v); + EINA_SAFETY_ON_NULL_RETURN(string); memset(buf, ' ', MIN(indent * 2, sizeof(buf) - 1)); @@ -654,7 +799,7 @@ break; } - case AZY_VALUE_BOOLEAN: + case AZY_VALUE_BOOL: { eina_strbuf_append_printf(string, "%s", v->int_val ? "true" : "false"); break; Modified: trunk/PROTO/azy/src/tests/client.c =================================================================== --- trunk/PROTO/azy/src/tests/client.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/tests/client.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -220,9 +220,17 @@ /* call undefined servlet methods */ { Azy_Content *content; + Azy_Value *struc; content = azy_content_new("T_Test1.undefined"); - azy_content_param_add(content, azy_value_struct_new_from_int("test", 100)); + struc = azy_value_struct_new(); + if (!struc) + { + azy_client_close(cli); + return ECORE_CALLBACK_CANCEL; + } + azy_value_struct_member_set(struc, "test", azy_value_int_new(100)); + azy_content_param_add(content, struc); ret = azy_client_call(cli, content, AZY_NET_TRANSPORT_JSON, NULL); if (check_err(err) || (!ret)) exit(1); Modified: trunk/PROTO/azy/src/tests/unit/t001_content.c =================================================================== --- trunk/PROTO/azy/src/tests/unit/t001_content.c 2010-12-04 04:10:25 UTC (rev 55252) +++ trunk/PROTO/azy/src/tests/unit/t001_content.c 2010-12-04 04:18:35 UTC (rev 55253) @@ -84,7 +84,7 @@ TEST_ASSERT(val != 0); TEST_ASSERT(azy_value_type_get(val) == AZY_VALUE_STRING); const char* str_val = 0; - rs = azy_value_to_string(val, &str_val); + rs = azy_value_string_get(val, &str_val); TEST_ASSERT(rs); TEST_ASSERT(str_val != 0); int param_match = !strcmp(str_val, ""); @@ -95,7 +95,7 @@ TEST_ASSERT(val != 0); TEST_ASSERT(azy_value_type_get(val) == AZY_VALUE_STRING); str_val = 0; - rs = azy_value_to_string(val, &str_val); + rs = azy_value_string_get(val, &str_val); TEST_ASSERT(rs); TEST_ASSERT(str_val != 0); param_match = !strcmp(str_val, "s2"); @@ -144,7 +144,7 @@ TEST_ASSERT(_assert_param_type(content, 0, AZY_VALUE_INT)); TEST_ASSERT(_assert_param_type(content, 1, AZY_VALUE_INT)); TEST_ASSERT(_assert_param_type(content, 2, AZY_VALUE_STRING)); - TEST_ASSERT(_assert_param_type(content, 3, AZY_VALUE_BOOLEAN)); + TEST_ASSERT(_assert_param_type(content, 3, AZY_VALUE_BOOL)); TEST_ASSERT(_assert_param_type(content, 4, AZY_VALUE_DOUBLE)); TEST_ASSERT(_assert_param_type(content, 5, AZY_VALUE_TIME)); TEST_ASSERT(_assert_param_type(content, 7, AZY_VALUE_ARRAY)); |