cJSON *pJsonTop = = cJSON_CreateObject();;/*json configuration, using to read and write config file */
if(pAlertConfStatic->ValidBoxRatio != 0.f)
{
cJSON *pJsonSubcp = cJSON_CreateNumber(pJsonSub->valuedouble);
cJSON_AddItemToObject( pJsonTopcp, "ValidBoxRatio", pJsonSubcp);
}
if(pAlertConfStatic->areaOverlapRatio != 0.f)
{
cJSON *pJsonSubcp = cJSON_CreateNumber(pJsonSub->valuedouble);
cJSON_AddItemToObject( pJsonTopcp, "areaOverlapRatio", pJsonSubcp);
}
if(pAlertConfStatic->StopDuration != 0)
{
cJSON *pJsonSubcp = cJSON_CreateNumber(pAlertConfStatic->StopDuration);
cJSON_AddItemToObject( pJsonTopcp, "StopDuration", pJsonSubcp);
}
if(pAlertConfStatic->TripWireNum)
{
cJSON *pJsonSubcp = cJSON_CreateObject();
for(int i = 0; i < pAlertConfStatic->TripWireNum; i++)
{
cJSON *pJsonItem = cJSON_CreateObject();
cJSON *pJsonAttrWarning = cJSON_CreateObject();
if((pAlertConfStatic->iva_TripWire_conf[i].direct)
{
cJSON *pJsonDirect = cJSON_CreateNumber(pAlertConfStatic->iva_TripWire_conf[i].direct);
cJSON_AddItemToObject( pJsonAttrWarning, "direct", pJsonDirect);
}
cJSON *pJsonPointOne = cJSON_CreateObject();
cJSON *pJsonPointTwo = cJSON_CreateObject();
cJSON *pJsonPointOneX = cJSON_CreateNumber(pAlertConfStatic->iva_TripWire_conf[i].warning[0].x);
cJSON *pJsonPointOneY = cJSON_CreateNumber(pAlertConfStatic->iva_TripWire_conf[i].warning[0].y);
cJSON_AddItemToObject( pJsonPointOne, "x", pJsonPointOneX);
cJSON_AddItemToObject( pJsonPointOne, "y", pJsonPointOneY);
cJSON *pJsonPointTwoX = cJSON_CreateNumber(pAlertConfStatic->iva_TripWire_conf[i].warning[1].x);
cJSON *pJsonPointTwoY = cJSON_CreateNumber(pAlertConfStatic->iva_TripWire_conf[i].warning[1].y);
cJSON_AddItemToObject( pJsonPointTwo, "x", pJsonPointTwoX);
cJSON_AddItemToObject( pJsonPointTwo, "y", pJsonPointTwoY);
cJSON_AddItemToObject( pJsonAttrWarning, "p0", pJsonPointOne);
cJSON_AddItemToObject( pJsonAttrWarning, "p1", pJsonPointTwo);
cJSON_AddItemToObject( pJsonItem, "warning", pJsonAtrrWarning);
cJSON_AddItemToObject( pJsonSubcp, pAlertConfStatic->iva_TripWire_conf[i].name, pJsonItem);
}
cJSON_AddItemToObject( pJsonTopcp, "TripWire", pJsonSubcp);
}
if(pAlertConfStatic->climbWallNum)
{
cJSON *pJsonSubcp = cJSON_CreateObject();
for(int i = 0; i < pAlertConfStatic->climbWallNum; i++)
{
cJSON *pJsonItem = cJSON_CreateObject();
cJSON *pJsonLineOne= cJSON_CreateObject();
cJSON *pJsonLinegOnePointOne = cJSON_CreateObject();
cJSON *pJsonLinegOnePointTwo = cJSON_CreateObject();
cJSON *pJsonLineTwo = cJSON_CreateObject();
cJSON *pJsonLinegTwoPointOne = cJSON_CreateObject();
cJSON *pJsonLinegTwoPointTwo = cJSON_CreateObject();
cJSON *pJsonLinegOnePointOneX = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[0].warning[0].x);
cJSON *pJsonLinegOnePointOneY = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[0].warning[0].y);
cJSON_AddItemToObject( pJsonLineOnePointOne, "x", pJsonLinegOnePointOneX);
cJSON_AddItemToObject( pJsonLineOnePointOne, "y", pJsonLinegOnePointOneY);
cJSON_AddItemToObject( pJsonLineOne, "p0", pJsonLineOnePointOne);
cJSON *pJsonLinegOnePointTwoX = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[0].warning[1].x);
cJSON *pJsonLinegOnePointTwoY = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[0].warning[1].y);
cJSON_AddItemToObject( pJsonLineOnePointTwo, "x", pJsonLinegOnePointTwoX);
cJSON_AddItemToObject( pJsonLineOnePointTwo, "y", pJsonLinegOnePointTwoY);
cJSON_AddItemToObject( pJsonLineOne, "p1", pJsonLineOnePointTwo);
cJSON *pJsonLinegTwoPointOneX = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[1].warning[0].x);
cJSON *pJsonLinegTwoPointOneY = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[1].warning[0].y);
cJSON_AddItemToObject( pJsonLineTwoPointOne, "x", pJsonLinegTwoPointOneX);
cJSON_AddItemToObject( pJsonLineTwoPointOne, "y", pJsonLinegTwoPointOneY);
cJSON_AddItemToObject( pJsonLineTwo, "p0", pJsonLineTwoPointOne);
cJSON *pJsonLinegTwoPointTwoX = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[1].warning[1].x);
cJSON *pJsonLinegTwoPointTwoY = cJSON_CreateNumber(pAlertConfStatic->iva_climb_conf[i].tripWire[1].warning[1].y);
cJSON_AddItemToObject( pJsonLineTwoPointTwo, "x", pJsonLinegTwoPointTwoX);
cJSON_AddItemToObject( pJsonLineTwoPointTwo, "y", pJsonLinegTwoPointTwoY);
cJSON_AddItemToObject( pJsonLineTwo, "p1", pJsonLineTwoPointTwo);
cJSON_AddItemToObject( pJsonItem, "warningOne", pJsonLineTwo);
cJSON_AddItemToObject( pJsonItem, "warningTwo", pJsonLineTwo);
cJSON_AddItemToObject( pJsonSubcp, pAlertConfStatic->iva_climb_conf[i].name, pJsonItem);
}
cJSON_AddItemToObject( pJsonTopcp, "climbWall", pJsonSubcp);
}
if(pAlertConfStatic->areaInvasionNum)
{
cJSON *pJsonSubcp = cJSON_CreateObject();
for(int i = 0; i < pAlertConfStatic->areaInvasionNum; i++)
{
cJSON *pJsonItem = cJSON_CreateObject();
cJSON *pJsonSidesNum = cJSON_CreateNumber(pAlertConfStatic->areaInvasion[i].sidesNum);
cJSON_AddItemToObject( pJsonItem, "sidesNum", pJsonSidesNum);
for(int j = 0; j < pAlertConfStatic->areaInvasion[i].sidesNum; j++)
{
cJSON *pJsonPoint = cJSON_CreateObject();
cJSON *pJsonPointX = cJSON_CreateNumber(pAlertConfStatic->areaInvasion[i].sides[j].x);
cJSON *pJsonPointY = cJSON_CreateNumber(pAlertConfStatic->areaInvasion[i].sides[j].y);
cJSON_AddItemToObject( pJsonPoint, "x", pJsonPointX);
cJSON_AddItemToObject( pJsonPoint, "y", pJsonPointY);
char pointName[16];
memset(pointName, 0, sizeof(16));
sprintf(pointName, "p%d", i);
cJSON_AddItemToObject( pJsonItem, pointName, pJsonPoint);
}
cJSON_AddItemToObject( pJsonSubcp, pAlertConfStatic->areaInvasion[i].name, pJsonItem);
}
cJSON_AddItemToObject( pJsonTopcp, "areaInvasion", pJsonSubcp);
}
if(pAlertConfStatic->areaLeaveNum)
{
cJSON *pJsonSubcp = cJSON_CreateObject();
for(int i = 0; i < pAlertConfStatic->areaLeaveNum; i++)
{
cJSON *pJsonItem = cJSON_CreateObject();
cJSON *pJsonSidesNum = cJSON_CreateNumber(pAlertConfStatic->areaLeave[i].sidesNum);
cJSON_AddItemToObject( pJsonItem, "sidesNum", pJsonSidesNum);
for(int j = 0; j < pAlertConfStatic->areaLeave[i].sidesNum; j++)
{
cJSON *pJsonPoint = cJSON_CreateObject();
cJSON *pJsonPointX = cJSON_CreateNumber(pAlertConfStatic->areaLeave[i].sides[j].x);
cJSON *pJsonPointY = cJSON_CreateNumber(pAlertConfStatic->areaLeave[i].sides[j].y);
cJSON_AddItemToObject( pJsonPoint, "x", pJsonPointX);
cJSON_AddItemToObject( pJsonPoint, "y", pJsonPointY);
char pointName[16];
memset(pointName, 0, sizeof(16));
sprintf(pointName, "p%d", i);
cJSON_AddItemToObject( pJsonItem, pointName, pJsonPoint);
}
cJSON_AddItemToObject( pJsonSubcp, pAlertConfStatic->areaLeave[i].name, pJsonItem);
}
cJSON_AddItemToObject( pJsonTopcp, "areaLeave", pJsonSubcp);
}
ret = APP_OK;
response.ret_code = ret;
ml_syscp_submit_rescmd(0, out, (char *)&response, sizeof(response));
APP_DBGPOS_ERR(APP_SYSMGR, "out stream_process_get_video result[%d] \n",ret);
//create all json objects from pAlertConf, ???
if(pJsonTopcp == NULL)
{
return 0;
}
char *pBuf = malloc(MAX_ALERT_CONF_BUF_LEN);
if(pBuf == NULL)
{
assert(0);
}
memset(pBuf, 0, MAX_ALERT_CONF_BUF_LEN);
snprintf(pBuf, MAX_ALERT_CONF_BUF_LEN - 1, "%s", cJSON_Print(pJsonTopcp));
cJSON_Delete(pJsonTopcp);
*ppbuf = pBuf;
return 0;