/** Gets the OBS status and generates a JSON encoded string representing the status (recording, streaming etc.). @return json encoded string */ const char* obsStatusToJSON() { json_t *obj = json_object(); json_object_set_new(obj, "recording", json_boolean(obs_frontend_recording_active())); json_object_set_new(obj, "streaming", json_boolean(obs_frontend_streaming_active())); json_object_set_new(obj, "replaybuffer", json_boolean(obs_frontend_replay_buffer_active())); const char *jsonString = json_dumps(obj, 0); free(obj); return jsonString; }
json_t* OBSAPIMessageHandler::HandleGetVolumes(OBSAPIMessageHandler* handler, json_t* message) { json_t* ret = GetOkResponse(); json_object_set_new(ret, "mic-volume", json_real(OBSGetMicVolume())); json_object_set_new(ret, "mic-muted", json_boolean(OBSGetMicMuted())); json_object_set_new(ret, "desktop-volume", json_real(OBSGetDesktopVolume())); json_object_set_new(ret, "desktop-muted", json_boolean(OBSGetDesktopMuted())); return ret; }
void Patch::writeChannels(json_t *jContainer, vector<channel_t> *channels) { json_t *jChannels = json_array(); for (unsigned i=0; i<channels->size(); i++) { json_t *jChannel = json_object(); channel_t channel = channels->at(i); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_TYPE, json_integer(channel.type)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_INDEX, json_integer(channel.index)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_COLUMN, json_integer(channel.column)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MUTE, json_integer(channel.mute)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MUTE_S, json_integer(channel.mute_s)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_SOLO, json_integer(channel.solo)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_VOLUME, json_real(channel.volume)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_PAN_LEFT, json_real(channel.panLeft)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_PAN_RIGHT, json_real(channel.panRight)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN, json_boolean(channel.midiIn)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_KEYPRESS, json_integer(channel.midiInKeyPress)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_KEYREL, json_integer(channel.midiInKeyRel)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_KILL, json_integer(channel.midiInKill)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_ARM, json_integer(channel.midiInArm)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_VOLUME, json_integer(channel.midiInVolume)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_MUTE, json_integer(channel.midiInMute)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_SOLO, json_integer(channel.midiInSolo)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L, json_boolean(channel.midiOutL)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L_PLAYING, json_integer(channel.midiOutLplaying)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L_MUTE, json_integer(channel.midiOutLmute)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L_SOLO, json_integer(channel.midiOutLsolo)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_SAMPLE_PATH, json_string(channel.samplePath.c_str())); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_KEY, json_integer(channel.key)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MODE, json_integer(channel.mode)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_BEGIN, json_integer(channel.begin)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_END, json_integer(channel.end)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_BOOST, json_real(channel.boost)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_REC_ACTIVE, json_integer(channel.recActive)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_PITCH, json_real(channel.pitch)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_READ_ACTIONS, json_integer(channel.midiInReadActions)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_PITCH, json_integer(channel.midiInPitch)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT, json_integer(channel.midiOut)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_CHAN, json_integer(channel.midiOutChan)); json_array_append_new(jChannels, jChannel); writeActions(jChannel, &channel.actions); #ifdef WITH_VST writePlugins(jChannel, &channel.plugins, PATCH_KEY_CHANNEL_PLUGINS); #endif } json_object_set_new(jContainer, PATCH_KEY_CHANNELS, jChannels); }
void WebSocketOBSTriggerHandler::DesktopVolumeChanged(float level, bool muted, bool finalValue) { json_t* update = json_object(); json_object_set_new(update, "update-type", json_string("VolumeChanged")); json_object_set_new(update, "channel", json_string("desktop")); json_object_set_new(update, "volume", json_real(level)); json_object_set_new(update, "muted", json_boolean(muted)); json_object_set_new(update, "finalValue", json_boolean(finalValue)); OSEnterMutex(this->updateQueueMutex); this->updates.Add(update); OSLeaveMutex(this->updateQueueMutex); }
Json::Json( json_type v ): data(NULL) { switch ( v ) { case JSON_ARRAY: data = json_array(); break; case JSON_OBJECT: data = json_object(); break; case JSON_FALSE: data = json_boolean(false); break; case JSON_TRUE: data = json_boolean(true); break; case JSON_INTEGER: data = json_integer(0); break; case JSON_REAL: data = json_real(0); break; case JSON_STRING: data = json_string(""); break; default: data = json_null(); break; } }
json_t *trp_route_to_json(TRP_ROUTE *route) { json_t *route_json = NULL; json_t *retval = NULL; TR_NAME *n; route_json = json_object(); if (route_json == NULL) goto cleanup; OBJECT_SET_OR_FAIL(route_json, "community", tr_name_to_json_string(trp_route_get_comm(route))); OBJECT_SET_OR_FAIL(route_json, "realm", tr_name_to_json_string(trp_route_get_realm(route))); if (trp_route_get_peer(route)->len > 0) OBJECT_SET_OR_FAIL(route_json, "peer", tr_name_to_json_string(trp_route_get_peer(route))); OBJECT_SET_OR_FAIL(route_json, "metric", json_integer(trp_route_get_metric(route))); /* add trust_router as hostname:port */ n = tr_hostname_and_port_to_name( trp_route_get_trust_router(route), trp_route_get_trust_router_port(route)); if (n == NULL) goto cleanup; OBJECT_SET_OR_FAIL(route_json, "trust_router", tr_name_to_json_string(n)); tr_free_name(n); /* add next_hop as hostname:port */ n = tr_hostname_and_port_to_name( trp_route_get_next_hop(route), trp_route_get_next_hop_port(route)); if (n == NULL) goto cleanup; OBJECT_SET_OR_FAIL(route_json, "next_hop", tr_name_to_json_string(n)); tr_free_name(n); OBJECT_SET_OR_FAIL(route_json, "selected", json_boolean(trp_route_is_selected(route))); OBJECT_SET_OR_FAIL(route_json, "local", json_boolean(trp_route_is_local(route))); OBJECT_SET_OR_SKIP(route_json, "expires", expiry_to_json_string(route)); /* succeeded - set the return value and increment the reference count */ retval = route_json; json_incref(retval); cleanup: if (route_json) json_decref(route_json); return retval; }
// sets a json value for the next index int json_array_add_bool(json_t *array, int *value, json_context_t *json_context) { int exit_code = 0; check_not_null(array); check_not_null(json_context); json_t *json_boolean_value = NULL; if (value != NULL) { json_boolean_value = json_boolean(*value); check_not_null(json_boolean_value); check_result(json_array_append_new(array, json_boolean_value), 0); json_boolean_value = NULL; } else { check_result(json_array_append(array, json_null()), 0); } goto cleanup; error: exit_code = -1; cleanup: if (json_boolean_value != NULL) { json_free(json_boolean_value); } return exit_code; }
static json_t* net_write_json_params(void) { json_t *params = json_object(); json_t *l = json_array(); json_t* o; int i; json_object_set(params, "count", json_integer(net->numParams)); for(i=0; i<net->numParams; i++) { o = json_object(); json_object_set(o, "idx", json_integer(i)); json_object_set(o, "label", json_string(net->params[i].desc.label)); json_object_set(o, "type", json_integer(net->params[i].desc.type)); json_object_set(o, "min", json_integer(net->params[i].desc.min)); json_object_set(o, "max", json_integer(net->params[i].desc.max)); json_object_set(o, "value", json_integer(net->params[i].data.value)); /// FIXME: this dumb indexing. play flag not stored correctly... json_object_set(o, "play", json_boolean(net_get_in_play(i + net->numIns))); json_array_append(l, o); } json_object_set(params, "data", l); return params; }
/* since /root <timestamp> [patterns] */ static void cmd_since(struct watchman_client* client, const json_ref& args) { const char *clockspec; /* resolve the root */ if (json_array_size(args) < 3) { send_error_response(client, "not enough arguments for 'since'"); return; } auto root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } auto clock_ele = json_array_get(args, 2); clockspec = json_string_value(clock_ele); if (!clockspec) { send_error_response(client, "expected argument 2 to be a valid clockspec"); return; } auto query = w_query_parse_legacy(root, args, 3, nullptr, clockspec, nullptr); auto res = w_query_execute(query.get(), root, nullptr); auto response = make_response(); response.set({{"is_fresh_instance", json_boolean(res.is_fresh_instance)}, {"clock", res.clockAtStartOfQuery.toJson()}, {"files", std::move(res.resultsArray)}}); add_root_warnings_to_response(response, root); send_and_dispose_response(client, std::move(response)); }
/* unsubscribe /root subname * Cancels a subscription */ static void cmd_unsubscribe( struct watchman_client* clientbase, const json_ref& args) { const char *name; bool deleted{false}; struct watchman_user_client *client = (struct watchman_user_client *)clientbase; auto root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } auto jstr = json_array_get(args, 2); name = json_string_value(jstr); if (!name) { send_error_response( client, "expected 2nd parameter to be subscription name"); return; } auto sname = json_to_w_string(jstr); deleted = client->unsubByName(sname); auto resp = make_response(); resp.set({{"unsubscribe", typed_string_to_json(name)}, {"deleted", json_boolean(deleted)}}); send_and_dispose_response(client, std::move(resp)); }
json_t *JsonParser::CopyToJsonT(const VarValue& v) { switch (v.type()) { case VarType::Null: return ::json_null(); case VarType::Bool: return json_boolean(v.ToBool()); case VarType::Int: return ::json_integer(v.ToInt64()); case VarType::Float: return ::json_real(v.ToDouble()); case VarType::String: return ::json_string(v.ToString()); case VarType::Array: { JsonHandle json(::json_array()); //!!!R VarValue r = JsonVarValueObj::FromJsonT(json); for (int i=0; i<v.size(); ++i) { CCheck(::json_array_append_new(json, CopyToJsonT(v[i]))); } return json.Detach(); } case VarType::Map: { JsonHandle json(::json_object()); vector<String> keys = v.Keys(); EXT_FOR (const String& key, keys) { CCheck(::json_object_set_new(json, key, CopyToJsonT(v[key]))); } return json.Detach(); } default: Throw(E_NOTIMPL); }
json_t* format_workspaces (i3ipcConnection *conn) { json_t *json_data_object = json_object(); json_t *json_desktops_array = json_array(); json_object_set_new(json_data_object, "desktops", json_desktops_array); GSList *workspaces = i3ipc_connection_get_workspaces(conn, NULL); workspaces = g_slist_sort(workspaces, (GCompareFunc)workspace_comparator); for (unsigned char i = 0; i < g_slist_length(workspaces); i++) { GSList *workspace = g_slist_nth(workspaces, i); i3ipcWorkspaceReply *data = workspace->data; json_t *json_desktop = json_object(); json_object_set_new(json_desktop, "name", json_string(data->name)); json_object_set_new(json_desktop, "clients_len", json_integer(i)); json_object_set_new(json_desktop, "is_urgent", json_boolean(data->urgent)); json_array_append_new(json_desktops_array, json_desktop); if (data->focused) { json_object_set_new(json_data_object, "current_desktop", json_integer(i)); } } return json_data_object; }
struct ast_json *ast_json_boolean(int value) { #if JANSSON_VERSION_HEX >= 0x020400 return (struct ast_json *)json_boolean(value); #else return value ? ast_json_true() : ast_json_false(); #endif }
void TeamCard::initBag(json_t *jsonArr) { this->card=nullptr; int gap=10; Size size=this->cardList->getInnerContainerSize(); XCard* xcard=XCard::record(Value(0)); int i=0; this->cardList->removeAllChildren(); for (rapidjson::GenericValue<rapidjson::UTF8<> >::MemberIterator it=xcard->doc.MemberonBegin(); it != xcard->doc.MemberonEnd(); it++ ){ rapidjson::Value& item=it->value; int xid=item["id"].GetInt(); json_t* cardData=json_object(); json_object_set(cardData, "isUse", json_boolean(false)); json_object_set(cardData, "xid", json_integer(xid)); json_t* teams = DataManager::getInstance()->getTeamData(); for(int j=0;j<json_array_size(teams);j++){ json_t* cards=json_object_get(json_array_get(teams, j),"cards"); for(int i=0;i<json_array_size(cards);i++){ int cid=json_integer_value(json_object_get(json_array_get(cards, i), "xid")); if(cid==xid){ json_object_set(cardData, "isUse", json_boolean(true)); break; } } } Card* card=Card::create(cardData); card->click=CC_CALLBACK_1(TeamCard::selectCard, this); this->cardList->getInnerContainer()->addChild(card); Size cardSize=card->getSize(); card->setPosition(Vec2(cardSize.width*0.5+gap+(cardSize.width+gap)*(i%3),(size.height-cardSize.height*0.5)-(cardSize.height+gap)*(i/3))); i++; } // for(int i=0;i<25;i++){ // Card* card=Card::create(); // card->click=CC_CALLBACK_1(TeamCard::selectCard, this); // this->cardList->getInnerContainer()->addChild(card); // Size cardSize=card->getSize(); // card->setPosition(Vec2(cardSize.width*0.5+gap+(cardSize.width+gap)*(i%3),(size.height-cardSize.height*0.5)-(cardSize.height+gap)*(i/3))); // } }
GhbValue* ghb_boolean_value(gboolean bval) { // Jansson boolean is singleton, no need for local static GhbValue *gval = json_boolean(bval); json_decref(gval); return gval; }
// ------------------------------------------------------------------------------------------------- static json_t* CreateJsonNodeFromIterator ( le_cfg_IteratorRef_t iterRef ///< The iterator to read from. ) // ------------------------------------------------------------------------------------------------- { char nodeName[LE_CFG_NAME_LEN_BYTES] = ""; le_cfg_nodeType_t type = le_cfg_GetNodeType(iterRef, ""); le_cfg_GetNodeName(iterRef, "", nodeName, sizeof(nodeName)); json_t* nodePtr = CreateJsonNode(nodeName, NodeTypeStr(type)); switch (type) { case LE_CFG_TYPE_EMPTY: json_object_set_new(nodePtr, JSON_FIELD_TYPE, json_string(NodeTypeStr(LE_CFG_TYPE_STEM))); json_object_set_new(nodePtr, JSON_FIELD_CHILDREN, json_array()); break; case LE_CFG_TYPE_BOOL: json_object_set_new(nodePtr, JSON_FIELD_VALUE, json_boolean(le_cfg_GetBool(iterRef, "", false))); break; case LE_CFG_TYPE_STRING: { char strBuffer[LE_CFG_STR_LEN_BYTES] = ""; le_cfg_GetString(iterRef, "", strBuffer, LE_CFG_STR_LEN_BYTES, ""); json_object_set_new(nodePtr, JSON_FIELD_VALUE, json_string(strBuffer)); } break; case LE_CFG_TYPE_INT: json_object_set_new(nodePtr, JSON_FIELD_VALUE, json_integer(le_cfg_GetInt(iterRef, "", false))); break; case LE_CFG_TYPE_FLOAT: json_object_set_new(nodePtr, JSON_FIELD_VALUE, json_real(le_cfg_GetFloat(iterRef, "", false))); break; case LE_CFG_TYPE_STEM: default: // Unknown type, nothing to do json_decref(nodePtr); nodePtr = NULL; break; } return nodePtr; }
static void cmd_debug_drop_privs( struct watchman_client* client, const json_ref&) { client->client_is_owner = false; auto resp = make_response(); resp.set("owner", json_boolean(client->client_is_owner)); send_and_dispose_response(client, std::move(resp)); }
json_t *json_pack_message (struct tgl_message *M) { json_t *res = json_object (); assert (json_object_set (res, "event", json_string ("message")) >= 0); //will overwriten to service, if service. assert (json_object_set (res, "id", json_integer (M->id)) >= 0); if (!(M->flags & TGLMF_CREATED)) { return res; } assert (json_object_set (res, "flags", json_integer (M->flags)) >= 0); if (tgl_get_peer_type (M->fwd_from_id)) { assert (json_object_set (res, "fwd_from", json_pack_peer (M->fwd_from_id, tgl_peer_get (TLS, M->fwd_from_id))) >= 0); assert (json_object_set (res, "fwd_date", json_integer (M->fwd_date)) >= 0); } if (M->reply_id) { assert (json_object_set (res, "reply_id", json_integer (M->reply_id)) >= 0); } if (M->flags & TGLMF_MENTION) { assert (json_object_set (res, "mention", json_true ()) >= 0); } assert (json_object_set (res, "from", json_pack_peer (M->from_id, tgl_peer_get (TLS, M->from_id))) >= 0); assert (json_object_set (res, "to", json_pack_peer (M->to_id, tgl_peer_get (TLS, M->to_id))) >= 0); assert (json_object_set (res, "out", json_boolean (M->flags & TGLMF_OUT)) >= 0); assert (json_object_set (res, "unread", json_boolean (M->flags & TGLMF_UNREAD)) >= 0); assert (json_object_set (res, "service", json_boolean (M->flags & TGLMF_SERVICE)) >= 0); assert (json_object_set (res, "date", json_integer (M->date)) >= 0); if (!(M->flags & TGLMF_SERVICE)) { if (M->message_len && M->message) { assert (json_object_set (res, "text", json_string (M->message)) >= 0); } if (M->media.type && M->media.type != tgl_message_media_none) { assert (json_object_set (res, "media", json_pack_media (&M->media)) >= 0); } } else { assert (json_object_set (res, "event", json_string ("service")) >= 0); assert (json_object_set (res, "action", json_pack_service (M)) >= 0); } return res; }
void WebSocketOBSTriggerHandler::StreamStopping(bool previewOnly) { json_t* update = json_object(); json_object_set_new(update, "update-type", json_string("StreamStopping")); json_object_set_new(update, "preview-only", json_boolean(previewOnly)); OSEnterMutex(this->updateQueueMutex); this->updates.Add(update); OSLeaveMutex(this->updateQueueMutex); }
void WebSocketOBSTriggerHandler::StreamStatus(bool streaming, bool previewOnly, UINT bytesPerSec, double strain, UINT totalStreamtime, UINT numTotalFrames, UINT numDroppedFrames, UINT fps) { json_t* update = json_object(); json_object_set_new(update, "update-type", json_string("StreamStatus")); json_object_set_new(update, "streaming", json_boolean(streaming)); json_object_set_new(update, "preview-only", json_boolean(previewOnly)); json_object_set_new(update, "bytes-per-sec", json_integer(bytesPerSec)); json_object_set_new(update, "strain", json_real(strain)); json_object_set_new(update, "total-stream-time", json_integer(totalStreamtime)); json_object_set_new(update, "num-total-frames", json_integer(numTotalFrames)); json_object_set_new(update, "num-dropped-frames", json_integer(numDroppedFrames)); json_object_set_new(update, "fps", json_integer(fps)); OSEnterMutex(this->updateQueueMutex); this->updates.Add(update); OSLeaveMutex(this->updateQueueMutex); }
json_t* OBSAPIMessageHandler::HandleGetAuthRequired(OBSAPIMessageHandler* handler, json_t* message) { json_t* ret = GetOkResponse(); json_object_set_new(ret, "authRequired", json_boolean(getRemoteConfig()->useAuth)); if(getRemoteConfig()->useAuth) { json_object_set_new(ret, "challenge", json_string(handler->challenge.c_str())); json_object_set_new(ret, "salt", json_string(getRemoteConfig()->authSalt.c_str())); } return ret; }
json_t * UITheme::ToJson() const { // Create entries json_t * jsonEntries = json_object(); for (const UIThemeWindowEntry & entry : Entries) { const WindowThemeDesc * wtDesc = GetWindowThemeDescriptor(entry.WindowClass); json_object_set_new(jsonEntries, wtDesc->WindowClassSZ, entry.ToJson()); } // Create theme object json_t * jsonTheme = json_object(); json_object_set_new(jsonTheme, "name", json_string(Name)); json_object_set_new(jsonTheme, "entries", jsonEntries); json_object_set_new(jsonTheme, "useLightsRide", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_RIDE)); json_object_set_new(jsonTheme, "useLightsPark", json_boolean(Flags & UITHEME_FLAG_USE_LIGHTS_PARK)); json_object_set_new(jsonTheme, "useAltScenarioSelectFont", json_boolean(Flags & UITHEME_FLAG_USE_ALTERNATIVE_SCENARIO_SELECT_FONT)); return jsonTheme; }
json_t *volume_json_object(RaidVolume_t *volume) { if (!volume) return NULL; json_t *obj = json_object(); json_object_set_new(obj, "active", json_boolean( volume->active )); json_object_set_new(obj, "alias", json_string(volume->alias)); json_object_set_new(obj, "basepath", json_string(volume->basepath)); json_object_set_new(obj, "raiddir", json_string(basename(volume->raidpath))); json_object_set_new(obj, "trashdir", json_string(basename(volume->trashpath))); if (!volume->active) return obj; json_object_set_new(obj, "capacity_total", json_integer(volume->capacity_total)); json_object_set_new(obj, "capacity_free", json_integer(volume->capacity_free)); json_object_set_new(obj, "capacity_used", json_integer(volume->capacity_used)); json_object_set_new(obj, "percent_free", json_integer(volume->percent_free)); json_object_set_new(obj, "raid_available", json_boolean( volume_is_raid_ready(volume) )); json_object_set_new(obj, "trash_available", json_boolean( volume_is_trash_ready(volume) )); return obj; }
void Config::save(const char *path) { json_t* json = json_object(); json_object_set_new(json, "useAuth", json_boolean(this->useAuth)); if(this->useAuth) { json_object_set_new(json, "authHash", json_string(this->authHash.c_str())); json_object_set_new(json, "authSalt", json_string(this->authSalt.c_str())); } json_dump_file(json, path, JSON_INDENT(2)); json_decref(json); }
error configuration_parser::parse_json_object( json_t* _obj, configuration_parser::object_t& _obj_out ) { const char* key = 0; json_t* val = 0; json_object_foreach( _obj, key, val ) { int type = json_typeof( val ); if ( JSON_INTEGER == type ) { _obj_out.set< int >( key, json_integer_value( val ) ); } else if ( JSON_STRING == type ) { _obj_out.set< std::string >( key, json_string_value( val ) ); } else if ( JSON_REAL == type ) { _obj_out.set< double >( key, json_real_value( val ) ); } else if ( JSON_TRUE == type || JSON_FALSE == type ) { _obj_out.set< bool >( key, json_boolean( val ) ); } else if ( JSON_NULL == type ) { _obj_out.set< std::string >( key, "NULL" ); } else if ( JSON_ARRAY == type ) { array_t arr; size_t idx = 0; json_t* obj = 0; json_array_foreach( val, idx, obj ) { object_t lt; irods::error err = parse_json_object( obj, lt ); if ( err.ok() ) { arr.push_back( lt ); } else { irods::log( PASS( err ) ); } } // array foreach
static json_t* convert(object_t* object) { switch (object->type) { case type_bool: return json_boolean(object->b); case type_nil: return json_null(); case type_int: return json_integer(object->i); case type_double: return json_real(object->d); case type_uint: // Note: The generator limits unsigned int to INT64_MAX. Jansson // doesn't allow integers outside the range of signed int64. return json_integer((int64_t)object->u); case type_str: return json_stringn((const char*)object->str, object->l); case type_array: { json_t* array = json_array(); for (size_t i = 0; i < object->l; ++i) { json_t* child = convert(object->children + i); if (!child || json_array_append_new(array, child) != 0) { json_decref(array); return NULL; } } return array; } case type_map: { json_t* map = json_object(); for (size_t i = 0; i < object->l; ++i) { const char* key = object->children[i * 2].str; json_t* child = convert(object->children + i * 2 + 1); if (!child || json_object_set_new(map, key, child) != 0) { json_decref(map); return NULL; } } return map; } default: assert(0); break; } return false; }
/* trigger-del /root triggername * Delete a trigger from a root */ static void cmd_trigger_delete(struct watchman_client *client, json_t *args) { w_root_t *root; json_t *resp; json_t *jname; w_string_t *tname; bool res; root = resolve_root_or_err(client, args, 1, false); if (!root) { return; } if (json_array_size(args) != 3) { send_error_response(client, "wrong number of arguments"); w_root_delref(root); return; } jname = json_array_get(args, 2); if (!json_is_string(jname)) { send_error_response(client, "expected 2nd parameter to be trigger name"); w_root_delref(root); return; } tname = json_to_w_string_incref(jname); w_root_lock(root, "trigger-del"); res = w_ht_del(root->commands, w_ht_ptr_val(tname)); w_root_unlock(root); if (res) { w_state_save(); } w_string_delref(tname); resp = make_response(); set_prop(resp, "deleted", json_boolean(res)); json_incref(jname); set_prop(resp, "trigger", jname); send_and_dispose_response(client, resp); w_root_delref(root); }
json_t* getSourceJson(XElement* source) { json_t* ret = json_object(); CTSTR name = source->GetName(); float x = source->GetFloat(TEXT("x")); float y = source->GetFloat(TEXT("y")); float cx = source->GetFloat(TEXT("cx")); float cy = source->GetFloat(TEXT("cy")); bool render = source->GetInt(TEXT("render")) > 0; json_object_set_new(ret, "name", json_string_wchar(name)); json_object_set_new(ret, "x", json_real(x)); json_object_set_new(ret, "y", json_real(y)); json_object_set_new(ret, "cx", json_real(cx)); json_object_set_new(ret, "cy", json_real(cy)); json_object_set_new(ret, "render", json_boolean(render)); return ret; }
/* Ensure that we're synchronized with the state of the * filesystem at the current time. * We do this by touching a cookie file and waiting to * observe it via inotify. When we see it we know that * we've seen everything up to the point in time at which * we're asking questions. * Returns true if we observe the change within the requested * time, false otherwise. * Must be called with the root UNLOCKED. This function * will acquire and release the root lock. */ bool watchman_root::syncToNow(std::chrono::milliseconds timeout) { w_perf_t sample("sync_to_now"); auto res = cookies.syncToNow(timeout); // We want to know about all timeouts if (!res) { sample.force_log(); } if (sample.finish()) { sample.add_root_meta(shared_from_this()); sample.add_meta( "sync_to_now", json_object({{"success", json_boolean(res)}, {"timeoutms", json_integer(timeout.count())}})); sample.log(); } return res; }
void Patch::writePlugins(json_t *jContainer, vector<plugin_t> *plugins, const char *key) { json_t *jPlugins = json_array(); for (unsigned j=0; j<plugins->size(); j++) { json_t *jPlugin = json_object(); plugin_t plugin = plugins->at(j); json_object_set_new(jPlugin, PATCH_KEY_PLUGIN_PATH, json_string(plugin.path.c_str())); json_object_set_new(jPlugin, PATCH_KEY_PLUGIN_BYPASS, json_boolean(plugin.bypass)); json_array_append_new(jPlugins, jPlugin); /* plugin params */ json_t *jPluginParams = json_array(); for (unsigned z=0; z<plugin.params.size(); z++) { json_array_append_new(jPluginParams, json_real(plugin.params.at(z))); } json_object_set_new(jPlugin, PATCH_KEY_PLUGIN_PARAMS, jPluginParams); } json_object_set_new(jContainer, key, jPlugins); }