Exemple #1
0
sc_result sc_helper_init(sc_memory_context const * ctx)
{
    g_message("Initialize sc-helper");

    _init_keynodes_str();

    sc_keynodes = g_new0(sc_addr, SC_KEYNODE_COUNT);

    if (resolve_nrel_system_identifier(ctx) != SC_RESULT_OK)
    {
        g_message("Can't resovle nrel_system_identifier node. Create the last one");

        sc_addr addr = sc_memory_node_new(ctx, sc_type_const | sc_type_node_norole);
        sc_addr link = sc_memory_link_new(ctx);
        sc_stream *stream = sc_stream_memory_new(keynodes_str[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER],
                                                 (sc_uint)(sizeof(sc_uchar) * strlen(keynodes_str[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER])),
                                                 SC_STREAM_FLAG_READ, SC_FALSE);
        sc_memory_set_link_content(ctx, link, stream);
        sc_stream_free(stream);

        sc_addr arc = sc_memory_arc_new(ctx, sc_type_arc_common | sc_type_const, addr, link);
        sc_memory_arc_new(ctx, sc_type_arc_pos_const_perm, addr, arc);
        sc_keynodes[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER] = addr;
    }

    sc_helper_is_initialized = SC_TRUE;

    return SC_RESULT_OK;
}
Exemple #2
0
// simple sc-links creation
gpointer create_link_thread(gpointer data)
{
    sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8));
    int count = GPOINTER_TO_INT(data);
    int result = count;
    for (int i = 0; i < count; ++i)
    {
        sc_addr addr = sc_memory_link_new(ctx);
        if (SC_ADDR_IS_EMPTY(addr))
            result = i + 1;
    }

    sc_memory_context_free(ctx);

    return GINT_TO_POINTER(result);
}
Exemple #3
0
scp_result check_link_parameter_1(sc_memory_context *context, const sc_char *operator_name, scp_operand *param1)
{
    if (SCP_ASSIGN == param1->param_type)
    {
        param1->addr = sc_memory_link_new(context);
        //! TODO Add numeric class for link
    }
    else
    {
        if (SC_FALSE == sc_memory_is_element(context, param1->addr))
        {
            return print_error(operator_name, "Parameter 1 has not value");
        }
        if (check_type(context, param1->addr, scp_type_link) == SCP_RESULT_FALSE)
        {
            return print_error(operator_name, "Parameter 1 must have link type");
        }
    }
    return SCP_RESULT_TRUE;
}
Exemple #4
0
sctpErrorCode sctpCommand::processCreateLink(quint32 cmdFlags, quint32 cmdId, QDataStream *params, QIODevice *outDevice)
{
    Q_UNUSED(cmdFlags);

    sc_addr addr = sc_memory_link_new();

    // send result
    sctpErrorCode result;
    if (SC_ADDR_IS_NOT_EMPTY(addr))
    {
        writeResultHeader(SCTP_CMD_CREATE_NODE, cmdId, SCTP_RESULT_OK, sizeof(addr), outDevice);
        outDevice->write((const char*)&addr, sizeof(addr));

        result = SCTP_ERROR_NO;
    }else
    {
        writeResultHeader(SCTP_CMD_CREATE_NODE, cmdId, SCTP_RESULT_FAIL, 0, outDevice);
        result = SCTP_ERROR;
    }

    return result;
}
Exemple #5
0
void test5()
{
    sc_uint32 i;
    sc_addr addr;
    sc_stream *stream = 0;

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    timer = g_timer_new();

    printf("Create %d links\n", link_append_count);

    //g_snprintf(test, 1024, "../CMakeLists.txt");
    g_timer_reset(timer);
    g_timer_start(timer);
    for (i = 0; i < link_append_count; i++)
    {
        addr = sc_memory_link_new();

        printf("Created sc-link: seg=%d, offset=%d, content=%d\n", addr.seg, addr.offset, i);

        stream = sc_stream_memory_new((char*)&i, sizeof(i), SC_STREAM_READ, SC_FALSE);
        sc_memory_set_link_content(addr, stream);
        sc_stream_free(stream);
    }

    g_timer_stop(timer);

    printf("Created links: %d\n", link_append_count);
    printf("Links per second: %f\n", link_append_count / g_timer_elapsed(timer, 0));

    printf("Segments count: %d\n", sc_storage_get_segments_count());
    print_storage_statistics();

    g_timer_destroy(timer);
}
bool GwfTranslator::processString(const String &data)
{
    tinyxml2::XMLDocument doc;
    tinyxml2::XMLError error = doc.Parse(data.c_str());

    if (error != tinyxml2::XML_SUCCESS)
    {
        THROW_EXCEPT(Exception::ERR_PARSE,
                     doc.GetErrorStr2(),
                     mParams.fileName,
                     -1);
    }

    tinyxml2::XMLElement *root = doc.FirstChildElement("GWF");
    if (!root)
    {
        THROW_EXCEPT(Exception::ERR_PARSE,
                     "Can't find root element",
                     mParams.fileName,
                     -1);
    }
    root = root->FirstChildElement("staticSector");
    if (!root)
    {
        THROW_EXCEPT(Exception::ERR_PARSE,
                     "Cna't find static sector",
                     mParams.fileName,
                     -1);
    }

    // collect elements
    std::vector<tinyxml2::XMLElement*> nodes;
    std::vector<tinyxml2::XMLElement*> edges;
    std::vector<tinyxml2::XMLElement*> buses;
    std::vector<tinyxml2::XMLElement*> all;

    static std::string s_arc = "arc";
    static std::string s_pair = "pair";
    static std::string s_bus = "bus";

    tinyxml2::XMLElement *el = root->FirstChildElement();
    while (el)
    {
        all.push_back(el);
        if (el->Name() == s_arc || el->Name() == s_pair)
            edges.push_back(el);
        else if (el->Name() == s_bus)
            buses.push_back(el);
        else
            nodes.push_back(el);

        el = el->NextSiblingElement();
    }

    static std::string s_node = "node";
    static std::string s_contour = "contour";

    tStringAddrMap id_map;
    tStringAddrMap::iterator itId;

    // create all nodes
    std::vector<tinyxml2::XMLElement*>::iterator it, itEnd = nodes.end();
    for (it = nodes.begin(); it != itEnd; ++it)
    {
        el = *it;

        String idtf = el->Attribute("idtf");
        String id = el->Attribute("id");
        sc_addr addr;

        itId = id_map.find(id);
        if (itId != id_map.end())
            continue;

        if (idtf.size() > 0)
        {
            if (getScAddr(idtf, addr))
            {
                id_map[id] = addr;
                continue;    // skip elements that already exists
            }
        }

        if (el->Name() == s_contour)
        {
            addr = sc_memory_node_new(sc_type_const | sc_type_node_struct);
            appendScAddr(addr, idtf);
        } else
        {
            tinyxml2::XMLElement *content = el->FirstChildElement("content");
            if (!content)
            {
                THROW_EXCEPT(Exception::ERR_PARSE,
                             "There are no child content for node with id=" + id,
                             mParams.fileName,
                             -1);
            }

            if (content->IntAttribute("type") == 0)
            {
                addr = sc_memory_node_new(convertType(el->Attribute("type")));
                appendScAddr(addr, idtf);
            } else
            {
                // need to create link
                addr = sc_memory_link_new();
                // setup content
                String data = content->GetText();

                if (content->IntAttribute("type") == 4)
                    data = base64_decode(data);

                sc_stream *stream = sc_stream_memory_new(data.c_str(), data.size(), SC_STREAM_READ, SC_FALSE);
                sc_memory_set_link_content(addr, stream);
                sc_stream_free(stream);

                if (mParams.autoFormatInfo)
                {
                    String ext = StringUtil::getFileExtension(content->Attribute("file_name"));
                    if (!ext.empty())
                        generateFormatInfo(addr, ext);
                }
            }
        }

        if (!idtf.empty())
            sc_helper_set_system_identifier(addr, idtf.c_str(), idtf.size());

        id_map[id] = addr;
    }

    // process buses
    itEnd = buses.end();
    for (it = buses.begin(); it != itEnd; ++it)
    {
        el = *it;

        tStringAddrMap::iterator itOwner = id_map.find(el->Attribute("owner"));
        if (itOwner == id_map.end())
            continue;

        id_map[el->Attribute("id")] = itOwner->second;
    }

    // now create edges
    bool created = true;
    while (created)
    {
        created = false;

        itEnd = edges.end();
        for (it = edges.begin(); it != itEnd; ++it)
        {
            el = *it;

            sc_addr addr;
            String id = el->Attribute("id");
            String idtf = el->Attribute("idtf");

            if (id_map.find(id) != id_map.end())
                continue;

            if (getScAddr(idtf, addr))
                continue;

            // get begin and end elements
            tStringAddrMap::iterator itB = id_map.find(el->Attribute("id_b"));
            if (itB == id_map.end())
                continue;

            tStringAddrMap::iterator itE = id_map.find(el->Attribute("id_e"));
            if (itE == id_map.end())
                continue;

            // create arc
            created = true;
            addr = sc_memory_arc_new(convertType(el->Attribute("type")), itB->second, itE->second);
            appendScAddr(addr, idtf);
            id_map[id] = addr;

            if (!idtf.empty())
                sc_helper_set_system_identifier(addr, idtf.c_str(), idtf.size());
        }
    }

    // now append elemnts into contours
    itEnd = all.end();
    for (it = all.begin(); it != itEnd; ++it)
    {
        el = *it;

        tStringAddrMap::iterator itSelf = id_map.find(el->Attribute("id"));
        if (itSelf == id_map.end())
            continue;

        tStringAddrMap::iterator itP = id_map.find(el->Attribute("parent"));
        if (itP == id_map.end())
            continue;

        sc_memory_arc_new(sc_type_arc_pos_const_perm, itP->second, itSelf->second);
    }

    return false;
}
sc_addr SCsTranslator::createScAddr(sElement *el)
{
    sc_addr addr;
    SC_ADDR_MAKE_EMPTY(addr);

    if (el->type & sc_type_node)
        addr = sc_memory_node_new(mContext, el->type);
    else if (el->type & sc_type_link)
    {
        addr = sc_memory_link_new(mContext);

        // setup link content
        if (el->link_is_file)
        {
            String file_path;
            if (_getAbsFilePath(el->file_path, file_path))
            {
                sc_stream *stream = sc_stream_file_new(file_path.c_str(), SC_STREAM_FLAG_READ);
                if (stream)
                {
                    sc_memory_set_link_content(mContext, addr, stream);
                    sc_stream_free(stream);
                } else
                {
                    THROW_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
                                 "Can't open file " + el->file_path,
                                 mParams.fileName,
                                 -1);
                }
            } else
            {
                THROW_EXCEPT(Exception::ERR_INVALID_PARAMS,
                             "Unsupported link type  " + el->file_path,
                             mParams.fileName,
                             -1);
            }

        } else
        {           
            sc_stream *stream = sc_stream_memory_new(el->link_data.data.data(), (sc_uint)el->link_data.data.size(), SC_STREAM_FLAG_READ, SC_FALSE);
            sc_memory_set_link_content(mContext, addr, stream);
            sc_stream_free(stream);
        }


        // generate format information
        if (mParams.autoFormatInfo)
        {
            if (el->link_is_file)
            {
				size_t n = el->file_path.find_last_of(".");
                if (n != String::npos)
					generateFormatInfo(addr, el->file_path.substr(n + 1));
            }
        }
    }
    else
    {
        assert(el->arc_src && el->arc_trg);
        if (SC_ADDR_IS_EMPTY(el->arc_src->addr) || SC_ADDR_IS_EMPTY(el->arc_trg->addr))
            return addr;
        addr = sc_memory_arc_new(mContext, el->type, el->arc_src->addr, el->arc_trg->addr);
    }

    el->addr = addr;

    return addr;
}
Exemple #8
0
sc_result sc_helper_set_system_identifier(sc_memory_context const * ctx, sc_addr addr, const sc_char* data, sc_uint32 len)
{
    sc_iterator5 *it5 = 0;
    sc_addr *results = 0;
    sc_uint32 results_count = 0;
    sc_stream *stream = 0;
    sc_uint32 i = 0;
    sc_addr idtf_addr, arc_addr;

    SC_ADDR_MAKE_EMPTY(idtf_addr)
    g_assert(sc_keynodes != 0);

    // check if specified system identifier already used
    stream = sc_stream_memory_new(data, sizeof(sc_char) * len, SC_STREAM_FLAG_READ, SC_FALSE);
    if (sc_memory_find_links_with_content(ctx, stream, &results, &results_count) == SC_RESULT_OK)
    {
        for (i = 0; i < results_count; i++)
        {
            it5 = sc_iterator5_a_a_f_a_f_new(ctx,
                                             0,
                                             sc_type_arc_common | sc_type_const,
                                             results[i],
                                             sc_type_arc_pos_const_perm,
                                             sc_keynodes[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER]);
            if (sc_iterator5_next(it5))
            {
                // don't foget to free allocated memory before return error
                sc_iterator5_free(it5);
                sc_stream_free(stream);
                g_free(results);
                return SC_RESULT_ERROR_INVALID_PARAMS;
            }

            sc_iterator5_free(it5);
        }

        g_free(results);
    }

    // if there are no elements with specified system identitifier, then we can use it
    idtf_addr = sc_memory_link_new(ctx);
    if (sc_memory_set_link_content(ctx, idtf_addr, stream) != SC_RESULT_OK)
    {
        sc_stream_free(stream);
        return SC_RESULT_ERROR;
    }

    // we doesn't need link data anymore
    sc_stream_free(stream);

    // setup new system identifier
    arc_addr = sc_memory_arc_new(ctx, sc_type_arc_common | sc_type_const, addr, idtf_addr);
    if (SC_ADDR_IS_EMPTY(arc_addr))
        return SC_RESULT_ERROR;

    arc_addr = sc_memory_arc_new(ctx, sc_type_arc_pos_const_perm, sc_keynodes[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER], arc_addr);
    if (SC_ADDR_IS_EMPTY(arc_addr))
        return SC_RESULT_ERROR;

    return SC_RESULT_OK;
}
Exemple #9
0
ScAddr ScMemoryContext::createLink()
{
    check_expr(isValid());
	return ScAddr(sc_memory_link_new(mContext));
}