Esempio n. 1
0
static __uint _on_add_edit_groups(PCRTK_PACKET p)
{
	RTK_CURSOR hNode, hGroup;
	PRTK_GROUP png, pg=0;
	__bool		bEdit;
	__uint count;

	if(p->data_size % sizeof(RTK_GROUP)){
		return 0;
	}
	if( !lock_rtdb(__true, 100) ){
		return 0;
	}
	hNode = HNODE_LOCAL_MACHINE;
	
	count = p->data_size / sizeof(RTK_GROUP);
	png = (PRTK_GROUP)p->data;
	bEdit = PACKET_TYPE(p) == PT_EditGroup? __true : __false;
	for(__uint i=0; i<count; i++, png++){
		hGroup = open_group(hNode, &png->key);
		pg = (PRTK_GROUP)cursor_get_item(hGroup);
		if(pg){
			memcpy(
				pg->description, 
				png->description, 
				sizeof(pg->description)
				);
			pg->period = png->period;
			fire_rtdb_event(EV_ModifyGroup, pg);
		}else{
			hGroup = create_group(hNode, png);
			pg = (PRTK_GROUP)cursor_get_item(hGroup);
		}
		if(pg){
			pg->d.flags = png->d.flags;
		}
		DEBUG_PRINTF((
			"Got group %s, flag=%08x\n", 
			(char *)CGroupName(png->key), 
			png->d.flags
			));
		close_handle(hGroup);		
	}
	unlock_rtdb();

	return count;
}
Esempio n. 2
0
RTDB_API RTK_CURSOR PMC_API create_group(
	RTK_CURSOR node,
	PRTK_GROUP grp
	)
{
	RTK_CURSOR	handle;
	RTK_NODE	*nd;
	RTK_GROUP	group;
	PGROUP_KEY	gk;

	if((__uint)node == 0x12345678){
		g_dwMaxTags = (__uint)grp;
		return 0;
	}

	gk = &grp->key;
	handle = open_group(node, gk);
	if(handle){
		return handle;
	}

	nd = (RTK_NODE*)cursor_get_item(node);
	if(!nd){
		return 0;
	}

	group = *grp;
	make_unified_key(group.key);
	ZeroMemory(&group.d, sizeof(group.d)); 
	group.node = nd->key;
	group.refcount = 0;
	group.itemtable=(void *)(new TAG_TABLE);
	if(!group.itemtable){
		utils_error("-- create_group --Not enough memory.");
		return __false;
	}
	handle = (RTK_CURSOR)_HGROUP::create(
		(GROUP_TABLE*)nd->itemtable, *gk, group
		);
	if(handle){
		FIRE_EVENT(
			OnAddGroup, ((PRTK_GROUP)cursor_get_item(handle))
			);
	}
	return handle;
}
Esempio n. 3
0
__uint _fastcall _read_tags(
	__uint count, 
	PCTAG_NAME names, 
	Ppmc_value_t values,
	__uint & existed
	)
{
	RTK_CURSOR	hNode, hTag;
	NODE_KEY	cachedNode;
	RTK_TAG		*pTag;
	__uint		i, valids;

	valids = 0;
	existed = 0;
	ZeroMemory(values, sizeof(values[0]) * count);
	if(!lock_rtdb(false, 1000)){
		return 0;
	}
	hNode = 0;
	hTag = 0;
	RTK_TIME now;
	rtk_time_mark(&now);
	hNode = 0;
	memset(&cachedNode, 0, sizeof(cachedNode));
	for(i=0; i<count; i++){
		if(!(cachedNode == names[i].node)){
			close_handle(hNode);
			hNode = 0;			
		}
		if(!hNode){
			hNode = open_node(&names[i].node);
			cachedNode = names[i].node;
		}
		if(!hNode){
			values[i].Flags &= ~TF_Valid;
			continue;
		}		
		hTag = open_tag(hNode, &names[i].sname);
		if(hTag){
			existed++;
			pTag = (RTK_TAG*)cursor_get_item(hTag);
			double diff;
			diff = rtk_time_diff(&now, &pTag->d.CachedTime);
			if(diff > (g_fltTagLife*2)){
				mark_expired(pTag);
			}
			values[i] = pTag->d.Value;
			valids++;
			close_handle(hTag);
		}else{
			values[i].Flags &= ~TF_Valid;
		}		
	}
	close_handle(hNode);
	unlock_rtdb();
	return valids;
}
Esempio n. 4
0
/*
	determine which tags should be saved to history database.
*/
void CInMemoryBuffer::buildStreamList()
{
	RTK_CURSOR hNode;
	RTK_CURSOR hGroup;
	RTK_CURSOR hTag;
	PCRTK_TAG  pTag;
	TAG_NAME tn;
	char nodeName[rtkm_node_key_length + 1];
	
	GetPrivateProfileString(
		"PMC",
		"ServerName",
		"LocalServer",
		nodeName,
		sizeof(nodeName),
		get_config_file()
		);
	CNodeName nodeKey(nodeName);

	//utils_debug("wlock 3\n");
	WriteLock();
	
	if(!lock_rtdb(__false, 100)){
		//utils_debug("release 6\n");
		Release();
		return;
	}
	
	// clear list
	clearStreamList();
	
	hNode = open_node(nodeKey);
	if(hNode){
		hGroup = cursor_open_first_subitem(hNode);
		while(!cursor_is_end(hGroup)){
			hTag = cursor_open_first_subitem(hGroup);
			while(!cursor_is_end(hTag)){
				pTag = (PCRTK_TAG)cursor_get_item(hTag);
				if(pTag->s.Flags & TF_SaveToHistory){
					tn.node = pTag->node;
					tn.sname.group = pTag->group;
					tn.sname.tag = pTag->key;
					addTag(&tn);
				}
				cursor_move_next(hTag);
			}
			close_handle(hTag);
			cursor_move_next(hGroup);
		}
		close_handle(hGroup);
	}

	unlock_rtdb();
	
	//utils_debug("release 7\n");
	Release();
}
Esempio n. 5
0
static __uint _on_add_edit_tags(PCRTK_PACKET p)
{
	ONLINE_CONFIG::reload_tags_ack *ack;
	RTK_CURSOR	hNode, hTag, hGroup;
	RTK_TAG		*pTag;
	RTK_GROUP	grp;
	__bool		bEdit;
	
	__uint tagcount, i;

	ack = (ONLINE_CONFIG::reload_tags_ack *)p->data;
	tagcount = p->data_size / sizeof(*ack);
	if(p->data_size % sizeof(*ack)){
		return 0;
	}
	ZeroMemory(&grp, sizeof(grp));

	if( !lock_rtdb(__true, 100) ){
		return 0;
	}

	hNode = HNODE_LOCAL_MACHINE;
	hTag = hGroup = 0;
	host_to_node(&g_ThisNode->key, &grp.node);

	if(PACKET_TYPE(p) == PT_EditTag){
		bEdit = __true;
	}else{
		bEdit = __false;
	}

	for(i=0; i<tagcount; i++){
		hGroup = open_group(hNode, &ack[i].tag.group);
		grp.key = ack[i].tag.group;
		if(!hGroup){
			hGroup = create_group(hNode, &grp);
		}
		if(hGroup){
			hTag = create_tag(hGroup, &ack[i].tag.key, &ack[i].tag.s);
			pTag  = (RTK_TAG*)cursor_get_item(hTag);
			if(pTag){
				*pTag = ack[i].tag;
				mark_expired(pTag);
				close_handle(hTag);
				if(bEdit){
					// add-tag event is auto-fired
					fire_rtdb_event(EV_ModifyTag, pTag);
				}				
			}					
		}
		close_handle(hGroup);
	}

	unlock_rtdb();

	return tagcount;
}
Esempio n. 6
0
RTDB_API RTK_CURSOR PMC_API create_tag(
	RTK_CURSOR group,
	PCTAG_KEY tag, 
	PCSTATIC_TAG_DATA sd
	)
{
	RTK_CURSOR	handle;
	RTK_GROUP * grp;
	RTK_TAG 	t;

	handle = open_tag_g(group, tag);
	if(handle){
		return handle;
	}

	if(g_dwTags >= g_dwMaxTags){
		rtk_set_last_error(RTDB_HARD_CONSTRAINTS);
		return 0;
	}

	grp = (RTK_GROUP*)cursor_get_item(group);
	if(!grp){
		return 0;
	}
	ZeroMemory(&t, sizeof(t));
	t.key = *tag;
	make_unified_key(t.key);
	t.s = *sd;
	t.node = grp->node;
	t.group = grp->key;
	handle = (RTK_CURSOR)_HTAG::create((TAG_TABLE*)grp->itemtable, t.key, t);
	RTK_TAG * pTag = (RTK_TAG*)cursor_get_item(handle);
	if(pTag){
		ZeroMemory(&pTag->d, sizeof(pTag->d));
		set_value_type(pTag->d.Value.Flags, get_value_type(pTag->s.Flags));
		RtkInitializeListHead(&pTag->d.DeviceLink);
		RtkInitializeListHead(&pTag->d.RefreshLink);
		FIRE_EVENT(OnAddTag, (pTag));
		g_dwTags++;
	}

	return handle;
}
Esempio n. 7
0
void CDCSItem::ReloadContents()
{
    RTK_CURSOR hNode;
    PRTK_NODE  pNode;
    CNodeItem  *item;

    RemoveChildren();
    // discover all running nodes
    // discover_nodes(1000);
    hNode = open_first_node();
    pNode = (PRTK_NODE)cursor_get_item(hNode);
    while( pNode ){
        item = new CNodeItem(&pNode->key);
        AddChild(item);
        cursor_move_next(hNode);
        pNode = (PRTK_NODE)cursor_get_item(hNode);
    }
    close_handle(hNode);
}
Esempio n. 8
0
RTDB_API PRTK_NODE PMC_API query_node(
	PCNODE_KEY node
	)
{
	RTK_CURSOR hNode;
	PRTK_NODE nd;
	hNode = open_node(node);
	nd = (PRTK_NODE)cursor_get_item(hNode);
	close_handle(hNode);
	return nd;
}
Esempio n. 9
0
RTDB_API PRTK_TAG PMC_API query_tag_g(
	RTK_CURSOR group, 
	PCTAG_KEY tag
	)
{
	assert(is_hgroup(group));
	RTK_CURSOR hTag;
	hTag = open_tag_g(group, tag);
	RTK_TAG * pTag = (RTK_TAG *)cursor_get_item(hTag);
	close_handle(hTag);
	return pTag;
}
Esempio n. 10
0
RTDB_API PRTK_TAG PMC_API query_tag(
	RTK_CURSOR node, 
	PCSHORT_TAG_NAME tag
	)
{
	assert(is_hnode(node));
	RTK_CURSOR handle;
	handle = open_tag(node, tag);
	PRTK_TAG p = (PRTK_TAG)cursor_get_item(handle);
	close_handle(handle);
	return p;
}
Esempio n. 11
0
void CDBItem::ReloadContents()
{
    CConfigurableItem *item;
    // discover_groups(&key, 2000);
    RTK_CURSOR hNode, hGroup;
    PRTK_GROUP pGroup;

    hNode = open_node(&key);
    if(!hNode){
        return;
    }
    hGroup = cursor_open_first_subitem(hNode);
    pGroup = (PRTK_GROUP)cursor_get_item(hGroup);
    while(pGroup){
        item = new CGroupItem(&key, &pGroup->key);
        AddChild(item);
        cursor_move_next(hGroup);
        pGroup = (PRTK_GROUP)cursor_get_item(hGroup);
    }
    close_handle(hGroup);
    close_handle(hNode);
}
Esempio n. 12
0
void attach_device_tags(PDEVICE_INFO d)
{
	RTK_CURSOR handle;
	PRTK_GROUP p;

	handle = cursor_open_first_subitem(HNODE_LOCAL_MACHINE);
	while(!cursor_is_end(handle)){
		p = (PRTK_GROUP)cursor_get_item(handle);
		RTK_CURSOR hTag;
		PRTK_TAG   pTag;
		hTag = cursor_open_first_subitem(handle);
		while(pTag = (PRTK_TAG)cursor_get_item(hTag)){
			if(pTag->s.Device == d->k){
				attach_tag_to_device(pTag, d);
			}
			cursor_move_next(hTag);
		}
		close_handle(hTag);
		cursor_move_next(handle);
	}
	close_handle(handle);
}
Esempio n. 13
0
RTDB_API RTK_CURSOR PMC_API open_tag_g(
	RTK_CURSOR hGroup,
	PCTAG_KEY tag
	)
{
	RTK_GROUP  *pGroup;

	pGroup = (RTK_GROUP*)cursor_get_item(hGroup);
	if(!pGroup){
		return 0;
	}
	return (RTK_CURSOR)_HTAG::find((TAG_TABLE*)pGroup->itemtable, *tag);
}
Esempio n. 14
0
RTDB_API RTK_CURSOR PMC_API open_group(
	RTK_CURSOR node,
	PCGROUP_KEY gk
	)
{
	RTK_NODE	*nd;

	nd = (RTK_NODE*)cursor_get_item(node);
	if(!nd){
		return 0;
	}

	return (RTK_CURSOR)_HGROUP::find((GROUP_TABLE*)nd->itemtable, *gk);
}
Esempio n. 15
0
RTDB_API PRTK_GROUP PMC_API query_group(
	RTK_CURSOR node, 
	PCGROUP_KEY key
	)
{
	RTK_CURSOR hGroup;
	hGroup = open_group(node, key);
	if(!hGroup){
		return 0;
	}
	PRTK_GROUP p;
	p = (PRTK_GROUP)cursor_get_item(hGroup);
	close_handle(hGroup);
	return p;
}
Esempio n. 16
0
/*
	_on_system()
*/
void PMC_API _on_system(PCRTK_PACKET packet, HVBUS bus)
{
#if 0
	if(get_power_state() != PWR_RUNNING){
		return;
	}
#endif
	{
		static __bool priorityBoosted = __false;
		if(!priorityBoosted){
			DWORD boost;
			boost = GetPrivateProfileInt(
				"vbus", 
				"SystemBoost", 
				THREAD_PRIORITY_ABOVE_NORMAL,
				get_config_file()
				);
			SetThreadPriority(GetCurrentThread(), boost);
			priorityBoosted = __true;
		}
	}

	if(packet->packet_type != PT_ServerClaim){
		return;
	}
	if(!lock_rtdb(__false, 1000)){
		return;
	}
	RTK_CURSOR	hNode;
	PRTK_NODE	pNode;
	TAG_NAME	tn;
	host_to_node(&packet->src.host, &tn.node);
	hNode = open_node(&tn.node);
	pNode = (PRTK_NODE)cursor_get_item(hNode);
	if(pNode){
		pNode->dogcount = g_NodeLife;
	}
	close_handle(hNode);
	unlock_rtdb();
	if(!pNode && g_Worker){
		memset(&tn.sname, 0, sizeof(tn.sname));
		g_Worker->inform_load(&tn, 1);
	}
}
Esempio n. 17
0
void PMC_API _on_rtdb(PCRTK_PACKET packet, HVBUS bus)
{
	// check for unknown node
	TAG_NAME	tn;
	PRTK_NODE pNode;

#if 0
	if(get_power_state() != PWR_RUNNING){
		return;
	}
#endif

	if(g_Worker){
		if(lock_rtdb(__false, 100)){
			RTK_CURSOR hNode;
			host_to_node(&packet->src.host, &tn.node);
			hNode = open_node(&tn.node);
			pNode = (PRTK_NODE)cursor_get_item(hNode);
			if(pNode){
				pNode->dogcount = g_NodeLife;
			}
			close_handle(hNode);
			unlock_rtdb();
			if(!hNode){
				memset(&tn.sname, 0, sizeof(tn.sname));
				// unknown node
				g_Worker->inform_load(&tn, 1);
			}			
			if(!hNode){
				return;
			}
		}
	}

	switch(PACKET_TYPE(packet)){
	case PT_ChangedData:
		update_changed_data(packet, __false);
		break;
	case PT_QueryData:
		_on_queried_data(packet);
		break;
	}
}
Esempio n. 18
0
RTDB_API RTK_CURSOR PMC_API create_node(PCNODE_KEY key, __uint context)
{
	RTK_CURSOR	handle;
	RTK_NODE item;

	handle = open_node(key);
	if(handle){
		return handle;
	}

	ZeroMemory(&item, sizeof(item));
	item.key = *key;
	item.context = context;
	item.itemtable = new GROUP_TABLE;
	if(!item.itemtable){
		return 0;
	}
	make_unified_key(item.key); 
	handle = (RTK_CURSOR)_HNODE::create(&g_Nodes, *key, item);
	if(handle){
		FIRE_EVENT(OnAddNode, ((PRTK_NODE)cursor_get_item(handle)));
	}
	return handle;
}
Esempio n. 19
0
/*
	Load data from storage to UI
*/
void __fastcall TframTag::UpdateView()
{
	//TODO: Add your source code here
	TComponent * comp;
	int i;
	PTAG_NAME name = &m_TagName;
	// update static information
	PRTK_TAG pTag = &m_Tag;
	char textname[TAGNAME_TEXT_LENGTH + 1];
	char buf[64];

	// temporarily disable unapplicable components
	tsException->TabVisible = false;
    
    btnWriteDevice->Enabled = (pTag->d.Value.Flags & TF_ReadOnly)? false : true;

	// now we update the UI to reflect the tag configuration
    /*
    0 开关量
    1 模拟量
    2 高精度模拟量
    3 8位整数
    4 16位整数
    5 32位整数
    6 64位整数
    7 无符号8位整数
    8 无符号16位整数
    9 无符号32位整数
    10 无符号64位整数
    11 日期
    */
	cmbType->OnChange = NULL;
	switch(get_value_type(pTag->s.Flags)){
	case dt_bool:
		cmbType->ItemIndex = 0;
		break;
	case dt_real4:
    	cmbType->ItemIndex = 1;
	    break;
	case dt_real8:
		cmbType->ItemIndex = 2;
		break;
    case dt_int8:
        cmbType->ItemIndex = 3;
        break;
    case dt_int16:
        cmbType->ItemIndex = 4;
        break;
    case dt_int32:
        cmbType->ItemIndex = 5;
        break;
    case dt_int64:
        cmbType->ItemIndex = 6;
        break;
    case dt_uint8:
        cmbType->ItemIndex = 7;
        break;
    case dt_uint16:
        cmbType->ItemIndex = 8;
        break;
    case dt_uint32:
        cmbType->ItemIndex = 9;
        break;
    case dt_uint64:
        cmbType->ItemIndex = 10;
        break;
	case dt_date:
    	cmbType->ItemIndex = 11;
    	break;
    default:
    	cmbType->ItemIndex = 12;
    	break;
	}
	cmbType->OnChange = cmbTypeChange;

	{
		cmbDevice->Ctl3D = false;
		CDeviceItems * ditems;
		AnsiString Url;
		Url = (char*)CNodeName(name->node);
		Url += ".DEVICES";
		ditems = dynamic_cast<CDeviceItems*>(g_DCS.Search(Url));
		if(ditems){
			if(!ditems->m_iRefreshCount){
				ditems->Refresh();
			}
		}
		cmbDevice->Items->Clear();
		cmbDevice->Text = "";
		if(ditems){
			CDeviceItem * ditem;
			ditem = dynamic_cast<CDeviceItem*>(ditems->GetFirstChild());
			while(ditem){
				cmbDevice->Items->Add((char*)CDeviceName(ditem->info.k));
				ditem = dynamic_cast<CDeviceItem*>(ditems->GetNextChild(ditem));
			}
		}
	}

	{
		PRTK_GROUP pgrp;
		RTK_CURSOR hgrp;
		hgrp = open_group_f(&name->node, &name->sname.group);
		pgrp = (PRTK_GROUP)cursor_get_item(hgrp);
		if(pgrp){
			if(pgrp->period > 50){
				tmrUpdater->Interval = pgrp->period;
			}
		}
		close_handle(hgrp);
	}

	edtTagName->Text = (char *)CTagName(name->sname.tag);
	edtCName->Text = pTag->s.Description;
	edtAddr->Text  = pTag->s.Address;
	cmbDevice->Text = (char*)CDeviceName(pTag->s.Device);
#define cc(name) \
	do{ if(pTag->s.Flags & TF_##name){\
			chk##name->Checked =  true;\
		}else{\
			chk##name->Checked = false;\
		}\
	}while(0)
	cc(HiHi);
	cc(Lo);
	cc(Hi);
	cc(LoLo);
	cc(On2Off);
	cc(Off2On);
	cc(Rate);
	cc(SaveToHistory);
    cc(Step);
/*
	// cutoff is obsolete
#define dd(name) chk##name->Checked = pTag->s.CutOffMask & TF_##name ? true : false;
	dd(HiHi);
	dd(Lo);
	dd(Hi);
	dd(LoLo);
	dd(On2Off);
	dd(Off2On);
*/
	if(pTag->s.Flags & TF_System){
		cmbDevice->Enabled = false;
		edtAddr->ReadOnly = true;
		cmbType->Enabled = false;
		cmbDevice->Color = clScrollBar;
		edtAddr->Color = clScrollBar;
		cmbType->Color = clScrollBar;
	}else{
		cmbDevice->Enabled = true;
		edtAddr->ReadOnly = false;
		cmbType->Enabled = true;
		cmbType->Color = clWindow;

		cmbDevice->Color = clWindow;
		edtAddr->Color = clWindow;
	}
	
	switch(get_value_type(pTag->s.Flags)){
	case dt_real4:
	case dt_real8:
    case dt_int64:
    case dt_uint64:
		#define aa(f) sprintf(buf, "%g", pTag->s.flt##f);edt##f->Text = buf;
		aa(HiHi);
		aa(Hi);
		aa(Lo);
		aa(LoLo);
		aa(AlarmDeadband);
		aa(MaxValue);
		aa(MinValue);
		aa(Rate);
		edtEU->Text = pTag->s.AnalogMsg.EU;
		tsAnalog->TabVisible = true;
		tsLogical->TabVisible = false;
		break;
	case dt_int8:
    case dt_int16:
	case dt_int32:
    case dt_uint8:
	case dt_uint16:
    case dt_uint32:
		aa(AlarmDeadband);
		aa(Rate);
		#undef aa
		#define aa(v, name) \
			sprintf(buf, "%d", pTag->s.v);\
			edt##name->Text = buf;
		aa(u_hihi.i, HiHi);
		aa(u_hi.i, Hi);
		aa(u_lo.i, Lo);
		aa(u_lolo.i, LoLo);
		aa(u_max.i, MaxValue);
		aa(u_min.i, MinValue);
		edtEU->Text   = pTag->s.AnalogMsg.EU;
		tsAnalog->TabVisible = true;
		tsLogical->TabVisible = false;
		break;
	case dt_date:
		tsArchive->TabVisible = true;
		tsAnalog->TabVisible = false;
		tsLogical->TabVisible = false;
		break;
	case dt_bool:
		edtOnMessage->Text = pTag->s.SwitchMsg.OnMsg;
		edtOffMessage->Text = pTag->s.SwitchMsg.OffMsg;
		tsLogical->TabVisible = true;
		tsAnalog->TabVisible = false;		
	default:
		assert(0);
		break;
	}

	tsAnalog->Visible = tsAnalog->TabVisible;
	tsLogical->Visible = tsLogical->TabVisible;
	tsException->Visible = tsException->TabVisible;
	tsArchive->Visible = tsArchive->TabVisible;
	
	edtAlarmRank->Text = pTag->s.AlarmRank;
    edtAlarmRank2->Text = pTag->s.AlarmRank;

	chkCompressing->Checked = true;
	edtCompMax->Enabled = chkCompressing->Checked;
	edtCompDev->Enabled = chkCompressing->Checked;
	edtCompDevPercent->Enabled = chkCompressing->Checked;
	edtCompMax->Text = IntToStr(pTag->s.CompMax);
	edtCompDev->Text = FloatToStr(pTag->s.CompDev);
    __r8 span = _getSpan(pTag);
    if(span > 1e-5){
		edtCompDevPercent->Text = FloatToStr(pTag->s.CompDev / span * 100);
    }

	TAG_NAME ctn;
	ZeroMemory(&ctn, sizeof(ctn));
	ctn.sname = pTag->s.CutOffTagName;
	tagname_to_text(&ctn, textname, sizeof(textname));
	
	// debugging output
	{
		char nn[128];
		*nn=0;
	#define __check_field__(field,name) \
		if(pTag->d.Value.Flags & TF_##field) {\
			if(*nn) {\
				strcat(nn,"+");\
				strcat(nn,#name);\
			}else{\
				strcpy(nn,#name);\
			}\
		}
		__check_field__(HiHi,h2)
		__check_field__(Hi,h)
		__check_field__(LoLo,l2)
		__check_field__(Lo,l)
		__check_field__(Rate,r)
		__check_field__(On2Off,off)
		__check_field__(Off2On,on)
		__check_field__(Alarm,alarm)
		__check_field__(Expired,expired)
		__check_field__(SharpChange,sharp)
		__check_field__(ReadOnly,read)
		__check_field__(Translated,trans)
		__check_field__(ConfigOk,ok)
		__check_field__(Valid,valid)
		utils_debug("%s flags=0x%08x,%s\n", textname, pTag->d.Value.Flags, nn);
	#undef __check_field__
	}

	// pg->Clear();
}
Esempio n. 20
0
__uint _on_queried_data(PCRTK_PACKET p)
{
	RTK_CURSOR	hNode, hTag, hGroup;
	RTK_TAG		*pTag;
	TAG_NAME	name;
	TAG_NAME	missing[MAX_MISSING_PERMITED];
	__uint		nMissing;
	
	QUERY_DATA_ENTRY *t;
	__uint tagcount, retcount, i;

	t = (QUERY_DATA_ENTRY *)p->data;
	tagcount = p->data_size / sizeof(*t);
	if(p->data_size % sizeof(QUERY_DATA_ENTRY)){
		return 0;
	}
	retcount = 0;
	if(!lock_rtdb(__false, 100)){
		return 0;
	}
	memset(&name, 0, sizeof(name));
	host_to_node(&p->src.host, &name.node);
	hNode = open_node(&name.node);
	hTag = hGroup = 0;
	
	if(!hNode){		
		unlock_rtdb();
		if(g_Worker){			
			g_Worker->inform_load(&name, 1);
		}
		return 0;
	}

	nMissing = 0;
	for(i=0; i<tagcount; i++){
		hGroup = open_group(hNode, &t[i].name.group);
		if(hGroup){
			hTag = open_tag_g(hGroup, &t[i].name.tag);
			if(hTag){
				pTag = (RTK_TAG*)cursor_get_item(hTag);
				pTag->d.Value = t[i].value;
				mark_fresh(pTag);
				close_handle(hTag);
				retcount++;
			}else{
				if(g_Worker){
					name.sname = t[i].name;
					missing[nMissing] = name;
					nMissing++;
				}
			}
			close_handle(hGroup);
		}else{
			if(g_Worker){
				missing[nMissing].node = name.node;
				missing[nMissing].sname.group = t[i].name.group;
				memset(&missing[nMissing].sname.tag, 0, sizeof(TAG_KEY));
				nMissing++;
			}
		}
	}
	close_handle(hNode);
	unlock_rtdb();
	if(g_Worker && nMissing){
		g_Worker->inform_load(missing, nMissing);
	}
	return retcount;
}
Esempio n. 21
0
PROXY_API __uint PMC_API update_changed_data(
	PCRTK_PACKET packet,
	__bool bThisIsAServer
	)
{
	CHANGED_DATA_ENTRY * t;
	CHANGED_DATA	* cd;
	__uint		i, nMissing;
	RTK_CURSOR	hNode, hGroup, hTag;
	TAG_NAME	name;
	PRTK_TAG	pTag;
	__uint		retcount = 0;
	TAG_NAME	missing[MAX_MISSING_PERMITED];

	if(packet->data_size <= sizeof(CHANGED_DATA)){
		return 0;
	}
	cd = (CHANGED_DATA*)packet->data;
	t = (CHANGED_DATA_ENTRY*)&cd[1];
	if(packet->data_size != cd->count * sizeof(CHANGED_DATA_ENTRY)
		+ sizeof(CHANGED_DATA)
	){
		return 0;
	}

#if 0
	for(i=0; i<cd->count; i++){
		utils_debug("%s.%s.%s=%f\n", 
			(char*)CHostName(packet->src.host),
			(char*)CGroupName(cd->group),
			(char*)CTagName(t[i].name),
			t[i].value.Value.fltValue
			);
	}
#endif

	memset(&name, 0, sizeof(name));
	host_to_node(&packet->src.host, &name.node);
	name.sname.group = cd->group;
	if(!lock_rtdb(__false, 100)){
		return 0;
	}
	if(bThisIsAServer){
		if(!(packet->src.host == g_ThisNode->key)){
			unlock_rtdb();
			return 0;
		}
		hNode = HNODE_LOCAL_MACHINE;
	}else{
		hNode = open_node(&name.node);
	}
	if(!hNode){
		unlock_rtdb();
		return 0;
	}
	hGroup = open_group(hNode, &cd->group);
	if(!hGroup){
		if(!bThisIsAServer){
			close_handle(hNode);
		}		
		unlock_rtdb();
		if(g_Worker){
			g_Worker->inform_load(&name, 1);
		}
		// 2003/5/27, in current implementation all following
		// tags are guaranteed to be in the same group, so there
		// is no need to proceed.
		return 0;
	}
	nMissing = 0;
	for(i=0; i<cd->count; i++){
		hTag = open_tag_g(hGroup, &t[i].name);
		if(hTag){
			pTag = (PRTK_TAG)cursor_get_item(hTag);
			pTag->d.Value = t[i].value;
			// pTag->d.Value.Flags = t[i].value.Flags;
			mark_fresh(pTag);
			close_handle(hTag);
			retcount++;
		}else{
			if(g_Worker && nMissing < MAX_MISSING_PERMITED){
				name.sname.tag = t[i].name;
				missing[nMissing] = name;
				nMissing++;				
			}
		}
	}
	close_handle(hGroup);
	if(!bThisIsAServer){
		close_handle(hNode);
	}
	unlock_rtdb();
	if(nMissing && g_Worker){
		if(nMissing > 16){
			memset(&missing[0].sname.tag, 0, sizeof(TAG_KEY));
			g_Worker->inform_load(missing, 1);
		}else{
			g_Worker->inform_load(missing, nMissing);
		}
	}

	return retcount;
}
Esempio n. 22
0
__uint _on_add_edit_tags(PCRTK_PACKET p, bool bGenerateEvents)
{
	ONLINE_CONFIG::reload_tags_ack *ack;
	RTK_CURSOR	hNode, hTag, hGroup;
	RTK_TAG		*pTag;
	NODE_KEY	nodekey;
	TAG_NAME	name;
	RTK_GROUP	grp;
	__bool bEditing;
	
	__uint tagcount, i;

	ack = (ONLINE_CONFIG::reload_tags_ack *)p->data;
	tagcount = p->data_size / sizeof(*ack);
	if(p->data_size % sizeof(*ack)){
		return 0;
	}
	if(!tagcount){
		return 0;
	}
	ZeroMemory(&grp, sizeof(grp));

	if((PACKET_TYPE(p) == PT_DiscoverTags) && g_Worker){
		TAG_NAME tn;
		memset(&tn, 0, sizeof(tn));
		tn.node = ack[0].tag.node;
		tn.sname.group = ack[0].tag.group;
		g_Worker->cancel_load(&tn);
	}

	if(!lock_rtdb(__true, 100)){
		return 0;
	}

	host_to_node(&p->src.host, &nodekey);
	hNode = create_node(&nodekey, 0);
	hTag = hGroup = 0;
	name.node = nodekey;
	grp.node = nodekey;
	if(hNode){
		for(i=0; i<tagcount; i++){
			hGroup = open_group(hNode, &ack[i].tag.group);
			grp.key = ack[i].tag.group;
			if(!hGroup){
				hGroup = create_group(hNode, &grp);
			}
			if(hGroup){
				bEditing = query_tag_g(hGroup, &ack[i].tag.key)? __true : __false;
				hTag = create_tag(hGroup, &ack[i].tag.key, &ack[i].tag.s);
				pTag  = (RTK_TAG*)cursor_get_item(hTag);
				if(pTag){
					*pTag = ack[i].tag;
					/*
						2003/5/27, leave tag's dynamic flags as they were
						2003/6/24, mark tag as newly received, but the valid flag
						is kept as set by server
					*/
					mark_fresh(pTag);
					close_handle(hTag);
					if(bGenerateEvents){
						name.sname.group = ack[i].tag.group;
						name.sname.tag   = ack[i].tag.key;
						rtk_queue_event(PT_AddTag, &name, &p->src);
					}
					if(bEditing){
						fire_rtdb_event(EV_ModifyTag, pTag);
					}
				}					
			}
			close_handle(hGroup);
		}
		close_handle(hNode);
	}

	unlock_rtdb();

	return tagcount;
}
Esempio n. 23
0
__uint _on_add_edit_groups(PCRTK_PACKET p, bool /* bGenerateEvents */)
{
	RTK_CURSOR hNode, hGroup;
	NODE_KEY nk;
	PRTK_GROUP png, pg=0;
	__uint count;

	if(p->data_size % sizeof(RTK_GROUP)){
		return 0;
	}
	if(!lock_rtdb(__true, 100)){
		return 0;
	}
	host_to_node(&p->src.host, &nk);
	hNode = open_node(&nk);
	if(!hNode){
		unlock_rtdb();
		return 0;
	}
	
	count = p->data_size / sizeof(RTK_GROUP);
	png = (PRTK_GROUP)p->data;
	for(__uint i=0; i<count; i++, png++){
		hGroup = open_group(hNode, &png->key);
		pg = (PRTK_GROUP)cursor_get_item(hGroup);
		if(pg){
			memcpy(
				pg->description, 
				png->description, 
				sizeof(pg->description)
				);
			pg->period = png->period;			
		}else{
			hGroup = create_group(hNode, png);
			pg = (PRTK_GROUP)cursor_get_item(hGroup);
		}
		if(pg){
			pg->d.flags = png->d.flags;
		}
		DEBUG_PRINTF((
			"Got group %s, flag=%08x\n", 
			(char *)CGroupName(png->key), 
			png->d.flags
			));
		close_handle(hGroup);
		if(pg /* && bGenerateEvents */){
			TAG_NAME name;
			name.node = nk;
			name.sname.group = png->key;
			rtk_queue_event(
				PT_AddGroup,
				&name,
				&p->src
				);
		}
	}
	close_handle(hNode);
	unlock_rtdb();

	return count;
}