Пример #1
0
static void ipc_json_describe_view(swayc_t *c, json_object *object) {
	json_object *props = json_object_new_object();
	float percent = ipc_json_child_percentage(c);
	const char *layout = (c->parent->type == C_CONTAINER) ?
		ipc_json_layout_description(c->parent->layout) : "none";
	const char *last_layout = (c->parent->type == C_CONTAINER) ?
		ipc_json_layout_description(c->parent->prev_layout) : "none";
	wlc_handle parent = wlc_view_get_parent(c->handle);

	json_object_object_add(object, "type", json_object_new_string((c->is_floating) ? "floating_con" : "con"));

	json_object_object_add(object, "scratchpad_state",
		json_object_new_string(ipc_json_get_scratchpad_state(c)));
	json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL);
	// TODO: make urgency actually work once Sway supports it
	json_object_object_add(object, "urgent", json_object_new_boolean(false));
	json_object_object_add(object, "layout",
		(strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
	json_object_object_add(object, "last_split_layout",
		(strcmp(last_layout, "null") == 0) ? NULL : json_object_new_string(last_layout));
	json_object_object_add(object, "workspace_layout",
		json_object_new_string(ipc_json_layout_description(swayc_parent_by_type(c, C_WORKSPACE)->workspace_layout)));

	json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(c)));
	json_object_object_add(object, "current_border_width", json_object_new_int(c->border_thickness));

	json_object_object_add(object, "rect", ipc_json_create_rect(c));
	json_object_object_add(object, "deco_rect", ipc_json_create_rect_from_geometry(c->title_bar_geometry));
	json_object_object_add(object, "geometry", ipc_json_create_rect_from_geometry(c->cached_geometry));
	json_object_object_add(object, "window_rect", ipc_json_create_rect_from_geometry(c->actual_geometry));

	json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL);

	json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat
	json_object_object_add(props, "class", c->class ? json_object_new_string(c->class) :
		c->app_id ? json_object_new_string(c->app_id) : NULL);
	json_object_object_add(props, "instance", c->instance ? json_object_new_string(c->instance) :
		c->app_id ? json_object_new_string(c->app_id) : NULL);
	json_object_object_add(props, "title", (c->name) ? json_object_new_string(c->name) : NULL);
	json_object_object_add(props, "transient_for", parent ? json_object_new_int(parent) : NULL);
	json_object_object_add(object, "window_properties", props);

	json_object_object_add(object, "fullscreen_mode",
		json_object_new_int(swayc_is_fullscreen(c) ? 1 : 0));
	json_object_object_add(object, "sticky", json_object_new_boolean(c->sticky));
	json_object_object_add(object, "floating", json_object_new_string(
		c->is_floating ? "auto_on" : "auto_off")); // we can't state the cause

	json_object_object_add(object, "app_id", c->app_id ? json_object_new_string(c->app_id) : NULL);
}
Пример #2
0
//TODO: this is kind of funky; a launchpoint of an app should really just present the info for the app.
json_object* LaunchPoint::toJSON() const
{
	json_object* json = json_object_new_object();
	json_object_object_add(json, (char*) "id",   json_object_new_string((char*) id().c_str()));
	if (m_appDesc) {
		json_object_object_add(json, (char*) "version", json_object_new_string(m_appDesc->version().c_str()));
		json_object_object_add(json, (char*) "appId", json_object_new_string((char*) m_appDesc->id().c_str()));
		json_object_object_add(json, (char*) "vendor", json_object_new_string((char*) m_appDesc->vendorName().c_str()));
		json_object_object_add(json, (char*) "vendorUrl", json_object_new_string((char *) m_appDesc->vendorUrl().c_str()));
		int appSize = 0;
		std::string packageId = m_appDesc->id();
		if (this->isDefault()) {
			PackageDescription* packageDesc = ApplicationManager::instance()->getPackageInfoByAppId(m_appDesc->id());
			if (packageDesc) {
				appSize = packageDesc->packageSize();
				packageId = packageDesc->id();
			}

		}
		json_object_object_add(json, (char*) "size", json_object_new_int(appSize));
		json_object_object_add(json, (char*) "packageId", json_object_new_string((char*) packageId.c_str()));

		if (m_appDesc->dockModeStatus()) {
			json_object_object_add(json, (char*) "exhibitionMode", json_object_new_boolean(true));
			json_object_object_add(json, (char*) "exhibitionModeTitle", json_object_new_string((char*)m_appDesc->dockModeTitle().c_str()));
		}
	} else {
		json_object_object_add(json, (char*) "size", json_object_new_int(0));
		json_object_object_add(json, (char*) "packageId", json_object_new_string((char*) m_appDesc->id().c_str()));
	}
	json_object_object_add(json, (char*) "removable", json_object_new_boolean(m_removable));

	json_object_object_add(json, (char*) "launchPointId", json_object_new_string((char*) launchPointId().c_str()));
	json_object_object_add(json, (char*) "title", json_object_new_string((char*) title().c_str()));
	json_object_object_add(json, (char*) "appmenu", json_object_new_string((char*)menuName().c_str()));
	json_object_object_add(json, (char*) "icon", json_object_new_string((char*) iconPath().c_str()));

	if (!params().empty() && m_appDesc->type() != ApplicationDescription::Type_Qt) {
        if (m_appDesc->type() == ApplicationDescription::Type_Qt) {
            json_object_object_add(json, (char*) "params", json_object_new_string(params().c_str()));
        }
        else {
    		json_object* paramsJson = json_tokener_parse(params().c_str());
	    	json_object_object_add(json, (char*) "params", paramsJson);
        }
	}

	return json;
}
Пример #3
0
void alfred_module_xbmc(const char *command, json_object *params) {
	if (alfred_authed()) {
		if (strcmp(command, "Pause") == 0) {
			alfred_xbmc_request("Player.PlayPause", 1, NULL);
		} else if (strcmp(command, "Next") == 0) {
			alfred_xbmc_request("Player.GoNext", 1, NULL);
		} else if (strcmp(command, "Previous") == 0) {
			alfred_xbmc_request("Player.GoPrevious", 1, NULL);
		} else if (strcmp(command, "Shuffle") == 0) {
			alfred_xbmc_request("Player.Shuffle", 1, NULL);
		} else if (strcmp(command, "Mute") == 0) {
			json_object *params = json_object_new_object();
			json_object *mute = json_object_new_boolean(TRUE);
			json_object_object_add(params, "mute", mute);
			alfred_xbmc_request("Application.SetMute", 0, params);
		} else if (strcmp(command, "Unmute") == 0) {
			json_object *params = json_object_new_object();
			json_object *mute = json_object_new_boolean(FALSE);
			json_object_object_add(params, "mute", mute);
			alfred_xbmc_request("Application.SetMute", 0, params);
		} else if (strcmp(command, "Volume") == 0) {
			// TODO: Do this right
			char *volume = alfred_json_get_string(params, "volume");

			if (volume) {
				json_object *params = json_object_new_object();
				json_object *vol = json_object_new_int(atoi(volume));
				json_object_object_add(params, "volume", vol);
				alfred_xbmc_request("Application.SetVolume", 0, params);
			} else {
				alfred_error_static(ALFRED_ERROR_INCORRECT_PARAMS);
			}
		} else if (strcmp(command, "Up") == 0) {
			alfred_xbmc_request("Input.Up", 0, params);
		} else if (strcmp(command, "Down") == 0) {
			alfred_xbmc_request("Input.Down", 0, params);
		} else if (strcmp(command, "Left") == 0) {
			alfred_xbmc_request("Input.Left", 0, params);
		} else if (strcmp(command, "Right") == 0) {
			alfred_xbmc_request("Input.Right", 0, params);
		} else if (strcmp(command, "Select") == 0) {
			alfred_xbmc_request("Input.Select", 0, params);
		} else {
			alfred_error_static(ALFRED_ERROR_UNKNOWN_COMMAND);
		}
	} else {
		alfred_error_static(ALFRED_ERROR_NOT_AUTHENTICATED);
	}
}
Пример #4
0
static void AddMetaData(char *oid, const char *metafile) {
  json_object *obj, *result, *child;

  obj = ReadMetaFile(metafile);
  if (obj == NULL) {
    obj = json_object_new_object();
    result = json_object_new_array();
    json_object_object_add(obj, "result", result);
  } else {
    json_object_object_get_ex(obj, "result", &result);
  }

  child = json_object_new_object();
  json_object_object_add(child, "type", json_object_new_string(Type));
  json_object_object_add(child, "object_id", json_object_new_string(oid));
  if (Printer != NULL) {
    json_object_object_add(child, "printer", json_object_new_string(Printer));
  }
  if (Title != NULL) {
    json_object_object_add(child, "title", json_object_new_string(Title));
  }
  if (ShowDialog) {
    json_object_object_add(child, "showdialog", json_object_new_boolean(TRUE));
  }
  if (Filename != NULL) {
    json_object_object_add(child, "filename", json_object_new_string(Filename));
  }
  if (Desc != NULL) {
    json_object_object_add(child, "description", json_object_new_string(Desc));
  }

  json_object_array_add(result, child);

  WriteMetaFile(metafile, obj);
}
Пример #5
0
int libgcm_send_json(struct gcm *g, struct json_object *j, const struct regid regids[])
{
	int ret = 0;
	struct json_object *id_array = _build_id_array(regids);

	struct json_object *body = json_object_new_object();
	json_object_object_add(body, "registration_ids", id_array);
	json_object_get(j);
	json_object_object_add(body, "data", j);

	//json_object_object_add(body, "collapse_key", j);
	json_object_object_add(body, "delay_while_idle", json_object_new_boolean(0));
	json_object_object_add(body, "time_to_live", json_object_new_int(43200));
	//json_object_object_add(body, "dry_run", json_object_new_boolean(1));

	const char *body_str = json_object_to_json_string(body);

	curl_easy_setopt(g->curl, CURLOPT_POSTFIELDS, body_str);
	curl_easy_setopt(g->curl, CURLOPT_HTTPHEADER, g->headerlist);

	g->last_result = curl_easy_perform(g->curl);

	if(g->last_result != CURLE_OK) {
		ret = -1;
	}

	json_object_put(body);

	return ret;
}
Пример #6
0
int cli_jsonbool(json_object *obj, const char* key, int i)
{
    json_type objty;
    json_object *fpobj;
    if (NULL == obj) {
        cli_dbgmsg("json: no parent object specified to cli_jsonbool\n");
        return CL_ENULLARG;
    }
    objty = json_object_get_type(obj);

    if (objty == json_type_object) {
        if (NULL == key) {
            cli_dbgmsg("json: null string specified as key to cli_jsonbool\n");
            return CL_ENULLARG;
        }
    }
    else if (objty != json_type_array) {
        return CL_EARG;
    }

    fpobj = json_object_new_boolean(i);
    if (NULL == fpobj) {
        cli_errmsg("json: no memory for json boolean object.\n");
        return CL_EMEM;
    }

    if (objty == json_type_object)
        json_object_object_add(obj, key, fpobj);
    else if (objty == json_type_array)
        json_object_array_add(obj, fpobj);

    return CL_SUCCESS;
}
Пример #7
0
int parse_object_hero(json_object *result, struct H3M_OD_ENTRY *od_entry)
{
	struct H3M_OD_BODY_DYNAMIC_HERO *body 
		= (struct H3M_OD_BODY_DYNAMIC_HERO *)od_entry->body;

	if (body->has_name) {
		json_object_object_add(result,
			"name", json_object_new_string((char *)body->name));
	}

	json_object_object_add(result,
			"owner", json_object_new_int(body->owner));

	if (body->has_face) {
		json_object_object_add(result,
			"portrait", json_object_new_int(body->face));
	}

	if (body->has_experience) {
		json_object_object_add(result,
			"experience", json_object_new_int(body->experience));
	}

	json_object_object_add(result,
			"gender", json_object_new_boolean(body->gender));

	return 0;
}
Пример #8
0
bool InputManager::processKeyState(LSHandle* handle, LSMessage* msg, void* userData)
{
    // {"get": string}
    VALIDATE_SCHEMA_AND_RETURN(handle,
                               msg,
                               SCHEMA_1(REQUIRED(get, string)));

	bool success = false;
	const char* keyString = NULL;
	QEvent::Type state = QEvent::None;
	LSError err;
	json_object* root = 0;

	LSErrorInit(&err);

	// get the text name of the key
	const char* str = LSMessageGetPayload(msg);
	if (!str) {
		g_debug("%s: Unable to get JSON payload from message", __PRETTY_FUNCTION__);
		return false;
	}

	root = json_tokener_parse(str);
	if (root && !is_error(root)) {

		// Get the key name from the msg -- the format will be {"get":"NAME"},
		// where NAME is something like ringer, slider, etc
		keyString = json_object_get_string(json_object_object_get(root, "get"));
		if (keyString) {

			// lookup the state of the key
			Qt::Key key = stringToKey(keyString);
			state = getKeyState(key);

			success = true;
		}
	}
	
	json_object* response = 0;
	if (success) {
		response = createKeyJson(keyString, state);
	}
	else {
		response = json_object_new_object();
	}
	json_object_object_add(response, "returnValue", json_object_new_boolean(success));

	if (!LSMessageReply(handle, msg, json_object_to_json_string(response), &err)) {
		LSErrorPrint(&err, stderr);
		LSErrorFree(&err);
	}

	if (root && !is_error(root))
		json_object_put(root);

	json_object_put(response);

	return true;
}
Пример #9
0
json_object *ipc_json_describe_output(swayc_t *output) {
	json_object *object = json_object_new_object();
	json_object *rect = json_object_new_object();
	json_object_object_add(rect, "x", json_object_new_int((int32_t) output->x));
	json_object_object_add(rect, "y", json_object_new_int((int32_t) output->y));
	json_object_object_add(rect, "width", json_object_new_int((int32_t) output->width));
	json_object_object_add(rect, "height", json_object_new_int((int32_t) output->height));

	json_object_object_add(object, "name", json_object_new_string(output->name));
	json_object_object_add(object, "active", json_object_new_boolean(true));
	json_object_object_add(object, "primary", json_object_new_boolean(false));
	json_object_object_add(object, "rect", rect);
	json_object_object_add(object, "current_workspace",
		output->focused ? json_object_new_string(output->focused->name) : NULL);

	return object;
}
Пример #10
0
int main(int argc, char **argv)
{
  struct json_object *my_string, *my_int, *my_object, *my_array;
  struct json_object *new_obj;
  int i;

  my_string = json_object_new_string("\t");
  printf("my_string=%s\n", json_object_get_string(my_string));
  printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
  json_object_put(my_string);

  my_string = json_object_new_string("foo");
  printf("my_string=%s\n", json_object_get_string(my_string));
  printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));

  my_int = json_object_new_int(9);
  printf("my_int=%d\n", json_object_get_int(my_int));
  printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int));

  my_array = json_object_new_array();
  json_object_array_add(my_array, json_object_new_int(1));
  json_object_array_add(my_array, json_object_new_int(2));
  json_object_array_add(my_array, json_object_new_int(3));
  json_object_array_put_idx(my_array, 4, json_object_new_int(5));
  printf("my_array=\n");
  for(i=0; i < json_object_array_length(my_array); i++) {
    struct json_object *obj = json_object_array_get_idx(my_array, i);
    printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
  }
  printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));    

  my_object = json_object_new_object();
  json_object_object_add(my_object, "abc", json_object_new_int(12));
  json_object_object_add(my_object, "foo", json_object_new_string("bar"));
  json_object_object_add(my_object, "bool0", json_object_new_boolean(0));
  json_object_object_add(my_object, "bool1", json_object_new_boolean(1));
  json_object_object_add(my_object, "baz", json_object_new_string("bang"));
  json_object_object_add(my_object, "baz", json_object_new_string("fark"));
  json_object_object_del(my_object, "baz");
  json_object_object_add(my_object, "arr", my_array);
  printf("my_object=\n");
  json_object_object_foreach(my_object, key, val) {
    printf("\t%s: %s\n", key, json_object_to_json_string(val));
  }
