ia64/xen-unstable

changeset 14643:7b17dd28500c

This patch adds serialization of sets with strings. I recursified the
serialization. Only sets with strings are supported so far.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Mar 29 15:06:12 2007 +0100 (2007-03-29)
parents 4b13fc910acf
children 6314d433d042
files tools/libxen/src/xen_common.c
line diff
     1.1 --- a/tools/libxen/src/xen_common.c	Thu Mar 29 15:14:26 2007 +0100
     1.2 +++ b/tools/libxen/src/xen_common.c	Thu Mar 29 15:06:12 2007 +0100
     1.3 @@ -1217,11 +1217,88 @@ static void parse_result(xen_session *se
     1.4  }
     1.5  
     1.6  
     1.7 +static void
     1.8 +make_body_add_type(enum abstract_typename typename, abstract_value *v,
     1.9 +                   xmlNode *params_node)
    1.10 +{
    1.11 +    char buf[20];
    1.12 +    switch (typename)
    1.13 +    {
    1.14 +    case STRING:
    1.15 +        add_param(params_node, "string", v->u.string_val);
    1.16 +        break;
    1.17 +
    1.18 +    case INT:
    1.19 +        snprintf(buf, sizeof(buf), "%"PRId64, v->u.int_val);
    1.20 +        add_param(params_node, "string", buf);
    1.21 +        break;
    1.22 +
    1.23 +    case FLOAT:
    1.24 +        snprintf(buf, sizeof(buf), "%lf", v->u.float_val);
    1.25 +        add_param(params_node, "double", buf);
    1.26 +        break;
    1.27 +
    1.28 +    case BOOL:
    1.29 +        add_param(params_node, "boolean", v->u.bool_val ? "1" : "0");
    1.30 +        break;
    1.31 +        
    1.32 +    case VOID:
    1.33 +        add_param(params_node, "string", "");
    1.34 +        break;
    1.35 +
    1.36 +    case ENUM:
    1.37 +        add_param(params_node, "string",
    1.38 +                  v->type->enum_marshaller(v->u.enum_val));
    1.39 +        break;
    1.40 +
    1.41 +    case SET:
    1.42 +    {
    1.43 +        const struct abstract_type *member_type = v->type->child;
    1.44 +        arbitrary_set *set_val = v->u.struct_val;
    1.45 +        abstract_value v;
    1.46 +        xmlNode *data_node = add_param_struct(params_node);
    1.47 +
    1.48 +        for (size_t i = 0; i < set_val->size; i++)
    1.49 +        {
    1.50 +            switch (member_type->typename) {
    1.51 +                case STRING:
    1.52 +                    v.u.string_val = (char *)set_val->contents[i];
    1.53 +                    make_body_add_type(member_type->typename, &v, data_node);
    1.54 +                    break;
    1.55 +                default:
    1.56 +                    assert(false);
    1.57 +            }
    1.58 +        }
    1.59 +    }
    1.60 +    break;
    1.61 +
    1.62 +    case STRUCT:
    1.63 +    {
    1.64 +        size_t member_count = v->type->member_count;
    1.65 +
    1.66 +        xmlNode *struct_node = add_param_struct(params_node);
    1.67 +
    1.68 +        for (size_t i = 0; i < member_count; i++)
    1.69 +        {
    1.70 +            const struct struct_member *mem = v->type->members + i;
    1.71 +            const char *key = mem->key;
    1.72 +            void *struct_value = v->u.struct_val;
    1.73 +
    1.74 +            add_struct_value(mem->type, struct_value + mem->offset,
    1.75 +                             add_struct_member, key, struct_node);
    1.76 +        }
    1.77 +    }
    1.78 +    break;
    1.79 +
    1.80 +    default:
    1.81 +        assert(false);
    1.82 +    }
    1.83 +}
    1.84 +
    1.85 +
    1.86  static char *
    1.87  make_body(const char *method_name, abstract_value params[], int param_count)
    1.88  {
    1.89 -    char buf[20];
    1.90 -
    1.91      xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    1.92      xmlNode *methodCall = xmlNewNode(NULL, BAD_CAST "methodCall");
    1.93      xmlDocSetRootElement(doc, methodCall);
    1.94 @@ -1235,56 +1312,7 @@ make_body(const char *method_name, abstr
    1.95      for (int p = 0; p < param_count; p++)
    1.96      {
    1.97          abstract_value *v = params + p;
    1.98 -        switch (v->type->typename)
    1.99 -        {
   1.100 -        case STRING:
   1.101 -            add_param(params_node, "string", v->u.string_val);
   1.102 -            break;
   1.103 -
   1.104 -        case INT:
   1.105 -            snprintf(buf, sizeof(buf), "%"PRId64, v->u.int_val);
   1.106 -            add_param(params_node, "string", buf);
   1.107 -            break;
   1.108 -
   1.109 -        case FLOAT:
   1.110 -            snprintf(buf, sizeof(buf), "%lf", v->u.float_val);
   1.111 -            add_param(params_node, "double", buf);
   1.112 -            break;
   1.113 -
   1.114 -        case BOOL:
   1.115 -            add_param(params_node, "boolean", v->u.bool_val ? "1" : "0");
   1.116 -            break;
   1.117 -            
   1.118 -        case VOID:
   1.119 -            add_param(params_node, "string", "");
   1.120 -            break;
   1.121 -
   1.122 -        case ENUM:
   1.123 -            add_param(params_node, "string",
   1.124 -                      v->type->enum_marshaller(v->u.enum_val));
   1.125 -            break;
   1.126 -
   1.127 -        case STRUCT:
   1.128 -        {
   1.129 -            size_t member_count = v->type->member_count;
   1.130 -
   1.131 -            xmlNode *struct_node = add_param_struct(params_node);
   1.132 -
   1.133 -            for (size_t i = 0; i < member_count; i++)
   1.134 -            {
   1.135 -                const struct struct_member *mem = v->type->members + i;
   1.136 -                const char *key = mem->key;
   1.137 -                void *struct_value = v->u.struct_val;
   1.138 -
   1.139 -                add_struct_value(mem->type, struct_value + mem->offset,
   1.140 -                                 add_struct_member, key, struct_node);
   1.141 -            }
   1.142 -        }
   1.143 -        break;
   1.144 -
   1.145 -        default:
   1.146 -            assert(false);
   1.147 -        }
   1.148 +        make_body_add_type(v->type->typename, v, params_node);
   1.149      }
   1.150  
   1.151      xmlBufferPtr buffer = xmlBufferCreate();