本文整理汇总了C++中json::Value::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::toString方法的具体用法?C++ Value::toString怎么用?C++ Value::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::toString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onSuccess
void onSuccess(download::Downloader *downloader) {
Log("listener: download success");
Json::Value message;
message["message"] = "success";
message["path"] = downloader->GetDownloadTask()->GetDownloadPath();
send(message.toString());
}
示例2: CheckAllStreams
void CheckAllStreams(JSON::Value & data){
long long int currTime = Util::epoch();
for (JSON::ObjIter jit = data.ObjBegin(); jit != data.ObjEnd(); jit++){
if ( !Util::Procs::isActive(jit->first)){
startStream(jit->first, jit->second);
}
if (currTime - lastBuffer[jit->first] > 5){
if (jit->second.isMember("error") && jit->second["error"].asString() != ""){
jit->second["online"] = jit->second["error"];
}else{
jit->second["online"] = 0;
}
}else{
jit->second["online"] = 1;
}
}
static JSON::Value strlist;
bool changed = false;
if (strlist["config"] != Storage["config"]){
strlist["config"] = Storage["config"];
changed = true;
}
if (strlist["streams"] != Storage["streams"]){
strlist["streams"] = Storage["streams"];
changed = true;
}
if (changed){
WriteFile("/tmp/mist/streamlist", strlist.toString());
}
}
示例3: CheckAllStreams
///\brief Checks all streams, restoring if needed.
///\param data The stream configuration for the server.
void CheckAllStreams(JSON::Value & data) {
long long int currTime = Util::epoch();
for (JSON::ObjIter jit = data.ObjBegin(); jit != data.ObjEnd(); jit++) {
if ( !Util::Procs::isActive(jit->first)) {
startStream(jit->first, jit->second);
}
if (currTime - lastBuffer[jit->first] > 5) {
if (jit->second.isMember("source") && jit->second["source"].asString().substr(0, 1) == "/" && jit->second.isMember("error")
&& jit->second["error"].asString() == "Available") {
jit->second["online"] = 2;
} else {
if (jit->second.isMember("error") && jit->second["error"].asString() == "Available") {
jit->second.removeMember("error");
}
jit->second["online"] = 0;
}
} else {
// assume all is fine
jit->second.removeMember("error");
jit->second["online"] = 1;
// check if source is valid
if (jit->second.isMember("live") && !jit->second.isMember("meta") || !jit->second["meta"]) {
jit->second["online"] = 0;
jit->second["error"] = "No (valid) source connected";
} else {
// for live streams, keep track of activity
if (jit->second["meta"].isMember("live")) {
if (jit->second["meta"]["lastms"] != jit->second["lastms"]) {
jit->second["lastms"] = jit->second["meta"]["lastms"];
jit->second["last_active"] = currTime;
}
// mark stream as offline if no activity for 5 seconds
if (jit->second.isMember("last_active") && jit->second["last_active"].asInt() < currTime - 5) {
jit->second["online"] = 0;
jit->second["error"] = "No (valid) source connected";
}
}
}
}
}
static JSON::Value strlist;
bool changed = false;
if (strlist["config"] != Storage["config"]) {
strlist["config"] = Storage["config"];
changed = true;
}
if (strlist["streams"] != Storage["streams"]) {
strlist["streams"] = Storage["streams"];
changed = true;
}
if (changed) {
WriteFile("/tmp/mist/streamlist", strlist.toString());
}
}
示例4: dump
std::string DownloadTask::dump() {
Json::Value root;
root["url"] = GetUrl();
root["download_path"] = GetDownloadPath();
root["md5"] = GetMd5();
root["file_size"] = Json::Value(GetFileSize());
root["progress"] = Json::Value(GetProgress());
root["breakpoint"] = Json::Value(GetBreakpoint());
return root.toString();
}
示例5: main
int main(int argc, char ** argv){
Util::Config conf(argv[0], PACKAGE_VERSION);
JSON::Value capa;
capa["desc"] = "Enables the raw MPEG Transport Stream protocol over TCP.";
capa["deps"] = "";
capa["required"]["streamname"]["name"] = "Stream";
capa["required"]["streamname"]["help"] = "What streamname to serve. For multiple streams, add this protocol multiple times using different ports.";
capa["required"]["streamname"]["type"] = "str";
capa["required"]["streamname"]["option"] = "--stream";
capa["optional"]["tracks"]["name"] = "Tracks";
capa["optional"]["tracks"]["help"] = "The track IDs of the stream that this connector will transmit separated by spaces";
capa["optional"]["tracks"]["type"] = "str";
capa["optional"]["tracks"]["option"] = "--tracks";
conf.addOption("streamname",
JSON::fromString("{\"arg\":\"string\",\"short\":\"s\",\"long\":\"stream\",\"help\":\"The name of the stream that this connector will transmit.\"}"));
conf.addOption("tracks",
JSON::fromString("{\"arg\":\"string\",\"value\":[\"\"],\"short\": \"t\",\"long\":\"tracks\",\"help\":\"The track IDs of the stream that this connector will transmit separated by spaces.\"}"));
conf.addConnectorOptions(8888, capa);
bool ret = conf.parseArgs(argc, argv);
if (conf.getBool("json")){
std::cout << capa.toString() << std::endl;
return -1;
}
if (!ret){
std::cerr << "Usage error: missing argument(s)." << std::endl;
conf.printHelp(std::cout);
return 1;
}
Socket::Server server_socket = Socket::Server(conf.getInteger("listen_port"), conf.getString("listen_interface"));
if ( !server_socket.connected()){
return 1;
}
conf.activate();
while (server_socket.connected() && conf.is_active){
Socket::Connection S = server_socket.accept();
if (S.connected()){ //check if the new connection is valid
pid_t myid = fork();
if (myid == 0){ //if new child, start MAINHANDLER
return Connector_TS::tsConnector(S, conf.getString("streamname"), conf.getString("tracks"));
}else{ //otherwise, do nothing or output debugging text
#if DEBUG >= 5
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
#endif
}
}
} //while connected
server_socket.close();
return 0;
} //main
示例6: main
///\brief The standard process-spawning main function.
int main(int argc, char ** argv){
Util::Config conf(argv[0], PACKAGE_VERSION);
JSON::Value capa;
capa["desc"] = "Enables the RTMP protocol which is used by Adobe Flash Player.";
capa["deps"] = "";
capa["url_rel"] = "/play/$";
capa["codecs"][0u][0u].append("H264");
capa["codecs"][0u][0u].append("H263");
capa["codecs"][0u][0u].append("VP6");
capa["codecs"][0u][1u].append("AAC");
capa["codecs"][0u][1u].append("MP3");
capa["methods"][0u]["handler"] = "rtmp";
capa["methods"][0u]["type"] = "flash/10";
capa["methods"][0u]["priority"] = 6ll;
conf.addConnectorOptions(1935, capa);
conf.parseArgs(argc, argv);
if (conf.getBool("json")){
std::cout << capa.toString() << std::endl;
return -1;
}
Socket::Server server_socket = Socket::Server(conf.getInteger("listen_port"), conf.getString("listen_interface"));
if ( !server_socket.connected()){
return 1;
}
conf.activate();
while (server_socket.connected() && conf.is_active){
Socket::Connection S = server_socket.accept();
if (S.connected()){ //check if the new connection is valid
pid_t myid = fork();
if (myid == 0){ //if new child, start MAINHANDLER
return Connector_RTMP::rtmpConnector(S);
}else{ //otherwise, do nothing or output debugging text
#if DEBUG >= 5
fprintf(stderr, "Spawned new process %i for socket %i\n", (int)myid, S.getSocket());
#endif
}
}
} //while connected
server_socket.close();
return 0;
} //main
示例7: getInfo
int getInfo(int argc, char* argv[]) {
if (argc < 2){
fprintf( stderr, "Usage: %s <filename>\n", argv[0] );
return 1;
}
DTSC::File F(argv[1]);
JSON::Value fileSpecs = F.getMeta().toJSON();
if( !fileSpecs ) {
char ** cmd = (char**)malloc(3*sizeof(char*));
cmd[0] = (char*)"ffprobe";
cmd[1] = argv[1];
cmd[2] = NULL;
int outFD = -1;
Util::Procs::StartPiped("FFProbe", cmd, 0, 0, &outFD);
while( Util::Procs::isActive("FFProbe")){ Util::sleep(100); }
FILE * outFile = fdopen( outFD, "r" );
char * fileBuf = 0;
size_t fileBufLen = 0;
while ( !(feof(outFile) || ferror(outFile)) && (getline(&fileBuf, &fileBufLen, outFile) != -1)){
std::string line = fileBuf;
if (line.find("Input") != std::string::npos){
std::string tmp = line.substr(line.find(", ") + 2);
fileSpecs["format"] = tmp.substr(0, tmp.find(","));
}
if (line.find("Duration") != std::string::npos){
std::string tmp = line.substr(line.find(": ", line.find("Duration")) + 2);
tmp = tmp.substr(0, tmp.find(","));
int length = (((atoi(tmp.substr(0,2).c_str()) * 60) + atoi(tmp.substr(3,2).c_str())) * 60) + atoi(tmp.substr(6,2).c_str());
fileSpecs["length"] = length;
length *= 100;
length += atoi(tmp.substr(9,2).c_str());
fileSpecs["lastms"] = length * 10;
}
if (line.find("bitrate") != std::string::npos ){
std::string tmp = line.substr(line.find(": ", line.find("bitrate")) + 2);
fileSpecs["bps"] = atoi(tmp.substr(0, tmp.find(" ")).c_str()) * 128;
}
if (line.find("Stream") != std::string::npos ){
std::string tmp = line.substr(line.find(" ", line.find("Stream")) + 1);
int strmIdx = fileSpecs["streams"].size();
int curPos = 0;
curPos = tmp.find(": ", curPos) + 2;
fileSpecs["streams"][strmIdx]["type"] = tmp.substr(curPos, tmp.find(":", curPos) - curPos);
curPos = tmp.find(":", curPos) + 2;
fileSpecs["streams"][strmIdx]["codec"] = tmp.substr(curPos, tmp.find_first_of(", ", curPos) - curPos);
curPos = tmp.find(",", curPos) + 2;
if (fileSpecs["streams"][strmIdx]["type"] == "Video"){
fileSpecs["streams"][strmIdx]["encoding"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
curPos = tmp.find(",", curPos) + 2;
fileSpecs["streams"][strmIdx]["width"] = atoi(tmp.substr(curPos, tmp.find("x", curPos) - curPos).c_str());
curPos = tmp.find("x", curPos) + 1;
fileSpecs["streams"][strmIdx]["height"] = atoi(tmp.substr(curPos, tmp.find(",", curPos) - curPos).c_str());
curPos = tmp.find(",", curPos) + 2;
fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128;
curPos = tmp.find(",", curPos) + 2;
fileSpecs["streams"][strmIdx]["fpks"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 1000);
fileSpecs["streams"][strmIdx].removeMember( "type" );
fileSpecs["video"] = fileSpecs["streams"][strmIdx];
}else if (fileSpecs["streams"][strmIdx]["type"] == "Audio"){
fileSpecs["streams"][strmIdx]["samplerate"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
curPos = tmp.find(",", curPos) + 2;
if (tmp.substr(curPos, tmp.find(",", curPos) - curPos) == "stereo"){
fileSpecs["streams"][strmIdx]["channels"] = 2;
}else if (tmp.substr(curPos, tmp.find(",", curPos) - curPos) == "mono"){
fileSpecs["streams"][strmIdx]["channels"] = 1;
}else{
fileSpecs["streams"][strmIdx]["channels"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
}
curPos = tmp.find(",", curPos) + 2;
fileSpecs["streams"][strmIdx]["samplewidth"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
curPos = tmp.find(",", curPos) + 2;
fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128;
fileSpecs["streams"][strmIdx].removeMember( "type" );
fileSpecs["audio"] = fileSpecs["streams"][strmIdx];
}
}
}
fclose( outFile );
fileSpecs.removeMember( "streams" );
} else {
fileSpecs["format"] = "dtsc";
if (DTSC::isFixed(fileSpecs)){
fileSpecs["is_fixed"] = 1ll;
}
JSON::Value tracks = fileSpecs["tracks"];
for(JSON::ObjIter trackIt = tracks.ObjBegin(); trackIt != tracks.ObjEnd(); trackIt++){
fileSpecs["tracks"][trackIt->first].removeMember("fragments");
fileSpecs["tracks"][trackIt->first].removeMember("keys");
fileSpecs["tracks"][trackIt->first].removeMember("parts");
}
}
printf( "%s", fileSpecs.toString().c_str() );
return 0;
}
示例8: doProcessSearchResult
bool Item::doProcessSearchResult(const QByteArray &response, int &newPagesCount)
{
QByteArray resp = response;
QBuffer buffer(&resp);
buffer.open(QIODevice::ReadOnly);
try
{
JSON::Reader reader(&buffer);
JSON::Object *rootObject, *object;
JSON::Array *array;
JSON::Value *value;
rootObject = dynamic_cast<JSON::Object *> (reader.element());
if (!rootObject)
{
qDebug() << metaObject()->className() << ": cannot find root object";
return false;
}
if (( (value = dynamic_cast<JSON::Value *> (rootObject->value("responseDetails"))) ) &&
!value->toString().compare("out of range start"))
{
newPagesCount = 1;
return false;
}
rootObject = dynamic_cast<JSON::Object *> (rootObject->value("responseData"));
if (!rootObject)
{
qDebug() << metaObject()->className() << ": cannot find responseData object";
return false;
}
array = dynamic_cast<JSON::Array *> (rootObject->value("results"));
if (!array || !array->size())
{
qDebug() << metaObject()->className() << ": cannot find photos array";
return false;
}
object = dynamic_cast<JSON::Object *> (array->at(0));
if (!object)
{
qDebug() << metaObject()->className() << ": cannot find object inside array";
return false;
}
value = dynamic_cast<JSON::Value *> (object->value("imageId"));
if (value)
_photoId = value->toString();
else
qDebug() << metaObject()->className() << ": cannot find imageId";
value = dynamic_cast<JSON::Value *> (object->value("url"));
if (value)
_photoUrl = value->toString();
else
{
value = dynamic_cast<JSON::Value *> (object->value("unescapedUrl"));
if (value)
_photoUrl = value->toString();
else
qDebug() << metaObject()->className() << ": cannot find url/unescapedUrl";
}
value = dynamic_cast<JSON::Value *> (object->value("originalContextUrl"));
if (value)
_sourceUrl = value->toString();
else
qDebug() << metaObject()->className() << ": cannot find originalContextUrl";
value = dynamic_cast<JSON::Value *> (object->value("title"));
if (value)
photoTitle = value->toString();
else
{
value = dynamic_cast<JSON::Value *> (object->value("titleNoFormatting"));
if (value)
photoTitle = value->toString();
else
qDebug() << metaObject()->className() << ": cannot find title/titleNoFormatting";
}
value = dynamic_cast<JSON::Value *> (object->value("width"));
if (value)
photoSize.setWidth(value->toInt());
else
qDebug() << metaObject()->className() << ": cannot find width";
value = dynamic_cast<JSON::Value *> (object->value("height"));
if (value)
photoSize.setHeight(value->toInt());
else
//.........这里部分代码省略.........
示例9: onFailed
void onFailed(download::Downloader *downloader, const std::string &reason) {
Log("listener: download failed");
Json::Value message;
message["message"] = "failed";
send(message.toString());
}
示例10: onStart
void onStart(download::Downloader *downloader) {
Log("listener: download started");
Json::Value message;
message["message"] = "start";
send(message.toString());
}
示例11: onRetry
void onRetry(download::Downloader *downloader, int count) {
Log("listener: download retry");
Json::Value message;
message["message"] = "retry";
send(message.toString());
}