#include "XNetSDKTest.h"
#include "XNetSDKSyn.h"
#include "OPLogQuery.h"
#include "OPLogQueryInfo.h"

USE_NS_NETSDK_CFG

int TestOPLogQuery()
{
	printf("%s\r\n", __FUNCTION__);
	int nRet = 0;
	char c = 0;
	while((c = getchar()) != 'q')
	{
		switch(c)
		{
		case 'g':
			{
				char sBeginTime[32] = {0};
				char sEndTime[32] = {0};
				OPLogQuery cfg;

				time_t tNow = time(NULL);
				struct tm tmNow = *localtime(&tNow);
				sprintf(sBeginTime, "%04d-%02d-%02d 00:00:00", tmNow.tm_year + 1900, tmNow.tm_mon + 1, tmNow.tm_mday);
				sprintf(sEndTime, "%04d-%02d-%02d 00:59:59", tmNow.tm_year + 1900, tmNow.tm_mon + 1, tmNow.tm_mday);

				cfg.BeginTime.SetValue(sBeginTime);	
				cfg.EndTime.SetValue(sEndTime);		
				char pOutBuffer[40960] = {0};
				int  nInOutBufSize = sizeof(pOutBuffer);
				const char *pCfg = cfg.ToString();

				nRet =XSDK_DevSetSysConfigSyn(g_hDevice, JK_OPLogQuery, pCfg, strlen(pCfg), pOutBuffer, &nInOutBufSize, 5000, EXCMD_LOGSEARCH_REQ);

				if(nRet >= 0)
				{
					JObjArrayObject<OPLogQueryInfo> OPLogQuery;
					OPLogQuery.Parse(pOutBuffer);

					printf("LogList:%d\r\n", OPLogQuery.objs.Size());
					for(int i = 0;i < OPLogQuery.objs.Size();i++)
					{
						printf("Data:%s, Position:%d, Type:%s, User:%s, Time:%s\r\n", OPLogQuery.objs[i].Data.Value(), OPLogQuery.objs[i].Position.Value(),
							OPLogQuery.objs[i].Type.Value(), OPLogQuery.objs[i].User.Value(), OPLogQuery.objs[i].Time.Value());
					}
				}
			}
			break;
		}
	}

	return 0;
}