Пример #11
0
static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) {
	int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1;
	const char *layout = ipc_json_layout_description(workspace->layout);

	json_object_object_add(object, "num", json_object_new_int(num));
	json_object_object_add(object, "output", (workspace->parent) ? json_object_new_string(workspace->parent->name) : NULL);
	json_object_object_add(object, "urgent", json_object_new_boolean(false));
	json_object_object_add(object, "type", json_object_new_string("workspace"));
	json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
}
Пример #12
0
void WebAppBase::createActivity()
{
	if (!m_page)
		return;

	// Setup an activity for this app if it is the top level app
	if (m_page->parent())
		return;

	LSError lsError;
	LSErrorInit(&lsError);

	json_object* payload = json_object_new_object();
	json_object* activityObj = json_object_new_object();
	json_object_object_add(activityObj, (char*) "name",
						   json_object_new_string(m_appId.c_str()));
	json_object_object_add(activityObj, (char*) "description",
						   json_object_new_string(m_processId.c_str()));
	json_object* activityTypeObj = json_object_new_object();
	json_object_object_add(activityTypeObj, (char*) "foreground",
						   json_object_new_boolean(true));
	json_object_object_add(activityObj, (char*) "type",
						   activityTypeObj);	

	json_object_object_add(payload, "activity", activityObj);
	json_object_object_add(payload, "subscribe", json_object_new_boolean(true));
	json_object_object_add(payload, "start", json_object_new_boolean(true));
	json_object_object_add(payload, "replace", json_object_new_boolean(true));

	if (!LSCallFromApplication(WebAppManager::instance()->m_servicePrivate,
							   "palm://com.palm.activitymanager/create",
							   json_object_to_json_string(payload),
							   m_page->getIdentifier(),
							   WebAppManager::activityManagerCallback,
							   this, &m_activityManagerToken, &lsError)) {
		g_critical("%s: %d. Failed in calling activity manager create: %s",
				   __PRETTY_FUNCTION__, __LINE__, lsError.message);
		LSErrorFree(&lsError);
	}

	json_object_put(payload);
}
Пример #13
0
json_object* EASPolicyManager::getPolicyStatus() const
{
	if (m_aggregate == 0)
		return 0;

	json_object* status = json_object_new_object();
	json_object_object_add(status, "enforced", json_object_new_boolean(m_isEnforced));
	json_object_object_add(status, "retriesLeft", json_object_new_int(m_retriesLeft));

	return status;
}
Пример #14
0
static void tick(int *len, char *buf, struct per_session_data *data) {
    int path_length = 0;
    path_t path;

    mask_t random_dots = EMPTY_MASK;

    json_object *result;
    const char *s;

    /* If it's a new game, only send the grid and don't compute a move. */
    if (data->new_game) {
        data->new_game = 0;
    } else {
        struct timeval tv;
        long ms;
        mask_t move;
        int no_moves;

        gettimeofday(&tv, NULL);
        ms = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
        if ((ms - data->last_updated) < MIN_UPDATE_INTERVAL) {
            return;
        }
        data->last_updated = ms;

        move = choose_move(data->grid, 0, 100, &no_moves);
        apply_move(data->grid, move);
        fill_grid(data->grid, GET_CYCLE_COLOR(move));
        if (no_moves) {
            random_dots = move;
        } else {
            mask_to_path(move, &path_length, path);
        }
    }

    result = json_object_new_object();
    json_object_object_add(result, "grid", json_grid(data->grid));
    if (path_length == 0 && random_dots == EMPTY_MASK) {
        json_object_object_add(result, "newGrid", json_object_new_boolean(TRUE));
    }
    if (random_dots) {
        json_object_object_add(result, "shrinkRandom", json_shrink_random(random_dots));
    }
    if (path_length) {
        json_object_object_add(result, "path", json_path(path_length, path));
    }

    s = json_object_to_json_string(result);
    *len = strlen(s);
    memcpy(buf, s, *len);
    buf[*len] = 0;

    json_object_put(result);
}
Пример #15
0
json_object* EASPolicy::toNewJSON() const
{
	json_object* policy = json_object_new_object();

	json_object_object_add(policy, "devicePasswordEnabled", json_object_new_boolean(m_passwordRequired));
	json_object_object_add(policy, "minDevicePasswordLength", json_object_new_int(m_minLength));
	json_object_object_add(policy, "maxDevicePasswordFailedAttempts", json_object_new_int(m_maxRetries));
	json_object_object_add(policy, "alphanumericDevicePasswordRequired", json_object_new_boolean(m_isAlphaNumeric));
	json_object_object_add(policy, "allowSimpleDevicePassword", json_object_new_boolean(m_allowSimplePassword));

	json_object_object_add(policy, "maxInactivityTimeDeviceLock", json_object_new_int(m_inactivityInSeconds));

	if (!m_id.empty()) {
	    json_object_object_add(policy, "_id", json_object_new_string(m_id.c_str()));
	}
	if (m_isDevicePolicy)
	    json_object_object_add(policy, "_kind", json_object_new_string("com.palm.securitypolicy.device:1"));

	return policy;
}
Пример #16
0
void ipc_get_workspaces_callback(swayc_t *workspace, void *data) {
	if (workspace->type == C_WORKSPACE) {
		json_object *workspace_json = ipc_json_describe_container(workspace);
		// override the default focused indicator because
		// it's set differently for the get_workspaces reply
		bool focused = root_container.focused == workspace->parent && workspace->parent->focused == workspace;
		json_object_object_del(workspace_json, "focused");
		json_object_object_add(workspace_json, "focused", json_object_new_boolean(focused));
		json_object_array_add((json_object *)data, workspace_json);
	}
}
Пример #17
0
json_object *ipc_json_describe_workspace(swayc_t *workspace) {
	int num = isdigit(workspace->name[0]) ? atoi(workspace->name) : -1;
	json_object *object = json_object_new_object();
	json_object *rect = json_object_new_object();
	json_object_object_add(rect, "x", json_object_new_int((int32_t) workspace->x));
	json_object_object_add(rect, "y", json_object_new_int((int32_t) workspace->y));
	json_object_object_add(rect, "width", json_object_new_int((int32_t) workspace->width));
	json_object_object_add(rect, "height", json_object_new_int((int32_t) workspace->height));

	json_object_object_add(object, "num", json_object_new_int(num));
	json_object_object_add(object, "name", json_object_new_string(workspace->name));
	json_object_object_add(object, "visible", json_object_new_boolean(workspace->visible));
	bool focused = root_container.focused == workspace->parent && workspace->parent->focused == workspace;
	json_object_object_add(object, "focused", json_object_new_boolean(focused));
	json_object_object_add(object, "rect", rect);
	json_object_object_add(object, "output", json_object_new_string(workspace->parent ? workspace->parent->name : "null"));
	json_object_object_add(object, "urgent", json_object_new_boolean(false));

	return object;
}
Пример #18
0
std::string TimeZoneService::getTimeZoneRules(const TimeZoneService::TimeZoneEntryList& entries)
{
	TimeZoneResultList totalResult;
	for (TimeZoneEntryList::const_iterator it = entries.begin();
		 it != entries.end(); ++it) {
		TimeZoneResultList r = getTimeZoneRuleOne(*it);
		totalResult.splice(totalResult.end(), r);
	}

	if (totalResult.empty()) {
		return std::string("{\"returnValue\": false, \"errorText\":\"Failed to retrieve results for specified timezones\"}");
	}

	json_object* obj = json_object_new_object();
	json_object_object_add(obj, "returnValue", json_object_new_boolean(true));

	json_object* array = json_object_new_array();
	for (TimeZoneResultList::const_iterator it = totalResult.begin();
		 it != totalResult.end(); ++it) {
		const TimeZoneResult& r = (*it);
		json_object* o = json_object_new_object();
		json_object_object_add(o, "tz", json_object_new_string(r.tz.c_str()));
		json_object_object_add(o, "year", json_object_new_int(r.year));
		json_object_object_add(o, "hasDstChange", json_object_new_boolean(r.hasDstChange));
		json_object_object_add(o, "utcOffset", json_object_new_int(r.utcOffset));
		json_object_object_add(o, "dstOffset", json_object_new_int(r.dstOffset));
		json_object_object_add(o, "dstStart", json_object_new_int(r.dstStart));
		json_object_object_add(o, "dstEnd", json_object_new_int(r.dstEnd));
		json_object_array_add(array, o);
		// printf("Name: %s, Year: %d, hasDstChange: %d, utcOffset: %lld, "
		// 	   "dstOffset: %lld, dstStart: %lld, dstEnd: %lld\n",
		// 	   r.tz.c_str(), r.year, r.hasDstChange,
		// 	   r.utcOffset, r.dstOffset, r.dstStart, r.dstEnd);
	}
	json_object_object_add(obj, "results", array);

	std::string res = json_object_to_json_string(obj);
	json_object_put(obj);
	
    return res;
}
Пример #19
0
json_object* IpAddress::getJSONObject() {
  json_object *my_object;
  char buf[64];

  my_object = json_object_new_object();

  json_object_object_add(my_object, "ipVersion", json_object_new_int(addr.ipVersion));
  json_object_object_add(my_object, "localHost", json_object_new_boolean(addr.localHost));
  json_object_object_add(my_object, "ip", json_object_new_string(print(buf, sizeof(buf))));

  return(my_object);
}
void PauseResumeMatchEvent::save (void)
{
    json_object *jMatchTime = json_object_new_string(matchTime.c_str());
    json_object *jPaused    = json_object_new_boolean(paused);
    json_object *jBZID      = json_object_new_string(bzID.c_str());

    json_object_object_add(jsonData, "match-time", jMatchTime);
    json_object_object_add(jsonData, "paused", jPaused);
    json_object_object_add(jsonData, "bzid", jBZID);

    json_object_object_add(jsonObj, "data", jsonData);
}
Пример #21
0
json_object* EASPolicy::toJSON() const
{
	json_object* policy = json_object_new_object();

	json_object* password = json_object_new_object();
	json_object_object_add(password, "enabled", json_object_new_boolean(m_passwordRequired));
	json_object_object_add(password, "minLength", json_object_new_int(m_minLength));
	json_object_object_add(password, "maxRetries", json_object_new_int(m_maxRetries));
	json_object_object_add(password, "alphaNumeric", json_object_new_boolean(m_isAlphaNumeric));
	if (m_passwordRequired && !m_isAlphaNumeric) {
		json_object_object_add(password, "allowSimplePassword", json_object_new_boolean(m_allowSimplePassword));
	}

	json_object_object_add (policy, "password", password);

	json_object_object_add(policy, "inactivityInSeconds", json_object_new_int(m_inactivityInSeconds));

	json_object_object_add(policy, "id", json_object_new_string(m_id.c_str()));

	return policy;
}
Пример #22
0
/**
 * Add new key - value pair to json object.
 * @param osName  Key name.
 * @param bValue   Boolean value.
 *
 * @since GDAL 2.3
 */
