scp_result resolve_numbers_1_2(const sc_char *operator_name, scp_operand *param1, scp_operand *param2, double *num1, double *num2) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data1, *data2; if (SCP_ASSIGN == param1->param_type || SCP_ASSIGN == param2->param_type) { return print_error(operator_name, "Both parameters must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(param1->addr)) { return print_error(operator_name, "Parameter 1 has not value"); } if (SC_FALSE == sc_memory_is_element(param2->addr)) { return print_error(operator_name, "Parameter 2 has not value"); } if (check_type(param1->addr, scp_type_link) == SCP_RESULT_FALSE || check_type(param2->addr, scp_type_link) == SCP_RESULT_FALSE) { return print_error(operator_name, "Both parameters must have link type"); } if (SCP_RESULT_FALSE == check_numeric_type(param1->addr) || SCP_RESULT_FALSE == check_numeric_type(param2->addr)) { return print_error(operator_name, "Both parameters must have numeric format"); } if (sc_memory_get_link_content(param1->addr, &stream) != SC_RESULT_OK) { return print_error(operator_name, "Parameter 1 content reading error"); } sc_stream_get_length(stream, &length); data1 = calloc(length, sizeof(sc_char)); sc_stream_read_data(stream, data1, length, &read_length); sc_stream_free(stream); if (sc_memory_get_link_content(param2->addr, &stream) != SC_RESULT_OK) { return print_error(operator_name, "Parameter 2 content reading error"); } sc_stream_get_length(stream, &length); data2 = calloc(length, sizeof(sc_char)); sc_stream_read_data(stream, data2, length, &read_length); sc_stream_free(stream); (*num1) = atof(data1); (*num2) = atof(data2); free(data1); free(data2); return SCP_RESULT_TRUE; }
scp_result printL(scp_operand *param, sc_bool new_line) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; if (SC_FALSE == sc_memory_is_element(param->addr)) { return print_error("print", "Parameter has not value"); } /*if (SCP_RESULT_FALSE == check_type(param->addr, sc_type_link)) { return print_error("print", "Parameter is not an sc-link"); }*/ if (sc_memory_get_link_content(param->addr, &stream) != SC_RESULT_OK) { return print_error("print", "Content reading error"); } sc_stream_get_length(stream, &length); data = calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); data[length] = '\0'; printf("%s", data); if (SC_TRUE == new_line) { printf("\n"); } sc_stream_free(stream); free(data); return SCP_RESULT_TRUE; }
static scp_result resolve_string(sc_memory_context *context, const sc_char *operator_name, const sc_char *parameter_name, scp_operand *param, char **str) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; if (SCP_ASSIGN == param->param_type) { return print_parameter_error(operator_name, parameter_name, "must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(context, param->addr)) { return print_parameter_error(operator_name, parameter_name, "has not value"); } if (SCP_RESULT_FALSE == check_type(context, param->addr, scp_type_link)) { return print_parameter_error(operator_name, parameter_name, "must have link type"); } if (SCP_RESULT_FALSE == check_string_type(context, param->addr)) { return print_parameter_error(operator_name, parameter_name, "must have string format"); } if (SC_RESULT_OK != sc_memory_get_link_content(context, param->addr, &stream)) { return print_parameter_error(operator_name, parameter_name, "content reading error"); } sc_stream_get_length(stream, &length); // extra byte needed for string terminator, which is neither counted nor read from an sc_stream data = calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); sc_stream_free(stream); size_t str_length = strlen(data) + 1; *str = calloc(str_length, sizeof(sc_char)); memcpy(*str, data, str_length); free(data); return SCP_RESULT_TRUE; }
scp_result resolve_number(sc_memory_context *context, const sc_char *operator_name, const sc_char *parameter_name, scp_operand *param, double *num) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data1; if (SCP_ASSIGN == param->param_type) { return print_parameter_error(operator_name, parameter_name, "must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(context, param->addr)) { return print_parameter_error(operator_name, parameter_name, "has not value"); } if (SCP_RESULT_FALSE == check_type(context, param->addr, scp_type_link)) { return print_parameter_error(operator_name, parameter_name, "must have link type"); } if (SCP_RESULT_FALSE == check_numeric_type(context, param->addr)) { return print_parameter_error(operator_name, parameter_name, "must have numeric format"); } if (SC_RESULT_OK != sc_memory_get_link_content(context, param->addr, &stream)) { return print_parameter_error(operator_name, parameter_name, "content reading error"); } sc_stream_get_length(stream, &length); data1 = calloc(length, sizeof(sc_char)); sc_stream_read_data(stream, data1, length, &read_length); sc_stream_free(stream); *num = atof(data1); free(data1); return SCP_RESULT_TRUE; }
void printIdtf(sc_memory_context *context, sc_addr element) { sc_addr idtf; sc_type type; sc_memory_get_element_type(context, element, &type); if ((sc_type_node & type) == sc_type_node || (sc_type_link & type) == sc_type_link ) { if (SC_RESULT_OK == sc_helper_get_system_identifier(context, element, &idtf)) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; sc_memory_get_link_content(context, idtf, &stream); sc_stream_get_length(stream, &length); data = (sc_char *)calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); data[length] = '\0'; printf("%s", data); sc_stream_free(stream); free(data); } else { printf("%u|%u", element.seg, element.offset); } } else { sc_addr elem1, elem2; sc_memory_get_arc_begin(context, element, &elem1); sc_memory_get_arc_end(context, element, &elem2); printf("("); printIdtf(context, elem1); printf(" -> "); printIdtf(context, elem2); printf(")"); } }
sctpErrorCode sctpCommand::processGetLinkContent(quint32 cmdFlags, quint32 cmdId, QDataStream *params, QIODevice *outDevice) { sc_addr addr; sc_stream *stream = (sc_stream*)nullptr; sc_char data_buffer[1024]; sc_uint32 data_len = 0; sc_uint32 data_written = 0; sc_uint32 data_read = 0; Q_UNUSED(cmdFlags); Q_ASSERT(params != 0); // read sc-addr of sc-element from parameters if (params->readRawData((char*)&addr, sizeof(addr)) != sizeof(addr)) return SCTP_ERROR_CMD_READ_PARAMS; sctpResultCode resCode = (sc_memory_get_link_content(addr, &stream) == SC_RESULT_OK) ? SCTP_RESULT_OK : SCTP_RESULT_FAIL; if (resCode == SCTP_RESULT_OK) { if (sc_stream_get_length(stream, &data_len) != SC_RESULT_OK) { resCode = SCTP_RESULT_FAIL; sc_stream_free(stream); stream = (sc_stream*)nullptr; } } // send result writeResultHeader(SCTP_CMD_GET_LINK_CONTENT, cmdId, resCode, data_len, outDevice); if (resCode == SCTP_RESULT_FAIL) { if (stream != nullptr) sc_stream_free(stream); return SCTP_ERROR; } // write content data while (sc_stream_eof(stream) != SC_TRUE) { // if there are any error to read data, then // write null into output if (sc_stream_read_data(stream, data_buffer, 1024, &data_read) != SC_RESULT_OK) { if (data_written < data_len) { quint32 len = data_len - data_written; sc_char *data = new sc_char[len]; memset(data, 0, len); outDevice->write(data, len); delete []data; sc_stream_free(stream); return SCTP_ERROR; } } outDevice->write(data_buffer, data_read); data_written += data_read; } Q_ASSERT(data_written == data_len); if (resCode == SCTP_RESULT_OK) sc_stream_free(stream); return SCTP_ERROR_NO; }
scp_result printEl(scp_operand *param) { sc_addr element = param->addr; sc_addr addr2, addr3; sc_addr idtf; sc_iterator3 *it = nullptr; sc_uint32 out_c = 0, in_c = 0; if (SC_FALSE == sc_memory_is_element(param->addr)) { return print_error("printEl", "Parameter has not value"); } if (SC_RESULT_OK == sc_helper_get_system_identifier(element, &idtf)) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; sc_memory_get_link_content(idtf, &stream); sc_stream_get_length(stream, &length); data = calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); data[length] = '\0'; printf("\nPrint element: %s =\n", data); sc_stream_free(stream); free(data); } else { printf("\nPrint element: %u|%u =\n", element.seg, element.offset); } it = sc_iterator3_a_a_f_new(0, 0, element); if (it == 0) { return SCP_RESULT_ERROR; } printf("Input arcs:\n"); while (SC_TRUE == sc_iterator3_next(it)) { in_c++; addr2 = sc_iterator3_value(it, 0); addr3 = sc_iterator3_value(it, 1); if (SC_RESULT_OK == sc_helper_get_system_identifier(addr3, &idtf)) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; sc_memory_get_link_content(idtf, &stream); sc_stream_get_length(stream, &length); data = calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); data[length] = '\0'; if (SCP_RESULT_TRUE == check_type(addr3, scp_type_arc_access)) { printf("\t%s <- ", data); } else { printf("\t%s <= ", data); } sc_stream_free(stream); free(data); } else { if (SCP_RESULT_TRUE == check_type(addr3, scp_type_arc_access)) { printf("\t%u|%u <- ", addr3.seg, addr3.offset); } else { printf("\t%u|%u <= ", addr3.seg, addr3.offset); } } if (SC_RESULT_OK == sc_helper_get_system_identifier(addr2, &idtf)) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; sc_memory_get_link_content(idtf, &stream); sc_stream_get_length(stream, &length); data = calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); data[length] = '\0'; printf("%s;\n", data); sc_stream_free(stream); free(data); } else { printf("%u|%u;\n", addr2.seg, addr2.offset); } } sc_iterator3_free(it); printf("Total input arcs: %d\n", in_c); it = sc_iterator3_f_a_a_new(element, 0, 0); if (it == 0) { return SCP_RESULT_ERROR; } printf("Output arcs:\n"); while (SC_TRUE == sc_iterator3_next(it)) { out_c++; addr2 = sc_iterator3_value(it, 1); addr3 = sc_iterator3_value(it, 2); if (SC_RESULT_OK == sc_helper_get_system_identifier(addr2, &idtf)) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; sc_memory_get_link_content(idtf, &stream); sc_stream_get_length(stream, &length); data = calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); data[length] = '\0'; if (SCP_RESULT_TRUE == check_type(addr2, scp_type_arc_access)) { printf("\t%s -> ", data); } else { printf("\t%s => ", data); } sc_stream_free(stream); free(data); } else { if (SCP_RESULT_TRUE == check_type(addr2, scp_type_arc_access)) { printf("\t%u|%u -> ", addr2.seg, addr2.offset); } else { printf("\t%u|%u => ", addr2.seg, addr2.offset); } } if (SC_RESULT_OK == sc_helper_get_system_identifier(addr3, &idtf)) { sc_stream *stream; sc_uint32 length = 0, read_length = 0; sc_char *data; sc_memory_get_link_content(idtf, &stream); sc_stream_get_length(stream, &length); data = calloc(length + 1, sizeof(sc_char)); sc_stream_read_data(stream, data, length, &read_length); data[length] = '\0'; printf("%s;\n", data); sc_stream_free(stream); free(data); } else { printf("%u|%u;\n", addr3.seg, addr3.offset); } } sc_iterator3_free(it); printf("Total output arcs: %d\n", out_c); return SCP_RESULT_TRUE; }
// -------------------------------------------------- sc_result agent_append_idtf(const sc_event *event, sc_addr arg) { sc_addr arc, el, link, n; sc_stream *content = 0; sc_uint8 *data = 0; sc_uint32 data_len = 0, read_bytes = 0; redisReply * reply = null_ptr; if (sc_memory_get_arc_end(s_default_ctx, arg, &arc) != SC_RESULT_OK) return SC_RESULT_ERROR; if (sc_memory_get_arc_begin(s_default_ctx, arg, &n) != SC_RESULT_OK) return SC_RESULT_ERROR; // get element if (sc_memory_get_arc_begin(s_default_ctx, arc, &el) != SC_RESULT_OK) return SC_RESULT_ERROR; if (sc_helper_check_arc(s_default_ctx, keynode_system_element, el, sc_type_arc_pos_const_perm) == SC_TRUE) return SC_RESULT_OK; // get sc-link if (sc_memory_get_arc_end(s_default_ctx, arc, &link) != SC_RESULT_OK) return SC_RESULT_ERROR; // get content of sc-link if (sc_memory_get_link_content(s_default_ctx, link, &content) != SC_RESULT_OK) return SC_RESULT_ERROR; // get length of data if (sc_stream_get_length(content, &data_len) != SC_RESULT_OK) { sc_stream_free(content); return SC_RESULT_ERROR; } data = g_malloc0(data_len + 1); if (sc_stream_read_data(content, data, data_len, &read_bytes) != SC_RESULT_OK || read_bytes != data_len) { sc_stream_free(content); g_free(data); return SC_RESULT_ERROR; } sc_result res = SC_RESULT_OK; sc_addr el_addr = el; if (SC_ADDR_IS_EQUAL(n, keynode_nrel_idtf)) el_addr = link; reply = do_sync_redis_command(redisCtx, "SET idtf:%s:%s %b", SC_ADDR_IS_EQUAL(n, keynode_nrel_main_idtf) ? str_main_idtf_postfix : (SC_ADDR_IS_EQUAL(n, keynode_nrel_idtf) ? str_idtf_postfix : str_sys_idtf_postfix), data, &el_addr, sizeof(el_addr)); if (reply == 0 || reply->type == REDIS_REPLY_ERROR) res = SC_RESULT_ERROR; if (reply) freeReplyObject(reply); sc_stream_free(content); g_free(data); return res; }