STDMETHODIMP CPmcDB::readSnapshot(BSTR tagName, VARIANT* tagValue) { TAG_NAME tn; tagname_by_textW(&tn, tagName); PRTK_TAG p; USES_CONVERSION; #if 0 COleDateTime dt; FILETIME ft; #endif if(!lock_rtdb(__false, 500)){ return S_FALSE; } p = query_tag_f(&tn); if(!p){ tagValue->bstrVal = SysAllocString(L"N.A."); tagValue->vt = VT_BSTR; unlock_rtdb(); return S_OK; } pmc_value_to_variant(&p->d.Value, tagValue); unlock_rtdb(); return S_OK; }
STDMETHODIMP CPmcDB::unlock(void) { // TODO: 在此添加实现代码 unlock_rtdb(); return S_OK; }
__uint PMC_API _on_drop_groups(PCRTK_PACKET packet) { __uint count, i, ret=0; RTK_CURSOR hNode, hGroup; PGROUP_KEY pgk; TAG_NAME name; NODE_KEY nk; count = packet->data_size / sizeof(GROUP_KEY); if(packet->data_size % sizeof(GROUP_KEY)){ return 0; } if( !lock_rtdb(true, 100) ){ return 0; } host_to_node(&packet->src.host, &nk); name.node = nk; hNode = open_node(&nk); if(hNode){ for(i=0, pgk=(PGROUP_KEY)packet->data; i<count; i++, pgk++){ name.sname.group = *pgk; hGroup = open_group(hNode, pgk); if(hGroup){ cursor_delete(hGroup); rtk_queue_event(PT_DropGroup, &name, &packet->src); ret++; } } close_handle(hNode); } unlock_rtdb(); return ret; }
static __uint PMC_API _on_drop_groups(PCRTK_PACKET packet) { __uint count, i, ret=0; RTK_CURSOR hNode, hGroup; PGROUP_KEY pgk; TAG_NAME name; count = packet->data_size / sizeof(GROUP_KEY); if(packet->data_size % sizeof(GROUP_KEY)){ return 0; } if( !lock_rtdb(true, 100) ){ return 0; } hNode = HNODE_LOCAL_MACHINE; for(i=0, pgk=(PGROUP_KEY)packet->data; i<count; i++, pgk++){ name.sname.group = *pgk; hGroup = open_group(hNode, pgk); if(hGroup){ cursor_delete(hGroup); ret++; } } unlock_rtdb(); return ret; }
/* 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(); }
__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; }
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; }
void CMcviewDlg::doAutoPopup() { // 2004/5/30, auto-popups do{ __uint i; static bool bPopupInited; CAutoPopup::popupEntry_t * ent; if(!bPopupInited){ autoPopups.init(); bPopupInited = true; } ent = autoPopups.entries; if(!lock_rtdb(__false, 1000)){ break; } for(i=0; i<autoPopups.nEntries; i++, ent++){ // PCRTK_TAG tag; bool bPopup; tag = query_tag_f(&ent->tn); if(!tag){ continue; } if(get_value_type(tag->s.Flags) != dt_bool){ continue; } bPopup = tag->d.Value.Value.b? true : false; if(!(ent->flags & popupWhenVariableIsOn)){ bPopup = !bPopup; } if(bPopup){ if(ent->flags & popupOverlay){ theView.LoadFile(ent->associatedPicture); }else{ PopupView(ent->associatedPicture); } }else{ if((ent->flags & popupAutoHide) && !(ent->flags & popupOverlay)){ CFView * view; view = FindView(ent->associatedPicture); if(view){ view->CloseWindow(); } } } } unlock_rtdb(); }while(0); }
RTDB_API void PMC_API uninit_rtdb(void) { lock_rtdb(__true, INFINITE); RTK_CURSOR hNode; close_handle(g_hLocalNode); g_hLocalNode = 0; hNode = open_first_node(); while( !cursor_is_end(hNode) ){ cursor_delete(hNode); hNode = open_first_node(); } close_handle(hNode); unlock_rtdb(); }
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; }
RTDB_API __bool PMC_API init_rtdb(void) { NODE_KEY localkey; lock_rtdb(__true, INFINITE); //若g_hLocalNode == 0, 则建立节点"@LOCAL" if(!g_hLocalNode){ memset(&localkey, 0, sizeof(localkey)); memcpy(&localkey, NKEY_LOCAL, sizeof(localkey)); g_hLocalNode = create_node(&localkey, 0); } unlock_rtdb(); if(!g_dwMaxTags){ g_dwMaxTags = (__uint)floor(g_fltMaxTags * g_fltMaxTags); } return __true; }
bool CInMemoryBuffer::dropTagSafe(PCTAG_NAME tn) { bool ret; //utils_debug("wlock 5\n"); WriteLock(); if(!lock_rtdb(__false, 100)){ Release(); return __false; } ret = dropTag(tn); unlock_rtdb(); //utils_debug("release 10\n"); Release(); return ret; }
/* _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); } }
/* 功能:注销IOSS模块 参数:无 返回:无 */ IO_API void PMC_API uninit_ioss() { //1 锁定实时库内存 if(!lock_rtdb(__true, 1000)){ return; } //2 注销数据刷新过程--删除实时库分派结构、关闭线程、清空类CDBRefresher中的组信息列表 g_Refresher.uninit(); //3 停止所有设备,清空系统设备列表g_Devices pnp_stop_devices(); //4 解除回调项CALLBACK_ITEM unregister_power_callback(_power_callback, 0); //5 解锁实时库内存 unlock_rtdb(); }
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; } }
PROXY_API __bool PMC_API discover_nodes_ex( __uint timeout, __uint * count, __bool bDiscardOld ) { __uint i; if(count){ *count = 0; } CDiscoverNodes *eye = new CDiscoverNodes(timeout); if(!eye){ return __false; } if(!eye->WaitResult()){ return __false; } if(bDiscardOld){ // clear database if( !lock_rtdb(__true, timeout) ){ return __false; } RTK_CURSOR cursor; cursor = open_first_node(); while(cursor){ cursor_delete(cursor); cursor = open_first_node(); } for(i=0; i<eye->c_nodes; i++){ cursor = create_node(&eye->nodes[i], 0); close_handle(cursor); } unlock_rtdb(); } if(count){ *count = eye->c_nodes; } return __true; }
/* 功能:将TAG_VALUE实时值写入设备。 参数: name 待写入实时值对应的 组名.标签名 value 待写入的实时值 返回:即设备驱动导出函数write_device()的返回值 */ IO_API __bool PMC_API io_write_device( PCSHORT_TAG_NAME name, PCTAG_VALUE value ) { __bool retval = __false; //1 锁定 if(!lock_rtdb(__false, 100)){ return __false; } //2 找到本地节点中的指定标签点的RTK_TAG,其中存有该标签点对应的设备信息 PRTK_TAG p = query_tag(HNODE_LOCAL_MACHINE, name); //3 将单点单实时值写入设备 if(p && !(p->d.Value.Flags & TF_ReadOnly)){ #if 0 { char valbuf[32]; if(get_value_type(p->s.Flags) == dt_real4){ sprintf(valbuf, "%f", value->fltValue); }else{ sprintf(valbuf, "%s", value->iValue? "On" : "Off"); } utils_debug( "WriteDevice(%s.%s)=%s\n", (char *)CGroupName(name->group), (char *)CTagName(name->tag), valbuf ); } #endif //调用设备驱动导出函数,将单点单实时值写入设备 retval = _writeDevice(p, value); } //4 解锁 unlock_rtdb(); return retval; }
void CInMemoryBuffer::archive(hislog_key_t now, int color) { __uint size; hislog_stream_list::iterator it; CHislogStream * str; if(now < m_endTime){ return; } //utils_debug("wlock 6\n"); WriteLock(); m_endTime = now; if(m_state != bs_logging){ //utils_debug("release 11\n"); Release(); return; } if(!lock_rtdb(__false, 100)){ //utils_debug("release 12\n"); Release(); return; } for(size = m_streams.size(), it = m_streams.begin(); size; it++, size--){ str = it->second; // if(str->m_color == color) { it->second->putSnapshot(now, NULL, false); } } unlock_rtdb(); //utils_debug("release 13\n"); Release(); }
void CInMemoryBuffer::stopRecord(hislog_key_t now) { __uint size; hislog_stream_list::iterator it; #if 1 { DEBUG_PRINTF(( "Recording stopped on %s\n", timeAsString(now).c_str() )); } #endif //utils_debug("wlock 2\n"); WriteLock(); if(m_state != bs_logging){ //utils_debug("release 3\n"); Release(); throw(m_state); } if(!lock_rtdb(__false, 100)){ //utils_debug("release 4\n"); Release(); return; } for(size = m_streams.size(), it = m_streams.begin(); size; it++, size--){ it->second->putSnapshot(now, NULL, __true); } m_state = bs_ready; unlock_rtdb(); //utils_debug("release 5\n"); Release(); }
void PMC_API _on_drop_tags(PCRTK_PACKET packet) { __uint count, i; PTAG_NAME name; count = packet->data_size / sizeof(TAG_NAME); if(packet->data_size % sizeof(TAG_NAME)){ return; } if( !lock_rtdb(true, 100) ){ return; } for(i=0, name=(PTAG_NAME)packet->data; i<count; i++, name++){ RTK_CURSOR hTag; hTag = open_tag_f(name); if(hTag){ cursor_delete(hTag); } rtk_queue_event(PT_DropTag, name, &packet->src); } unlock_rtdb(); }
/* 功能:将pmc_value_t实时值写入设备 参数: name 待写入实时值对应的 组名.标签名 value 待写入的实时值 返回:即设备驱动导出函数write_device()的返回值 */ IO_API __bool PMC_API io_write_device_ex( PCSHORT_TAG_NAME name, PCpmc_value_t value ) { pmc_value_t value2; __bool retval = __false; if(!lock_rtdb(__false, 100)){ return __false; } PRTK_TAG p = query_tag(HNODE_LOCAL_MACHINE, name); if(p && !(p->d.Value.Flags & TF_ReadOnly)){ ZeroMemory(&value2, sizeof(value2)); set_value_type(value2.Flags, get_value_type(p->s.Flags)); if(pmc_type_cast(value, &value2)){ retval = _writeDevice(p, &value2.Value); } } unlock_rtdb(); return retval; }
PROXY_API __bool PMC_API discover_tags_ex( PCNODE_KEY node, PCGROUP_KEY group, __uint timeout, __uint * count, __bool bDiscardOld ) { RTK_CURSOR crGroup; if(count){ *count = 0; } if(bDiscardOld){ if(!lock_rtdb(__true, timeout/2)){ return __false; } crGroup = open_group_f(node, group); if(crGroup){ cursor_clear_subitems(crGroup); close_handle(crGroup); } unlock_rtdb(); } CDiscoverTags *eye; eye = new CDiscoverTags(node, group, timeout); if(!eye){ return __false; } if(!eye->WaitResult()){ return __false; } if(count){ *count = eye->c_items; } return __true; }
static void PMC_API _on_drop_tags(PCRTK_PACKET packet) { __uint count, i; PTAG_NAME name; RTK_CURSOR hNode; count = packet->data_size / sizeof(TAG_NAME); if(packet->data_size % sizeof(TAG_NAME)){ return; } if( !lock_rtdb(true, 100) ){ return; } hNode = HNODE_LOCAL_MACHINE; for(i=0, name=(PTAG_NAME)packet->data; i<count; i++, name++){ RTK_CURSOR hTag; hTag = open_tag(hNode, &name->sname); if(hTag){ cursor_delete(hTag); } } unlock_rtdb(); }
PROXY_API __bool PMC_API discover_groups_ex( PCNODE_KEY key, __uint timeout, __uint * count, __bool bDiscardOld ) { if(count){ *count = 0; } if(bDiscardOld){ // clean database if(!lock_rtdb(__true, timeout/2)){ return 0; } RTK_CURSOR crNode; crNode = open_node(key); if(crNode){ cursor_clear_subitems(crNode); close_handle(crNode); } unlock_rtdb(); } CDiscoverGroups *eye = new CDiscoverGroups(key, timeout); if(!eye){ return __false; } if(!eye->WaitResult()){ return __false; } if(count){ *count = eye->c_items; } return __true; }
__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; }
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; }
__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; }
__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; }