Example #1
0
/**
 * @brief Convert result to an unsigned long int
 * @param res Result
 * @return Unsigned long int
 */
unsigned long int
esql_res_to_ulong(const Esql_Res *res)
{
   const Esql_Row *row;
   const Eina_Value_Struct_Member *member;
   Eina_Value tmp, conv;
   unsigned long int ret;

   EINA_SAFETY_ON_NULL_RETURN_VAL(res, 0);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(res->row_count > 1, 0);
   if (!res->row_count) return 0;
   row = EINA_INLIST_CONTAINER_GET(res->rows, Esql_Row);

   member = row->res->desc->members;
   if (!eina_value_struct_value_get(&(row->value), member->name, &tmp))
     return 0;

   conv.type = EINA_VALUE_TYPE_ULONG;
   if (!eina_value_convert(&tmp, &conv)) goto error_convert;

   eina_value_flush(&tmp);
   if (!eina_value_pget(&conv, &ret))
     return 0;

   return ret;

 error_convert:
   eina_value_flush(&tmp);
   return 0;
}
Example #2
0
static cJSON *
azy_value_serialize_struct_json(const Eina_Value *val)
{
   Eina_Value_Struct st;
   cJSON *object;
   unsigned int x;

   eina_value_pget(val, &st);
   object = cJSON_CreateObject();
   for (x = 0; x < st.desc->member_count; x++)
     {
        Eina_Value m;

        eina_value_struct_value_get(val, st.desc->members[x].name, &m);
        cJSON_AddItemToObject(object, st.desc->members[x].name, azy_value_serialize_json(&m));
        eina_value_flush(&m);
     }
   return object;
}
Example #3
0
/**
 * @brief Convert result to a binary blob
 * @param res Result
 * @return Allocated binary blob (must be freed)
 */
unsigned char *
esql_res_to_blob(const Esql_Res *res, unsigned int *size)
{
   const Esql_Row *row;
   const Eina_Value_Struct_Member *member;
   Eina_Value tmp, conv;
   Eina_Value_Blob blob;
   unsigned char *ret = NULL;

   if (size) *size = 0;

   EINA_SAFETY_ON_NULL_RETURN_VAL(res, NULL);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(res->row_count > 1, NULL);
   if (!res->row_count) return NULL;
   row = EINA_INLIST_CONTAINER_GET(res->rows, Esql_Row);

   member = row->res->desc->members;
   if (!eina_value_struct_value_get(&(row->value), member->name, &tmp))
     return NULL;

   if (!eina_value_setup(&conv, EINA_VALUE_TYPE_BLOB)) goto error_setup;
   if (!eina_value_convert(&tmp, &conv)) goto error;
   if (!eina_value_pget(&conv, &blob)) goto error;

   ret = malloc(blob.size);
   EINA_SAFETY_ON_NULL_GOTO(ret, error);

   memcpy(ret, blob.memory, blob.size);
   if (size) *size = blob.size;

 error:
   eina_value_flush(&conv);
 error_setup:
   eina_value_flush(&tmp);
   return ret;
}
Eina_Bool
_message_iter_from_eina_value_struct(const char *signature, Eldbus_Message_Iter *iter, const Eina_Value *value)
{
   unsigned i;
   DBusSignatureIter signature_iter;
   Eina_Bool r = EINA_TRUE;
   char *type;
   Eina_Value_Struct st;

   EINA_SAFETY_ON_FALSE_RETURN_VAL(
            eina_value_type_get(value) == EINA_VALUE_TYPE_STRUCT, EINA_FALSE);
   EINA_SAFETY_ON_FALSE_RETURN_VAL(
      eina_value_pget(value, &st), EINA_FALSE);

   dbus_signature_iter_init(&signature_iter, signature);
   i = 0;
   while ((type = dbus_signature_iter_get_signature(&signature_iter)))
     {
        DBG("type: %s", type);
        if (type[0] != 'v' && !type[1])
          r = _basic_append(type[0], value, st.desc, i, iter);
        else if (type[0] == 'a')
          {
             Eina_Value value_array;

             EINA_SAFETY_ON_FALSE_RETURN_VAL(
                      _compatible_type(type[0], st.desc->members[i].type),
                      EINA_FALSE);
             eina_value_struct_value_get(value, st.desc->members[i].name,
                                         &value_array);
             r = _array_append(type, &value_array, iter);
             eina_value_flush(&value_array);
          }
        else if (type[0] == '(')
          {
             Eina_Value inner_st;
             Eldbus_Message_Iter *sub_iter;
             char *sub_sig;
             unsigned len = strlen(type+1) -1;
             sub_sig = alloca(sizeof(char) * len);
             memcpy(sub_sig, type+1, len);
             sub_sig[len-1] = 0;
             EINA_SAFETY_ON_FALSE_RETURN_VAL(
                         _compatible_type(type[0], st.desc->members[i].type),
                         EINA_FALSE);
             eina_value_struct_value_get(value, st.desc->members[i].name, &inner_st);
             eldbus_message_iter_arguments_append(iter, type, &sub_iter);
             r = _message_iter_from_eina_value_struct(sub_sig, sub_iter,
                                                      &inner_st);
             eldbus_message_iter_container_close(iter, sub_iter);
          }
        else if (type[0] == 'v')
          {
             ERR("Variant not supported");
             r = EINA_FALSE;
          }
        else
          {
             ERR("Unknown type %c", type[0]);
             r = EINA_FALSE;
          }
        i++;
        dbus_free(type);
        if (!r || !dbus_signature_iter_next(&signature_iter)) break;
     }
   return r;
}