Example #1
0
def gen_mod(mod):
    submod = SubModule('iksemel', mod)
    submod.add_enum('ikstype', IKSTYPE)
    submod.add_enum('iksubtype', IKSUBTYPE)
    submod.add_enum('ikshowtype', IKSHOWTYPE)
    add_classes(submod)
    add_functions(submod)
Example #2
0
def load_module(module, parent):
    print "Processing module `%s'" % module['name']
    mod = SubModule(module['name'], parent)

    for enum in module['enums']:
        print " - enum `%s'" % enum['name']
        mod.add_enum(enum['name'], enum['entries'])

    overrided = []

    for func in module['functions']:
        name = func['name']['name']
        custom_name = name.replace('ta_%s_' % mod.name, '')
        func['name']['pyname'] = custom_name

        # Adding method to a different list. This list holds methods
        # that are not generated by pybindgen.
        get_overrided = OVERRIDES.get(name)

        if get_overrided == '':
            # this empty string means that we have overrided the
            # method aiming to do not generate it
            continue
        elif get_overrided:
            # This means that a valid override was found.
            func['override'] = get_overrided
            overrided.append(func)
            continue

        try:
            mod.add_function(name,
                             retval(func['rtype'], caller_owns_return=True),
                             handle_params(func, parent),
                             custom_name=custom_name)
        except Exception, e:
            warnings.warn('Skipping func %s, something wrong happened. %s' %
                          (name, str(e)))
