Example #1
0
	Json::Value writeJson () {
		Json::Value json;
		json.resize(size());
		Json::ArrayIndex k=0;
		for (size_t i=0; i<_setStates.size(); ++i, ++k) {
			Json::Value jsonState;
			jsonState["name"] = _setStates[i].name();
//			jsonState["type"] = "set";
			jsonState["value"] = _setStates[i].getSet(_setStates[i].get()); // Get the actual value, not index
			json[k] = jsonState;
		}
		for (size_t i=0; i<_intStates.size(); ++i, ++k) {
			Json::Value jsonState;
			jsonState["name"] = _intStates[i].name();
//			jsonState["type"] = "int";
			jsonState["value"] = _intStates[i].get();
			json[k] = jsonState;
		}
		for (size_t i=0; i<_realStates.size(); ++i, ++k) {
			Json::Value jsonState;
			jsonState["name"] = _realStates[i].name();
//			jsonState["type"] = "real";
			jsonState["value"] = _realStates[i].get();
			json[k] = jsonState;
		}
		return json;
	}
void
ServerMethods::transaction (const Json::Value &params, Json::Value &response)
{
  std::string sessionId;
  Json::Value operations;
  std::string uniqueId = generateUUID();

  requireParams (params);

  getOrCreateSessionId (sessionId, params);

  JsonRpc::getArray (params, "operations", operations);
  Json::Value responses;

  for (uint i = 0; i < operations.size(); i++) {
    bool ret;

    Json::Value &reqParams = operations[i][JSON_RPC_PARAMS];

    reqParams[SESSION_ID] = sessionId;

    if (!operations[i][JSON_RPC_ID].isConvertibleTo (Json::ValueType::uintValue)
        || operations[i][JSON_RPC_ID].asUInt() != i) {
      Json::Value data;

      KurentoException ke (MALFORMED_TRANSACTION,
                           "Id of request '" + std::to_string (i) +
                           "' should be '" + std::to_string (i) + "'");

      data[TYPE] = ke.getType();

      throw JsonRpc::CallException (ke.getCode (), ke.getMessage (), data);
    }

    try {
      operations[i][JSON_RPC_ID] = uniqueId + "_" + std::to_string (
                                     operations[i][JSON_RPC_ID].asUInt() );
    } catch (...) {
      GST_ERROR ("Error setting id");
    }

    injectRefs (reqParams, responses);

    ret = handler.process (operations[i], responses[i]);

    responses[i][JSON_RPC_ID] = i;

    if (!ret) {
      break;
    }
  }

  if (responses.isNull () ) {
    responses.resize (0);
  }

  response[VALUE] = responses;
  response[SESSION_ID] = sessionId;
}
Example #3
0
inline Json::Value toJsonArrayOfObjects(const std::vector<T>& vec)
{
    Json::Value json;
    json.resize(vec.size());

    for (std::size_t i(0); i < vec.size(); ++i)
    {
        json[static_cast<Json::ArrayIndex>(i)] = vec[i].toJson();
    }

    return json;
}
Example #4
0
void
fill_json(Json::Value& dest, unsigned int depth) {
    int r = 0;

    if (depth < MAX_DEPTH / 5) {
        r = 4 + rand() % 2;
    } else if (depth > MAX_DEPTH) {
        r = rand() % 4;
    } else {
        r = rand() % 6;
    }

    if (r == 0) {
        dest = true;
    } else if (r == 1) {
        dest = 1337;
    } else if (r == 2) {
        dest = 64813.101;
    } else if (r == 3) {
        std::string s;
        size_t size = rand() % (10 * BASE_SIZE);
        s.reserve(size);
        for (size_t i = 0; i < size; ++i) {
            s.push_back(char(30 + rand() % 30));
        }
        dest = std::move(s);
    } else if (r == 4) {
        size_t size = rand() % (BASE_SIZE / 10);
        dest.resize(size);
        for (size_t i = 0; i < size; ++i) {
            Json::Value d;
            fill_json(d, depth + 1);
            dest[(unsigned int)i] = std::move(d);
        }
    } else if (r == 5) {
        for (size_t i = 0; i < size_t(rand() % (BASE_SIZE / 10)); ++i) {
            std::string key;
            size_t size = rand() % BASE_SIZE;
            key.reserve(size);
            for (size_t i = 0; i < size; ++i) {
                key.push_back(char(30 + rand() % 30));
            }

            Json::Value d;
            fill_json(d, depth + 1);

            dest[key] = std::move(d);
        }
    }
}
Example #5
0
bool CRProductDepot::fillAccountProducts2Json( const CRFetchAccountProducts& fapParam, Json::Value& valProducts, int& nErrCode ) {
	product_list_type* pProductList = NULL;
	product_list_type::iterator itProduct, iendProduct;
    name2pl_map_type::iterator itName2PL;
	nErrCode = CRERR_SRV_NONE;
	
	// clear cache.
	itName2PL = m_mapName2ProductListCache.find( fapParam.m_strAccountName );
	if ( itName2PL != m_mapName2ProductListCache.end() ) {
	    delete itName2PL->second;
		itName2PL->second = NULL;
		m_mapName2ProductListCache.clear();
		_clearRAPFDBFlag( fapParam.m_strAccountName );
	}
	//
	if ( !_loadAccountProductsFromDB( fapParam, nErrCode ) )
	    return false;
	//
	itName2PL = m_mapName2ProductListCache.find( fapParam.m_strAccountName );
	if ( itName2PL == m_mapName2ProductListCache.end() ) {
		valProducts.resize(0);
	    return true; // means no product published.
	}

	// save cache version, not finish.
	//itName2PL = m_mapName2ProductListCache.find( fapParam.m_strAccountName );
	//if ( itName2PL == m_mapName2ProductListCache.end() ) {
	//	if ( !_loadAccountProductsFromDB( fapParam, nErrCode ) )
	//		return false;
	//	itName2PL = m_mapName2ProductListCache.find( fapParam.m_strAccountName );
	//	if ( itName2PL == m_mapName2ProductListCache.end() )
	//		return false;
	//}

	pProductList = itName2PL->second;
	assert( pProductList );
	iendProduct = pProductList->end();
	for ( itProduct = pProductList->begin(); itProduct!=iendProduct; ++itProduct ) {
	    Json::Value valPItem;
        if ( !_fillProduct2Item( *itProduct, valPItem ) )
			continue;
		valProducts.append( valPItem );
	}

	return true;
}
void AnimationBuilder::interpolateFrame(ParamsFile &pnew, int frameno)
{
	for(auto itP = A.begin(); itP != A.end(); itP ++){
		if((*itP).second.lastSetIndex >= (*itP).second.F.size() - 1){
			continue;
		}

		int nextFrameIndex = (*itP).second.lastSetIndex + 1;
		KeyFrame nextFrame = (*itP).second.F[nextFrameIndex];

		if(nextFrame.frameno == frameno){
			*((*itP).second.jsonPtr) = nextFrame.val;

			(*itP).second.lastSetIndex = nextFrameIndex;
		}else if(nextFrame.interp != "none"){
			int fi = (*itP).second.F[(*itP).second.lastSetIndex].frameno;
			int ff = nextFrame.frameno;
			Json::Value i = (*itP).second.F[(*itP).second.lastSetIndex].val;
			Json::Value f = nextFrame.val;

			if((*itP).second.pType == SVT_INT){
				*((*itP).second.jsonPtr) =
					animationInterpolate(nextFrame.interp, frameno, fi, ff, i.asInt(), f.asInt());
			}else if((*itP).second.pType == SVT_REAL){
				*((*itP).second.jsonPtr) =
					animationInterpolate(nextFrame.interp, frameno, fi, ff, i.asDouble(), f.asDouble());
			}else if((*itP).second.pType == SVT_COLOR){
				Json::Value arr = Json::Value(Json::ValueType::arrayValue);
				arr.resize(3);
				arr[0] = animationInterpolate(nextFrame.interp, frameno, fi, ff,
							i[0].asDouble(), f[0].asDouble());
				arr[1] = animationInterpolate(nextFrame.interp, frameno, fi, ff,
							i[1].asInt(), f[1].asInt());
				arr[2] = animationInterpolate(nextFrame.interp, frameno, fi, ff,
							i[2].asInt(), f[2].asInt());
				*((*itP).second.jsonPtr) = arr;
			}else if((*itP).second.pType == SVT_COMPLEX){
				std::complex<double> zi = getComplexValueFromString(i.asString());
				std::complex<double> zf = getComplexValueFromString(f.asString());
				std::complex<double> z = animationInterpolate(nextFrame.interp, frameno, fi, ff, zi, zf);
				std::string res = concat("", z.real()) + concat("+", z.imag()) + "i";
				*((*itP).second.jsonPtr) = res;
			}
		}
	}
}
Example #7
0
void PartContainer::save(Json::Value& value) const
{
	Container::save(value);

	value["attachments"].resize(0);

	for(Part* part : *this)
	{
		Json::Value attachments;

		attachments.resize(0);

		for(Part* attachedPart : getAttachedParts(part))
		{
			attachments.append(getIndexOf(attachedPart));
		}

		value["attachments"].append(attachments);
	}
}
Example #8
0
static void Serialize( const NoteData &o, Json::Value &root )
{
	root = Json::Value(Json::arrayValue);
	for(int t=0; t < o.GetNumTracks(); t++ )
	{
		NoteData::TrackMap::const_iterator begin, end;
		o.GetTapNoteRange( t, 0, MAX_NOTE_ROW, begin, end );
		//NoteData::TrackMap tm = o.GetTrack(t);
		//FOREACHM_CONST( int, TapNote, tm, iter )
		for( ; begin != end; ++begin )
		{
			int iRow = begin->first;
			TapNote tn = begin->second;
			root.resize( root.size()+1 );
			Json::Value &root2 = root[ root.size()-1 ];
			root2 = Json::Value(Json::arrayValue);
			root2.resize(3);
			root2[(unsigned)0] = NoteRowToBeat(iRow);
			root2[1] = t;
			Serialize( tn, root2[2] );
		}
	}
}
Example #9
0
void Manifest::save(const bool primary, const std::string postfix) const
{
    auto m(m_endpoint.getSubEndpoint("m"));

    Json::Value json;
    json["fileStats"] = m_fileStats.toJson();
    json["pointStats"] = m_pointStats.toJson();
    Json::Value& fileInfo(json["fileInfo"]);

    // If we have a postfix (and therefore we're a subset), we'll just write
    // everything out together even if it's huge.  The split-up metadata is a
    // read-time optimization - we'll need to wake everything up to merge at
    // build time anyway.
    const auto n(size());
    const bool dense(n <= denseSize || postfix.size());
    fileInfo.resize(n);

    if (dense || (m.isLocal() && !arbiter::fs::mkdirp(m.root())))
    {
        for (Json::ArrayIndex i(0); i < n; ++i)
        {
            fileInfo[i] = m_fileInfo[i].toJson(primary);
        }
    }
    else
    {
        assert(postfix.empty());

        for (Json::ArrayIndex i(0); i < n; ++i)
        {
            // We're storing the file info separately, so the "fileInfo" key
            // will just contain path/bounds instead of the full info object.
            json["remote"] = true;
            json["chunkSize"] = static_cast<Json::UInt64>(chunkSize);
            fileInfo[i]["path"] = m_fileInfo[i].path();

            if (const auto b = m_fileInfo[i].bounds())
            {
                fileInfo[i]["bounds"] = b->toJson();
            }
        }

        // TODO Could pool these.
        for (Json::ArrayIndex i(0); i < n; i += chunkSize)
        {
            Json::Value chunk;
            chunk.resize(std::min(chunkSize, n - i));

            for (Json::ArrayIndex c(0); c < chunk.size(); ++c)
            {
                chunk[c] = m_fileInfo[i + c].toJson(primary);
            }

            io::ensurePut(m, std::to_string(i), chunk.toStyledString());
        }
    }

    io::ensurePut(
            m_endpoint,
            "entwine-manifest" + postfix,
            primary ? json.toStyledString() : toFastString(json));
}
Example #10
0
static std::string xml2jsonstr(const XML4NLP & xml, std::string str_type) {
  Json::Value root;

  int paragraphNum = xml.CountParagraphInDocument();

  for (int pid = 0; pid < paragraphNum; ++ pid) {
    Json::Value paragraph;

    int stnsNum = xml.CountSentenceInParagraph(pid);
    for (int sid = 0; sid < stnsNum; ++sid) {
      Json::Value sentence;

      std::vector<std::string> vecWord;
      std::vector<std::string> vecPOS;
      std::vector<std::string> vecNETag;
      std::vector<std::pair<int, std::string>> vecParse;
      //std::vector<std::vector<std::string>> vecSemResult;
      std::vector<std::vector<std::pair<int, std::string>>> vecSemResult;
      std::vector<std::pair<int, std::vector<std::pair<const char *, std::pair< int, int > > > > > vecSRLResult;

      // seg
      xml.GetWordsFromSentence(vecWord, pid, sid);

      // postag
      if (str_type == LTP_SERVICE_NAME_POSTAG
          || str_type == LTP_SERVICE_NAME_NER
          || str_type == LTP_SERVICE_NAME_DEPPARSE
          || str_type == LTP_SERVICE_NAME_SRL
          || str_type == LTP_SERVICE_NAME_ALL) {
        xml.GetPOSsFromSentence(vecPOS, pid, sid);
      }

      // ner
      if (str_type == LTP_SERVICE_NAME_NER
          || str_type == LTP_SERVICE_NAME_SRL
          || str_type == LTP_SERVICE_NAME_ALL) {
        xml.GetNEsFromSentence(vecNETag, pid, sid);
      }

      // dp
      if (str_type == LTP_SERVICE_NAME_DEPPARSE
          || str_type == LTP_SERVICE_NAME_SRL
          || str_type == LTP_SERVICE_NAME_ALL) {
        xml.GetParsesFromSentence(vecParse, pid, sid);
      }

      // srl
      if (str_type == LTP_SERVICE_NAME_SRL
          || str_type == LTP_SERVICE_NAME_ALL) {
        // get by word
      }

      for (int wid = 0; wid < vecWord.size(); ++wid) {
        Json::Value word;
        word["id"] = wid;
        word["cont"] = vecWord[wid];

        // postag
        if (str_type == LTP_SERVICE_NAME_POSTAG
            || str_type == LTP_SERVICE_NAME_NER
            || str_type == LTP_SERVICE_NAME_DEPPARSE
            || str_type == LTP_SERVICE_NAME_SRL
            || str_type == LTP_SERVICE_NAME_ALL) {
          word["pos"] = vecPOS[wid];

        }

        // ner
        if (str_type == LTP_SERVICE_NAME_NER
            || str_type == LTP_SERVICE_NAME_SRL
            || str_type == LTP_SERVICE_NAME_ALL) {
          word["ne"] = vecNETag[wid];
        }

        // dp
        if (str_type == LTP_SERVICE_NAME_DEPPARSE
            || str_type == LTP_SERVICE_NAME_SRL
            || str_type == LTP_SERVICE_NAME_ALL) {
          word["parent"] = vecParse[wid].first;
          word["relate"] = vecParse[wid].second;
        }

        // srl
        if (str_type == LTP_SERVICE_NAME_SRL
            || str_type == LTP_SERVICE_NAME_ALL) {
          Json::Value args;
          std::vector<std::string> vecType;
          std::vector<std::pair<int, int>> vecBegEnd;
          xml.GetPredArgToWord(pid, sid, wid, vecType, vecBegEnd);
          if (vecType.size() != 0) {
            for (int arg_id = 0; arg_id < vecType.size(); ++arg_id) {
              Json::Value arg;
              arg["id"] = arg_id;
              arg["type"] = vecType[arg_id];
              arg["beg"] = vecBegEnd[arg_id].first;
              arg["end"] = vecBegEnd[arg_id].second;
              args.append(arg);
            }
          } else {
            args.resize(0);
          }
          word["arg"] = args;
        }

        sentence.append(word);
      }

      paragraph.append(sentence);
    } // sentence
    root.append(paragraph);
  } // paragraph
  return root.toStyledString();
}