void CPLJSONObject::Add(const std::string &osName, bool bValue)
{
    std::string objectName;
    CPLJSONObject object = GetObjectByPath( osName, objectName );
    if( object.IsValid() &&
        json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) ==
            json_type_object )
    {
        json_object *poVal = json_object_new_boolean( bValue );
        json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()),
                                           objectName.c_str(), poVal );
    }
}
Пример #23
0
json_object *ipc_json_describe_container(swayc_t *c) {
	if (!(sway_assert(c, "Container must not be null."))) {
		return NULL;
	}

	json_object *object = json_object_new_object();

	json_object_object_add(object, "id", json_object_new_int((int)c->id));
	json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL);
	json_object_object_add(object, "rect", ipc_json_create_rect(c));
	json_object_object_add(object, "visible", json_object_new_boolean(c->visible));
	json_object_object_add(object, "focused", json_object_new_boolean(c == current_focus));

	switch (c->type) {
	case C_ROOT:
		json_object_object_add(object, "type", json_object_new_string("root"));
		break;

	case C_OUTPUT:
		ipc_json_describe_output(c, object);
		break;

	case C_CONTAINER: // fallthrough
	case C_VIEW:
		ipc_json_describe_view(c, object);
		break;

	case C_WORKSPACE:
		ipc_json_describe_workspace(c, object);
		break;

	case C_TYPES: // fallthrough; this should never happen, I'm just trying to silence compiler warnings
	default:
		break;
	}

	return object;
}
Пример #24
0
//get state of the device( e.g. isActivate/isConnected)
OSStatus MicoFogCloudGetState(mico_Context_t* const context,
                              MVDGetStateRequestData_t getStateRequestData,
                              void* outDevState)
{
  //OSStatus err = kUnknownErr;
  mico_Context_t *inContext = context;
  json_object* report = (json_object*)outDevState;
  
  if((NULL == context) || (NULL == outDevState)){
    return kParamErr;
  }
  
  json_object_object_add(report, "isActivated",
                         json_object_new_boolean(inContext->flashContentInRam.appConfig.fogcloudConfig.isActivated)); 
    json_object_object_add(report, "isBinding",
                         json_object_new_boolean(inContext->flashContentInRam.appConfig.fogcloudConfig.owner_binding)); 
  json_object_object_add(report, "isConnected",
                         json_object_new_boolean(inContext->appStatus.fogcloudStatus.isCloudConnected));
  json_object_object_add(report, "version",
                         json_object_new_string(inContext->flashContentInRam.appConfig.fogcloudConfig.romVersion));
  
  return kNoErr;
}
json_object* SearchServiceManager::getSearchServiceList() 
{
	json_object* objArray = json_object_new_array();
	
	for(ServiceInfoList::iterator it=m_serviceInfoList.begin(); it != m_serviceInfoList.end(); ++it) {
		
		const SearchServiceInfo* serviceInfo = (*it);
		
		json_object* infoObj = json_object_new_object();
		json_object_object_add(infoObj,(char*) "serviceID",json_object_new_string((char*) serviceInfo->m_serviceID.c_str()));
		json_object_object_add(infoObj,(char*) "title",json_object_new_string((char*) serviceInfo->m_title.c_str()));
		json_object_object_add(infoObj,(char*) "serviceURL",json_object_new_string((char*) serviceInfo->m_serviceURL.c_str()));
		json_object_object_add(infoObj,(char*) "action",json_object_new_string((char*) serviceInfo->m_action.c_str()));
		json_object_object_add(infoObj,(char*) "timeout",json_object_new_int((int) serviceInfo->m_timeout));
		json_object_object_add(infoObj,(char*) "enabled",json_object_new_boolean(serviceInfo->m_enabled));
		json_object_object_add(infoObj,(char*) "preventDelete",json_object_new_boolean(serviceInfo->m_preventDelete));
		
		json_object_array_add(objArray, infoObj);
	}
	
	return objArray;
	
}
Пример #26
0
Файл: json.c Проект: Goos/r3
json_object * r3_edge_to_json_object(const edge * e) {
    json_object *obj;

    obj = json_object_new_object();
    json_object_object_add(obj, "pattern", json_object_new_string(e->pattern));
    json_object_object_add(obj, "opcode", json_object_new_int(e->opcode));
    json_object_object_add(obj, "slug", json_object_new_boolean(e->has_slug));

    if (e->child) {
        json_object *node_obj = r3_node_to_json_object(e->child);
        json_object_object_add(obj, "child", node_obj);
    }
    return obj;
}
Пример #27
0
bool InputManager::processSubscription(LSHandle* handle, LSMessage* msg, void* userData)
{
    SUBSCRIBE_SCHEMA_RETURN(handle, msg);

	// process subscriptions for a group of keys
	bool retVal = false;
	LSError lserror;
	LSErrorInit(&lserror);
	bool subscribed = false;
	json_object* json = json_object_new_object();

	if (LSMessageIsSubscription(msg)) {
		retVal = LSSubscriptionProcess(handle, msg, &subscribed, &lserror);
		if (!retVal) {
			LSErrorPrint (&lserror, stderr);
			LSErrorFree (&lserror);
			goto Error;
		}
	} else {
		json_object_object_add(json, "errorCode", json_object_new_int(-1));
		json_object_object_add(json, "errorText", json_object_new_string("We were expecting a subscribe type message, but we did not recieve one."));
	}

Error:

	json_object_object_add(json, "returnValue", json_object_new_boolean(retVal));
	json_object_object_add(json, "subscribed", json_object_new_boolean(subscribed));
	

	if (!LSMessageReply(handle, msg, json_object_to_json_string(json), &lserror)) {
		LSErrorPrint(&lserror, stderr);
		LSErrorFree (&lserror);
	}
	json_object_put(json);

	return true;	// message has been processed, don't call the callback anymore
}
Пример #28
0
iot_json_t *iot_json_add_member(iot_json_t *o, const char *key,
                                iot_json_type_t type, ...)
{
    iot_json_t *m;
    const char *s;
    bool        b;
    int         i, l;
    double      d;
    va_list     ap;

    va_start(ap, type);
    switch (type) {
    case IOT_JSON_STRING:
        s = va_arg(ap, const char *);
        l = va_arg(ap, int);
        if (l < 0)
            m = json_object_new_string(s);
        else
            m = json_object_new_string_len(s, l);
        break;
    case IOT_JSON_BOOLEAN:
        b = va_arg(ap, int);
        m = json_object_new_boolean(b);
        break;
    case IOT_JSON_INTEGER:
        i = va_arg(ap, int);
        m = json_object_new_int(i);
        break;
    case IOT_JSON_DOUBLE:
        d = va_arg(ap, double);
        m = json_object_new_double(d);
        break;
    case IOT_JSON_OBJECT:
        m = json_object_new_object();
        break;
    case IOT_JSON_ARRAY:
        m = json_object_new_array();
        break;
    default:
        m = NULL;
        errno = EINVAL;
    }
    va_end(ap);

    if (m != NULL)
        json_object_object_add(o, key, m);

    return m;
}
void ApplicationDescription::getAppDescriptionString(std::string &descString) const
{
    // Compose json string from the app description object  -------------------------------
    // This will only include the integer and string fields of App Description

    json_object* json = json_object_new_object();

    json_object_object_add(json, (char*) "id",   json_object_new_string((char*) m_id.c_str()));
    json_object_object_add(json, (char*) "category",   json_object_new_string((char*) m_category.c_str()));
    json_object_object_add(json, (char*) "main",   json_object_new_string((char*) m_entryPoint.c_str()));
    json_object_object_add(json, (char*) "version",   json_object_new_string((char*) m_version.c_str()));
    json_object_object_add(json, (char*) "noWindow",   json_object_new_boolean(m_isHeadLess));
    json_object_object_add(json, (char*) "splashicon", json_object_new_string((char*) m_splashIconName.c_str()));
    json_object_object_add(json, (char*) "splashBackground", json_object_new_string((char*) m_splashBackgroundName.c_str()));
    json_object_object_add(json, (char*) "miniicon", json_object_new_string((char*) m_miniIconName.c_str()));
    json_object_object_add(json, (char*) "transparent",   json_object_new_boolean(m_hasTransparentWindows));
    json_object_object_add(json, (char*) "folderPath", json_object_new_string((char*) m_folderPath.c_str()));
    json_object_object_add(json, (char*) "removable",   json_object_new_boolean(m_isRemovable));
    json_object_object_add(json, (char*) "userHideable",   json_object_new_boolean(m_isUserHideable));
    json_object_object_add(json, (char*) "visible",   json_object_new_boolean(m_isVisible));
    json_object_object_add(json, (char*) "hardwareFeaturesNeeded",   json_object_new_int(m_hardwareFeaturesNeeded));
    json_object_object_add(json, (char*) "type",   json_object_new_int(m_type));
    json_object_object_add(json, (char*) "attributes", json_object_new_string((char*) m_attributes.c_str()));
    json_object_object_add(json, (char*) "vendor", json_object_new_string((char*) m_vendorName.c_str()));
    json_object_object_add(json, (char*) "vendorUrl", json_object_new_string((char*) m_vendorUrl.c_str()));
    json_object_object_add(json, (char*) "size", json_object_new_int((int)m_appSize));
    json_object_object_add(json, (char*) "runtimeMemoryRequired", json_object_new_int((int)m_runtimeMemoryRequired));
    json_object_object_add(json, (char*) "appmenu",json_object_new_string((char*) m_appmenuName.c_str()));
    json_object_object_add(json, (char*) "launchinnewgroup", json_object_new_boolean(m_launchInNewGroup));
    json_object_object_add(json, (char*) "requestedWindowOrientation", json_object_new_string((char*) m_requestedWindowOrientation.c_str()));
    json_object_object_add(json, (char*) "tapToShareSupported",   json_object_new_boolean(m_tapToShareSupported));

    if (m_dockMode) {
        json_object_object_add(json, (char*) "dockMode", json_object_new_boolean(true));
        json_object_object_add(json, (char*) "exhibitionMode", json_object_new_boolean(true));
    }

    descString = json_object_to_json_string(json);

    json_object_put(json);
}
Пример #30
0
OSStatus MICOAddSwitchCellToSector(json_object* menus, char* const name,  boolean switcher, char* const privilege)
{
  OSStatus err;
  json_object *object;
  err = kNoErr;

  object = json_object_new_object();
  require_action(object, exit, err = kNoMemoryErr);
  json_object_object_add(object, "N", json_object_new_string(name));      
  json_object_object_add(object, "C", json_object_new_boolean(switcher));
  json_object_object_add(object, "P", json_object_new_string(privilege)); 
  json_object_array_add(menus, object);

exit:
  return err;
}