void CGldEditorView::LoadObject(OBJECT *obj)
{
	CListCtrl &list = GetListCtrl();
	
	int nColumns = list.GetHeaderCtrl()?list.GetHeaderCtrl()->GetItemCount():0;
	for (int i=0; i<nColumns; i++)
		list.DeleteColumn(0);

	CRect wr;
	list.GetClientRect(&wr);
	int nCol=0;
	int nWid=0;
	#define W(X) (nWid+=X,X)
	int Name = list.InsertColumn(nCol++,"Name",LVCFMT_LEFT,W(150),nCol);
	int Type = list.InsertColumn(nCol++,"Type",LVCFMT_LEFT,W(100),nCol);
	int Class = list.InsertColumn(nCol++,"Class",LVCFMT_LEFT,W(150),nCol);
	int Access = list.InsertColumn(nCol++,"Access",LVCFMT_LEFT,W(100),nCol);
	int Data = list.InsertColumn(nCol++,"Data",LVCFMT_RIGHT,W(100),nCol);
	int Description = list.InsertColumn(nCol++,"Description",LVCFMT_LEFT,wr.Width()-nWid,nCol);
	#undef W

	int nItem;
	char buffer[1024]="";
	CLASS *oclass;
	PROPERTY *prop;

	nItem = list.InsertItem(list.GetItemCount(),"clock");
	list.SetItemText(nItem,Type,"TIMESTAMP");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PROTECTED");
	list.SetItemText(nItem,Data,convert_from_timestamp(obj->clock,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"name");
	list.SetItemText(nItem,Type,"OBJECTNAME");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,object_name(obj));

	nItem = list.InsertItem(list.GetItemCount(),"id");
	list.SetItemText(nItem,Type,"OBJECTNUM");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"REFERENCE");
	sprintf(buffer,"%d",obj->id);
	list.SetItemText(nItem,Data,buffer);

	nItem = list.InsertItem(list.GetItemCount(),"class");
	list.SetItemText(nItem,Type,"CLASSNAME");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"REFERENCE");
	list.SetItemText(nItem,Data,obj->oclass->name);

	nItem = list.InsertItem(list.GetItemCount(),"size");
	list.SetItemText(nItem,Type,"OBJECTRANK");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"REFERENCE");
	sprintf(buffer,"%d",obj->oclass->size);
	list.SetItemText(nItem,Data,buffer);

	nItem = list.InsertItem(list.GetItemCount(),"parent");
	list.SetItemText(nItem,Type,"OBJECTNAME");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,object_name(obj->parent));

	nItem = list.InsertItem(list.GetItemCount(),"rank");
	list.SetItemText(nItem,Type,"OBJECTRANK");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	sprintf(buffer,"%d",obj->rank);
	list.SetItemText(nItem,Data,buffer);

	nItem = list.InsertItem(list.GetItemCount(),"in_svc");
	list.SetItemText(nItem,Type,"TIMESTAMP");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_timestamp(obj->in_svc,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"out_svc");
	list.SetItemText(nItem,Type,"TIMESTAMP");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_timestamp(obj->out_svc,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"latitude");
	list.SetItemText(nItem,Type,"double");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_latitude(obj->latitude,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"longitude");
	list.SetItemText(nItem,Type,"double");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PUBLIC");
	list.SetItemText(nItem,Data,convert_from_latitude(obj->longitude,buffer,sizeof(buffer))?buffer:"");

	nItem = list.InsertItem(list.GetItemCount(),"flags");
	list.SetItemText(nItem,Type,"set");
	list.SetItemText(nItem,Class,"OBJECTHDR");
	list.SetItemText(nItem,Access,"PROTECTED");
	list.SetItemText(nItem,Data,convert_from_set(buffer,sizeof(buffer),&(obj->flags),object_flag_property())?buffer:"");

	for (oclass=obj->oclass; oclass!=NULL; oclass=oclass->parent)
	{
		list.InsertItem(list.GetItemCount(),"");
		for (prop=class_get_first_property(oclass); prop!=NULL; prop=class_get_next_property(prop))
		{
			nItem = list.InsertItem(list.GetItemCount(),prop->name);
			list.SetItemText(nItem,Type,class_get_property_typename(prop->ptype));
			list.SetItemText(nItem,Class,oclass->name);
			list.SetItemText(nItem,Access,convert_from_enumeration(buffer,sizeof(buffer),&(prop->access),object_access_property())?buffer:"");
			list.SetItemText(nItem,Data,object_get_value_by_name(obj,prop->name,buffer,sizeof(buffer))?buffer:"(error)");
			list.SetItemText(nItem,Description,prop->description);
		}
	};
}
示例#2
0
/** Process an incoming XML data request
	@returns non-zero on success, 0 on failure (errno set)
 **/