def register_types(module):
    root_module = module.get_root()

    submodule = SubModule("torrent_error_type", parent=root_module)
    submodule.add_enum(
        "tr_stat_errtype",
        [
            ("OK", "TR_STAT_OK"),
            ("TRACKER_WARNING", "TR_STAT_TRACKER_WARNING"),
            ("TRACKER_ERROR", "TR_STAT_TRACKER_ERROR"),
            ("LOCAL_ERROR", "TR_STAT_LOCAL_ERROR"),
        ],
    )

    submodule = SubModule("torrent_activity", parent=root_module)
    submodule.add_enum(
        "tr_torrent_activity",
        [
            ("STOPPED", "TR_STATUS_STOPPED"),
            ("CHECK_WAIT", "TR_STATUS_CHECK_WAIT"),
            ("CHECK", "TR_STATUS_CHECK"),
            ("DOWNLOAD_WAIT", "TR_STATUS_DOWNLOAD_WAIT"),
            ("DOWNLOAD", "TR_STATUS_DOWNLOAD"),
            ("SEED_WAIT", "TR_STATUS_SEED_WAIT"),
            ("SEED", "TR_STATUS_SEED"),
        ],
    )

    submodule = SubModule("tracker_state", parent=root_module)
    submodule.add_enum(
        "tr_tracker_state",
        [
            ("INACTIVE", "TR_TRACKER_INACTIVE"),
            ("WAITING", "TR_TRACKER_WAITING"),
            ("QUEUED", "TR_TRACKER_QUEUED"),
            ("ACTIVE", "TR_TRACKER_ACTIVE"),
        ],
    )

    submodule = SubModule("scheduled_days", parent=root_module)
    submodule.add_enum(
        "tr_sched_day",
        [
            ("SUN", "TR_SCHED_SUN"),
            ("MON", "TR_SCHED_MON"),
            ("TUES", "TR_SCHED_TUES"),
            ("WED", "TR_SCHED_WED"),
            ("THURS", "TR_SCHED_THURS"),
            ("FRI", "TR_SCHED_FRI"),
            ("SAT", "TR_SCHED_SAT"),
            ("WEEKDAY", "TR_SCHED_WEEKDAY"),
            ("WEEKEND", "TR_SCHED_WEEKEND"),
            ("ALL", "TR_SCHED_ALL"),
        ],
    )

    submodule = SubModule("encryption_mode", parent=root_module)
    submodule.add_enum(
        "tr_encryption_mode",
        [
            ("CLEAR_PREFERRED", "TR_CLEAR_PREFERRED"),
            ("ENCRYPTION_PREFERRED", "TR_ENCRYPTION_PREFERRED"),
            ("ENCRYPTION_REQUIRED", "TR_ENCRYPTION_REQUIRED"),
        ],
    )

    submodule = SubModule("direction", parent=root_module)
    submodule.add_enum(
        "tr_direction",
        [
            ("CLIENT_TO_PEER", "TR_CLIENT_TO_PEER"),
            ("UP", "TR_UP"),
            ("PEER_TO_CLIENT", "TR_PEER_TO_CLIENT"),
            ("DOWN", "TR_DOWN"),
        ],
    )

    submodule = SubModule("ratio_limit", parent=root_module)
    submodule.add_enum(
        "tr_ratiolimit",
        [
            ("GLOBAL", "TR_RATIOLIMIT_GLOBAL"),
            ("SINGLE", "TR_RATIOLIMIT_SINGLE"),
            ("UNLIMITED", "TR_RATIOLIMIT_UNLIMITED"),
        ],
    )

    submodule = SubModule("idle_limit", parent=root_module)
    submodule.add_enum(
        "tr_idlelimit",
        [("GLOBAL", "TR_IDLELIMIT_GLOBAL"), ("SINGLE", "TR_IDLELIMIT_SINGLE"), ("UNLIMITED", "TR_IDLELIMIT_UNLIMITED")],
    )

    submodule = SubModule("preallocation_mode", parent=root_module)
    submodule.add_enum(
        "tr_preallocation_mode",
        [("NONE", "TR_PREALLOCATE_NONE"), ("SPARCE", "TR_PREALLOCATE_SPARSE"), ("FULL", "TR_PREALLOCATE_FULL")],
    )

    submodule = SubModule("completeness", parent=root_module)
    submodule.add_enum(
        "tr_completeness", [("LEECH", "TR_LEECH"), ("SEED", "TR_SEED"), ("PARTIAL_SEED", "TR_PARTIAL_SEED")]
    )

    submodule = SubModule("rpc_callback_type", parent=root_module)
    submodule.add_enum(
        "tr_rpc_callback_type",
        [
            ("TORRENT_ADDED", "TR_RPC_TORRENT_ADDED"),
            ("TORRENT_STARTED", "TR_RPC_TORRENT_STARTED"),
            ("TORRENT_STOPPED", "TR_RPC_TORRENT_STOPPED"),
            ("TORRENT_REMOVING", "TR_RPC_TORRENT_REMOVING"),
            ("TORRENT_THRASHING", "TR_RPC_TORRENT_TRASHING"),
            ("TORRENT_CHANGED", "TR_RPC_TORRENT_CHANGED"),
            ("TORRENT_MOVED", "TR_RPC_TORRENT_MOVED"),
            ("SESSION_CHANGED", "TR_RPC_SESSION_CHANGED"),
            ("SESSION_QUEUE_POSITIONS_CHANGED", "TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED"),
            ("SESSION_CLOSE", "TR_RPC_SESSION_CLOSE"),
        ],
    )

    submodule = SubModule("rpc_callback_status", parent=root_module)
    submodule.add_enum("tr_rpc_callback_status", [("OK", "TR_RPC_OK"), ("NOREMOVE", "TR_RPC_NOREMOVE")])

    submodule = SubModule("port_forwarding", parent=root_module)
    submodule.add_enum(
        "tr_port_forwarding",
        [
            ("ERROR", "TR_PORT_ERROR"),
            ("UNMAPPED", "TR_PORT_UNMAPPED"),
            ("UNMAPPING", "TR_PORT_UNMAPPING"),
            ("MAPPING", "TR_PORT_MAPPING"),
            ("MAPPED", "TR_PORT_MAPPED"),
        ],
    )

    submodule = SubModule("msg_level", parent=root_module)
    submodule.add_enum("tr_msg_level", [("ERROR", "TR_MSG_ERR"), ("INF", "TR_MSG_INF"), ("DEBUG", "TR_MSG_DBG")])

    submodule = SubModule("parse_result", parent=root_module)
    submodule.add_enum(
        "tr_parse_result", [("OK", "TR_PARSE_OK"), ("ERROR", "TR_PARSE_ERR"), ("DUPLICATE", "TR_PARSE_DUPLICATE")]
    )

    submodule = SubModule("torrent_constructor_mode", parent=root_module)
    submodule.add_enum("tr_ctorMode", [("FALLBACK", "TR_FALLBACK"), ("FORCE", "TR_FORCE")])

    submodule = SubModule("location_state", parent=root_module)
    submodule.add_enum("", [("MOVING", "TR_LOC_MOVING"), ("DONE", "TR_LOC_DONE"), ("ERROR", "TR_LOC_ERROR")])

    submodule = SubModule("priority", parent=root_module)
    submodule.add_enum("", [("LOW", "TR_PRI_LOW"), ("NORMAL", "TR_PRI_NORMAL"), ("HIGH", "TR_PRI_HIGH")])

    submodule = SubModule("peers_from_index", parent=root_module)
    submodule.add_enum(
        "",
        [
            ("INCOMING", "TR_PEER_FROM_INCOMING"),
            ("LPD", "TR_PEER_FROM_LPD"),
            ("TRACKER", "TR_PEER_FROM_TRACKER"),
            ("DHT", "TR_PEER_FROM_DHT"),
            ("PEX", "TR_PEER_FROM_PEX"),
            ("RESUME", "TR_PEER_FROM_RESUME"),
            ("LTEP", "TR_PEER_FROM_LTEP"),
        ],
    )

    submodule = SubModule("benc_serialization_mode", parent=root_module)
    submodule.add_enum(
        "tr_fmt_mode", [("BENC", "TR_FMT_BENC"), ("JSON", "TR_FMT_JSON"), ("JSON_LEAN", "TR_FMT_JSON_LEAN")]
    )

    submodule = SubModule("benc_type", parent=root_module)
    submodule.add_enum(
        "",
        [
            ("INT", "TR_TYPE_INT"),
            ("STRING", "TR_TYPE_STR"),
            ("LIST", "TR_TYPE_LIST"),
            ("DICT", "TR_TYPE_DICT"),
            ("BOOL", "TR_TYPE_BOOL"),
            ("REAL", "TR_TYPE_REAL"),
        ],
    )
    ## tr_info.cc
    module.begin_section("tr_info")
    module.add_struct(
        "tr_info",
        no_constructor=True,
        no_copy=True,
        memory_policy=TrFreeFunctionPolicy("tr_metainfoFree"),
        custom_name="TorrentInfo",
    )

    module.add_struct("tr_file", no_constructor=True, no_copy=True, custom_name="File")

    module.add_struct("tr_piece", no_constructor=True, no_copy=True, custom_name="FilePiece")

    module.add_struct("tr_tracker_info", no_constructor=True, no_copy=True, custom_name="TrackerInfo")

    module.add_struct(
        "tr_tracker_stat", no_constructor=True, no_copy=True, free_function="tr_free", custom_name="TrackerStats"
    )
    module.end_section("tr_info")

    ## tr_torrent.cc
    module.begin_section("tr_torrent")
    torrent = module.add_struct(
        "tr_torrent",
        no_constructor=True,
        no_copy=True,
        memory_policy=TrFreeFunctionPolicy("tr_torrentFree"),
        custom_name="Torrent",
    )
    # torrent.cannot_be_constructed = "use factory function Session.torrent_new()"

    module.add_struct(
        "tr_ctor",
        no_constructor=True,
        no_copy=True,
        memory_policy=TrFreeFunctionPolicy("tr_ctorFree"),
        custom_name="TorrentConstructor",
    )

    module.add_struct(
        "tr_stat",
        no_constructor=True,
        no_copy=True,
        memory_policy=TrFreeFunctionPolicy("tr_free"),
        custom_name="TorrentStats",
    )

    module.add_struct(
        "tr_peer_stat",
        no_constructor=True,
        no_copy=True,
        memory_policy=TrFreeFunctionPolicy("tr_free"),
        custom_name="PeerStats",
    )

    module.add_struct(
        "tr_file_stat", no_constructor=True, no_copy=True, free_function="tr_free", custom_name="FileStats"
    )
    module.end_section("tr_torrent")

    ## tr_session.cc
    module.begin_section("tr_session")
    module.add_struct(
        "tr_session",
        no_constructor=True,
        no_copy=True,
        memory_policy=TrFreeFunctionPolicy("tr_sessionClose"),
        custom_name="Session",
    )

    module.add_struct(
        "tr_session_stats",
        no_constructor=True,
        no_copy=True,
        memory_policy=cppclass.FreeFunctionPolicy("tr_free"),
        custom_name="SessionStats",
    )

    module.add_struct(
        "tr_msg_list", no_constructor=True, no_copy=True, free_function="tr_freeMessageList", custom_name="Message"
    )
    module.end_section("tr_session")

    ## tr_benc.cc
    module.begin_section("tr_benc")
    submodule = SubModule("bencode", parent=root_module)
    benc = submodule.add_struct("Benc", no_constructor=True, no_copy=True, memory_policy=BencMemoryPolicy())
    benc.full_name = "tr_benc"

    submodule.add_struct("BencInt", parent=benc, no_constructor=True, no_copy=True).full_name = "tr_benc"

    submodule.add_struct("BencString", parent=benc, no_constructor=True, no_copy=True).full_name = "tr_benc"

    submodule.add_struct("BencList", parent=benc, no_constructor=True, no_copy=True).full_name = "tr_benc"

    submodule.add_struct("BencDict", parent=benc, no_constructor=True, no_copy=True).full_name = "tr_benc"

    submodule.add_struct("BencBool", parent=benc, no_constructor=True, no_copy=True).full_name = "tr_benc"

    submodule.add_struct("BencReal", parent=benc, no_constructor=True, no_copy=True).full_name = "tr_benc"
    module.end_section("tr_benc")

    typehandlers.add_type_alias("uint32_t", "tr_piece_index_t")
    typehandlers.add_type_alias("uint32_t", "tr_file_index_t")
    typehandlers.add_type_alias("uint32_t*", "tr_file_index_t*")
    typehandlers.add_type_alias("long int", "time_t")
    typehandlers.add_type_alias("int8_t", "tr_priority_t")
    typehandlers.add_type_alias("uint16_t", "tr_port")
