std::shared_ptr<b2dJson> JsonLoader::load() { if (getJson()) { throw new std::runtime_error("Already loaded"); } readFromString(filename); createSprites(); triggerFactories(); return getJson(); }
void JsonLoader::moveAllBy(const b2Vec2& delta) { if (!getJson()) { throw new std::runtime_error("Nothing loaded yet"); } std::vector<b2Body*> bodies; getJson()->getAllBodies(bodies); for (auto& body : bodies) { body->SetTransform(body->GetPosition() + delta, body->GetAngle()); } }
// Create DSP Factory bool Server::compile_Data(connection_info_struct* con_info){ if(con_info->fSHAKey != ""){ // Sort out compilation options int argc = con_info->fCompilationOptions.size(); const char* argv[argc]; for(int i=0; i<argc; i++){ argv[i] = (con_info->fCompilationOptions[i]).c_str(); } string error(""); con_info->fLLVMFactory = createDSPFactoryFromString(con_info->fNameApp, con_info->fFaustCode, argc, argv, "", error, atoi(con_info->fOptLevel.c_str())); if(con_info->fLLVMFactory){ fAvailableFactories[con_info->fSHAKey] = make_pair(con_info->fNameApp, con_info->fLLVMFactory); // Once the factory is compiled, the json is stored as answerstring con_info->fAnswerstring = getJson(con_info); return true; } } con_info->fAnswerstring = "Impossible to generate SHA1 key"; return false; }
void reFBXAsset::load() { clearChildren(); bool importNeeded = true; ifstream ifs(metaPath().toStdString().c_str(), ios::in); if (!ifs.fail()) { Json::Reader reader; Json::Value root; reader.parse(ifs, root); QString hash = root["hash"].asString().c_str(); if (fileHash() == hash) { loadJson(root); importNeeded = false; } } if (importNeeded) import(); loadNodeAssets(); Json::StyledWriter writer; ofstream fs(metaPath().toStdString().c_str(), ios::out); fs << writer.write(getJson()); fs.close(); }
void QDropboxAccount::_init() { if(!isValid()) { valid = false; return; } if(!hasKey("referral_link") || !hasKey("display_name") || !hasKey("uid") || !hasKey("country") || !hasKey("quota_info") || !hasKey("email")) { #ifdef QTDROPBOX_DEBUG qDebug() << "json invalid 1" << endl; #endif valid = false; return; } QDropboxJson* quota = getJson("quota_info"); if(!quota->hasKey("shared") || !quota->hasKey("quota") || !quota->hasKey("normal")) { #ifdef QTDROPBOX_DEBUG qDebug() << "json invalid 2" << endl; #endif valid = false; return; } _referralLink.setUrl(getString("referral_link"), QUrl::StrictMode); _displayName = getString("display_name"); _uid = getInt("uid"); _country = getString("country"); _email = getString("email"); _quotaShared = quota->getUInt("shared", true); _quota = quota->getUInt("quota", true); _quotaNormal = quota->getUInt("normal", true); valid = true; #ifdef QTDROPBOX_DEBUG qDebug() << "== account data ==" << endl; qDebug() << "reflink: " << _referralLink << endl; qDebug() << "displayname: " << _displayName << endl; qDebug() << "uid: " << _uid << endl; qDebug() << "country: " << _country << endl; qDebug() << "email: " << _email << endl; qDebug() << "quotaShared: " << _quotaShared << endl; qDebug() << "quotaNormal: " << _quotaNormal << endl; qDebug() << "quotaUsed: " << _quota << endl; qDebug() << "== account data end ==" << endl; #endif return; }
void test_profile_view(){ HTTPClientSession s(HOST, PORT); HTTPRequest request(HTTPRequest::HTTP_GET, std::string("/api/v1/profile/").append(created_profile_uuid)); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); std::string data; StreamCopier::copyToString(rs, data); LOGDEBUG("response:"<<data); JSONNode node = getJson(data); assert_response(node); assert(node.contains("data")); assert(node["data"].contains("format")); assert(node["data"]["format"].contains("id")); assert(node["data"]["format"]["id"]=="matroska"); assert(node["data"].contains("video")); assert(node["data"]["video"].contains("id")); assert(node["data"]["video"]["id"]=="mpeg4"); assert(node["data"].contains("audio")); }
void ApplicationResource::doPOST(Descriptor& socket, HttpMessage& request, const char* remainingPath) { std::string key; if (request.queryParameterMap.find("action") < 0) { key = "_default"; } else { key = request.queryParameterMap["action"][0]; } std::shared_lock<std::shared_mutex> readLock(mutex); if (! getJson()["_actions"].contains(key)) throw HttpCode::Http406; runApplication(getJson()["_actions"][key].toString()); sendStatus(socket, HttpCode::Http204); }
Json::Value doTx (RPC::Context& context) { if (!context.params.isMember (jss::transaction)) return rpcError (rpcINVALID_PARAMS); bool binary = context.params.isMember (jss::binary) && context.params[jss::binary].asBool (); auto const txid = context.params[jss::transaction].asString (); if (!isHexTxID (txid)) return rpcError (rpcNOT_IMPL); auto txn = getApp().getMasterTransaction ().fetch (uint256 (txid), true); if (!txn) return rpcError (rpcTXN_NOT_FOUND); Json::Value ret = txn->getJson (1, binary); if (txn->getLedger () == 0) return ret; if (auto lgr = context.netOps.getLedgerBySeq (txn->getLedger ())) { bool okay = false; if (binary) { std::string meta; if (lgr->getMetaHex (txn->getID (), meta)) { ret[jss::meta] = meta; okay = true; } } else { TransactionMetaSet::pointer txMeta; if (lgr->getTransactionMeta (txn->getID (), txMeta)) { okay = true; auto meta = txMeta->getJson (0); addPaymentDeliveredAmount (meta, context, txn, txMeta); ret[jss::meta] = meta; } } if (okay) ret[jss::validated] = context.netOps.isValidated (lgr); } return ret; }
SerializedValidation::SerializedValidation(SerializerIterator& sit, bool checkSignature) : STObject(sValidationFormat, sit, sfValidation), mTrusted(false) { mNodeID = RippleAddress::createNodePublic(getFieldVL(sfSigningPubKey)).getNodeID(); assert(mNodeID.isNonZero()); if (checkSignature && !isValid()) { Log(lsTRACE) << "Invalid validation " << getJson(0); throw std::runtime_error("Invalid validation"); } }
/** * Instantiate an application and dump a single JSON object, * representing a ledger, to standard out. */ void LedgerDump::dumpLedger (int ledgerNum) { std::unique_ptr <Application> app (make_Application ()); app->setup (); auto &lm = app->getLedgerMaster (); auto ledger = lm.getLedgerBySeq (ledgerNum); std::cout << ledger->getJson (LEDGER_JSON_DUMP_TSTR| LEDGER_JSON_EXPAND) << std::endl; exit (0); }
void TextureBuffer::extendBufferBytes(size_t addSize) { if (getState() != AbstractResource::LOADED) LITE3D_THROW(getName() << " resource unavailable"); if (!lite3d_texture_buffer_extend(&mTexture, addSize, getJson().getBool(L"Dynamic", false) ? LITE3D_VBO_DYNAMIC_DRAW : LITE3D_VBO_STATIC_DRAW)) { LITE3D_THROW(getName() << " texture buffer extend failed, probably it is not supported"); } }
Json::Value STTx::getJson (int options, bool binary) const { if (binary) { Json::Value ret; Serializer s = STObject::getSerializer (); ret[jss::tx] = strHex (s.peekData ()); ret[jss::hash] = to_string (getTransactionID ()); return ret; } return getJson(options); }
void test_profile_create(){ HTTPClientSession s(HOST, PORT); HTTPRequest request(HTTPRequest::HTTP_POST, "/api/v1/profile/"); //std::ostringstream os; JSONNode base(JSON_NODE); base.push_back(JSONNode("name","test profile")); base.push_back(JSONNode("description","test description")); JSONNode format(JSON_NODE); format.set_name("format"); format.push_back(JSONNode("id","mp4")); base.push_back(format); JSONNode video(JSON_NODE); video.set_name("video"); //video.push_back(JSONNode("id","mpeg4")); video.push_back(JSONNode("id","libx264")); video.push_back(JSONNode("qscale","4")); video.push_back(JSONNode("aubq","8")); video.push_back(JSONNode("me_range","16")); video.push_back(JSONNode("qmin","4")); video.push_back(JSONNode("qmax","51")); video.push_back(JSONNode("qcomp","0.6")); video.push_back(JSONNode("qdiff","4")); base.push_back(video); JSONNode audio(JSON_NODE); audio.set_name("audio"); audio.push_back(JSONNode("id","mp2")); audio.push_back(JSONNode("ar","44100")); audio.push_back(JSONNode("ac","2")); base.push_back(audio); //request.write(os); std::ostream & os=s.sendRequest(request); os << base.write_formatted(); HTTPResponse response; std::istream& rs = s.receiveResponse(response); std::string data; StreamCopier::copyToString(rs, data); LOGDEBUG("response:"<<data); JSONNode node = getJson(data); assert_response(node); assert(node.contains("uuid")); created_profile_uuid=node["uuid"].as_string(); }
void load(char const * const url) { bound_buffer bb; getJson(&bb, url); /* if (failed) { response::errorish(std::string(bb.first, bb.length)); free(bb.first); } */ response::log("Loaded JSON data"); inject(bb.first); dealloc_bound_buffer(&bb); }
std::unique_ptr<IR::Root> JsonConfigParser::parse(const std::string& input) { Json::Value json_root; getJson(json_root, input); auto ir_root = std::make_unique<IR::Root>(); for (const auto& ruleset : json_root.get("rulesets", {})) { ir_root->rulesets.emplace_back(parseRuleset(ruleset)); } ir_root->version = json_root.get("version", "").asString(); IR::dumpIR(*ir_root); return ir_root; }
bool dsp_server_connection_info::getFactoryFromSHAKey(DSPServer* server) { // Will increment factory reference counter... llvm_dsp_factory* factory = getDSPFactoryFromSHAKey(fSHAKey); //llvm_dsp_factory* factory = getCDSPFactoryFromSHAKey(fSHAKey.c_str()); if (factory) { getJson(factory); return true; } else { fAnswer = "Factory not found"; return false; } }
void test_profile_list(){ HTTPClientSession s(HOST, PORT); HTTPRequest request(HTTPRequest::HTTP_GET, std::string("/api/v1/profile/")); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); std::string data; StreamCopier::copyToString(rs, data); LOGDEBUG("response:"<<data); JSONNode node = getJson(data); assert_response(node); }
STValidation::STValidation (SerialIter& sit, bool checkSignature) : STObject (getFormat (), sit, sfValidation) { mNodeID = calcNodeID( PublicKey(makeSlice (getFieldVL (sfSigningPubKey)))); assert (mNodeID.isNonZero ()); if (checkSignature && !isValid ()) { JLOG (debugLog().error()) << "Invalid validation" << getJson (0); Throw<std::runtime_error> ("Invalid validation"); } }
void test_profile_delete(){ HTTPClientSession s(HOST, PORT); HTTPRequest request(HTTPRequest::HTTP_DELETE, std::string("/api/v1/profile/").append(created_profile_uuid)); s.sendRequest(request); HTTPResponse response; std::istream& rs = s.receiveResponse(response); std::string data; StreamCopier::copyToString(rs, data); LOGDEBUG("response:"<<data); JSONNode node = getJson(data); assert_response(node); assert(node["response"]["status"]=="ok"); }
bool Server::getJsonFromKey(connection_info_struct* con_info){ string SHA_Key = con_info->fSHAKey; con_info->fNameApp = fAvailableFactories[SHA_Key].first; con_info->fLLVMFactory = fAvailableFactories[SHA_Key].second; if(con_info->fLLVMFactory){ con_info->fAnswerstring = getJson(con_info); return true; } else{ con_info->fAnswerstring = "Factory Not Found!"; return false; } }
void JsonLoader::createSprites() { std::vector<b2dJsonImage*> b2dImages; getJson()->getAllImages(b2dImages); cocos2d::Sprite* sprite = nullptr; for (auto& def : b2dImages) { if (def->body) { sprite = &createPhysicsSprites(*def); } else { sprite = &createStaticSprites(*def); } applyCommonSettings(*def, *sprite); box2dContainer.addChild(sprite, def->renderOrder); } }
bool dsp_server_connection_info::getFactoryFromSHAKey(DSPServer* server) { // Will increment factory reference counter... #ifdef LLVM_DSP_FACTORY dsp_factory* factory = getDSPFactoryFromSHAKey(fSHAKey); #else dsp_factory* factory = getInterpreterDSPFactoryFromSHAKey(fSHAKey); #endif if (factory) { getJson(factory); return true; } else { fAnswer = "Factory not found"; return false; } }
void getJson(cJSON *root){ cJSON *p = cJSON_GetObjectItem(root,"name"); if(p){ printf("name:%s\n",p->valuestring); } p = cJSON_GetObjectItem(root,"age"); if(p){ printf("age:%d\n",p->valueint); } p = cJSON_GetObjectItem(root,"money"); if(p){ printf("money:%lf\n",p->valuedouble); } if(p = cJSON_GetObjectItem(root,"child")){ getJson(p); } }
void STLedgerEntry::setSLEType () { mFormat = LedgerFormats::getInstance().findByType ( static_cast <LedgerEntryType> (getFieldU16 (sfLedgerEntryType))); if (mFormat == nullptr) throw std::runtime_error ("invalid ledger entry type"); type_ = mFormat->getType (); if (!setType (mFormat->elements)) { WriteLog (lsWARNING, SerializedLedger) << "Ledger entry not valid for type " << mFormat->getName (); WriteLog (lsWARNING, SerializedLedger) << getJson (0); throw std::runtime_error ("ledger entry not valid for type"); } }
void test_profile_update(){ HTTPClientSession s(HOST, PORT); HTTPRequest request(HTTPRequest::HTTP_PUT, std::string("/api/v1/profile/").append(created_profile_uuid)); JSONNode base(JSON_NODE); base.push_back(JSONNode("name","test profile")); base.push_back(JSONNode("description","test description")); JSONNode format(JSON_NODE); format.set_name("format"); format.push_back(JSONNode("id","matroska")); base.push_back(format); JSONNode video(JSON_NODE); video.set_name("video"); video.push_back(JSONNode("id","mpeg4")); base.push_back(video); JSONNode audio(JSON_NODE); audio.set_name("audio"); audio.push_back(JSONNode("id","mp2")); audio.push_back(JSONNode("ar","44100")); audio.push_back(JSONNode("ac","2")); base.push_back(audio); //request.write(os); std::ostream & os=s.sendRequest(request); os << base.write_formatted(); HTTPResponse response; std::istream& rs = s.receiveResponse(response); std::string data; StreamCopier::copyToString(rs, data); LOGDEBUG("response:"<<data); JSONNode node = getJson(data); assert_response(node); assert(node.contains("uuid")); assert(node["uuid"]==created_profile_uuid); }
void STLedgerEntry::setSLEType () { mFormat = LedgerFormats::getInstance().findByType ( static_cast <LedgerEntryType> (getFieldU16 (sfLedgerEntryType))); if (mFormat == nullptr) Throw<std::runtime_error> ("invalid ledger entry type"); type_ = mFormat->getType (); if (!setType (mFormat->elements)) { if (auto j = debugLog().error()) { j << "Ledger entry not valid for type " << mFormat->getName (); j << "Object: " << getJson (0); } Throw<std::runtime_error> ("ledger entry not valid for type"); } }
/** * Instantiate an application, enumerate all its ledgers, and dump them * to `filename` as a stream of JSON objects, one per ledger, * delimited by the `DUMP_DELIM` character. */ void LedgerDump::dumpTransactions (std::string const& filename) { std::ofstream out (filename); require(bool(out), "Cannot open output file"); std::unique_ptr <Application> app (make_Application ()); std::uint32_t minLedgerSeq = 0, maxLedgerSeq = static_cast<uint32_t> (-1); app->setup (); auto &lm = app->getLedgerMaster (); std::map< std::uint32_t, std::pair<uint256, uint256> > ledgerHashes = Ledger::getHashesByIndex (minLedgerSeq, maxLedgerSeq); WriteLog (lsINFO, LedgerDump) << "Dumping " << ledgerHashes.size () << " ledgers to " << filename; auto nLedgers = 0; for (auto const &ix : ledgerHashes) { if (nLedgers != 0) { out << DUMP_DELIM << std::endl; } if ((nLedgers & 0xfff) == 0) { Job j; app->doSweep (j); } nLedgers++; auto ledger = lm.getLedgerBySeq (ix.first); out << ledger->getJson (LEDGER_JSON_BULK) << std::endl; } WriteLog (lsINFO, LedgerDump) << "Dumped " << ledgerHashes.size() << " ledgers to " << filename; exit (0); }
void WebServiceFSM::update() { if(state == UpstreamState::IDLE && !command_available && delayExpired()) { state = UpstreamState::FETCH_CMD; } if(state == UpstreamState::IDLE && command_completed) { state = UpstreamState::ACKING; } if(state == UpstreamState::ACKING && delayExpired()) { JsonObject& obj = jsonBuffer.createObject(); command.toJson(obj); if (transmitJson("PUT","http://localhost:8080/commands",obj)) { state = UpstreamState::IDLE; } else { setDelay(READ_AGAIN_COOLDOWN_TIME); // which delay period to use? } } if(state == UpstreamState::FETCH_CMD) { auto& obj = getJson("http://localhost:8080/commands?pid=0"); if (!obj.success()) { setDelay(READ_AGAIN_COOLDOWN_TIME); state = UpstreamState::IDLE; } else { if (command.fromJson(obj)) { command_available = true; command_completed = false; state = UpstreamState::IDLE; } else { setDelay(READ_AGAIN_COOLDOWN_TIME); state = UpstreamState::IDLE; } } } if(state == UpstreamState::SENDING && delayExpired()) { // to be implemented later, when mothership has sensor status } }
SerializedLedgerEntry::SerializedLedgerEntry (const Serializer& s, uint256 const& index) : STObject (sfLedgerEntry), mIndex (index), mMutable (true) { SerializerIterator sit (const_cast<Serializer&> (s)); // we know 's' isn't going away set (sit); uint16 type = getFieldU16 (sfLedgerEntryType); LedgerFormats::Item const* const item = LedgerFormats::getInstance()->findByType (static_cast <LedgerEntryType> (type)); if (item == nullptr) throw std::runtime_error ("invalid ledger entry type"); mType = item->getType (); if (!setType (item->elements)) { WriteLog (lsWARNING, SerializedLedgerLog) << "Ledger entry not valid for type " << mFormat->getName (); WriteLog (lsWARNING, SerializedLedgerLog) << getJson (0); throw std::runtime_error ("ledger entry not valid for type"); } }
bool Ledger::assertSane (beast::Journal ledgerJ) const { if (info_.hash.isNonZero () && info_.accountHash.isNonZero () && stateMap_ && txMap_ && (info_.accountHash == stateMap_->getHash ().as_uint256()) && (info_.txHash == txMap_->getHash ().as_uint256())) { return true; } Json::Value j = getJson (*this); j [jss::accountTreeHash] = to_string (info_.accountHash); j [jss::transTreeHash] = to_string (info_.txHash); JLOG (ledgerJ.fatal()) << "ledger is not sane" << j; assert (false); return false; }