Ejemplo n.º 1
0
/** Callback for LBFGS optimization to show progress
 * @param[in] instance The user data passed to the LBFGS optimizer
 * @param[in] x The current variable assignments
 * @param[in] g The current gradients
 * @param[in] fx The current negative log-likelihood value
 * @param[in] xnorm The euclidean norm of the variables
 * @param[in] gnorm The euclidean norm of the gradients
 * @param[in] step The step size for the current iteration
 * @param[in] nvar The number of variables
 * @param[in] k The number of the current iteration
 * @param[in] ls The number of evaluations called for the current iteration
 */
static int progress(
	void *instance,
	const conjugrad_float_t *x,
	const conjugrad_float_t *g,
	const conjugrad_float_t fx,
	const conjugrad_float_t xnorm,
	const conjugrad_float_t gnorm,
	const conjugrad_float_t step,
	int n,
	int k,
	int ls
) {
	//printf("iter\teval\tf(x)    \t║x║     \t║g║     \tstep\n");
	printf("%-4d\t%-4d\t%-8g\t%-8g\t%-8.8g\t%-3.3g\n", k, ls, fx, xnorm, gnorm, step);

#ifdef JANSSON
	userdata *ud = (userdata *)instance;
	json_t *meta_steps = (json_t *)ud->meta_steps;

	json_t *ms = json_object();
	json_object_set(ms, "iteration", json_integer(k));
	json_object_set(ms, "eval", json_integer(ls));
	json_object_set(ms, "fx", json_real(fx));
	json_object_set(ms, "xnorm", json_real(xnorm));
	json_object_set(ms, "gnorm", json_real(gnorm));
	json_object_set(ms, "step", json_real(step));

	json_array_append(meta_steps, ms);

#endif

	return 0;
}
Ejemplo n.º 2
0
/**
 * fitness is either log likelihood or sum of square
 */