Example #4
0
def generate(file_):
    # Declare modules
    bamboo = Module('bamboo', cpp_namespace="::bamboo")
    bits = SubModule('bits', bamboo)
    module = SubModule('module', bamboo)
    traits = SubModule('traits', bamboo)
    dcfile = SubModule('dcfile', bamboo)
    wire = SubModule('wire', bamboo)

    # Declare includes
    bits.add_include('"bits/byteorder.h"')
    bits.add_include('"bits/sizetag.h"')
    bits.add_include('"bits/errors.h"')
    module.add_include('"module/Array.h"')
    module.add_include('"module/Class.h"')
    module.add_include('"module/Type.h"')
    module.add_include('"module/Field.h"')
    module.add_include('"module/KeywordList.h"')
    module.add_include('"module/Method.h"')
    module.add_include('"module/Module.h"')
    module.add_include('"module/MolecularField.h"')
    module.add_include('"module/NumericRange.h"')
    module.add_include('"module/Numeric.h"')
    module.add_include('"module/Parameter.h"')
    module.add_include('"module/Struct.h"')
    module.add_include('"module/Value.h"')
    traits.add_include('"traits/hashes.h"')
    dcfile.add_include('"dcfile/format.h"')
    dcfile.add_include('"dcfile/parse.h"')
    dcfile.add_include('"dcfile/write.h"')
    wire.add_include('"wire/Datagram.h"')
    wire.add_include('"wire/DatagramIterator.h"')

    # Declare classes
    indexError = bamboo.add_exception('out_of_range',
        custom_name = 'IndexError',
        foreign_cpp_namespace = 'std',
        message_rvalue = 'exc.what()',
        is_standard_error = True)
    nullError = bamboo.add_exception('invalid_argument',
        custom_name = 'TypeError',
        foreign_cpp_namespace = 'std',
        message_rvalue = "'\"NoneType' object\" + exc.reason()",
        is_standard_error = True)
    clsKeywordList = module.add_class('KeywordList',
        docstring = classDocstrings['KeywordList'])
    clsModule = module.add_class('Module',
        docstring = classDocstrings['Module'])
    clsType = module.add_class('Type',
        docstring = classDocstrings['Type'])
    clsNumType = module.add_class('Numeric',parent = clsType,
        docstring = classDocstrings['Numeric'])
    clsArrType = module.add_class('Array', parent = clsType,
        docstring = classDocstrings['Array'])
    clsMethod = module.add_class('Method', parent = clsType,
        docstring = classDocstrings['Method'])
    clsStruct = module.add_class('Struct', parent = clsType,
        docstring = classDocstrings['Struct'])
    clsClass = module.add_class('Class', parent = clsStruct,
        docstring = classDocstrings['Class'])
    clsParam = module.add_class('Parameter',
        docstring = classDocstrings['Parameter'])
    clsField = module.add_class('Field', parent = clsKeywordList,
        docstring = classDocstrings['Field'])
    clsMolecular = module.add_class('MolecularField', parent = [clsField, clsStruct])
    structImport = module.add_struct('Import')
    structNumber = module.add_struct('Number')
    structNumericRange = module.add_struct('NumericRange')
    dgOverflowError = wire.add_exception('DatagramOverflow', message_rvalue = 'exc.what()')
    dgiEOFError = wire.add_exception('DatagramIteratorEOF', message_rvalue = 'exc.what()')
    clsDatagram = wire.add_class('Datagram',
        docstring = classDocstrings['Datagram'])
    clsDgIter = wire.add_class('DatagramIterator',
        docstring = classDocstrings['DatagramIterator'])

    # Declare enums
    enumSubtype = module.add_enum('Subtype', [
        'kTypeInt8', 'kTypeInt16', 'kTypeInt32', 'kTypeInt64', 'kTypeUint8', 'kTypeUint16',
        'kTypeUint32', 'kTypeUint64', 'kTypeChar', 'kTypeFloat32', 'kTypeFloat64', 'kTypeString',
        'kTypeVarstring', 'kTypeBlob', 'kTypeVarblob', 'kTypeStruct', 'kTypeMethod', 'kTypeInvalid'])
    enumNumtype = structNumber.add_enum('Type', ['kNaN', 'kInt', 'kUint', 'kFloat'])

    # Wrap STL containers
    bits.add_container('std::vector<std::string>', 'std::string', 'vector', custom_name = 'StringCollection')

    # Declare member variables
    structImport.add_copy_constructor()
    structImport.add_constructor([param('const std::string &', 'moduleName')])
    structImport.add_instance_attribute('module', 'std::string')
    structImport.add_instance_attribute('symbols', 'std::vector<std::string>')
    structNumber.add_copy_constructor()
    structNumber.add_instance_attribute('type', 'bamboo::Number::Type')
    structNumber.add_instance_attribute('integer', 'int64_t')
    structNumber.add_instance_attribute('uinteger', 'uint64_t')
    structNumber.add_instance_attribute('floating', 'double')
    structNumericRange.add_copy_constructor()
    structNumericRange.add_instance_attribute('type', 'bamboo::Number::Type')
    structNumericRange.add_instance_attribute('min', 'Number')
    structNumericRange.add_instance_attribute('max', 'Number')

    # Declare functions/methods
    clsKeywordList.add_constructor([])
    clsKeywordList.add_copy_constructor()
    add_method(clsKeywordList, 'has_keyword', retval('bool'),
               [param('std::string', 'keyword')], is_const = True)
    add_method(clsKeywordList, 'has_matching_keywords', retval('bool'),
               [param('const bamboo::KeywordList&', 'other')], is_const = True)
    add_method(clsKeywordList, 'num_keywords', retval('size_t'), [], is_const = True)
    add_method(clsKeywordList, 'get_keyword', retval('std::string'),
               [param('unsigned int', 'n')],
               is_const = True, throw = [indexError])
    add_method(clsKeywordList, 'add_keyword', retval('bool'), [param('std::string', 'keyword')])
    add_method(clsKeywordList, 'copy_keywords', None, [param('const bamboo::KeywordList&', 'other')])
    clsModule.add_constructor([])
    add_method(clsModule, 'num_classes', retval('size_t'), [], is_const = True)
    add_method(clsModule, 'num_structs', retval('size_t'), [], is_const = True)
    add_method(clsModule, 'num_types', retval('size_t'), [], is_const = True)
    add_method(clsModule, 'get_class',
               retval_ref('bamboo::Class *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsModule, 'get_struct',
               retval_ref('bamboo::Struct *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsModule, 'class_by_id',
               retval_ref('bamboo::Class *'),
               [param('unsigned int', 'id')])
    add_method(clsModule, 'class_by_name',
               retval_ref('bamboo::Class *'),
               [param('std::string', 'name')])
    add_method(clsModule, 'type_by_id',
               retval_ref('bamboo::Type *'),
               [param('unsigned int', 'id')])
    add_method(clsModule, 'type_by_name',
               retval_ref('bamboo::Type *'),
               [param('std::string', 'name')])
    add_method(clsModule, 'field_by_id',
               retval_ref('bamboo::Field *'),
               [param('unsigned int', 'id')])
    add_method(clsModule, 'num_imports', retval('size_t'), [], is_const = True)
    add_method(clsModule, 'get_import',
               retval_ref('bamboo::Import *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsModule, 'has_keyword', retval('bool'),
               [param('std::string', 'keyword')], is_const = True)
    add_method(clsModule, 'num_keywords', retval('size_t'), [], is_const = True)
    add_method(clsModule, 'get_keyword', retval('std::string'),
               [param('unsigned int', 'n')],
               is_const = True, throw = [indexError])
    add_method(clsModule, 'add_class', retval('bool'),
               [param('std::unique_ptr<Class>', 'dclass')])
    add_method(clsModule, 'add_struct', retval('bool'),
               [param('std::unique_ptr<Struct>', 'dstruct')])
    add_method(clsModule, 'add_import', None,
               [param('std::unique_ptr<Import>', 'import')])
    add_method(clsModule, 'add_typedef', retval('bool'),
               [param('std::string', 'name'),
                param('Type *', 'type', transfer_ownership = False)])
    add_method(clsModule, 'add_keyword', None, [param('std::string', 'keyword')])
    clsType.add_constructor([], visibility='protected')
    add_method(clsType, 'subtype', retval('bamboo::Subtype'), [], is_const = True)
    add_method(clsType, 'has_fixed_size', retval('bool'), [], is_const = True)
    add_method(clsType, 'fixed_size', retval('size_t'), [], is_const = True)
    add_method(clsType, 'has_alias', retval('bool'), [], is_const = True)
    add_method(clsType, 'alias', retval('std::string'), [], is_const = True)
    add_method(clsType, 'set_alias', None, [param('std::string', 'alias')])
    add_method(clsType, 'as_struct', retval_ref('bamboo::Struct *'), [])
    add_method(clsType, 'as_method', retval_ref('bamboo::Method *'), [])
    add_method(clsType, 'as_array', retval_ref('bamboo::Array *'), [])
    add_method(clsType, 'as_numeric', retval_ref('bamboo::Numeric *'), [])
    add_method(clsType, 'to_string', retval('std::string'), [])
    clsNumType.add_constructor([param('bamboo::Subtype', 'subtype')])
    add_method(clsNumType, 'divisor', retval('unsigned int'), [], is_const = True)
    add_method(clsNumType, 'has_modulus', retval('bool'), [], is_const = True)
    add_method(clsNumType, 'modulus', retval('double'), [], is_const = True)
    add_method(clsNumType, 'has_range', retval('bool'), [], is_const = True)
    add_method(clsNumType, 'range', retval('bamboo::NumericRange'), [], is_const = True)
    add_method(clsNumType, 'set_divisor', retval('bool'), [param('unsigned int', 'divisor')])
    add_method(clsNumType, 'set_modulus', retval('bool'), [param('double', 'modulus')])
    add_method(clsNumType, 'set_range', retval('bool'), [param('const NumericRange&', 'range')])
    clsArrType.add_constructor([
               param('bamboo::Type *', 'elementType', transfer_ownership = False),
               param('bamboo::NumericRange', 'arraySize', default_value = 'bamboo::NumericRange()')])
    add_method(clsArrType, 'element_type', retval_ref('const bamboo::Type *'), [], is_const = True)
    add_method(clsArrType, 'array_size', retval('unsigned int'), [], is_const = True)
    add_method(clsArrType, 'has_range', retval('bool'), [], is_const = True)
    add_method(clsArrType, 'range', retval('bamboo::NumericRange'), [], is_const = True)
    clsMethod.add_constructor([])
    add_method(clsMethod, 'num_parameters', retval('size_t'), [], is_const = True)
    add_method(clsMethod, 'get_parameter', retval_ref('bamboo::Parameter *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsMethod, 'parameter_by_name', retval_ref('bamboo::Parameter *'),
               [param('std::string', 'name')]),
    add_method(clsMethod, 'add_parameter', retval('bool'), [param('std::unique_ptr<Parameter>', 'param')])
    clsStruct.add_constructor([
               param('bamboo::Module *', 'module', transfer_ownership = False),
               param('std::string', 'name')])
    add_method(clsStruct, 'id', retval('unsigned int'), [], is_const = True)
    add_method(clsStruct, 'name', retval('std::string'), [], is_const = True)
    add_method(clsStruct, 'module', retval_ref('bamboo::Module *'), [])
    add_method(clsStruct, 'num_fields', retval('size_t'), [], is_const = True)
    add_method(clsStruct, 'get_field', retval_ref('bamboo::Field *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsStruct, 'field_by_id', retval_ref('bamboo::Field *'),
               [param('unsigned int', 'id')])
    add_method(clsStruct, 'field_by_name', retval_ref('bamboo::Field *'),
               [param('std::string', 'name')])
    add_method(clsStruct, 'add_field', retval('bool'), [param('std::unique_ptr<Field>', 'field')])
    add_method(clsStruct, 'as_class', retval_ref('bamboo::Class *'), [])
    clsClass.add_constructor([
               param('bamboo::Module *', 'module', transfer_ownership = False),
               param('std::string', 'name')])
    add_method(clsClass, 'num_parents', retval('size_t'), [], is_const = True)
    add_method(clsClass, 'get_parent', retval_ref('bamboo::Class *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsClass, 'num_children', retval('size_t'), [], is_const = True)
    add_method(clsClass, 'get_child', retval_ref('bamboo::Class *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsClass, 'has_constructor', retval('bool'), [], is_const = True)
    add_method(clsClass, 'constructor', retval_ref('bamboo::Field *'), [])
    add_method(clsClass, 'num_base_fields', retval('size_t'), [], is_const = True)
    add_method(clsClass, 'get_base_field', retval_ref('bamboo::Field *'),
               [param('unsigned int', 'n')],
               throw = [indexError])
    add_method(clsClass, 'add_parent', retval('bool'),
               [param('bamboo::Class *', 'parent', transfer_ownership = False)])
    clsParam.add_constructor([
               param('bamboo::Type *', 'type', transfer_ownership = False),
               param('std::string', 'name', default_value = '""')])
    add_method(clsParam, 'name', retval('std::string'), [], is_const = False)
    add_method(clsParam, 'type', retval_ref('bamboo::Type *'), [])
    add_method(clsParam, 'get_method', retval_ref('bamboo::Method *'), [])
    add_method(clsParam, 'has_default_value', retval('bool'), [], is_const = True),
    #add_method(clsParam, 'default_value', retval('const bamboo::Value'), [], is_const = True)
    add_method(clsParam, 'set_name', retval('bool'), [param('std::string', 'name')])
    add_method(clsParam, 'set_type', retval('bool'),
               [param('bamboo::Type *', 'type', transfer_ownership = False)]),
    #add_method(clsParam, 'set_default_value', retval('bool'), [param('const bamboo::Value', 'value')])
    #add_method(clsParam, 'set_default_value', retval('bool'), [param('const bamboo::Buffer&', 'value')])
    clsField.add_constructor([
               param('bamboo::Type *', 'type', transfer_ownership = False),
               param('std::string', 'name', default_value = '""')])
    add_method(clsField, 'id', retval('unsigned int'), [], is_const = True)
    add_method(clsField, 'name', retval('std::string'), [], is_const = False)
    add_method(clsField, 'type', retval_ref('bamboo::Type *'), [])
    add_method(clsField, 'record', retval_ref('bamboo::Struct *'), [])
    add_method(clsField, 'has_default_value', retval('bool'), [], is_const = True),
    #add_method(clsField, 'default_value', retval('const bamboo::Value'), [], is_const = True)
    add_method(clsField, 'set_name', retval('bool'), [param('std::string', 'name')])
    add_method(clsField, 'set_type', None,
               [param('bamboo::Type *', 'type', transfer_ownership = False)]),
    #add_method(clsField, 'set_default_value', retval('bool'), [param('const bamboo::Value', 'value')])
    #add_method(clsField, 'set_default_value', retval('bool'), [param('const bamboo::Buffer&', 'value')])
    clsMolecular.add_constructor([
               param('bamboo::Class *', 'cls', transfer_ownership = False),
               param('std::string', 'name')])
    clsDatagram.add_constructor([])
    clsDatagram.add_copy_constructor()
    add_method(clsDatagram, 'size', retval('size_t'), [], is_const = True)
    add_method(clsDatagram, 'cap', retval('size_t'), [], is_const = True)
    add_method(clsDatagram, 'add_bool', None, [param('bool', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_char', None, [param('char', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_int8', None, [param('int8_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_int16', None, [param('int16_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_int32', None, [param('int32_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_int64', None, [param('int64_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_uint8', None, [param('uint8_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_uint16', None, [param('uint16_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_uint32', None, [param('uint32_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_uint64', None, [param('uint64_t', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_float32', None, [param('float', 'value')], throw = [dgOverflowError])
    add_method(clsDatagram, 'add_float64', None, [param('double', 'value')], throw = [dgOverflowError])
    add_custom_method(clsDatagram, 'add_data')
    add_custom_method(clsDatagram, 'add_value')
    add_custom_method(clsDatagram, 'data', ('METH_NOARGS',))
    # add_string also moonlights as add_blob and addBlob
    add_method(clsDatagram, 'add_string', None, [param('std::string', 'value')], throw = [dgOverflowError])
    clsDgIter.add_constructor([
            param('const bamboo::Datagram&', 'dg'),
            param('size_t', 'offset', default_value = '0')])
    clsDgIter.add_copy_constructor()
    add_method(clsDgIter, 'tell', retval('size_t'), [], is_const = True)
    add_method(clsDgIter, 'seek', None, [param('size_t', 'offset')])
    add_method(clsDgIter, 'skip', None, [param('size_t', 'length')], throw = [dgiEOFError])
    add_method(clsDgIter, 'skip_type', None,
               [param('const bamboo::Type *', 'type', transfer_ownership = False)], throw = [dgiEOFError])
    add_method(clsDgIter, 'remaining', retval('size_t'), [], is_const = True)
    add_method(clsDgIter, 'read_bool', retval('bool'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_char', retval('char'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_int8', retval('int8_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_int16', retval('int16_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_int32', retval('int32_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_int64', retval('int64_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_uint8', retval('uint8_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_uint16', retval('uint16_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_uint32', retval('uint32_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_uint64', retval('uint64_t'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_float32', retval('float'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_float64', retval('double'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_size', retval('size_t'), [], throw = [dgiEOFError])
    # read_string also moonlights as read_blob and readBlob
    add_method(clsDgIter, 'read_string', retval('std::string'), [], throw = [dgiEOFError])
    add_method(clsDgIter, 'read_datagram', retval('bamboo::Datagram'), [], throw = [dgiEOFError])
    add_custom_method(clsDgIter, 'read_value')
    #add_method(clsDgIter, 'read_value', retval('bamboo::Value'),
    #           [param('const bamboo::Type *', 'type', transfer_ownership = False)])
    #add_method(clsDgIter, 'read_data', retval('std::string'), [param('size_t', 'length')])
    #add_method(clsDgIter, 'read_remainder', retval('std::string'), [])
    add_function(traits, 'legacy_hash', retval('uint32_t'),
                 [param('const bamboo::Module *', 'module', transfer_ownership = False)])
    add_function(dcfile, 'read_dcfile', retval('bamboo::Module *', caller_owns_return = True),
                 [param('std::string', 'filename')])
    add_function(dcfile, 'parse_dcfile', retval('bool'),
                 [param('bamboo::Module *', 'module', transfer_ownership = False),
                  param('std::string', 'filename')])
    #add_function(dcfile, 'parse_dcvalue', retval('bamboo::Buffer'),
    #             [param('const bamboo::Type *', 'type', transfer_ownership = False),
    #              param('std::string', 'formattedValue'), param('bool&', 'isError')])

    bamboo.generate(file_)
Example #5
0
def register_types(module):
    root_module = module.get_root()

    submodule = SubModule('torrent_error_type', parent=root_module)
    submodule.add_enum('tr_stat_errtype',
                       [('OK', 'TR_STAT_OK'),
                        ('TRACKER_WARNING', 'TR_STAT_TRACKER_WARNING'),
                        ('TRACKER_ERROR', 'TR_STAT_TRACKER_ERROR'),
                        ('LOCAL_ERROR', 'TR_STAT_LOCAL_ERROR')])

    submodule = SubModule('torrent_activity', parent=root_module)
    submodule.add_enum('tr_torrent_activity',
                       [('STOPPED', 'TR_STATUS_STOPPED'),
                        ('CHECK_WAIT', 'TR_STATUS_CHECK_WAIT'),
                        ('CHECK', 'TR_STATUS_CHECK'),
                        ('DOWNLOAD_WAIT', 'TR_STATUS_DOWNLOAD_WAIT'),
                        ('DOWNLOAD', 'TR_STATUS_DOWNLOAD'),
                        ('SEED_WAIT', 'TR_STATUS_SEED_WAIT'),
                        ('SEED', 'TR_STATUS_SEED')])

    submodule = SubModule('tracker_state', parent=root_module)
    submodule.add_enum('tr_tracker_state',
                       [('INACTIVE', 'TR_TRACKER_INACTIVE'),
                        ('WAITING', 'TR_TRACKER_WAITING'),
                        ('QUEUED', 'TR_TRACKER_QUEUED'),
                        ('ACTIVE', 'TR_TRACKER_ACTIVE')])

    submodule = SubModule('scheduled_days', parent=root_module)
    submodule.add_enum('tr_sched_day', [('SUN', 'TR_SCHED_SUN'),
                                        ('MON', 'TR_SCHED_MON'),
                                        ('TUES', 'TR_SCHED_TUES'),
                                        ('WED', 'TR_SCHED_WED'),
                                        ('THURS', 'TR_SCHED_THURS'),
                                        ('FRI', 'TR_SCHED_FRI'),
                                        ('SAT', 'TR_SCHED_SAT'),
                                        ('WEEKDAY', 'TR_SCHED_WEEKDAY'),
                                        ('WEEKEND', 'TR_SCHED_WEEKEND'),
                                        ('ALL', 'TR_SCHED_ALL')])

    submodule = SubModule('encryption_mode', parent=root_module)
    submodule.add_enum('tr_encryption_mode',
                       [('CLEAR_PREFERRED', 'TR_CLEAR_PREFERRED'),
                        ('ENCRYPTION_PREFERRED', 'TR_ENCRYPTION_PREFERRED'),
                        ('ENCRYPTION_REQUIRED', 'TR_ENCRYPTION_REQUIRED')])

    submodule = SubModule('direction', parent=root_module)
    submodule.add_enum('tr_direction',
                       [('CLIENT_TO_PEER', 'TR_CLIENT_TO_PEER'),
                        ('UP', 'TR_UP'),
                        ('PEER_TO_CLIENT', 'TR_PEER_TO_CLIENT'),
                        ('DOWN', 'TR_DOWN')])

    submodule = SubModule('ratio_limit', parent=root_module)
    submodule.add_enum('tr_ratiolimit',
                       [('GLOBAL', 'TR_RATIOLIMIT_GLOBAL'),
                        ('SINGLE', 'TR_RATIOLIMIT_SINGLE'),
                        ('UNLIMITED', 'TR_RATIOLIMIT_UNLIMITED')])

    submodule = SubModule('idle_limit', parent=root_module)
    submodule.add_enum('tr_idlelimit',
                       [('GLOBAL', 'TR_IDLELIMIT_GLOBAL'),
                        ('SINGLE', 'TR_IDLELIMIT_SINGLE'),
                        ('UNLIMITED', 'TR_IDLELIMIT_UNLIMITED')])

    submodule = SubModule('preallocation_mode', parent=root_module)
    submodule.add_enum('tr_preallocation_mode',
                       [('NONE', 'TR_PREALLOCATE_NONE'),
                        ('SPARCE', 'TR_PREALLOCATE_SPARSE'),
                        ('FULL', 'TR_PREALLOCATE_FULL')])

    submodule = SubModule('completeness', parent=root_module)
    submodule.add_enum('tr_completeness',
                       [('LEECH', 'TR_LEECH'), ('SEED', 'TR_SEED'),
                        ('PARTIAL_SEED', 'TR_PARTIAL_SEED')])

    submodule = SubModule('rpc_callback_type', parent=root_module)
    submodule.add_enum('tr_rpc_callback_type',
                       [('TORRENT_ADDED', 'TR_RPC_TORRENT_ADDED'),
                        ('TORRENT_STARTED', 'TR_RPC_TORRENT_STARTED'),
                        ('TORRENT_STOPPED', 'TR_RPC_TORRENT_STOPPED'),
                        ('TORRENT_REMOVING', 'TR_RPC_TORRENT_REMOVING'),
                        ('TORRENT_THRASHING', 'TR_RPC_TORRENT_TRASHING'),
                        ('TORRENT_CHANGED', 'TR_RPC_TORRENT_CHANGED'),
                        ('TORRENT_MOVED', 'TR_RPC_TORRENT_MOVED'),
                        ('SESSION_CHANGED', 'TR_RPC_SESSION_CHANGED'),
                        ('SESSION_QUEUE_POSITIONS_CHANGED',
                         'TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED'),
                        ('SESSION_CLOSE', 'TR_RPC_SESSION_CLOSE')])

    submodule = SubModule('rpc_callback_status', parent=root_module)
    submodule.add_enum('tr_rpc_callback_status',
                       [('OK', 'TR_RPC_OK'), ('NOREMOVE', 'TR_RPC_NOREMOVE')])

    submodule = SubModule('port_forwarding', parent=root_module)
    submodule.add_enum('tr_port_forwarding',
                       [('ERROR', 'TR_PORT_ERROR'),
                        ('UNMAPPED', 'TR_PORT_UNMAPPED'),
                        ('UNMAPPING', 'TR_PORT_UNMAPPING'),
                        ('MAPPING', 'TR_PORT_MAPPING'),
                        ('MAPPED', 'TR_PORT_MAPPED')])

    submodule = SubModule('msg_level', parent=root_module)
    submodule.add_enum('tr_msg_level', [('ERROR', 'TR_MSG_ERR'),
                                        ('INF', 'TR_MSG_INF'),
                                        ('DEBUG', 'TR_MSG_DBG')])

    submodule = SubModule('parse_result', parent=root_module)
    submodule.add_enum('tr_parse_result',
                       [('OK', 'TR_PARSE_OK'), ('ERROR', 'TR_PARSE_ERR'),
                        ('DUPLICATE', 'TR_PARSE_DUPLICATE')])

    submodule = SubModule('torrent_constructor_mode', parent=root_module)
    submodule.add_enum('tr_ctorMode', [('FALLBACK', 'TR_FALLBACK'),
                                       ('FORCE', 'TR_FORCE')])

    submodule = SubModule('location_state', parent=root_module)
    submodule.add_enum('',
                       [('MOVING', 'TR_LOC_MOVING'), ('DONE', 'TR_LOC_DONE'),
                        ('ERROR', 'TR_LOC_ERROR')])

    submodule = SubModule('priority', parent=root_module)
    submodule.add_enum('', [('LOW', 'TR_PRI_LOW'), ('NORMAL', 'TR_PRI_NORMAL'),
                            ('HIGH', 'TR_PRI_HIGH')])

    submodule = SubModule('peers_from_index', parent=root_module)
    submodule.add_enum('', [('INCOMING', 'TR_PEER_FROM_INCOMING'),
                            ('LPD', 'TR_PEER_FROM_LPD'),
                            ('TRACKER', 'TR_PEER_FROM_TRACKER'),
                            ('DHT', 'TR_PEER_FROM_DHT'),
                            ('PEX', 'TR_PEER_FROM_PEX'),
                            ('RESUME', 'TR_PEER_FROM_RESUME'),
                            ('LTEP', 'TR_PEER_FROM_LTEP')])

    submodule = SubModule('benc_serialization_mode', parent=root_module)
    submodule.add_enum('tr_fmt_mode', [('BENC', 'TR_FMT_BENC'),
                                       ('JSON', 'TR_FMT_JSON'),
                                       ('JSON_LEAN', 'TR_FMT_JSON_LEAN')])

    submodule = SubModule('benc_type', parent=root_module)
    submodule.add_enum('', [('INT', 'TR_TYPE_INT'), ('STRING', 'TR_TYPE_STR'),
                            ('LIST', 'TR_TYPE_LIST'), ('DICT', 'TR_TYPE_DICT'),
                            ('BOOL', 'TR_TYPE_BOOL'),
                            ('REAL', 'TR_TYPE_REAL')])
    ## tr_info.cc
    module.begin_section('tr_info')
    module.add_struct('tr_info',
                      no_constructor=True,
                      no_copy=True,
                      memory_policy=TrFreeFunctionPolicy('tr_metainfoFree'),
                      custom_name='TorrentInfo')

    module.add_struct('tr_file',
                      no_constructor=True,
                      no_copy=True,
                      custom_name='File')

    module.add_struct('tr_piece',
                      no_constructor=True,
                      no_copy=True,
                      custom_name='FilePiece')

    module.add_struct('tr_tracker_info',
                      no_constructor=True,
                      no_copy=True,
                      custom_name='TrackerInfo')

    module.add_struct('tr_tracker_stat',
                      no_constructor=True,
                      no_copy=True,
                      free_function='tr_free',
                      custom_name='TrackerStats')
    module.end_section('tr_info')

    ## tr_torrent.cc
    module.begin_section('tr_torrent')
    torrent = module.add_struct(
        'tr_torrent',
        no_constructor=True,
        no_copy=True,
        memory_policy=TrFreeFunctionPolicy('tr_torrentFree'),
        custom_name='Torrent')
    #torrent.cannot_be_constructed = "use factory function Session.torrent_new()"

    module.add_struct('tr_ctor',
                      no_constructor=True,
                      no_copy=True,
                      memory_policy=TrFreeFunctionPolicy('tr_ctorFree'),
                      custom_name='TorrentConstructor')

    module.add_struct('tr_stat',
                      no_constructor=True,
                      no_copy=True,
                      memory_policy=TrFreeFunctionPolicy('tr_free'),
                      custom_name='TorrentStats')

    module.add_struct('tr_peer_stat',
                      no_constructor=True,
                      no_copy=True,
                      memory_policy=TrFreeFunctionPolicy('tr_free'),
                      custom_name='PeerStats')

    module.add_struct('tr_file_stat',
                      no_constructor=True,
                      no_copy=True,
                      free_function='tr_free',
                      custom_name='FileStats')
    module.end_section('tr_torrent')

    ## tr_session.cc
    module.begin_section('tr_session')
    module.add_struct('tr_session',
                      no_constructor=True,
                      no_copy=True,
                      memory_policy=TrFreeFunctionPolicy('tr_sessionClose'),
                      custom_name='Session')

    module.add_struct('tr_session_stats',
                      no_constructor=True,
                      no_copy=True,
                      memory_policy=cppclass.FreeFunctionPolicy('tr_free'),
                      custom_name='SessionStats')

    module.add_struct('tr_msg_list',
                      no_constructor=True,
                      no_copy=True,
                      free_function='tr_freeMessageList',
                      custom_name='Message')
    module.end_section('tr_session')

    ## tr_benc.cc
    module.begin_section('tr_benc')
    submodule = SubModule('bencode', parent=root_module)
    benc = submodule.add_struct('Benc',
                                no_constructor=True,
                                no_copy=True,
                                memory_policy=BencMemoryPolicy())
    benc.full_name = 'tr_benc'

    submodule.add_struct('BencInt',
                         parent=benc,
                         no_constructor=True,
                         no_copy=True).full_name = 'tr_benc'

    submodule.add_struct('BencString',
                         parent=benc,
                         no_constructor=True,
                         no_copy=True).full_name = 'tr_benc'

    submodule.add_struct('BencList',
                         parent=benc,
                         no_constructor=True,
                         no_copy=True).full_name = 'tr_benc'

    submodule.add_struct('BencDict',
                         parent=benc,
                         no_constructor=True,
                         no_copy=True).full_name = 'tr_benc'

    submodule.add_struct('BencBool',
                         parent=benc,
                         no_constructor=True,
                         no_copy=True).full_name = 'tr_benc'

    submodule.add_struct('BencReal',
                         parent=benc,
                         no_constructor=True,
                         no_copy=True).full_name = 'tr_benc'
    module.end_section('tr_benc')

    typehandlers.add_type_alias('uint32_t', 'tr_piece_index_t')
    typehandlers.add_type_alias('uint32_t', 'tr_file_index_t')
    typehandlers.add_type_alias('uint32_t*', 'tr_file_index_t*')
    typehandlers.add_type_alias('long int', 'time_t')
    typehandlers.add_type_alias('int8_t', 'tr_priority_t')
    typehandlers.add_type_alias('uint16_t', 'tr_port')