Ejemplo n.º 1
0
Archivo: rpc.py Proyecto: spirali/kaira
def write_client_init_function(builder):
    builder.line("void calib_init(int argc, char **argv)")
    builder.block_begin()
    builder.line("client.connect();")

    for net in builder.project.nets:
        declaration = library.get_library_function_declaration(net)
        builder.line("client.register_function({0}, {1}, &${2}_id);",
                     writer.const_string(net.name),
                     writer.const_string(declaration), net.name)
    builder.block_end()
Ejemplo n.º 2
0
Archivo: rpc.py Proyecto: Kobzol/kaira
def write_client_init_function(builder):
    builder.line("void calib_init(int argc, char **argv)")
    builder.block_begin()
    builder.line("client.connect();")

    for net in builder.project.nets:
        declaration = library.get_library_function_declaration(net)
        builder.line("client.register_function({0}, {1}, &${2}_id);",
                writer.const_string(net.name),
                writer.const_string(declaration),
                net.name)
    builder.block_end()
Ejemplo n.º 3
0
Archivo: rpc.py Proyecto: spirali/kaira
def write_server_main(builder):
    builder.line("int main(int argc, char **argv)")
    builder.block_begin()
    builder.line("calib_init(argc, argv);")
    builder.line("CaServer server;")

    for net in builder.project.nets:
        declaration = library.get_library_function_declaration(net)
        builder.line("server.register_function({0},{1},{2});",
                     writer.const_string(net.name),
                     writer.const_string(declaration), net.name)
    builder.line("server.run();")
    builder.line("return 0;")
    builder.block_end()
Ejemplo n.º 4
0
Archivo: rpc.py Proyecto: Kobzol/kaira
def write_server_main(builder):
    builder.line("int main(int argc, char **argv)")
    builder.block_begin()
    builder.line("calib_init(argc, argv);")
    builder.line("CaServer server;")

    for net in builder.project.nets:
        declaration = library.get_library_function_declaration(net)
        builder.line("server.register_function({0},{1},{2});",
                  writer.const_string(net.name),
                  writer.const_string(declaration),
                  net.name)
    builder.line("server.run();")
    builder.line("return 0;")
    builder.block_end()
Ejemplo n.º 5
0
def write_transition_forward(builder, tr):
    if tr.code is not None:
        write_vars_struct(builder, tr)
        write_transition_user_function(builder, tr, forward=True)

    write_tokens_struct(builder, tr)

    class_name = "Transition_{0.id}".format(tr)
    builder.write_class_head(class_name, "ca::TransitionDef")
    builder.write_constructor(class_name,
                              "",
                              [ "ca::TransitionDef({0}, {1}, {2}, {3})".format(
                                    tr.id,
                                    const_string(tr.name),
                                    const_boolean(not tr.has_code()),
                                    tr.priority) ])
    builder.write_method_end()
    builder.line("ca::FireResult full_fire(ca::ThreadBase *thread, ca::NetBase *net);")
    builder.line("void* fire_phase1(ca::ThreadBase *thread, ca::NetBase *net);")
    builder.line("void fire_phase2(ca::ThreadBase *thread, ca::NetBase *net, void *data);")
    builder.line("void fire_phase2_ro_binding"
                 "(ca::ThreadBase *thread, ca::NetBase *net, void *data);")
    builder.line("void cleanup_binding(void *data);")
    builder.line("bool is_enable(ca::ThreadBase *thread, ca::NetBase *net);")
    if builder.pack_bindings:
        builder.line("void pack_binding(ca::Packer &packer, void *data);")
        builder.line("ca::FireResult full_fire_with_binding(ca::ThreadBase *thread, ca::NetBase *net, ca::Packer &$packer);")
    builder.write_class_end()
    builder.line("static Transition_{0.id} transition_{0.id};",
        tr, const_boolean(not tr.has_code()))
    builder.emptyline();
Ejemplo n.º 6
0
def write_parameters(builder):
    for p in builder.project.get_parameters():
        policy = "ca::PARAMETER_" + p.get_policy().upper()
        if p.get_policy() == "mandatory":
            default = ""
        else:
            default = ", " + p.default
        if p.get_type() == "int":
            builder.line("ca::ParameterInt param::{0}({1}, {2}, {3}{4});",
                         p.name,
                         const_string(p.name),
                         const_string(p.description),
                         policy,
                         default)
        elif p.get_type() == "double":
            builder.line("ca::ParameterDouble param::{0}({1}, {2}, {3}{4});",
                         p.name,
                         const_string(p.name),
                         const_string(p.description),
                         policy,
                         default)
        elif p.get_type() == "std::string":
            builder.line("ca::ParameterString param::{0}({1}, {2}, {3}{4});",
                         p.name,
                         const_string(p.name),
                         const_string(p.description),
                         policy,
                         default)
        else:
            utils.PtpException("Invalid type '{0}' for parameter '{1}'".format(
                                    p.get_type(), p.name))
