sf::Vector3i parseVector3i(const std::string theValue, const sf::Vector3i theDefault) { sf::Vector3i anResult = theDefault; // Buscamos la primera coma size_t anComma1Offset = theValue.find_first_of(',', 0); if (anComma1Offset != std::string::npos) { sf::Int32 anX = parseInt32(theValue.substr(0, anComma1Offset), theDefault.x); // Buscamos la siguiente coma size_t anComma2Offset = theValue.find_first_of(',', anComma1Offset + 1); if (anComma2Offset != std::string::npos) { sf::Int32 anY = parseInt32(theValue.substr(anComma1Offset + 1, anComma2Offset), theDefault.y); sf::Int32 anZ = parseInt32(theValue.substr(anComma2Offset + 1), theDefault.z); // Ahora que los 3 valores han sido parseados, devolvemos el vector encontrado anResult.x = anX; anResult.y = anY; anResult.z = anZ; } } // Devolvemos el resultado que hemos encontrado o el valor theDefault que se nos ha proporcionado return anResult; }
sf::IntRect parseIntRect(const std::string theValue, const sf::IntRect theDefault) { sf::IntRect anResult = theDefault; // Buscamos la primera coma size_t anComma1Offset = theValue.find_first_of(','); if (anComma1Offset != std::string::npos) { sf::Int32 anLeft = parseInt32(theValue.substr(0, anComma1Offset), theDefault.left); // Buscamos la siguiente coma size_t anComma2Offset = theValue.find_first_of(',', anComma1Offset + 1); if (anComma2Offset != std::string::npos) { sf::Int32 anTop = parseInt32(theValue.substr(anComma1Offset + 1, anComma2Offset), theDefault.top); // Buscamos la siguiente coma size_t anComma3Offset = theValue.find_first_of(',', anComma2Offset + 1); if (anComma3Offset != std::string::npos) { // Get the width and height values sf::Int32 anWidth = parseInt32(theValue.substr(anComma2Offset + 1, anComma3Offset), theDefault.width); sf::Int32 anHeight = parseInt32(theValue.substr(anComma3Offset + 1), theDefault.height); // Now that all 4 values have been parsed, return the color found anResult.left = anLeft; anResult.top = anTop; anResult.width = anWidth; anResult.height = anHeight; } } } // Devolvemos el resultado que hemos encontrado o el valor theDefault que se nos ha proporcionado return anResult; }
sf::Vector3i parseVector3i(const std::string theValue, const sf::Vector3i theDefault) { sf::Vector3i anResult = theDefault; // Try to find the first comma size_t anComma1Offset = theValue.find_first_of(',', 0); if(anComma1Offset != std::string::npos) { Int32 anX = parseInt32(theValue.substr(0, anComma1Offset), theDefault.x); // Try to find the next comma size_t anComma2Offset = theValue.find_first_of(',',anComma1Offset+1); if(anComma2Offset != std::string::npos) { Int32 anY = parseInt32(theValue.substr(anComma1Offset+1, anComma2Offset), theDefault.y); Int32 anZ = parseInt32(theValue.substr(anComma2Offset+1), theDefault.z); // Now that all 3 values have been parsed, return the Vector3f found anResult.x = anX; anResult.y = anY; anResult.z = anZ; } } // Return the result found or theDefault assigned above return anResult; }
void parseDiagnosticInfo(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, const char *szFieldName) { gint iOffset = *pOffset; guint8 EncodingMask; proto_tree *mask_tree; proto_tree *subtree; proto_item *ti; proto_item *ti_inner; ti = proto_tree_add_text(tree, tvb, *pOffset, -1, "%s: DiagnosticInfo", szFieldName); subtree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo); /* parse encoding mask */ EncodingMask = tvb_get_guint8(tvb, iOffset); ti_inner = proto_tree_add_text(subtree, tvb, iOffset, 1, "EncodingMask"); mask_tree = proto_item_add_subtree(ti_inner, ett_opcua_diagnosticinfo); proto_tree_add_item(mask_tree, hf_opcua_diag_mask_symbolicflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); proto_tree_add_item(mask_tree, hf_opcua_diag_mask_namespaceflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); proto_tree_add_item(mask_tree, hf_opcua_diag_mask_localizedtextflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); proto_tree_add_item(mask_tree, hf_opcua_diag_mask_additionalinfoflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerstatuscodeflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerdiaginfoflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); iOffset++; if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG) { parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_symbolicid); } if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG) { parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_namespace); } if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG) { parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_localizedtext); } if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG) { parseString(subtree, tvb, &iOffset, hf_opcua_diag_additionalinfo); } if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG) { parseStatusCode(subtree, tvb, &iOffset, hf_opcua_diag_innerstatuscode); } if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG) { parseDiagnosticInfo(subtree, tvb, &iOffset, "Inner DiagnosticInfo"); } proto_item_set_end(ti, tvb, iOffset); *pOffset = iOffset; }
sf::Vector2i parseVector2i(const std::string theValue, const sf::Vector2i theDefault) { sf::Vector2i anResult = theDefault; // Try to find the first comma size_t anCommaOffset = theValue.find_first_of(','); if(anCommaOffset != std::string::npos) { Int32 anX = parseInt32(theValue.substr(0,anCommaOffset), theDefault.x); Int32 anY = parseInt32(theValue.substr(anCommaOffset+1), theDefault.y); // Now that both values have been parsed, return the vector found anResult.x = anX; anResult.y = anY; } // Return the result found or theDefault assigned above return anResult; }
sf::IntRect parseIntRect(const std::string theValue, const sf::IntRect theDefault) { sf::IntRect anResult = theDefault; // Try to find the first comma size_t anComma1Offset = theValue.find_first_of(','); if(anComma1Offset != std::string::npos) { sf::Int32 anLeft = parseInt32(theValue.substr(0,anComma1Offset), theDefault.left); // Try to find the next comma size_t anComma2Offset = theValue.find_first_of(',',anComma1Offset+1); if(anComma2Offset != std::string::npos) { sf::Int32 anTop = parseInt32(theValue.substr(anComma1Offset+1,anComma2Offset), theDefault.top); // Try to find the next comma size_t anComma3Offset = theValue.find_first_of(',',anComma2Offset+1); if(anComma3Offset != std::string::npos) { // Get the width and height values sf::Int32 anWidth = parseInt32(theValue.substr(anComma2Offset+1,anComma3Offset), theDefault.width); sf::Int32 anHeight = parseInt32(theValue.substr(anComma3Offset+1), theDefault.height); // Now that all 4 values have been parsed, return the color found anResult.left = anLeft; anResult.top = anTop; anResult.width = anWidth; anResult.height = anHeight; } } } // Return the result found or theDefault assigned above return anResult; }
void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, const char *szFieldName) { proto_item *ti = proto_tree_add_text(tree, tvb, *pOffset, -1, "%s: Variant", szFieldName); proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_variant); gint iOffset = *pOffset; guint8 EncodingMask; gint32 ArrayDimensions = 0; EncodingMask = tvb_get_guint8(tvb, iOffset); proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN); iOffset++; if (EncodingMask & VARIANT_ARRAYMASK) { /* type is encoded in bits 0-5 */ switch(EncodingMask & 0x3f) { case OpcUaType_Null: break; case OpcUaType_Boolean: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Boolean, parseBoolean); break; case OpcUaType_SByte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_SByte, parseSByte); break; case OpcUaType_Byte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Byte, parseByte); break; case OpcUaType_Int16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int16, parseInt16); break; case OpcUaType_UInt16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt16, parseUInt16); break; case OpcUaType_Int32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int32, parseInt32); break; case OpcUaType_UInt32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt32, parseUInt32); break; case OpcUaType_Int64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int64, parseInt64); break; case OpcUaType_UInt64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt64, parseUInt64); break; case OpcUaType_Float: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Float, parseFloat); break; case OpcUaType_Double: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Double, parseDouble); break; case OpcUaType_String: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_String, parseString); break; case OpcUaType_DateTime: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_DateTime, parseDateTime); break; case OpcUaType_Guid: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Guid, parseGuid); break; case OpcUaType_ByteString: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_ByteString, parseByteString); break; case OpcUaType_XmlElement: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_XmlElement, parseXmlElement); break; case OpcUaType_NodeId: parseArrayComplex(subtree, tvb, &iOffset, "NodeId", parseNodeId); break; case OpcUaType_ExpandedNodeId: parseArrayComplex(subtree, tvb, &iOffset, "ExpandedNodeId", parseExpandedNodeId); break; case OpcUaType_StatusCode: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_StatusCode, parseStatusCode); break; case OpcUaType_DiagnosticInfo: parseArrayComplex(subtree, tvb, &iOffset, "DiagnosticInfo", parseDiagnosticInfo); break; case OpcUaType_QualifiedName: parseArrayComplex(subtree, tvb, &iOffset, "QualifiedName", parseQualifiedName); break; case OpcUaType_LocalizedText: parseArrayComplex(subtree, tvb, &iOffset, "LocalizedText", parseLocalizedText); break; case OpcUaType_ExtensionObject: parseArrayComplex(subtree, tvb, &iOffset, "ExtensionObject", parseExtensionObject); break; case OpcUaType_DataValue: parseArrayComplex(subtree, tvb, &iOffset, "DataValue", parseDataValue); break; case OpcUaType_Variant: parseArrayComplex(subtree, tvb, &iOffset, "Variant", parseVariant); break; } if (EncodingMask & VARIANT_ARRAYDIMENSIONS) { proto_item *ti_2 = proto_tree_add_text(subtree, tvb, iOffset, -1, "ArrayDimensions"); proto_tree *subtree_2 = proto_item_add_subtree(ti_2, ett_opcua_array); int i; /* read array length */ ArrayDimensions = tvb_get_letohl(tvb, iOffset); proto_tree_add_item(subtree_2, hf_opcua_ArraySize, tvb, iOffset, 4, ENC_LITTLE_ENDIAN); if (ArrayDimensions > MAX_ARRAY_LEN) { proto_item *pi; pi = proto_tree_add_text(subtree_2, tvb, iOffset, 4, "ArrayDimensions length %d too large to process", ArrayDimensions); PROTO_ITEM_SET_GENERATED(pi); return; } iOffset += 4; for (i=0; i<ArrayDimensions; i++) { parseInt32(subtree_2, tvb, &iOffset, hf_opcua_Int32); } proto_item_set_end(ti_2, tvb, iOffset); } } else { /* type is encoded in bits 0-5 */ switch(EncodingMask & 0x3f) { case OpcUaType_Null: break; case OpcUaType_Boolean: parseBoolean(subtree, tvb, &iOffset, hf_opcua_Boolean); break; case OpcUaType_SByte: parseSByte(subtree, tvb, &iOffset, hf_opcua_SByte); break; case OpcUaType_Byte: parseByte(subtree, tvb, &iOffset, hf_opcua_Byte); break; case OpcUaType_Int16: parseInt16(subtree, tvb, &iOffset, hf_opcua_Int16); break; case OpcUaType_UInt16: parseUInt16(subtree, tvb, &iOffset, hf_opcua_UInt16); break; case OpcUaType_Int32: parseInt32(subtree, tvb, &iOffset, hf_opcua_Int32); break; case OpcUaType_UInt32: parseUInt32(subtree, tvb, &iOffset, hf_opcua_UInt32); break; case OpcUaType_Int64: parseInt64(subtree, tvb, &iOffset, hf_opcua_Int64); break; case OpcUaType_UInt64: parseUInt64(subtree, tvb, &iOffset, hf_opcua_UInt64); break; case OpcUaType_Float: parseFloat(subtree, tvb, &iOffset, hf_opcua_Float); break; case OpcUaType_Double: parseDouble(subtree, tvb, &iOffset, hf_opcua_Double); break; case OpcUaType_String: parseString(subtree, tvb, &iOffset, hf_opcua_String); break; case OpcUaType_DateTime: parseDateTime(subtree, tvb, &iOffset, hf_opcua_DateTime); break; case OpcUaType_Guid: parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid); break; case OpcUaType_ByteString: parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString); break; case OpcUaType_XmlElement: parseXmlElement(subtree, tvb, &iOffset, hf_opcua_XmlElement); break; case OpcUaType_NodeId: parseNodeId(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_ExpandedNodeId: parseExpandedNodeId(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_StatusCode: parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode); break; case OpcUaType_DiagnosticInfo: parseDiagnosticInfo(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_QualifiedName: parseQualifiedName(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_LocalizedText: parseLocalizedText(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_ExtensionObject: parseExtensionObject(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_DataValue: parseDataValue(subtree, tvb, &iOffset, "Value"); break; case OpcUaType_Variant: parseVariant(subtree, tvb, &iOffset, "Value"); break; } } proto_item_set_end(ti, tvb, iOffset); *pOffset = iOffset; }
int Index::init(const char *path, const char *file) { P_WARNING("start to init Index"); Config conf(path, file); if (conf.parse() < 0) { P_WARNING("failed to load [%s][%s]", path, file); return -1; } m_conf.index_path = conf["INDEX_PATH"]; m_conf.index_meta_file = conf["INDEX_META_FILE"]; m_conf.dump_flag_file = conf["DUMP_FLAG_FILE"]; m_conf.inc_processor = conf["INC_PROCESSOR"]; if (!parseInt32(conf["INC_DAS_WARNING_TIME"], m_conf.inc_das_warning_time)) { m_conf.inc_das_warning_time = 60*60*24*3; /* 默认3天没更新则报警 */ } P_WARNING("Index Confs:"); P_WARNING(" [INDEX_PATH]: %s", m_conf.index_path.c_str()); P_WARNING(" [INDEX_META_FILE]: %s", m_conf.index_meta_file.c_str()); P_WARNING(" [DUMP_FLAG_FILE]: %s", m_conf.dump_flag_file.c_str()); P_WARNING(" [INC_PROCESSOR]: %s", m_conf.inc_processor.c_str()); P_WARNING(" [INC_DAS_WARNING_TIME]: %d ms", m_conf.inc_das_warning_time); thread_func_t proc = NULL; { std::map<std::string, thread_func_t>::const_iterator it = s_inc_processors.find(std::string(m_conf.inc_processor.c_str())); if (it == s_inc_processors.end()) { P_WARNING("unregistered inc processor[%s]", m_conf.inc_processor.c_str()); return -1; } proc = it->second; if (proc == NULL) { P_WARNING("invalid registered inc processor[%s]", m_conf.inc_processor.c_str()); return -1; } } if (m_dual_dir.init(m_conf.index_path.c_str()) < 0) { P_WARNING("failed to init index path"); return -1; } m_dump_fw.create(m_conf.dump_flag_file.c_str()); std::string using_path = m_dual_dir.using_path(); if (m_inc_reader.init(using_path.c_str(), m_conf.index_meta_file.c_str()) < 0) { P_WARNING("failed to init increment reader[%s][%s]", using_path.c_str(), m_conf.index_meta_file.c_str()); return -1; } uint32_t level_num = 0; if (parseUInt32(conf["level_num"], level_num)) { for (uint32_t i = 0; i < level_num; ++i) { char tmpbuf[256]; ::snprintf(tmpbuf, sizeof tmpbuf, "level_%d", i); uint32_t level = 0; std::string conf_path; std::string conf_file; std::string level_name; if (!parseUInt32(conf[tmpbuf], level)) { P_WARNING("failed to parse %s", tmpbuf); goto FAIL; } if (level >= m_index.size()) { m_index.resize(level + 1, NULL); } ::snprintf(tmpbuf, sizeof tmpbuf, "level_%d_conf_path", i); conf_path = conf[tmpbuf]; ::snprintf(tmpbuf, sizeof tmpbuf, "level_%d_conf_file", i); conf_file = conf[tmpbuf]; ::snprintf(tmpbuf, sizeof tmpbuf, "level_%d_name", i); level_name = conf[tmpbuf]; m_index[level] = new (std::nothrow) LevelIndex; if (NULL == m_index[level] || m_index[level]-> init(conf_path.c_str(), conf_file.c_str()) < 0) { goto FAIL; } ::snprintf(tmpbuf, sizeof tmpbuf, "L%u_%s", level, level_name.c_str()); m_level2dirname[level] = tmpbuf; } if (0) { FAIL: for (size_t i = 0; i < m_index.size(); ++i) { if (m_index[i]) { delete m_index[i]; } } m_index.clear(); return -1; } std::map<size_t, std::string>::const_iterator it = m_level2dirname.begin(); while (it != m_level2dirname.end()) { P_WARNING("level[%d]'s dirname: %s", int(it->first), it->second.c_str()); ++it; } } if (m_level2dirname.size() == 0) { P_WARNING("must have at least one level"); return -1; } P_WARNING("level num: %u", level_num); int ret = ::pthread_create(&m_inc_tid, NULL, proc, this); if (ret != 0) { P_WARNING("failed to create increment_thread, ret=%d", ret); return -1; } P_WARNING("init Index ok"); return 0; }