void RuntimeJsImpl::onReload(const rapidjson::Document &dArgParse, rapidjson::Document &dReplyParse) { if (dArgParse.HasMember("modulefiles")){ auto& allocator = dReplyParse.GetAllocator(); rapidjson::Value bodyvalue(rapidjson::kObjectType); const rapidjson::Value& objectfiles = dArgParse["modulefiles"]; for (rapidjson::SizeType i = 0; i < objectfiles.Size(); i++){ if (!reloadScript(objectfiles[i].GetString())) { bodyvalue.AddMember(rapidjson::Value(objectfiles[i].GetString(), allocator) , rapidjson::Value(1) , allocator); } } if (0 == objectfiles.Size()) { reloadScript(""); } dReplyParse.AddMember("body", bodyvalue, dReplyParse.GetAllocator()); }else { reloadScript(""); } dReplyParse.AddMember("code", 0, dReplyParse.GetAllocator()); }
void Robot::Process_Heartbeat(rapidjson::Document& jsRequest, rapidjson::Document& jsResponse, string& sResponse) { rapidjson::Document::AllocatorType& allocator = jsResponse.GetAllocator(); jsResponse.AddMember("errcode", 0, allocator); jsResponse.AddMember("errmsg", "ok", allocator); sResponse = JsonDocToString(jsResponse); }
bool JsonUtils::CreateError(rapidjson::Document& document, int err, const std::string& message) { rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); document.SetObject(); document.AddMember("code", err, allocator); document.AddMember("message", rapidjson::Value(message.c_str(), allocator), allocator); }
void FCServer::jsonServerInfo(rapidjson::Document &message) { // Server version message.AddMember("version", kFCServerVersion, message.GetAllocator()); // Server configuration message.AddMember("config", rapidjson::kObjectType, message.GetAllocator()); message.DeepCopy(message["config"], mConfig); }
void RuntimeJsImpl::onStartDebuger(const rapidjson::Document& dArgParse, rapidjson::Document& dReplyParse) { if (loadScriptFile(ConfigParser::getInstance()->getEntryFile())) { dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); } else { dReplyParse.AddMember("code",1,dReplyParse.GetAllocator()); } }
void GraphIF::fillJSON(rapidjson::Document& jsonDoc, rapidjson::Document::AllocatorType& allocator, unsigned short depth) { jsonDoc.AddMember("Number of vertices", vertexSet->size(), allocator); jsonDoc.AddMember("Number of edges", edgeSet->size(), allocator); jsonDoc.AddMember("Vertex set", JSONUtils::getDepthLimitedJSON(vertexSet, allocator, "VertexSetIF", depth), allocator); jsonDoc.AddMember("Edge set", JSONUtils::getDepthLimitedJSON(edgeSet, allocator, "EdgeSetIF", depth), allocator); }
void EdgeSetIF::fillJSON(rapidjson::Document& jsonDoc, rapidjson::Document::AllocatorType& allocator, unsigned short depth) { rapidjson::Value edgeSet(rapidjson::kArrayType); jsonDoc.AddMember("Number of edges", numberOfEdges, allocator); begin(); while (hasNext()) { edgeSet.PushBack( JSONUtils::getDepthLimitedJSON(next(), allocator, "EdgeIF", depth), allocator); } jsonDoc.AddMember("Edge set", edgeSet, allocator); }
void VertexSetIF::fillJSON(rapidjson::Document& jsonDoc, rapidjson::Document::AllocatorType& allocator, unsigned short depth) { rapidjson::Value vertexSet(rapidjson::kArrayType); jsonDoc.AddMember("Number of vertices", numberOfVertices, allocator); begin(); while (hasNext()) { vertexSet.PushBack( JSONUtils::getDepthLimitedJSON(next(), allocator, "VertexIF", depth), allocator); } jsonDoc.AddMember("Vertex set", vertexSet, allocator); }
void tws::wtss::prepare_timeseries_response(const timeseries_request_parameters& parameters, const timeseries_validated_parameters& vparameters, rapidjson::Document& doc, rapidjson::Value& jattributes, rapidjson::Document::AllocatorType& allocator) { // prepare result part in response rapidjson::Value jresult(rapidjson::kObjectType); jresult.AddMember("attributes", jattributes, allocator); // add timeline in the response rapidjson::Value jtimeline(rapidjson::kArrayType); std::size_t init_pos = vparameters.timeline->pos(vparameters.start_time_idx); std::size_t fin_pos = vparameters.timeline->pos(vparameters.end_time_idx); tws::core::copy_string_array(std::begin(vparameters.timeline->time_points()) + init_pos, std::begin(vparameters.timeline->time_points()) + (fin_pos + 1), jtimeline, allocator); jresult.AddMember("timeline", jtimeline, allocator); // add the pixel center location in response rapidjson::Value jcenter(rapidjson::kObjectType); jcenter.AddMember("latitude", vparameters.pixel_center_latitude, allocator); jcenter.AddMember("longitude", vparameters.pixel_center_longitude, allocator); jresult.AddMember("center_coordinates", jcenter, allocator); // prepare the query part in response rapidjson::Value jquery(rapidjson::kObjectType); jquery.AddMember("coverage", parameters.cv_name.c_str(), allocator); rapidjson::Value jqattributes(rapidjson::kArrayType); tws::core::copy_string_array(parameters.queried_attributes.begin(), parameters.queried_attributes.end(), jqattributes, allocator); jquery.AddMember("attributes", jqattributes, allocator); jquery.AddMember("latitude", parameters.latitude, allocator); jquery.AddMember("longitude", parameters.longitude, allocator); doc.AddMember("result", jresult, allocator); doc.AddMember("query", jquery, allocator); }
void FCServer::jsonDeviceMessage(rapidjson::Document &message) { /* * If this message has a "device" member and doesn't match any server-global * message types, give each matching device a chance to handle it. */ const Value &device = message["device"]; bool matched = false; if (device.IsObject()) { for (unsigned i = 0; i != mUSBDevices.size(); i++) { USBDevice *usbDev = mUSBDevices[i]; if (usbDev->matchConfiguration(device)) { matched = true; usbDev->writeMessage(message); if (message.HasMember("error")) break; } } } if (!matched) { message.AddMember("error", "No matching device found", message.GetAllocator()); } }
void MainWindow::addOptionsToDoc(rapidjson::Document &doc) { rapidjson::Value options(rapidjson::kObjectType); if (nodalDispCheckBox->isChecked()) { options.AddMember("save_nodal_displacements", true, doc.GetAllocator()); rapidjson::Value rj_val; std::string val = nodalDispLineEdit->displayText().toStdString(); rj_val.SetString(val.c_str(), val.length(), doc.GetAllocator()); options.AddMember("nodal_displacements_filename", rj_val, doc.GetAllocator()); } if (nodalForcesCheckBox->isChecked()) { options.AddMember("save_nodal_forces", true, doc.GetAllocator()); rapidjson::Value rj_val; std::string val = nodalForcesLineEdit->displayText().toStdString(); rj_val.SetString(val.c_str(), val.length(), doc.GetAllocator()); options.AddMember("nodal_forces_filename", rj_val, doc.GetAllocator()); } if (tieForcesCheckBox->isChecked()) { options.AddMember("save_tie_forces", true, doc.GetAllocator()); rapidjson::Value rj_val; std::string val = tieForcesLineEdit->displayText().toStdString(); rj_val.SetString(val.c_str(), val.length(), doc.GetAllocator()); options.AddMember("ties_forces_filename", rj_val, doc.GetAllocator()); } if (reportCheckBox->isChecked()) { options.AddMember("save_report", true, doc.GetAllocator()); rapidjson::Value rj_val; std::string val = tieForcesLineEdit->displayText().toStdString(); rj_val.SetString(val.c_str(), val.length(), doc.GetAllocator()); options.AddMember("report_filename", rj_val, doc.GetAllocator()); } options.AddMember("verbose", true, doc.GetAllocator()); doc.AddMember("options", options, doc.GetAllocator()); }
void CPlayer::Serialize(string name, rapidjson::Document& root) { rapidjson::Value json; json.SetObject(); _SerializeFieldI64(Role_Attrib_ID, root, root); _SerializeFieldI64(Role_Attrib_UserID, root, root); _SerializeFieldInt(Role_Attrib_TemplateID, root, root); _SerializeFieldStr(Role_Attrib_Name, root, root); _SerializeFieldI64(Role_Attrib_SceneID, json, root); _SerializeFieldInt(Role_Attrib_Position, json, root); _SerializeFieldInt(Role_Attrib_Vocation, json, root); _SerializeFieldInt(Role_Attrib_Sex, json, root); _SerializeFieldInt(Role_Attrib_Level, json, root); _SerializeFieldI64(Role_Attrib_Exp, json, root); _SerializeFieldInt(Role_Attrib_GoldCoin, json, root); _SerializeFieldInt(Role_Attrib_SilverCoin, json, root); _SerializeFieldInt(Role_Attrib_Fighting, json, root); _SerializeFieldStr(Role_Attrib_CreateTime, json, root); _SerializeFieldStr(Role_Attrib_LoginTime, json, root); _SerializeFieldStr(Role_Attrib_LogoutTime, json, root); root.AddMember(name.c_str(), root.GetAllocator(), json, root.GetAllocator()); }
void Workers::threadsSummary(rapidjson::Document &doc) { uv_mutex_lock(&m_mutex); const uint64_t pages[2] = { m_status.hugePages, m_status.pages }; const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo); uv_mutex_unlock(&m_mutex); auto &allocator = doc.GetAllocator(); rapidjson::Value hugepages(rapidjson::kArrayType); hugepages.PushBack(pages[0], allocator); hugepages.PushBack(pages[1], allocator); doc.AddMember("hugepages", hugepages, allocator); doc.AddMember("memory", memory, allocator); }
void RuntimeLuaImpl::onStartDebuger(const rapidjson::Document& dArgParse, rapidjson::Document& dReplyParse) { // Lua char szDebugArg[1024] = {0}; sprintf(szDebugArg, "require('debugger')(%s,'%s')",dArgParse["debugcfg"].GetString(), ""); startScript(szDebugArg); dReplyParse.AddMember("code", 0, dReplyParse.GetAllocator()); }
void EdgeIF::fillJSON(rapidjson::Document& jsonDoc, rapidjson::Document::AllocatorType& allocator, unsigned short depth) { jsonDoc.AddMember("Edge cost", edgeCost, allocator); jsonDoc.AddMember("Connection type", rapidjson::StringRef( EnumUtils::getEdgeConnectionTypeString(connectionType)), allocator); jsonDoc.AddMember("Is hidden?", rapidjson::StringRef(EnumUtils::getVisibilityString(visibility)), allocator); jsonDoc.AddMember("u", JSONUtils::getDepthLimitedJSON(edgeConnection.first, allocator, "VertexIF", depth), allocator); jsonDoc.AddMember("v", JSONUtils::getDepthLimitedJSON(edgeConnection.second, allocator, "VertexIF", depth), allocator); }
void RuntimeJsImpl::onPrecompile(const rapidjson::Document& dArgParse, rapidjson::Document& dReplyParse) { const rapidjson::Value& objectfiles = dArgParse["modulefiles"]; for (rapidjson::SizeType i = 0; i < objectfiles.Size(); i++) { ScriptingCore::getInstance()->compileScript(objectfiles[i].GetString()); } dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); }
void FCServer::jsonListConnectedDevices(rapidjson::Document &message) { message.AddMember("devices", rapidjson::kArrayType, message.GetAllocator()); Value &list = message["devices"]; for (unsigned i = 0; i != mUSBDevices.size(); i++) { USBDevice *usbDev = mUSBDevices[i]; list.PushBack(rapidjson::kObjectType, message.GetAllocator()); mUSBDevices[i]->describe(list[i], message.GetAllocator()); } }
void MainWindow::addMemberToDoc(rapidjson::Document &doc, const std::string &key, const std::string &value) { rapidjson::Value rj_key; rj_key.SetString(key.c_str(), key.length(), doc.GetAllocator()); rapidjson::Value rj_val; rj_val.SetString(value.c_str(), value.length(), doc.GetAllocator()); doc.AddMember(rj_key, rj_val, doc.GetAllocator()); }
static inline bool pyobj2doc_pair(PyObject *key, PyObject *value, rapidjson::Document& doc) { const char *key_string; PyObject *utf8_item = NULL; PyObject *pyobj = NULL; #ifdef PY3 if (!PyUnicode_Check(key)) { pyobj = PyObject_Str(key); if (pyobj == NULL) { PyErr_SetString(PyExc_TypeError, "not support key type"); return false; } utf8_item = PyUnicode_AsUTF8String(pyobj); } else { utf8_item = PyUnicode_AsUTF8String(key); } key_string = PyBytes_AsString(utf8_item); #else if (PyString_Check(key)) { key_string = PyString_AsString(key); } else if (PyUnicode_Check(key)) { utf8_item = PyUnicode_AsUTF8String(key); key_string = PyBytes_AsString(utf8_item); } else { PyObject *pyobj = PyObject_Str(key); if (pyobj == NULL) { PyErr_SetString(PyExc_TypeError, "not support key type"); return false; } Py_DECREF(key); key_string = PyString_AsString(pyobj); } #endif rapidjson::Value s; s.SetString(key_string, doc.GetAllocator()); Py_XDECREF(pyobj); Py_XDECREF(utf8_item); rapidjson::Value _v; if (false == pyobj2doc(value, _v, doc)) { return false; } doc.AddMember(s, _v, doc.GetAllocator()); return true; }
static inline void pyobj2doc_pair(PyObject *key, PyObject *value, rapidjson::Document& doc) { const char *key_string; #ifdef PY3 PyObject *utf8_item; utf8_item = PyUnicode_AsUTF8String(key); key_string = PyBytes_AsString(utf8_item); #else key_string = PyString_AsString(key); #endif rapidjson::Value s; s.SetString(key_string, doc.GetAllocator()); rapidjson::Value _v; pyobj2doc(value, _v, doc); doc.AddMember(s, _v, doc.GetAllocator()); }
void RuntimeJsImpl::onClearCompile(const rapidjson::Document& dArgParse, rapidjson::Document& dReplyParse) { if (dArgParse.HasMember("modulefiles") && dArgParse["modulefiles"].Size() != 0) { const rapidjson::Value& objectfiles = dArgParse["modulefiles"]; for (rapidjson::SizeType i = 0; i < objectfiles.Size(); i++) { ScriptingCore::getInstance()->cleanScript(objectfiles[i].GetString()); } } else { std::unordered_map<std::string, JSScript*> filenameScript = ScriptingCore::getInstance()->getFileScript(); filenameScript.clear(); } dReplyParse.AddMember("code",0,dReplyParse.GetAllocator()); }
void serializeEntities(rapidjson::Document &root, size_t start, size_t end, tbb::concurrent_vector<Entity*> &entities) { using namespace rapidjson; // Create the positions. //Value positions; //positions.parse rapidjson::Value positions; positions.SetArray(); rapidjson::Document::AllocatorType& allocator = root.GetAllocator(); for(size_t i = start; i < end; ++i) { Entity* entity = entities[i]; if (entity->pathNodes) { // Only write out those with a path rapidjson::Value entityValue; entityValue.SetObject(); //std::cout << "serializing entity id: " << entity->id << std::endl; rapidjson::Value entityId; entityId.SetInt(entity->id); rapidjson::Value xPosition; rapidjson::Value yPosition; xPosition.SetDouble(entity->position.x); yPosition.SetDouble(entity->position.y); entityValue.AddMember("id", entityId, allocator); entityValue.AddMember("x", xPosition, allocator); entityValue.AddMember("y", yPosition, allocator); positions.PushBack(entityValue, allocator); } } root.AddMember("positions", positions, root.GetAllocator()); }
void addShaderToCache(uint32_t p_ShaderHash, const char* p_GpuProgramName, const SpirvBuffer& p_SpirvBuffer) { if (_shaderCache.HasMember(p_GpuProgramName)) { _shaderCache[p_GpuProgramName].SetUint(p_ShaderHash); } else { rapidjson::Value fileName = rapidjson::Value(p_GpuProgramName, _shaderCache.GetAllocator()); _shaderCache.AddMember(fileName, p_ShaderHash, _shaderCache.GetAllocator()); } _INTR_STRING cacheFileName = _shaderCachePath + p_GpuProgramName + ".cached"; _INTR_OFSTREAM of(cacheFileName.c_str(), std::ofstream::binary); of.write((const char*)p_SpirvBuffer.data(), p_SpirvBuffer.size() * sizeof(uint32_t)); of.close(); saveShaderCache(); }
// The AST entry point. Here begins everything. bool SuperastCPP::TraverseTranslationUnitDecl( clang::TranslationUnitDecl* unitDecl) { // Create the block object at root of DOM document.SetObject(); // Set the pointer. Statements from root will be added here addId(document); document.AddMember("statements", rapidjson::kArrayType, allocator); for (auto declaration : unitDecl->decls()) { TRY_TO(TraverseDecl(declaration)); if (!sonValue.IsNull()) { if (sonValue.IsArray()) { addElemsToArray(document["statements"], sonValue); } else { document["statements"].PushBack(sonValue, allocator); } } } return true; }
void FCServer::cbJsonMessage(libwebsocket *wsi, rapidjson::Document &message, void *context) { // Received a JSON message from a WebSockets client. // Replies are formed by modifying the original message. FCServer *self = (FCServer*) context; const Value &vtype = message["type"]; if (!vtype.IsString()) { lwsl_notice("NOTICE: Received JSON is missing mandatory \"type\" string\n"); return; } const char *type = vtype.GetString(); // Hold the event lock while dispatching self->mEventMutex.lock(); if (!strcmp(type, "list_connected_devices")) { self->jsonListConnectedDevices(message); } else if (!strcmp(type, "server_info")) { self->jsonServerInfo(message); } else if (message.HasMember("device")) { self->jsonDeviceMessage(message); } else { message.AddMember("error", "Unknown message type", message.GetAllocator()); } self->mEventMutex.unlock(); // Remove heavyweight members we should never reply with message.RemoveMember("pixels"); // All messages get a reply, and we leave any extra parameters on the message // so that clients can keep track of asynchronous completions. self->mNetServer.jsonReply(wsi, message); }
void resolve_dependencies(IContentManager* content_mgr, rapidjson::Document& d) { d.AddMember("dependencies", rapidjson::Value(rapidjson::kArrayType), d.GetAllocator()); }
void HrConvertUtil::WriteMaterialData(rapidjson::Document& doc) { rapidjson::Value materialObj(rapidjson::kObjectType); rapidjson::Value materialCountValue(rapidjson::kNumberType); materialCountValue.SetUint(m_modelDesc.vecMaterialDataInfo.size()); materialObj.AddMember(rapidjson::StringRef("MaterialCount"), materialCountValue, doc.GetAllocator()); for (int nMaterialIndex = 0; nMaterialIndex < m_modelDesc.vecMaterialDataInfo.size(); ++nMaterialIndex) { std::string strSubMaterialName = "Material_" + std::to_string(nMaterialIndex); rapidjson::Value subMaterialKey(rapidjson::kStringType); subMaterialKey.SetString(strSubMaterialName.c_str(), doc.GetAllocator()); rapidjson::Value subMaterialObj(rapidjson::kObjectType); rapidjson::Value nameValue(rapidjson::kStringType); nameValue.SetString(m_modelDesc.vecMaterialDataInfo[nMaterialIndex].strMaterialName.c_str(), doc.GetAllocator()); subMaterialObj.AddMember(rapidjson::StringRef("Name"), nameValue, doc.GetAllocator()); rapidjson::Value albedoValue(rapidjson::kStringType); std::string strAlbedo = HrStringUtil::StringFormat("%.2f|%.2f|%.2f|%.2f|" , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Albedo[0] , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Albedo[1] , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Albedo[2] , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Albedo[3]); albedoValue.SetString(strAlbedo.c_str(), doc.GetAllocator()); subMaterialObj.AddMember(rapidjson::StringRef("Albedo"), albedoValue, doc.GetAllocator()); rapidjson::Value emissiveValue(rapidjson::kStringType); std::string strEmissive = HrStringUtil::StringFormat("%.2f|%.2f|%.2f|%.2f|" , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Emissive[0] , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Emissive[1] , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Emissive[2] , m_modelDesc.vecMaterialDataInfo[nMaterialIndex].v4Emissive[3]); emissiveValue.SetString(strEmissive.c_str(), doc.GetAllocator()); subMaterialObj.AddMember(rapidjson::StringRef("Emissibe"), emissiveValue, doc.GetAllocator()); rapidjson::Value shininessValue(rapidjson::kNumberType); shininessValue.SetFloat(m_modelDesc.vecMaterialDataInfo[nMaterialIndex].fMetalness); subMaterialObj.AddMember(rapidjson::StringRef("Metalness"), shininessValue, doc.GetAllocator()); rapidjson::Value reflectiveValue(rapidjson::kNumberType); reflectiveValue.SetFloat(m_modelDesc.vecMaterialDataInfo[nMaterialIndex].fRoughness); subMaterialObj.AddMember(rapidjson::StringRef("Roughness"), reflectiveValue, doc.GetAllocator()); rapidjson::Value opacityValue(rapidjson::kNumberType); opacityValue.SetFloat(m_modelDesc.vecMaterialDataInfo[nMaterialIndex].fOpacity); subMaterialObj.AddMember(rapidjson::StringRef("Opacity"), opacityValue, doc.GetAllocator()); rapidjson::Value twoSidedValue(rapidjson::kNumberType); if (m_modelDesc.vecMaterialDataInfo[nMaterialIndex].bTwoSided) twoSidedValue.SetInt(1); else twoSidedValue.SetInt(0); subMaterialObj.AddMember(rapidjson::StringRef("TwoSided"), twoSidedValue, doc.GetAllocator()); for (int nTexIndex = 0; nTexIndex < HrModelDataInfo::HrMaterialDataInfo::TS_NUMTEXTURESLOTS; ++nTexIndex) { std::string strTextKey = "Texture_" + std::to_string(nTexIndex); rapidjson::Value textureKey(rapidjson::kStringType); textureKey.SetString(strTextKey.c_str(), doc.GetAllocator()); rapidjson::Value textureValue(rapidjson::kStringType); std::string strTexturePath = m_modelDesc.vecMaterialDataInfo[nMaterialIndex].m_arrTexNames[nTexIndex]; if (strTexturePath.size() > 0) { std::string strTexFileName = Hr::HrFileUtils::Instance()->GetFileNameWithSuffix(strTexturePath); std::string strTexPath = "Texture\\" + strTexFileName; textureValue.SetString(strTexPath.c_str(), doc.GetAllocator()); } else { textureValue.SetString(rapidjson::StringRef(""), doc.GetAllocator()); } subMaterialObj.AddMember(textureKey, textureValue, doc.GetAllocator()); } materialObj.AddMember(subMaterialKey, subMaterialObj, doc.GetAllocator()); } doc.AddMember(rapidjson::StringRef("Materials"), materialObj, doc.GetAllocator()); }
void HrConvertUtil::WriteMeshData(rapidjson::Document& doc) { rapidjson::Value meshesObj(rapidjson::kObjectType); rapidjson::Value meshCountObj(rapidjson::kNumberType); meshCountObj.SetUint(m_modelDesc.vecSubMeshInfo.size()); meshesObj.AddMember(rapidjson::StringRef("SubMeshesCount"), meshCountObj, doc.GetAllocator()); for (size_t nSubMeshIndex = 0; nSubMeshIndex < m_modelDesc.vecSubMeshInfo.size(); ++nSubMeshIndex) { const HrModelDataInfo::HrSubMeshDataInfo& subMeshInfo = m_modelDesc.vecSubMeshInfo[nSubMeshIndex]; rapidjson::Value subMeshKeyObj(rapidjson::kStringType); std::string strSubMeshName = ("SubMesh_" + std::to_string(nSubMeshIndex)); subMeshKeyObj.SetString(strSubMeshName.c_str(), doc.GetAllocator()); rapidjson::Value subMeshValueObj(rapidjson::kObjectType); { rapidjson::Value nameValueObj(rapidjson::kStringType); if (subMeshInfo.strMeshName.empty()) nameValueObj.SetString(subMeshInfo.strMeshName.c_str(), doc.GetAllocator()); else nameValueObj.SetString(subMeshInfo.strMeshName.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("Name"), nameValueObj, doc.GetAllocator()); } { if (subMeshInfo.bAllIndices) { std::string strIndices; for (int nIndiceIndex = 0; nIndiceIndex < subMeshInfo.vecIndices.size(); ++nIndiceIndex) { strIndices += std::to_string(subMeshInfo.vecIndices[nIndiceIndex]); strIndices += ","; } rapidjson::Value indicesValueObj(rapidjson::kStringType); indicesValueObj.SetString(strIndices.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("Indices"), indicesValueObj, doc.GetAllocator()); } } { std::string strVertices; for (int nVerticeIndex = 0; nVerticeIndex < subMeshInfo.vecVertexPos.size(); ++nVerticeIndex) { Vector3 vPos = subMeshInfo.vecVertexPos[nVerticeIndex] * m_fOutputUnitScale; strVertices += MakeFloat3StringWithEndMark(vPos); } rapidjson::Value verticesValueObj(rapidjson::kStringType); verticesValueObj.SetString(strVertices.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("Vertices"), verticesValueObj, doc.GetAllocator()); } { std::string strTangents; for (int nTangentIndex = 0; nTangentIndex < subMeshInfo.vecTangent.size(); ++nTangentIndex) { Vector3 vTangent = subMeshInfo.vecTangent[nTangentIndex]; strTangents += MakeFloat3StringWithEndMark(vTangent); } rapidjson::Value tangentsValueObj(rapidjson::kStringType); tangentsValueObj.SetString(strTangents.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("Tangents"), tangentsValueObj, doc.GetAllocator()); } { std::string strBinormals; for (int nBinormalIndex = 0; nBinormalIndex < subMeshInfo.vecBinormal.size(); ++nBinormalIndex) { Vector3 vBinormal = subMeshInfo.vecBinormal[nBinormalIndex]; strBinormals += MakeFloat3StringWithEndMark(vBinormal); } rapidjson::Value binormalValueObj(rapidjson::kStringType); binormalValueObj.SetString(strBinormals.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("Binormals"), binormalValueObj, doc.GetAllocator()); } { std::string strNormals; for (int nNormalIndex = 0; nNormalIndex < subMeshInfo.vecNormal.size(); ++nNormalIndex) { Vector3 vecNormal = subMeshInfo.vecNormal[nNormalIndex]; strNormals += MakeFloat3StringWithEndMark(vecNormal); } rapidjson::Value normalsValueObj(rapidjson::kStringType); normalsValueObj.SetString(strNormals.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("Normals"), normalsValueObj, doc.GetAllocator()); } { std::string strUVs; for (int nUVIndex = 0; nUVIndex < subMeshInfo.vecUV.size(); ++nUVIndex) { float2 uv = subMeshInfo.vecUV[nUVIndex]; char cTemp[30]; std::sprintf(cTemp, "%.2f", uv[0]); strUVs += cTemp; strUVs += ","; std::sprintf(cTemp, "%.2f", uv[1]); strUVs += cTemp; strUVs += "|"; } rapidjson::Value uvsValueObj(rapidjson::kStringType); uvsValueObj.SetString(strUVs.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("UVs"), uvsValueObj, doc.GetAllocator()); } { std::string strAABB; strAABB += MakeFloat3StringWithEndMark(subMeshInfo.aabb.Min()); strAABB += MakeFloat3StringWithEndMark(subMeshInfo.aabb.Max()); rapidjson::Value aabbValueObj(rapidjson::kStringType); aabbValueObj.SetString(strAABB.c_str(), doc.GetAllocator()); subMeshValueObj.AddMember(rapidjson::StringRef("AABB"), aabbValueObj, doc.GetAllocator()); } meshesObj.AddMember(subMeshKeyObj, subMeshValueObj, doc.GetAllocator()); } doc.AddMember(rapidjson::StringRef("Meshes"), meshesObj, doc.GetAllocator()); }
void Robot::Process_Register(rapidjson::Document& jsRequest, rapidjson::Document& jsResponse, string& sResponse) { rapidjson::Document::AllocatorType& allocator = jsResponse.GetAllocator(); int nErrcode = 0; string sErrmsg = "ok"; if (!IsRegistered()) { jsResponse.AddMember("question_bank_version", "1", allocator); string sRobotid = ""; if (jsRequest.HasMember("body") && jsRequest["body"].IsObject()) { rapidjson::Value& body = jsRequest["body"]; if (body.HasMember("robot_id") && body["robot_id"].IsString()) { sRobotid = body["robot_id"].GetString(); } else if (jsRequest.HasMember("mac") && jsRequest["mac"].IsObject()) { sRobotid = body["mac"].GetString(); } if (!sRobotid.empty()) { // 清除robot_id对应的旧链接 SAContainerSingleLock csl(&RobotService::instance().m_robotManager.m_mapRobot, true); SPRobotPtr spRobot = RobotService::instance().m_robotManager.FindRobot(sRobotid); bool bSuccess = true; if (spRobot) { if (spRobot->isCreateisElapsed(10000)) { // 旧链接创建超过10s,可踢掉 log.error( format("break session '%s'",spRobot->GetRobotID())); spRobot->Close(); spRobot->SetValid(false); } else { log.warning(format("connect frequency too high,reserve old connection'%s'!", spRobot->GetRobotID())); SATCPConnectionPtr spSocket = m_spSocket; spSocket->Close(); bSuccess = false; nErrcode = 6; sErrmsg = "connect frequency too high,reserve old connection!"; } } if (bSuccess) { m_bIsRegistered = true; m_sID = sRobotid; RobotService::instance().m_robotManager.AddRobot(GetRobotPtr()); //RobotService::instance().m_mapUnkownList.RemoveKey(m_sClient); } csl.Unlock(); } else { nErrcode = 8; sErrmsg = "invalid msg data,miss robot_id param!"; log.warning("invalid msg data,miss robot_id param!"); } } else { nErrcode = 7; sErrmsg = "invalid msg data,miss necessary param!"; log.warning("invalid msg data,miss necessary param!"); } } else { nErrcode = 5; sErrmsg = "Process register failed,already registered!"; log.error("Process register failed,already registered!"); } jsResponse.AddMember("errcode", 0, allocator); jsResponse.AddMember("errmsg", "ok", allocator); sResponse = JsonDocToString(jsResponse); }