CVariant CKadOperation::AddCallRes(const CVariant& CallRes, CKadNode* pNode) { SOpProgress* pProgress = GetProgress(pNode); CVariant FilteredRes = CallRes.Clone(false); // Make a Shellow Copy const CVariant& Results = CallRes["RET"]; CVariant Filtered; for(uint32 i=0; i < Results.Count(); i++) { CVariant Result = Results.At(i).Clone(false); // Make a Shellow Copy const CVariant& XID = Result["XID"]; // this checks if this particular response is the last and and if this node is done if(pProgress) // might be NULL if we filter our own index response right now { SOpStatus &Status = pProgress->Calls[XID]; Status.Results++; if(!Result.Get("MORE")) Status.Done = true; // this marks that no more results are to be expected form this node } SOpStatus* pStatus = NULL; TCallOpMap::iterator I = m_CallMap.find(XID); if(I != m_CallMap.end()) { pStatus = &I->second.Status; pStatus->Results++; // count the response even if it gets filtered lateron if(!pStatus->Done) pStatus->Done = IsDone(SOpProgress::GetCalls, XID); } if(m_pOperator) { CKadOperator::TRequestMap& ResuestMap = m_pOperator->GetRequests(); CKadOperator::TRequestMap::iterator I = ResuestMap.find(XID); if(I != ResuestMap.end()) // this should not fail { SOpStatus* pAuxStatus = &I->second.Status; pAuxStatus->Results++; // count the response even if it gets filtered lateron if(!pAuxStatus->Done) pAuxStatus->Done = IsDone(SOpProgress::GetCalls, XID); } } if(!Result.Has("ERR")) { if(m_pOperator && m_pOperator->IsValid()) { try { if(m_pOperator->AddCallRes(Result["RET"], XID)) continue; // intercepted response - Note: if we add a response to this request now it wil be marked as no more results if thats so } catch(const CJSException& Exception) { LogReport(Exception.GetFlag(), Exception.GetLine(), Exception.GetError()); } } } //else // LogLine(LOG_ERROR | LOG_DEBUG, L"Got Execution Error %s", Result["ERR"].To<wstring>().c_str()); // check if this is a call we issued, that is one not present in the call map, in that case its never to be relayed if(pStatus) { // UpdateMore sets the "MORE" flag on the packet we relay further down to the source, and checks if we considder this request done if(!pStatus->Done) Result.Insert("MORE", true); else Result.Remove("MORE"); Filtered.Append(Result); } } if(m_pOperator) // add new result to the filtered list Filtered.Merge(m_pOperator->GetResponses()); FilteredRes.Insert("RET", Filtered); return FilteredRes; }