int http_xml_request(HTTP *http,char *uri)
{
	char arg1[1024]="", arg2[1024]="";
	int nargs = sscanf(uri,"%1023[^/=\r\n]/%1023[^\r\n=]",arg1,arg2);
	char *value = strchr(uri,'=');
	char buffer[1024]="";
	OBJECT *obj=NULL;
	char *id;

	/* value */
	if (value) *value++;

	/* decode %.. */
	http_decode(arg1);
	http_decode(arg2);
	if (value) http_decode(value);

	/* process request */
	switch (nargs) {

	/* get global variable */
	case 1: 

		/* find the variable */
		if (global_getvar(arg1,buffer,sizeof(buffer))==NULL)
		{
			output_error("global variable '%s' not found", arg1);
			return 0;
		}

		/* assignment, if any */
		if (value) global_setvar(arg1,value);
		
		/* post the response */
		http_format(http,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
		http_format(http,"<globalvar>\n\t<name>%s</name>\n\t<value>%s</value>\n</globalvar>\n",
			arg1, http_unquote(buffer));
		http_type(http,"text/xml");
		return 1;

	/* get object property */
	case 2:

		/* find the object */
		id = strchr(arg1,':');
		if ( id==NULL )
			obj = object_find_name(arg1);
		else
			obj = object_find_by_id(atoi(id+1));
		if ( obj==NULL )
		{
			output_error("object '%s' not found", arg1);
			return 0;
		}

		/* post the current value */
		if ( !object_get_value_by_name(obj,arg2,buffer,sizeof(buffer)) )
		{
			output_error("object '%s' property '%s' not found", arg1, arg2);
			return 0;
		}

		/* assignment, if any */
		if ( value && !object_set_value_by_name(obj,arg2,value) )
		{
			output_error("cannot set object '%s' property '%s' to '%s'", arg1, arg2, value);
			return 0;
		}

		/* post the response */
		http_format(http,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<property>\n");
		http_format(http,"\t<object>%s</object>\n", arg1);
		http_format(http,"\t<name>%s</name>\n", arg2);
		http_format(http,"\t<value>%s</value>\n", http_unquote(buffer));
		/* TODO add property type info */
		http_format(http,"</property>\n");
		http_type(http,"text/xml");
		return 1;

	default:
		return 0;
	}
	return 0;
}
示例#3
0
static mxArray *get_object_data(OBJECT *obj)
{
	mxArray *plhs[1];

	/* set the standard info */
#define ERROR "(error)"
#define NONE "(none)"
	char *fnames[1024] = {"id","class","parent","rank","clock","latitude","longitude","in_svc","out_svc","flags",NULL}; // };
	int nFields = 0;
	int nData = 0;
	char value[1024];
	PROPERTY *prop;
	mxArray *pId = mxCreateString(convert_from_object(value,sizeof(value),&obj,NULL)?value:ERROR);
	mxArray *pClass = mxCreateString(obj->oclass->name);
	mxArray *pParent = mxCreateString(obj->parent!=NULL&&convert_from_object(value,sizeof(value),&(obj->parent),NULL)?value:NONE);
	mxArray *pRank = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL);
	mxArray *pClock = mxCreateString(convert_from_timestamp(obj->clock,value,sizeof(value))?value:ERROR);
	mxArray *pLatitude = mxCreateString(convert_from_latitude(obj->latitude,value,sizeof(value))?value:NONE);
	mxArray *pLongitude = mxCreateString(convert_from_longitude(obj->longitude,value,sizeof(value))?value:NONE);
	mxArray *pInSvc = mxCreateString(convert_from_timestamp(obj->in_svc,value,sizeof(value))?value:ERROR);
	mxArray *pOutSvc = mxCreateString(convert_from_timestamp(obj->out_svc,value,sizeof(value))?value:ERROR);
	mxArray *pFlags = mxCreateString(convert_from_set(value,sizeof(value),(void*)&obj->flags,object_flag_property())?value:ERROR);

	*(OBJECTRANK*)mxGetPr(pRank) = obj->rank;

	/* count the number of header items */
	while (fnames[nFields]!=NULL) nFields++;

	/* count the number of object properties and assign the field names */
	for (prop=class_get_first_property(obj->oclass);  prop!=NULL; prop=class_get_next_property(prop))
		/** @todo don't damage the original fieldname when making it safe for Matlab */
		fnames[nFields+nData++] = make_fieldname(prop->name);

	/* construct the return value */
	plhs[0] = mxCreateStructMatrix(1,1,nFields+nData,fnames);

	/* construct the header fields */
	mxSetFieldByNumber(plhs[0],0,0,pId);
	mxSetFieldByNumber(plhs[0],0,1,pClass);
	mxSetFieldByNumber(plhs[0],0,2,pParent);
	mxSetFieldByNumber(plhs[0],0,3,pRank);
	mxSetFieldByNumber(plhs[0],0,4,pClock);
	mxSetFieldByNumber(plhs[0],0,5,pLatitude);
	mxSetFieldByNumber(plhs[0],0,6,pLongitude);
	mxSetFieldByNumber(plhs[0],0,7,pInSvc);
	mxSetFieldByNumber(plhs[0],0,8,pOutSvc);
	mxSetFieldByNumber(plhs[0],0,9,pFlags);

	/* construct the data fields */
	for (prop=class_get_first_property(obj->oclass);  prop!=NULL; nFields++,prop=class_get_next_property(prop))
	{
		mxArray *pValue;
		if (prop->ptype==PT_double)
		{
			pValue = mxCreateDoubleMatrix(1,1,mxREAL);
			*(double*)mxGetPr(pValue) = *object_get_double(obj,prop);
		}
		else if (prop->ptype==PT_int32)
		{
			pValue = mxCreateDoubleMatrix(1,1,mxREAL);
			*(double*)mxGetPr(pValue) = (double)*object_get_int32(obj,prop);
		}
		else if (prop->ptype==PT_complex)
		{
			complex *pData = object_get_complex(obj,prop);
			pValue = mxCreateDoubleMatrix(1,1,mxCOMPLEX);
			*(double*)mxGetPr(pValue) = pData->r;
			*(double*)mxGetPi(pValue) = pData->i;
		}
		else 
		{
			pValue = mxCreateString(object_get_value_by_name(obj,prop->name,value,sizeof(value))?value:ERROR);
		}
		mxSetFieldByNumber(plhs[0],0,nFields,pValue);
	}
	return plhs[0];
}