Ejemplo n.º 7
0
def write_main_setup(builder, init_function="ca::init", start_process=True):
    builder.line("ca::project_description({0});", const_string(builder.project.description))
    builder.line("std::vector<ca::Parameter*> parameters;")
    for p in builder.project.get_parameters():
        builder.line("parameters.push_back(&param::{0});", p.get_name())

    builder.emptyline()
    builder.line("{0}(argc, argv, parameters, {1});", init_function, writer.const_boolean(builder.project.tracing))
    builder.emptyline()

    for net in builder.project.nets:
        write_register_net(builder, net)

    defs = ["def_{0.id}".format(net) for net in builder.project.nets]
    builder.line("ca::NetDef *defs[] = {{{0}}};", ",".join(defs))
    builder.line("ca::setup({0}, defs, {1});", len(defs), const_boolean(start_process))
Ejemplo n.º 8
0
def write_main_setup(builder, init_function="ca::init", start_process=True):
    builder.line("ca::project_description({0});",
                 const_string(builder.project.description))
    builder.line("std::vector<ca::Parameter*> parameters;")
    for p in builder.project.get_parameters():
        builder.line("parameters.push_back(&param::{0});", p.get_name())

    builder.emptyline()
    builder.line("{0}(argc, argv, parameters, {1});", init_function,
                 writer.const_boolean(builder.project.tracing))
    builder.emptyline()

    for net in builder.project.nets:
        write_register_net(builder, net)

    defs = ["def_{0.id}".format(net) for net in builder.project.nets]
    builder.line("ca::NetDef *defs[] = {{{0}}};", ",".join(defs))
    builder.line("ca::setup({0}, defs, {1});", len(defs),
                 const_boolean(start_process))
Ejemplo n.º 9
0
def write_transition_forward(builder, tr):
    if tr.code is not None:
        write_vars_struct(builder, tr)
        write_transition_user_function(builder, tr, forward=True)

    write_tokens_struct(builder, tr)

    class_name = "Transition_{0.id}".format(tr)
    builder.write_class_head(class_name, "ca::TransitionDef")
    if tr.collective:
        transition_type = "ca::TRANSITION_COLLECTIVE"
    elif tr.has_code():
        transition_type = "ca::TRANSITION_NORMAL"
    else:
        transition_type = "ca::TRANSITION_IMMEDIATE"

    builder.write_constructor(class_name, "", [
        "ca::TransitionDef({0}, {1}, {2}, {3})".format(
            tr.id, const_string(tr.name), transition_type, tr.priority)
    ])
    builder.write_method_end()
    builder.line(
        "ca::FireResult full_fire(ca::ThreadBase *thread, ca::NetBase *net);")
    builder.line(
        "ca::Binding* fire_phase1(ca::ThreadBase *thread, ca::NetBase *net);")
    builder.line(
        "void fire_phase2(ca::ThreadBase *thread, ca::NetBase *net, ca::Binding *data);"
    )
    builder.line("bool is_enable(ca::ThreadBase *thread, ca::NetBase *net);")
    if tr.collective:
        builder.line("bool is_blocked(ca::Binding *data);")
    if builder.pack_bindings:
        builder.line(
            "void pack_binding(ca::Packer &packer, ca::Binding *data);")
        builder.line(
            "ca::FireResult full_fire_with_binding(ca::ThreadBase *thread, ca::NetBase *net, ca::Packer &$packer);"
        )
    builder.write_class_end()
    builder.line("static Transition_{0.id} transition_{0.id};", tr,
                 const_boolean(not tr.has_code()))
    builder.emptyline()
Ejemplo n.º 10
0
def write_transition_forward(builder, tr):
    if tr.code is not None:
        write_vars_struct(builder, tr)
        write_transition_user_function(builder, tr, forward=True)

    write_tokens_struct(builder, tr)

    class_name = "Transition_{0.id}".format(tr)
    builder.write_class_head(class_name, "ca::TransitionDef")
    if tr.collective:
        transition_type = "ca::TRANSITION_COLLECTIVE"
    elif tr.has_code():
        transition_type = "ca::TRANSITION_NORMAL"
    else:
        transition_type = "ca::TRANSITION_IMMEDIATE"

    builder.write_constructor(class_name,
                              "",
                              [ "ca::TransitionDef({0}, {1}, {2}, {3})".format(
                                    tr.id,
                                    const_string(tr.name),
                                    transition_type,
                                    tr.priority) ])
    builder.write_method_end()
    builder.line("ca::FireResult full_fire(ca::ThreadBase *thread, ca::NetBase *net);")
    builder.line("ca::Binding* fire_phase1(ca::ThreadBase *thread, ca::NetBase *net);")
    builder.line("void fire_phase2(ca::ThreadBase *thread, ca::NetBase *net, ca::Binding *data);")
    builder.line("bool is_enable(ca::ThreadBase *thread, ca::NetBase *net);")
    if tr.collective:
        builder.line("bool is_blocked(ca::Binding *data);")
    if builder.pack_bindings:
        builder.line("void pack_binding(ca::Packer &packer, ca::Binding *data);")
        builder.line("ca::Binding* unpack_binding(ca::Unpacker &unpacker);")
        builder.line("ca::FireResult full_fire_with_binding(ca::ThreadBase *thread, ca::NetBase *net, ca::Packer &$packer);")
    builder.write_class_end()
    builder.line("static Transition_{0.id} transition_{0.id};",
        tr, const_boolean(not tr.has_code()))
    builder.emptyline();