示例#1
0
def convert_to_jtype(obj_name, field_name, c_type):
    """ Convert from a C type ("uint_32") to a java type ("U32")
    and return a JType object with the size, internal type, and marshalling functions"""
    if obj_name in exceptions and field_name in exceptions[obj_name]:
        return exceptions[obj_name][field_name]
    elif (obj_name == "of_header" or loxi_utils.class_is_message(obj_name)
          ) and field_name == "type" and c_type == "uint8_t":
        return of_type
    elif field_name == "type" and re.match(r'of_action.*', obj_name):
        return action_type
    elif field_name == "err_type":
        return JType("OFErrorType", 'short') \
            .op(read='bb.readShort()', write='bb.writeShort($name)')
    elif loxi_utils.class_is(obj_name,
                             "of_error_msg") and field_name == "data":
        return error_cause_data
    elif field_name == "stats_type":
        return JType("OFStatsType", 'short') \
            .op(read='bb.readShort()', write='bb.writeShort($name)')
    elif field_name == "type" and re.match(r'of_instruction.*', obj_name):
        return instruction_type
    elif loxi_utils.class_is(
            obj_name, "of_flow_mod"
    ) and field_name == "table_id" and c_type == "uint8_t":
        return table_id_default_zero
    elif loxi_utils.class_is(
            obj_name, "of_flow_mod"
    ) and field_name == "out_group" and c_type == "uint32_t":
        return of_group_default_any
    elif field_name == "table_id" and c_type == "uint8_t":
        return table_id
    elif field_name == "version" and c_type == "uint8_t":
        return of_version
    elif field_name == "buffer_id" and c_type == "uint32_t":
        return buffer_id
    elif field_name == "group_id" and c_type == "uint32_t":
        return of_group
    elif field_name == 'datapath_id':
        return datapath_id
    elif field_name == 'actions' and obj_name == 'of_features_reply':
        return action_type_set
    elif field_name == "table_id" and re.match(r'of_bsn_gentable.*', obj_name):
        return gen_table_id
    elif field_name == "bundle_id" and re.match(r'of_bundle_.*', obj_name):
        return bundle_id
    elif c_type in default_mtype_to_jtype_convert_map:
        return default_mtype_to_jtype_convert_map[c_type]
    elif re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type):
        return gen_list_jtype(list_cname_to_java_name(c_type))
    elif c_type in enum_java_types():
        return enum_java_types()[c_type]
    else:
        print("WARN: Couldn't find java type conversion for '%s' in %s:%s" %
              (c_type, obj_name, field_name))
        jtype = name_c_to_caps_camel(re.sub(r'_t$', "", c_type))
        return JType(jtype)
示例#2
0
def convert_to_jtype(obj_name, field_name, c_type):
    """ Convert from a C type ("uint_32") to a java type ("U32")
    and return a JType object with the size, internal type, and marshalling functions"""
    if obj_name in exceptions and field_name in exceptions[obj_name]:
        return exceptions[obj_name][field_name]
    elif ( obj_name == "of_header" or loxi_utils.class_is_message(obj_name)) and field_name == "type" and c_type == "uint8_t":
        return of_type
    elif field_name == "type" and re.match(r'of_action.*', obj_name):
        return action_type
    elif field_name == "err_type":
        return JType("OFErrorType", 'short') \
            .op(read='bb.readShort()', write='bb.writeShort($name)')
    elif loxi_utils.class_is(obj_name, "of_error_msg") and field_name == "data":
        return error_cause_data
    elif field_name == "stats_type":
        return JType("OFStatsType", 'short') \
            .op(read='bb.readShort()', write='bb.writeShort($name)')
    elif field_name == "type" and re.match(r'of_instruction.*', obj_name):
        return instruction_type
    elif loxi_utils.class_is(obj_name, "of_flow_mod") and field_name == "table_id" and c_type == "uint8_t":
        return table_id_default_zero
    elif loxi_utils.class_is(obj_name, "of_flow_mod") and field_name == "out_group" and c_type == "uint32_t":
        return of_group_default_any
    elif field_name == "table_id" and c_type == "uint8_t":
        return table_id
    elif field_name == "version" and c_type == "uint8_t":
        return of_version
    elif field_name == "buffer_id" and c_type == "uint32_t":
        return buffer_id
    elif field_name == "group_id" and c_type == "uint32_t":
        return of_group
    elif field_name == 'datapath_id':
        return datapath_id
    elif field_name == 'actions' and obj_name == 'of_features_reply':
        return action_type_set
    elif field_name == "table_id" and re.match(r'of_bsn_gentable.*', obj_name):
        return gen_table_id
    elif field_name == "bundle_id" and re.match(r'of_bundle_.*', obj_name):
        return bundle_id
    elif c_type in default_mtype_to_jtype_convert_map:
        return default_mtype_to_jtype_convert_map[c_type]
    elif re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type):
        return gen_list_jtype(list_cname_to_java_name(c_type))
    elif c_type in enum_java_types():
        return enum_java_types()[c_type]
    else:
        print "WARN: Couldn't find java type conversion for '%s' in %s:%s" % (c_type, obj_name, field_name)
        jtype = name_c_to_caps_camel(re.sub(r'_t$', "", c_type))
        return JType(jtype)