コード例 #1
0
void pack_rf_evt_links(json_t *result, rf_link_t *link)
{
	int32 i = 0;
	json_t *array = NULL;
	json_t *listener = NULL;

	array = json_array();
	if (array == NULL) {
		HTTPD_ERR("json array request fail\n");
		return;
	}

	for (i = 0; i < RF_EVENT_MAX_LISTENER_NUM; i++) {
		listener = NULL;
		listener = json_object();
		if (listener != NULL) {
			if (strlen(link->subscription[i]) != 0) {
				add_json_string(listener, RMM_JSON_RF_LISTENER, (uint8 *)(link->subscription[i]));
				json_array_add(array, listener);
			}
		}
	}
	json_object_add(result, RMM_JSON_RF_SUBSCRIPTION, array);

	add_json_string(result, RMM_JSON_RF_SELF, (uint8 *)link->self);
}
コード例 #2
0
static json_t *tzone_coll_get(struct rest_uri_param *param)
{
	collections_t *tzone_collections = NULL;
	uint32 tzone_num = 0;
	result_t rs = RESULT_OK;
	json_t *result = NULL;
	json_t *tzone = NULL;
	json_t *array = NULL;
	int32 i;
	int32 zone_num = 0;

	zone_num = libwrap_get_asset_num(MC_TYPE_TZONE);
	if (zone_num == 0) {
		HTTPD_ERR("get thermal zone num fail\n");
		return NULL;
	}

	tzone_collections = (collections_t *)malloc(zone_num * sizeof(collections_t));
	if (tzone_collections == NULL)
		return NULL;

	memset(tzone_collections, 0, zone_num * sizeof(collections_t));

	rs = libwrap_get_tzone_coll(tzone_collections, &tzone_num);
	if (rs != RESULT_OK) {
		HTTPD_ERR("get cooling zone collection fail, result is %d\n", rs);
		return NULL;
	}

	result = json_object();
	if (result == NULL) {
		HTTPD_ERR("result json object request error\n");
		return NULL;
	}

	array = json_array();
	if (array == NULL) {
		HTTPD_ERR("json array request error\n");
		return NULL;
	}

	for (i = 0; i < tzone_num; i++) {
		tzone = NULL;
		tzone = json_object();
		if (tzone != NULL) {
			add_json_integer(tzone, RMM_JSON_ID, tzone_collections[i].id);
			add_json_string(tzone, RMM_JSON_UUID, tzone_collections[i].uuid);
			add_json_string(tzone, RMM_JSON_NAME, tzone_collections[i].name);
			update_href_host(tzone_collections[i].href, HREF_URL_LEN, param->host);
			add_json_string(tzone, RMM_JSON_HREF, tzone_collections[i].href);
			json_array_add(array, tzone);
		}
	}
	json_object_add(result, RMM_JSON_THERMAL_ZONES, array);

	if (tzone_collections)
		free(tzone_collections);

	return result;
}
コード例 #3
0
int32 pack_rf_base_json(json_t *result, const rf_base_t *base)
{
	add_json_string(result, RMM_JSON_OEM, (uint8 *)base->oem);
	add_json_string(result, RMM_JSON_DESC, (uint8 *)base->name);
	add_json_string(result, RMM_JSON_MODIFY, (uint8 *)base->modify_date);
	add_json_string(result, RMM_JSON_TYPE, (uint8 *)base->type);
	add_json_string(result, RMM_JSON_DESC, (uint8 *)base->description);

	return 0;
}
コード例 #4
0
int32 pack_fru_info(const fru_info_t *fru_info, json_t *fru)
{
	add_json_string(fru, RMM_JSON_SERIAL_NUM, fru_info->serial_num);
	add_json_string(fru, RMM_JSON_MANUFACTURE, fru_info->manufacture);
	add_json_string(fru, RMM_JSON_MODEL_NUM, fru_info->model);
	add_json_string(fru, RMM_JSON_PART_NUM, fru_info->part_num);
	add_json_string(fru, RMM_JSON_FIRMWARE_VER, fru_info->fw_ver);

	return 0;
}
コード例 #5
0
int32 pack_basic_element_info(const base_element_t *be, json_t *result)
{
	add_json_integer(result, RMM_JSON_ID, be->id);
	add_json_string(result, RMM_JSON_UUID, be->uuid);
	add_json_string(result, RMM_JSON_NAME, be->name);
	add_json_string(result, RMM_JSON_DESC, be->desc);
	add_json_string(result, RMM_JSON_CREATED_DATE, be->create_date);
	add_json_string(result, RMM_JSON_UPDATED_DATE, be->update_date);

	return 0;
}
コード例 #6
0
static int32 pack_tzone_basic_info(const tzone_member_t *tzone_member, json_t *result)
{
	add_json_integer(result, RMM_JSON_TZONE_ID, tzone_member->be.id);
	add_json_string(result, RMM_JSON_UUID, tzone_member->be.uuid);
	add_json_string(result, RMM_JSON_NAME, tzone_member->be.name);
	add_json_string(result, RMM_JSON_DESC, tzone_member->be.desc);
	add_json_string(result, RMM_JSON_CREATED_DATE, tzone_member->be.create_date);
	add_json_string(result, RMM_JSON_UPDATED_DATE, tzone_member->be.update_date);

	return 0;
}
コード例 #7
0
static int32 pack_mbp_basic_info(mbp_member_t *mbp_member, json_t *result)
{
	pack_basic_element_info(&(mbp_member->be), result);
	/*
	add_json_integer(result, RMM_JSON_MBP_ID, mbp_member->be.id);
	add_json_string(result, RMM_JSON_UUID, mbp_member->be.uuid);
	*/
	add_json_string(result, RMM_JSON_MBP_MBPID, mbp_member->MBPID);
	add_json_string(result, RMM_JSON_HW_ADDR, mbp_member->MBPHWAddress);
	add_json_string(result, RMM_JSON_IP_ADDR, mbp_member->MBPIPAddress);
	add_json_string(result, RMM_JSON_FW_STATE, mbp_member->fw_state);

	return 0;
}
コード例 #8
0
static int32 pack_fan_basic_info(const fan_member_t *fan_member, json_t *result)
{
	pack_basic_element_info(&(fan_member->be), result);
	/*
	add_json_integer(result, RMM_JSON_FAN_ID, fan_member->be.id);
	add_json_string(result, RMM_JSON_UUID, fan_member->be.uuid);
	*/
	add_json_integer(result, RMM_JSON_ENABLE_STATE, fan_member->enable_state);
	add_json_integer(result, RMM_JSON_HEALTH_STATE, fan_member->health_state);
	add_json_string(result, RMM_JSON_DESIRED_SPEED, fan_member->desired_speed);
	add_json_integer(result, RMM_JSON_TACHOMETER_READING, fan_member->tachometer.reading);
	add_json_string(result, RMM_JSON_METRE_STATE, fan_member->tachometer.current_state);

	return 0;
}
コード例 #9
0
int32 prepare_get_action(const avail_action_t *av_action, json_t *action, int32 index)
{
	if (action == NULL) {
		HTTPD_ERR("action json array request fail\n");
		return -1;
	}
	if (0 != strcmp((int8 *)(av_action[index].action), ""))
		add_json_string(action, RMM_JSON_ACTION, av_action[index].action);

	return 0;
}
コード例 #10
0
ファイル: general_handler.c プロジェクト: intelrsasw/intelRSD
int32 rf_evt_pack_json(json_t *result, const int32 *evt_types, rf_evt_svc_t *service)
{
	int32 i = 0;
	json_t *types_array = NULL;
	json_t *listener = NULL;
	json_t *status = NULL;

	json_object_add(result, RMM_JSON_ODATA_CONTEXT, json_string(service->links.odata_context));
	json_object_add(result, RMM_JSON_ODATA_ID, json_string(service->links.odata_id));
	add_json_string(result, RMM_JSON_ODATA_TYPE, service->fixed.odata_type);
	add_json_string(result, RMM_JSON_RF_ID, service->fixed.id);
	add_json_string(result, RMM_JSON_RF_NAME, service->fixed.name);

	status = json_object();
	if (status != NULL) {
		add_json_string(status, RMM_JSON_RF_STATUS_STATE, service->fixed.status.state);
		add_json_string(status, RMM_JSON_RF_STATUS_HEALTH, service->fixed.status.health);
	}
	json_object_add(result, RMM_JSON_RF_STATUS, status);

	if (service->fixed.service_enabled)
		json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_true());
	else
		json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_false());

	add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY, service->fixed.retry);

	add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY_INTERVAL, service->fixed.retry_interval);


	types_array = json_array();
	if (types_array == NULL)
		return -1;

	for (i = 0;  i < MAX_EVT_ACTION_NUM; i++) {
		if (evt_types[i] == 0)
			continue;

		json_array_add(types_array, json_string((int8 *)rf_evt_msg[i].type_name));
	}
	json_object_add(result, RMM_JSON_RF_SUPPORTED_EVT_TYPES, types_array);

	listener = json_object();
	if (listener == NULL) 
		return -1;

	add_json_string(listener, RMM_JSON_ODATA_ID, service->links.subscriptions);
	json_object_add(result, RMM_JSON_RF_SUBSCRIPTION, listener);

	return 0;
}
コード例 #11
0
static json_t *mbp_get(struct rest_uri_param *param)
{
	int32 idx = 0;
	result_t rs = RESULT_OK;
	json_t *result = NULL;
	json_t *fru = NULL;
	json_t *av_action = NULL;
	json_t *rs_json = NULL;
	json_t *cap = NULL;
	mbp_member_t mbp_member = { {0} };
	json_t *loc = NULL;

	idx = get_asset_idx(param, "mbp_id", MC_TYPE_CM);
	if (idx == -1) {
		HTTPD_ERR("get mbp index fail\n");
		return NULL;
	}

	rs = libwrap_get_mbp_by_idx(idx, &mbp_member);
	if (rs != RESULT_OK) {
		HTTPD_ERR("get mbp info fail, result is %d\n", rs);
		return NULL;
	}

	result = json_object();
	if (result == NULL) {
		HTTPD_ERR("result json object request fail\n");
		return NULL;
	}

	pack_mbp_basic_info(&mbp_member, result);

	loc = json_object();
	if (loc == NULL) {
		HTTPD_ERR("loc json object request fail\n");
		return NULL;
	}

    add_loc_info(loc, (int32)mbp_member.loc.units, RMM_JSON_RACK_UNITS);
	add_loc_info(loc, mbp_member.loc.u_location, RMM_JSON_ULOC);
	add_loc_info(loc, mbp_member.loc.u_height, RMM_JSON_UHEIGHT);
	add_loc_info(loc, mbp_member.loc.x_location, RMM_JSON_XLOC);
	json_object_add(result, RMM_JSON_RACK_LOC, loc);

	add_json_string(result, RMM_JSON_ASSET_TAG, mbp_member.asset.asset_tag);

	fru = json_object();
	if (fru != NULL) {
		pack_fru_info(&(mbp_member.asset.fru), fru);
		json_object_add(result, RMM_JSON_FRU_INFO, fru);
	}

	av_action = json_array();
	if (av_action == NULL) {
		HTTPD_ERR("available action array request fail\n");
		return NULL;
	}

	/* action reset */
	json_t *action = NULL;

	action = json_object();
	if (0 != prepare_get_action(mbp_member.av_action, action, 0)) {
		HTTPD_ERR("action prepare fail\n");
		return NULL;
	}

	cap = json_array();
	if (cap != NULL) {
		json_t *property = NULL;
		json_t *allow_values = NULL;

		allow_values = json_array();
		/* soft reset */
		property = json_object();
		if ((property != NULL) && (allow_values != NULL)) {
			if (0 != strcmp((int8 *)(mbp_member.av_action[0].cap[0].property), "")) {
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(mbp_member.av_action[0].cap[0].property)));
				json_array_add(allow_values, json_string((int8 *)(mbp_member.av_action[0].cap[0].av)));
			}
			json_object_add(property, RMM_JSON_ALLOWABLE_VALUES, allow_values);
			json_array_add(cap, property);
		}
		json_object_add(action, RMM_JSON_CAPABILITIES, cap);
	}
	json_array_add(av_action, action);


	/* action SetUartTarget */
	action = NULL;
	action = json_object();
	if (0 != prepare_get_action(mbp_member.av_action, action, 1)) {
		HTTPD_ERR("action prepare fail\n");
		return NULL;
	}

	cap = NULL;
	cap = json_array();
	if (cap != NULL) {
		json_t *property = NULL;

		/* targetIndex */
		property = json_object();
		if (property != NULL) {
			if (0 != strcmp((int8 *)(mbp_member.av_action[1].cap[0].property), ""))
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(mbp_member.av_action[1].cap[0].property)));
			json_array_add(cap, property);
		}
		json_object_add(action, RMM_JSON_CAPABILITIES, cap);
	}
	json_array_add(av_action, action);

	/* action Update */
	action = NULL;
	action = json_object();
	if (prepare_get_action(mbp_member.av_action, action, 2)) {
		HTTPD_ERR("action prepare fail\n");
		return NULL;
	}

	cap = NULL;
	cap = json_array();
	if (cap != NULL) {
		json_t *property = NULL;

		property = json_object();
		if (property != NULL) {
			if (0 != strcmp((int8 *)(mbp_member.av_action[2].cap[0].property), ""))
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(mbp_member.av_action[2].cap[0].property)));
			json_array_add(cap, property);
		}
		json_object_add(action, RMM_JSON_CAPABILITIES, cap);
	}
	json_array_add(av_action, action);

	json_object_add(result, RMM_JSON_AVALIBLE_ACTIONS, av_action);

	return result;
}
コード例 #12
0
static json_t *mbp_coll_get(struct rest_uri_param *param)
{
	collections_t *mbp_collections = NULL;
	uint32 mbp_num = 0;
	int32 i;
	int32 cm_num = 0;
	result_t rs = RESULT_OK;
	json_t *result = NULL;
	json_t *array = NULL;
	json_t *sub_mbp = NULL;

	cm_num = libwrap_get_asset_num(MC_TYPE_CM);
	if (cm_num == 0) {
		HTTPD_ERR("get mbp num fail\n");
		return NULL;
	}

	mbp_collections = (collections_t *)malloc(cm_num * sizeof(collections_t));
	if (mbp_collections == NULL)
		return NULL;

	memset(mbp_collections, 0, cm_num * sizeof(collections_t));

	rs = libwrap_get_mbp_coll(mbp_collections, &mbp_num);
	if (rs != RESULT_OK) {
		HTTPD_ERR("get mbp coll info fail, result is %d\n", rs);
		return NULL;
	}

	result = json_object();
	if (result == NULL) {
		HTTPD_ERR("result json object request fail\n");
		return NULL;
	}

	array = json_array();
	if (array == NULL) {
		HTTPD_ERR("json array request fail\n");
		return NULL;
	}

	for (i = 0; i < mbp_num; i++) {
		sub_mbp = NULL;
		sub_mbp = json_object();
		if (sub_mbp == NULL) {
			HTTPD_ERR("sub mbp json object request fail\n");
			return NULL;
		}

		add_json_integer(sub_mbp, RMM_JSON_ID, mbp_collections[i].id);
		add_json_string(sub_mbp, RMM_JSON_UUID, mbp_collections[i].uuid);
		add_json_string(sub_mbp, RMM_JSON_NAME, mbp_collections[i].name);
		update_href_host(mbp_collections[i].href, HREF_URL_LEN, param->host);
		add_json_string(sub_mbp, RMM_JSON_HREF, mbp_collections[i].href);
		json_array_add(array, sub_mbp);
	}
	json_object_add(result, RMM_JSON_MBPS, array);

	if (mbp_collections)
		free(mbp_collections);

	return result;
}
コード例 #13
0
int gami_register_req(gami_reg_t *reg_info)
{
	jrpc_req_pkg_t req_pkg = {};
	json_t *cap_array = NULL;
	json_t *cap = NULL;
	int i = 0;
	int rc;
	int64 ip = reg_info->ip_addr;
	int64 port = reg_info->port;

	printf("gami_register, name %s, ip %d, port %d.\n", reg_info->name, reg_info->ip_addr, reg_info->port);
	fill_param(&req_pkg, JRPC_GAMI_REG_NAME, reg_info->name, JSON_STRING);
	fill_param(&req_pkg, JRPC_GAMI_REG_IP, &ip, JSON_INTEGER);
	fill_param(&req_pkg, JRPC_GAMI_REG_PORT, &port, JSON_INTEGER);

	/*mbp*/
	cap_array = json_array();
	if (cap_array == NULL) {
		return -1;
	}

	for (i = 0; i < GAMI_MAX_CAP_NUM; i++) {
		if (strlen((char *)reg_info->capability.cap_mbp[i]) != 0) {
			cap = NULL;
			cap = json_object();
			if (cap == NULL) {
				return -1;
			}
			add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_mbp[i]);
			json_array_add(cap_array, cap);
		}
	}
	fill_param(&req_pkg, JRPC_GAMI_REG_CAP_MBP, cap_array, JSON_ARRAY);

	/*psu*/
	cap_array = json_array();
	if (cap_array == NULL) {
		return -1;
	}

	for (i = 0; i < GAMI_MAX_CAP_NUM; i++) {
		if (strlen((char *)reg_info->capability.cap_psu[i]) != 0) {
			cap = NULL;
			cap = json_object();
			if (cap == NULL) {
				return -1;
			}
			add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_psu[i]);
			json_array_add(cap_array, cap);
		}
	}
	fill_param(&req_pkg, JRPC_GAMI_REG_CAP_PSU, cap_array, JSON_ARRAY);

	/*fan*/
	cap_array = json_array();
	if (cap_array == NULL) {
		return -1;
	}

	for (i = 0; i < GAMI_MAX_CAP_NUM; i++) {
		if (strlen((char *)reg_info->capability.cap_fan[i]) != 0) {
			cap = NULL;
			cap = json_object();
			if (cap == NULL) {
				return -1;
			}
			add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_fan[i]);
			json_array_add(cap_array, cap);
		}
	}
	fill_param(&req_pkg, JRPC_GAMI_REG_CAP_FAN, cap_array, JSON_ARRAY);

	/*drawer*/
	cap_array = json_array();
	if (cap_array == NULL) {
		return -1;
	}

	for (i = 0; i < GAMI_MAX_CAP_NUM; i++) {
		if (strlen((char *)reg_info->capability.cap_drawer[i]) != 0) {
			cap = NULL;
			cap = json_object();
			if (cap == NULL) {
				return -1;
			}
			add_json_string(cap, JRPC_GAMI_CAP_NAME, (unsigned char *)reg_info->capability.cap_drawer[i]);
			json_array_add(cap_array, cap);
		}
	}
	fill_param(&req_pkg, JRPC_GAMI_REG_CAP_DRAWER, cap_array, JSON_ARRAY);

	rc = send_msg_to_registerd(&req_pkg, REG_APP);

	return rc;
}
コード例 #14
0
static json_t *fan_get(struct rest_uri_param *param)
{
	fan_member_t fan_member = { {0} };
	result_t rs = RESULT_OK;
	json_t *result = NULL;
	json_t *threshold = NULL;
	json_t *av_action = NULL;
	json_t *fru = NULL;
	json_t *property = NULL;
	json_t *action = NULL;
	json_t *cap = NULL;
	int32 tzone_idx = 0, fan_idx = 0;
	json_t *loc = NULL;

	tzone_idx = get_asset_idx(param, "zone_id", MC_TYPE_TZONE);
	if (tzone_idx == -1) {
		HTTPD_ERR("get cooling zone index fail\n");
		return NULL;
	}

	fan_idx = get_asset_idx(param, "fan_id", MC_TYPE_FAN);
	if (fan_idx == -1) {
		HTTPD_ERR("get fan index fail\n");
		return NULL;
	}

	rs = libwrap_get_tzone_fan_by_idx(tzone_idx, fan_idx,  &fan_member);
	if (rs != RESULT_OK) {
		HTTPD_ERR("get fan fail, result is %d\n", rs);
		return NULL;
	}

	result = json_object();
	if (result == NULL) {
		HTTPD_ERR("result json object request fail\n");
		return NULL;
	}

	pack_fan_basic_info(&fan_member, result);

	loc = json_object();
	if (loc != NULL) {
		add_loc_info(loc, (int32)fan_member.fan_loc.units, RMM_JSON_RACK_UNITS);
		add_loc_info(loc, fan_member.fan_loc.u_location, RMM_JSON_ULOC);
		add_loc_info(loc, fan_member.fan_loc.u_height, RMM_JSON_UHEIGHT);
        add_loc_info(loc, fan_member.fan_loc.x_location, RMM_JSON_XLOC);
	}
	json_object_add(result, RMM_JSON_RACK_LOC, loc);

	threshold = NULL;
	threshold = json_array();
	if (threshold == NULL) {
		HTTPD_ERR("threshold array request error\n");
		return NULL;
	}

	fan_add_property(threshold, property, fan_member.tachometer.threshold.lower_non_critical, RMM_JSON_LOWER_NON_CRITICAL);
	fan_add_property(threshold, property, fan_member.tachometer.threshold.upper_non_critical, RMM_JSON_UPPER_NON_CRITICAL);
	fan_add_property(threshold, property, fan_member.tachometer.threshold.lower_critical, RMM_JSON_LOWER_CRITICAL);
	fan_add_property(threshold, property, fan_member.tachometer.threshold.upper_critical, RMM_JSON_UPPER_CRITICAL);

	json_object_add(result, RMM_JSON_THRESHOLD, threshold);
	add_json_string(result, RMM_JSON_PRESENCE, fan_member.presence);
	add_json_string(result, RMM_JSON_ASSET_TAG, fan_member.asset.asset_tag);

	add_json_integer(result, RMM_JSON_SPEED_UNIT, fan_member.speed_unit);// 0--PWM, 1---RPM

	fru = json_object();
	if (fru != NULL) {
		pack_fru_info(&(fan_member.asset.fru), fru);
		json_object_add(result, RMM_JSON_FRU_INFO, fru);
	}

	av_action = json_array();
	if (av_action == NULL) {
		HTTPD_ERR("available action array request fail\n");
		return NULL;
	}

	/* requestStateChange */
	action = json_object();
	if (0 != prepare_get_action(fan_member.av_action, action, 0)) {
		HTTPD_ERR("action prepare fail\n");
		return NULL;
	}

	cap = json_array();
	if (cap != NULL) {
		json_t *property = NULL;
		json_t *allow_values = NULL;

		allow_values = json_array();
		property = json_object();
		if ((property != NULL) && (allow_values != NULL)) {
			if (0 != strcmp((int8 *)(fan_member.av_action[0].cap[0].property), "")) {
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[0].cap[0].property)));
				json_array_add(allow_values, json_integer(str2int((int8 *)fan_member.av_action[0].cap[0].av)));
			}
		}

		property = NULL;
		property = json_object();
		if ((property != NULL) && (allow_values != NULL)) {
			if (0 != strcmp((int8 *)(fan_member.av_action[0].cap[1].property), "")) {
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[0].cap[1].property)));
				json_array_add(allow_values, json_integer(str2int((int8 *)fan_member.av_action[0].cap[1].av)));
			}
		}
		json_object_add(property, RMM_JSON_ALLOWABLE_VALUES, allow_values);
		json_array_add(cap, property);
		json_object_add(action, RMM_JSON_CAPABILITIES, cap);
	}
	json_array_add(av_action, action);

	/* SetDesiredSpeed */
	action = NULL;
	action = json_object();
	if (0 != prepare_get_action(fan_member.av_action, action, 1)) {
		HTTPD_ERR("action prepare fail\n");
		return NULL;
	}

	cap = NULL;
	cap = json_array();
	if (cap != NULL) {
		json_t *property = NULL;
		json_t *allow_values = NULL;

		allow_values = json_array();
		property = json_object();
		if ((property != NULL) && (allow_values != NULL)) {
			if (0 != strcmp((int8 *)(fan_member.av_action[1].cap[0].property), "")) {
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[1].cap[0].property)));
				json_array_add(allow_values, json_string((int8 *)(fan_member.av_action[1].cap[0].av)));
			}

			if (0 != strcmp((int8 *)(fan_member.av_action[1].cap[1].property), "")) {
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[1].cap[1].property)));
				json_array_add(allow_values, json_string((int8 *)(fan_member.av_action[1].cap[1].av)));
			}
			json_object_add(property, RMM_JSON_ALLOWABLE_VALUES, allow_values);
			json_array_add(cap, property);
		}

		property = NULL;
		property = json_object();
		if (property != NULL) {
			if (0 != strcmp((int8 *)(fan_member.av_action[1].cap[2].property), "")) {
				json_object_add(property, RMM_JSON_PROPERTY_NAME, json_string((int8 *)(fan_member.av_action[1].cap[2].property)));
				json_array_add(cap, property);
			}
		}
		json_object_add(action, RMM_JSON_CAPABILITIES, cap);
	}
	json_array_add(av_action, action);
	json_object_add(result, RMM_JSON_AVALIBLE_ACTIONS, av_action);
	return result;
}
コード例 #15
0
static json_t *fan_coll_get(struct rest_uri_param *param)
{
	collections_t *tzone_fan_coll = NULL;
	uint32 fan_num = 0;
	int8 *p_tzone_id = NULL;
	result_t rs = RESULT_OK;
	json_t *result = NULL;
	json_t *fan = NULL;
	json_t *array = NULL;
	int32 tzone_idx = 0;
	int32 i;

	tzone_fan_coll = (collections_t *)malloc(MAX_PWM_NUM * sizeof(collections_t));
	if (tzone_fan_coll == NULL)
		return NULL;

	memset(tzone_fan_coll, 0, MAX_PWM_NUM * sizeof(collections_t));

	tzone_idx = get_asset_idx(param, "zone_id", MC_TYPE_TZONE);
	if (tzone_idx == -1) {
		HTTPD_ERR("get cooling zone index fail\n");
		return NULL;
	}

	rs = libwrap_get_tzone_fan_coll(tzone_idx, tzone_fan_coll, &fan_num);
	if (rs != RESULT_OK) {
		HTTPD_ERR("get fan collection fail, result is %d\n", rs);
		return NULL;
	}

	result = json_object();
	if (result == NULL) {
		HTTPD_ERR("result json object request fail\n");
		return NULL;
	}

	array = json_array();
	if (array == NULL) {
		HTTPD_ERR("json array request fail\n");
		return NULL;
	}

	for (i = 0; i < fan_num; i++) {
		fan = NULL;
		fan = json_object();
		if (NULL != fan) {
			add_json_integer(fan, RMM_JSON_ID, tzone_fan_coll[i].id);
			add_json_string(fan, RMM_JSON_UUID, tzone_fan_coll[i].uuid);
			add_json_string(fan, RMM_JSON_NAME, tzone_fan_coll[i].name);
			update_href_host(tzone_fan_coll[i].href, HREF_URL_LEN, param->host);
			add_json_string(fan, RMM_JSON_HREF, tzone_fan_coll[i].href);
			json_array_add(array, fan);
		}
	}
	json_object_add(result, RMM_JSON_FANS, array);

	if (tzone_fan_coll)
		free(tzone_fan_coll);

	return result;
}
コード例 #16
0
static json_t *tzone_get(struct rest_uri_param *param)
{
	tzone_member_t tzone_member = { {0} };
	result_t rs = RESULT_OK;
	json_t *result = NULL;
	json_t *loc = NULL;
	int32 tzone_idx = 0;
	int32 presence_len = 0;

	tzone_idx = get_asset_idx(param, "zone_id", MC_TYPE_TZONE);
	if (tzone_idx == -1) {
		HTTPD_ERR("get cooling zone index fail\n");
		return NULL;
	}

	rs = libwrap_get_tzone_by_idx(tzone_idx, &tzone_member);
	if (rs != RESULT_OK) {
		HTTPD_ERR("get cooling zone fail, result is %d\n", rs);
		return NULL;
	}

	result = json_object();
	if (result == NULL) {
		HTTPD_ERR("result json object request fail\n");
		return NULL;
	}

	/*pack_tzone_basic_info(&tzone_member, result);*/
	pack_basic_element_info((const base_element_t *)&(tzone_member.be), result);

	loc = json_object();
	if (loc != NULL) {
		add_loc_info(loc, (int32)tzone_member.tzone_loc.units, RMM_JSON_RACK_UNITS);
		add_loc_info(loc, tzone_member.tzone_loc.u_location, RMM_JSON_ULOC);
		add_loc_info(loc, tzone_member.tzone_loc.u_height, RMM_JSON_UHEIGHT);
        add_loc_info(loc, (int32)tzone_member.tzone_loc.x_location, RMM_JSON_XLOC);
	}
	json_object_add(result, RMM_JSON_RACK_LOC, loc);

	add_json_string(result, RMM_JSON_PRESENCE, (uint8 *)(tzone_member.presence));
	add_json_string(result, RMM_JSON_POLICY, tzone_member.policy);

	add_json_integer(result, RMM_JSON_PRESENT_TEMP, tzone_member.pres_temp);
	add_json_integer(result, RMM_JSON_OUT_LET_TEMP, tzone_member.outlet_temp);
	add_json_integer(result, RMM_JSON_AIRFLOW, tzone_member.volumetric_airflow);
	
	//TBD: it can be saved in memdb
	add_json_integer(result, RMM_JSON_MAX_FANS_SUPPORTED, MAX_PWM_NUM);
	presence_len = strlen(tzone_member.presence);
	if ((presence_len > -1) && (presence_len < 9)) {
		int32 i = 0;
		int32 number_fan = 0;
		for(i = 0; i < presence_len; i++) {
			if (tzone_member.presence[i] == 49)//"1"
				number_fan++;
		}
		add_json_integer(result, RMM_JSON_NUM_OF_FANS_PRESENT, number_fan);
	}

	return result;
}