void ssm_print_trace(FILE *stream, ssm_theta_t *theta, ssm_nav_t *nav, const double fitness, const int index)
{
    int i;
    ssm_parameter_t *parameter;

#if SSM_JSON
    json_t *jout = json_object();
#endif

    for(i=0; i < nav->theta_all->length; i++) {
        parameter = nav->theta_all->p[i];
#if SSM_JSON
        json_object_set_new(jout, parameter->name, json_real(parameter->f_inv(gsl_vector_get(theta, i))));
#else
        fprintf(stream, "%g,", parameter->f_inv(gsl_vector_get(theta, i)));
#endif
    }

#if SSM_JSON
    json_object_set_new(jout, "fitness", isnan(fitness) ? json_null() : json_real(fitness));
    json_object_set_new(jout, "index", json_integer(index)); // m
    ssm_json_dumpf(stream, "trace", jout);
#else
    fprintf(stream, "%g,%d\n", fitness, index);
#endif
}
Ejemplo n.º 3
0
json_t*
process_quaternion(const struct aiQuaternion* quat)
{
    json_t* json = json_array();
    json_array_append(json, json_real(quat->w));
    json_array_append(json, json_real(quat->x));
    json_array_append(json, json_real(quat->y));
    json_array_append(json, json_real(quat->z));
    return json;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
/**
SerializeAllToJson:
Creates a single file containing all the correlogram feature vectors and the max feature vector
    @param[in] correlograms: pointer to array of correlograms to be serialize.
    @param[in] MaxFeatureVector: array of double values containing the maximum value from every correlogram for each bin
    @param[in] bins: number of quantization bins.
    @param[in] filename: string of where to write out to.
    @param[in] numCorrelograms: the number of correlograms within correlograms

*/
void SerializeAllToJson(Correlogram ** correlograms,double* MaxFeatureVector,const int bins, char * filename,int numCorrelograms)
{
    json_t* jsonCollection = json_array();
    json_t* corr;
    json_t* jsonFileName;
    json_t* featureVector;
    json_t* vectorVals;
    int i;
    int j;

    for (j=0; j<numCorrelograms; j++)
    {
        featureVector= json_array();
        jsonFileName = json_string(correlograms[j]->fileName);
        corr= json_object();
        // Build feature vector json array
        for (i=0; i<bins; i++)
        {
            vectorVals = json_real(correlograms[j]->FeatureVector[i]);
            json_array_append_new(featureVector,vectorVals);
        }

    // add both feature vector and file name to json object
    json_object_set_new(corr,"FileName",jsonFileName);
    json_object_set_new(corr,"FeatureVector",featureVector);

        json_array_append_new(jsonCollection,corr);
        free(correlograms[j]->fileName);
        free(correlograms[j]->FeatureVector);
        free(correlograms[j]);
    }
    featureVector = json_array();
    jsonFileName = json_string("MaxFeatureVector");
    corr= json_object();
    for (i=0;i<bins;i++)
    {
        vectorVals = json_real(MaxFeatureVector[i]);
        json_array_append_new(featureVector,vectorVals);
    }
    json_object_set_new(corr,"FileName",jsonFileName);
    json_object_set_new(corr,"FeatureVector",featureVector);

    json_array_append_new(jsonCollection,corr);


    json_dump_file(jsonCollection,filename,JSON_INDENT(2));



    // need to call jansson specific free
    json_object_clear(corr);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
static void run_tests()
{
    json_t *integer, *real;
    json_int_t i;
    double d;

    integer = json_integer(5);
    real = json_real(100.1);

    if(!integer)
        fail("unable to create integer");
    if(!real)
        fail("unable to create real");

    i = json_integer_value(integer);
    if(i != 5)
        fail("wrong integer value");

    d = json_real_value(real);
    if(d != 100.1)
        fail("wrong real value");

    d = json_number_value(integer);
    if(d != 5.0)
        fail("wrong number value");
    d = json_number_value(real);
    if(d != 100.1)
        fail("wrong number value");

    json_decref(integer);
    json_decref(real);

#ifdef NAN
    real = json_real(NAN);
    if(real != NULL)
        fail("could construct a real from NaN");

    real = json_real(1.0);
    if(json_real_set(real, NAN) != -1)
        fail("could set a real to NaN");

    if(json_real_value(real) != 1.0)
        fail("real value changed unexpectedly");

    json_decref(real);
#endif

#ifdef INFINITY
    test_inifity();
#endif
}
Ejemplo n.º 8
0
static json_t *json_serialize_pspec (const GValue *value)
{
    /* Only types in json-glib but G_TYPE_BOXED */
    switch (G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (value))) {
        case G_TYPE_STRING:
            if (!g_value_get_string (value))
        break;
            else 
            return json_string (g_value_get_string (value));
        case G_TYPE_BOOLEAN:
            if (g_value_get_boolean (value))
                return json_true ();
            else return json_false ();
        case G_TYPE_INT:
            return json_integer (g_value_get_int (value));
        case G_TYPE_UINT:
            return json_integer (g_value_get_uint (value));
        case G_TYPE_LONG:
            return json_integer (g_value_get_long (value));
        case G_TYPE_ULONG:
            return json_integer (g_value_get_ulong (value));
        case G_TYPE_INT64:
            return json_integer (g_value_get_int64 (value));
        case G_TYPE_FLOAT:
            return json_real (g_value_get_float (value));
        case G_TYPE_DOUBLE:
            return json_real (g_value_get_double (value));
        case G_TYPE_CHAR:
            return json_integer (g_value_get_schar (value));
        case G_TYPE_UCHAR:
            return json_integer (g_value_get_uchar (value));
        case G_TYPE_ENUM:
            return json_integer (g_value_get_enum (value));
        case G_TYPE_FLAGS:
            return json_integer (g_value_get_flags (value));
        case G_TYPE_NONE:
            break;
        case G_TYPE_OBJECT:
            {
            GObject *object = g_value_get_object (value);
            if (object)
                return json_gobject_serialize (object);
            }
            break;
        defalut:
            g_warning("Unsuppoted type `%s'",g_type_name (G_VALUE_TYPE (value)));
    }
    return json_null(); 
}
Ejemplo n.º 9
0
void ssm_print_ar(FILE *stream, ssm_adapt_t *adapt, const int index)
{
#if SSM_JSON
    json_t *jout = json_object();

    json_object_set_new(jout, "ar", json_real(adapt->ar));
    json_object_set_new(jout, "ar_smoothed", json_real(adapt->ar_smoothed));
    json_object_set_new(jout, "eps", json_real(adapt->eps));
    json_object_set_new(jout, "index", json_integer(index)); // m

    ssm_json_dumpf(stream, "ar", jout);
#else
    fprintf(stream, "%g,%g,%g,%d\n", adapt->ar, adapt->ar_smoothed, adapt->eps, index);
#endif
}
Ejemplo n.º 10
0
void on_timer_fire(uv_timer_t *timer) {
    static int count = 0;

    DSLink *link = timer->data;

    if (count == 3) {
        printf("We are done.\n");
        uv_timer_stop(timer);
        uv_close((uv_handle_t *) timer, (uv_close_cb) dslink_free);
        dslink_close(link);
        return;
    }


    // set value
    json_t *value = json_real(rand());
    configure_request(dslink_requester_set(
        link,
        "/data/c-sdk/requester/testNumber",
        value
    ));
    json_decref(value);

    // stream invoke
    json_t *params = json_object();
    json_object_set_new(params, "Path", json_string("/data/test_c_sdk"));
    json_object_set_new(params, "Value", json_integer(count));
    RequestHolder *holder = streamInvokeRef->data;
    dslink_requester_invoke_update_params(link, holder->rid, params);
    json_decref(params);

    count++;
}
Ejemplo n.º 11
0
void saveRevenueMovements(char * save_path)
{
    json_t * json_revenue = json_object();
    
    json_t * array = json_array();

    json_t * json_total = json_real(total);
    
    for (struct revenue * revenue = firstRevenueMovement; revenue!=0; revenue=revenue->next)
    {
        json_array_append(array, createRevenueArray(revenue));
    }
    
    int i  = json_object_set(json_revenue, "total", json_total);
    
    int j  = json_object_set(json_revenue, "revenue", array);
    
    if (i == -1 || j == -1)
    {
        printf("errore non è possibile scrivere il file");
    }
    
    json_dump_file(json_revenue, strcat(save_path, "/revenue.json"), JSON_INDENT(3));
    
}
Ejemplo n.º 12
0
void ZnpActorPublishDeviceDataEvent(IEEEADDRESS macId, BYTE endPoint, BYTE nDataCount, PZNPACTORDATA *pData)
{
	if (pZnpActor == NULL) return;
	json_t* eventJson = json_object();
	json_t* paramsJson = json_object();
	char* macIdString = IeeeToString(macId);
	json_t* macIdJson = json_string(macIdString);
	free(macIdString);
	char* endpointString = malloc(20);
	sprintf(endpointString, "%d", endPoint);
	json_t* endpointJson = json_string(endpointString);
	free(endpointString);
	json_t* protocolJson = json_string("zigbee");
	json_object_set(paramsJson, "macId", macIdJson);
	json_object_set(paramsJson, "endpoint", endpointJson);
	json_object_set(paramsJson, "protocol", protocolJson);
	json_decref(macIdJson);
	json_decref(endpointJson);
	json_decref(protocolJson);
	json_t* dataJson;
	json_t* valueJson;
	dataJson = json_object();
	BYTE nIndex = 0;
	while (nDataCount > 0)
	{
		switch (pData[nIndex]->nDataType)
		{
		case ZNP_DATA_TYPE_INTERGER:
			valueJson = json_integer((int)(*((int*)(pData[nIndex]->value))));
			break;
		case ZNP_DATA_TYPE_FLOAT:
			valueJson = json_real((double)(*((double*)(pData[nIndex]->value))));
			break;
		case ZNP_DATA_TYPE_STRING:
			valueJson = json_string(pData[nIndex]->value);
			break;
		default:
			json_decref(dataJson);
			json_decref(paramsJson);
			json_decref(eventJson);
			return;
			break;
		}
		json_object_set(dataJson, pData[nIndex]->dataName, valueJson);
		json_decref(valueJson);
		nDataCount--;
		nIndex++;
	}
	json_object_set(paramsJson, "data", dataJson);
	json_decref(dataJson);
	json_object_set(eventJson, "params", paramsJson);
	json_decref(paramsJson);
	char* eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4));
	json_decref(eventJson);
	//char* topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/device_data");
	char* topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/device_data");
	ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName);
	free(topicName);
	free(eventMessage);
}
Ejemplo n.º 13
0
int main ()
{
	json_t *units, *current_unit, *stats, *targetArea;
	json_error_t error;
	const char *unitname;

	units = json_load_file ("./BattleAbilities.json", 0, &error);
	if (!units) {
		/* the error variable contains error information */
		printf ("load error \n");
		exit (1);
	}
	printf ("proceeding %d ablilities...\n", (int)json_object_size (units));

	json_object_foreach (units, unitname, current_unit) {

		json_object_del (current_unit, "damageAnimationType");	/* remove damageAnimationType  */

		stats = json_object_get (current_unit, "stats");
		if (stats) {
			targetArea = json_object_get (stats, "targetArea");
			if (targetArea)
				json_object_set(targetArea, "aoeOrderDelay", json_real (0.0));
		}else
			printf ("get targetArea error\n");

	}
Ejemplo n.º 14
0
void CreateJSONMaxFeatureVector(double * MaxFeatureVector,const int bins,char * filename)
{
    json_t* corr = json_object();
    json_t* jsonFileName = json_string("MaxFeatureVector");
    json_t* featureVector = json_array();
    json_t* vectorVals;
    int i;

    // Build feature vector json array
    for (i=0; i<bins; i++)
    {
        vectorVals = json_real(MaxFeatureVector[i]);
        if (json_array_append_new(featureVector,vectorVals))
        {
            printf("Cannot append %f to json array",MaxFeatureVector[i]);
            puts(strerror(errno));
            exit(1);
        }
    }
    // add both feature vector and file name to json object
    json_object_set_new(corr,"FileName",jsonFileName);
    json_object_set_new(corr,"FeatureVector",featureVector);

    json_dump_file(corr,filename,JSON_INDENT(2));


    // need to call jansson specific free
    json_object_clear(corr);

}
Ejemplo n.º 15
0
json_t* nonstring(char* arg)
{
    json_t* temp;
    char* endptr;
    if (!strcmp(arg, "null") || !strcmp(arg, "n"))
        {return json_null();}
    if (!strcmp(arg, "true") || !strcmp(arg, "t"))
        {return json_true();}
    if (!strcmp(arg, "false") || !strcmp(arg, "f"))
        {return json_false();}
    if (!strcmp(arg, "array") || !strcmp(arg, "[]"))
        {return json_array();}
    if (!strcmp(arg, "object") || !strcmp(arg, "{}"))
        {return json_object();}
    errno = 0;
    temp = json_integer(strtol(arg, &endptr, 10));
    if (!errno && *endptr=='\0')
        {return temp;}
    errno = 0;
    temp = json_real(strtod(arg, &endptr));
    if (!errno && *endptr=='\0')
        {return temp;}
    arg_err("parse error: illegal nonstring on arg %i, \"%s\"");
    return json_null();
}
Ejemplo n.º 16
0
void on_invoke_timer_fire(uv_timer_t *timer) {
    DSLink *link = timer->data;

    if (count == 3) {
        printf("We are done.\n");
        uv_timer_stop(timer);
        uv_close((uv_handle_t *) timer, (uv_close_cb) dslink_free);
        dslink_close(link);
        return;
    }

    json_t *params = json_object();
    json_object_set_new(params, "command", json_string("ls"));

    configure_request(dslink_requester_invoke(
        link,
        "/downstream/System/Execute_Command",
        params,
        on_invoke_updates
    ));

    configure_request(dslink_requester_set(
        link,
        "/data/c-sdk/requester/testNumber",
        json_real(rand())
    ));

    count++;
}
Ejemplo n.º 17
0
Archivo: rpc.c Proyecto: dyustc/searaft
json_t *jsonize_param(const struct data_t *param) {
    switch(param->type) {
        case RPC_INT:
            return json_integer(*(json_int_t *)param->value);
        case RPC_REAL:
            return json_real(*(double *)param->value);
        case RPC_STRING:
            return json_string((char *)param->value);
        case RPC_VECTOR: {
            json_t *vector = json_array();
            if(vector) {
                for(int i = 0; i < param->length; i++) {
                    json_t *json_child = jsonize_param(param->child[i]);
                    if(!json_child || json_array_append_new(vector, json_child)) {
                        if(json_child) json_decref(json_child);
                        json_decref(vector);
                        return NULL;
                    }
                }
                return vector;
            }
        }
    }
    return NULL;
}
Ejemplo n.º 18
0
//----------------------------------------------------------------//
json_t* _luaToJSON ( lua_State* L, int idx ) {
	
	switch ( lua_type ( L, idx )) {
		
		case LUA_TBOOLEAN: {
		
			bool value = lua_toboolean ( L, idx ) == 0 ? false : true;
			return value ? json_true () : json_false ();
		}
		case LUA_TTABLE: {
			
			return lua_objlen ( L, idx ) ? _luaToJSONArray ( L, idx ) : _luaToJSONObject ( L, idx );
		}
		case LUA_TSTRING: {
			
			cc8* str = lua_tostring ( L, idx );
			return json_string ( str );
		}
		case LUA_TNUMBER: {
		
			double real = lua_tonumber ( L, idx );
			return json_real ( real );
		}
		
		case LUA_TLIGHTUSERDATA: {
		
			return json_null ();
		}
	};

	return 0;
}
Ejemplo n.º 19
0
// sets a json value for the next index
int json_array_add_double(json_t *array, double *value, json_context_t *json_context)
{
  int exit_code = 0;

  json_t *json_real_value = NULL;

  check_not_null(array);
  check_not_null(json_context);

  if (value != NULL)
  {
    json_real_value = json_real(*value);
    check_not_null(json_real_value);

    check_result(json_array_append_new(array, json_real_value), 0);

    json_real_value = NULL;
  }
  else
  {
    check_result(json_array_append(array, json_null()), 0);
  }

  goto cleanup;

error:

  exit_code = -1;

cleanup:

  if (json_real_value != NULL) { json_free(json_real_value); }

  return exit_code;
}
Ejemplo n.º 20
0
/*=========================================================================*\
    Parse ICY inband data, will write all key/val pairs to result.
      Values are of string type.
    Returns NULL on error or an object with key-value pairs for identified
    fields
\*=========================================================================*/
json_t *icyParseInband( const char *icyInband )
{
  json_t *jObj;
  DBGMSG( "icyParseInband: \"%s\".", icyInband );

/*------------------------------------------------------------------------*\
    Create result container
\*------------------------------------------------------------------------*/
  jObj = json_object();
  if( !jObj ) {
    logerr( "icyExtractHeaders: Out of memory." );
    return NULL;
  }
  json_object_set( jObj, "timestamp", json_real(srvtime()) );

/*------------------------------------------------------------------------*\
    Use segmentation function
\*------------------------------------------------------------------------*/
  if( _segmentKeyValList(icyInband,jObj,NULL)<0 ) {
    logerr( "icyParseInband: Cannot parse message \"%s\".", icyInband );
    json_decref( jObj );
    return NULL;
  }

/*------------------------------------------------------------------------*\
    That's it
\*------------------------------------------------------------------------*/
  return jObj;
}
Ejemplo n.º 21
0
char * MessageBuilder::buildEvent(  char const * name, double value ) const
{
	json_t *array = eventBase(name);
	json_array_append_new(array, json_real(value));
    char * string = json_dumps(array, 0);
	json_decref(array);
	return string;
}
Ejemplo n.º 22
0
json_t*
process_vertex_weight(const struct aiVertexWeight* w)
{
    json_t* json = json_object();
    json_object_set(json, "vertex_id", json_integer(w->mVertexId));
    json_object_set(json, "weight", json_real(w->mWeight));
    return json;
}
Ejemplo n.º 23
0
void JSONObject::putDouble(char * key, double value) {

	json_t * obj = json_real(value);
	
	json_object_set(root, key, obj);

	json_decref(obj);
}
Ejemplo n.º 24
0
/* Message Handlers */
json_t* OBSAPIMessageHandler::HandleGetVersion(OBSAPIMessageHandler* handler, json_t* message)
{
    json_t* ret = GetOkResponse();

    json_object_set_new(ret, "version", json_real(OBS_REMOTE_VERSION));
    
    return ret;
}
Ejemplo n.º 25
0
// -------------------------------------------------------------------------------------------------
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;
}
Ejemplo n.º 26
0
static void test_inifity()
{
    json_t *real = json_real(INFINITY);
    if (real != NULL)
       fail("could construct a real from Inf");

    real = json_real(1.0);
    if (json_real_set(real, INFINITY) != -1)
	    fail("could set a real to Inf");

    if (json_real_value(real) != 1.0)
       fail("real value changed unexpectedly");

    json_decref(real);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
}
Ejemplo n.º 27
0
void Patch::writeCommons(json_t *jContainer)
{
  json_object_set_new(jContainer, PATCH_KEY_HEADER,         json_string(header.c_str()));
  json_object_set_new(jContainer, PATCH_KEY_VERSION,        json_string(version.c_str()));
  json_object_set_new(jContainer, PATCH_KEY_VERSION_MAJOR,  json_integer(versionMajor));
  json_object_set_new(jContainer, PATCH_KEY_VERSION_MINOR,  json_integer(versionMinor));
  json_object_set_new(jContainer, PATCH_KEY_VERSION_PATCH,  json_integer(versionPatch));
  json_object_set_new(jContainer, PATCH_KEY_NAME,           json_string(name.c_str()));
  json_object_set_new(jContainer, PATCH_KEY_BPM,            json_real(bpm));
  json_object_set_new(jContainer, PATCH_KEY_BARS,           json_integer(bars));
  json_object_set_new(jContainer, PATCH_KEY_BEATS,          json_integer(beats));
  json_object_set_new(jContainer, PATCH_KEY_QUANTIZE,       json_integer(quantize));
  json_object_set_new(jContainer, PATCH_KEY_MASTER_VOL_IN,  json_real(masterVolIn));
  json_object_set_new(jContainer, PATCH_KEY_MASTER_VOL_OUT, json_real(masterVolOut));
	json_object_set_new(jContainer, PATCH_KEY_METRONOME,      json_integer(metronome));
	json_object_set_new(jContainer, PATCH_KEY_LAST_TAKE_ID,   json_integer(lastTakeId));
	json_object_set_new(jContainer, PATCH_KEY_SAMPLERATE,     json_integer(samplerate));
}
Ejemplo n.º 28
0
void JSON::setFloat(const char *key, float value)
{
    if (!_json)
    {
        return;
    }

    json_object_set_new(_json, key, json_real(value));
}
Ejemplo n.º 29
0
json_t *bunser(const char *buf, const char *end, int *needed,
               json_error_t *jerr)
{
    json_int_t ival;

    switch (buf[0]) {
    case BSER_INT8:
    case BSER_INT16:
    case BSER_INT32:
    case BSER_INT64:
        if (!bunser_int(buf, end - buf, needed, &ival)) {
            snprintf(jerr->text, sizeof(jerr->text),
                     "invalid integer encoding");
            return NULL;
        }
        return json_integer(ival);

    case BSER_STRING:
    {
        const char *start;
        json_int_t len;

        if (!bunser_string(buf, end - buf, needed, &start, &len)) {
            snprintf(jerr->text, sizeof(jerr->text),
                     "invalid string encoding");
            return NULL;
        }

        return json_string_binary(start, len);
    }

    case BSER_REAL:
        *needed = sizeof(double) + 1;
        return json_real(*(double*)(buf+1));
    case BSER_TRUE:
        *needed = 1;
        return json_true();
    case BSER_FALSE:
        *needed = 1;
        return json_false();
    case BSER_NULL:
        *needed = 1;
        return json_null();
    case BSER_ARRAY:
        return bunser_array(buf, end, needed, jerr);
    case BSER_TEMPLATE:
        return bunser_template(buf, end, needed, jerr);
    case BSER_OBJECT:
        return bunser_object(buf, end, needed, jerr);
    default:
        snprintf(jerr->text, sizeof(jerr->text),
                 "invalid bser encoding type %02x", (int)buf[0]);
        return NULL;
    }

    return NULL;
}
Ejemplo n.º 30
0
void JSON::setNumber(const char *key, double value)
{
    if (!_json)
    {
        return;
    }

    json_object_set_new(_json, key, json_real(value));
}