void CPacketQueue::Add(CAutoPtr<Packet> p) { CAutoLock cAutoLock(this); if(p) { m_size += p->GetDataSize(); if(p->bAppendable && !p->bDiscontinuity && !p->pmt && p->rtStart == Packet::INVALID_TIME && !IsEmpty() && GetTail()->rtStart != Packet::INVALID_TIME) { Packet* tail = GetTail(); int oldsize = tail->GetCount(); int newsize = tail->GetCount() + p->GetCount(); tail->SetCount(newsize, max(1024, newsize)); // doubles the reserved buffer size memcpy(tail->GetData() + oldsize, p->GetData(), p->GetCount()); /* GetTail()->Append(*p); // too slow */ return; } } AddTail(p); }
HRESULT CBaseSplitterFilter::DeleteOutputs() { m_rtDuration = 0; m_pRetiredOutputs.RemoveAll(); CAutoLock cAutoLockF(this); if(m_State != State_Stopped) return VFW_E_NOT_STOPPED; while(m_pOutputs.GetCount()) { CAutoPtr<CBaseSplitterOutputPin> pPin = m_pOutputs.RemoveHead(); if(IPin* pPinTo = pPin->GetConnected()) pPinTo->Disconnect(); pPin->Disconnect(); // we can't just let it be deleted now, something might have AddRefed on it (graphedit...) m_pRetiredOutputs.AddTail(pPin); } CAutoLock cAutoLockPM(&m_csPinMap); m_pPinMap.RemoveAll(); CAutoLock cAutoLockMT(&m_csmtnew); m_mtnew.RemoveAll(); RemoveAll(); ResRemoveAll(); ChapRemoveAll(); m_fontinst.UninstallFonts(); m_pSyncReader.Release(); return S_OK; }
TAG_METHOD_IMPL(CWSDLBindingParser, OnOperation) { TRACE_PARSE_ENTRY(); CWSDLBinding * pCurr = GetBinding(); if (pCurr != NULL) { CAutoPtr<CWSDLPortTypeOperation> spElem; spElem.Attach( new CWSDLPortTypeOperation ); if (spElem != NULL) { SetXMLElementInfo(spElem, pCurr, GetLocator()); CAutoPtr<CWSDLOperationParser> p( new CWSDLOperationParser(GetReader(), this, GetLevel(), spElem) ); if (p) { if (g_ParserList.AddHead(p) != NULL) { if (SUCCEEDED(p.Detach()->GetAttributes(pAttributes))) { if (pCurr->AddOperation(spElem) != NULL) { spElem.Detach(); return S_OK; } } } } } } EmitErrorHr(E_OUTOFMEMORY); return E_FAIL; }
int CEASpliterFilter::eav_get_packet( int size) { AVPacket *pkt = (AVPacket *)m_pkt; //int ret= av_new_packet(pkt, size); //if(ret<0) // return ret; pkt->pos= m_pFile->GetPos();//url_ftell(s); //ret= m_pFile->ByteRead( pkt->data, size); //get_buffer(s, pkt->data, size); //if(ret<=0) // av_free_packet(pkt); //else{ pkt->size= size; CAutoPtr<Packet> p; p.Attach(new Packet()); p->TrackNumber = pkt->stream_index; p->rtStart = pkt->pts; p->rtStop = p->rtStart + pkt->duration; p->bSyncPoint = pkt->flags; p->SetCount(size); m_pFile->ByteRead(p->GetData(), p->GetCount()); HRESULT hr = DeliverPacket(p); //} return (hr == S_OK); }
void COPCItem::getProperties(const CAtlArray<CPropertyDescription> &propsToRead, ATL::CAutoPtrArray<SPropertyValue> &propsRead){ unsigned noProperties = (DWORD)propsToRead.GetCount(); VARIANT *pValues = NULL; HRESULT *pErrors = NULL; DWORD *pPropertyIDs = new DWORD[noProperties]; for (unsigned i = 0; i < noProperties; i++){ pPropertyIDs[i] = propsToRead.GetAt(i).id; } propsRead.RemoveAll(); propsRead.SetCount(noProperties); USES_CONVERSION; HRESULT res = group.getServer().getPropertiesInterface()->GetItemProperties(T2OLE(name), noProperties, pPropertyIDs, &pValues, &pErrors); delete []pPropertyIDs; if (FAILED(res)){ throw OPCException("Failed to restrieve property values", res); } for (unsigned i = 0; i < noProperties; i++){ CAutoPtr<SPropertyValue> v; if (!FAILED(pErrors[i])){ v.Attach(new SPropertyValue(propsToRead[i], pValues[i])); } propsRead[i]=v; } COPCClient::comFree(pErrors); COPCClient::comFreeVariant(pValues, noProperties); }
STDMETHODIMP Commit(DWORD grfCommitFlags) { RETURNIFFAILED(m_spMemStream->Commit(grfCommitFlags)); if (m_bDirty) { m_bDirty=false; // Get stream size STATSTG stat; m_spMemStream->Stat(&stat, STATFLAG_NONAME); // Get stream data HGLOBAL hData; GetHGlobalFromStream(m_spMemStream, &hData); // Convert to string CUniString strData; if (hData && stat.cbSize.QuadPart) { strData=FormatBinaryData((unsigned char*)GlobalLock(hData), (size_t)stat.cbSize.QuadPart, 64); GlobalUnlock(hData); } // Save it m_pEntry->SetValue(strData); } return S_OK; };
bool CDVDSession::SendKey(DVD_KEY_TYPE KeyType, BYTE* pKeyData) { CAutoPtr<DVD_COPY_PROTECT_KEY> key; switch (KeyType) { case DvdChallengeKey: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_CHALLENGE_KEY_LENGTH]); key->KeyLength = DVD_CHALLENGE_KEY_LENGTH; Reverse(key->KeyData, pKeyData, 10); break; case DvdBusKey2: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_BUS_KEY_LENGTH]); key->KeyLength = DVD_BUS_KEY_LENGTH; Reverse(key->KeyData, pKeyData, 5); break; default: break; } if (!key) { return false; } key->SessionId = m_session; key->KeyType = KeyType; key->KeyFlags = 0; DWORD BytesReturned; return !!DeviceIoControl(m_hDrive, IOCTL_DVD_SEND_KEY, key, key->KeyLength, NULL, 0, &BytesReturned, NULL); }
CAutoPtr<Packet> CPacketQueue::Remove() { CAutoLock cAutoLock(this); ASSERT(__super::GetCount() > 0); CAutoPtr<Packet> p = RemoveHead(); if(p) m_size -= p->GetDataSize(); return p; }
void ReadTestPRES2() { unsigned long dwTotalTickCount = KLSTD::GetSysTickCount(); KLPRES_CreateEventsStorageServer( L"Test server", L"Test product", L"Test version", L"c:\\test\\jrnl\\slowdata\\events.xml", L"c:\\test\\jrnl\\slowdata\\events" ); printf( "\nPRES Server created, %d msec...", KLSTD::GetSysTickCount() - dwTotalTickCount ); //ComponentId compId( L"Test product", L"5.0.0.0", L"", L"Test instance" ); CAutoPtr<EventsStorage> pEventsStorage; KLPRES_CreateEventsStorageProxy( L"Test server", ComponentId(), ComponentId(), & pEventsStorage, true ); printf( "\nPRES Proxy created, %d msec...", KLSTD::GetSysTickCount() - dwTotalTickCount ); printf( "\nStart to iterate subscriptions..." ); pEventsStorage->ResetSubscriptionsIterator( ComponentId() ); int nSubscr = 0; int nPausedSubscr = 0; std::wstring sID; vector<wstring> vectPausedSubscr; do { CPointer<SubscriptionInfo> pSI; if (! pEventsStorage->GetNextSubscription( & pSI, sID) ) break; nSubscr++; if( pSI->bPaused ) { vectPausedSubscr.push_back( sID ); nPausedSubscr++; } printf( "\n...%ls, paused: %d", sID.c_str(), int(pSI->bPaused) ); } while(true); printf( "\nFinish, %d msec, %d subscriptions, %d paused...", KLSTD::GetSysTickCount() - dwTotalTickCount, nSubscr, nPausedSubscr ); //pEventsStorage->ResumeSubscription( vectPausedSubscr[10] ); /* for( int i = 0; i < vectPausedSubscr.size(); i++ ) { pEventsStorage->ResumeSubscription( vectPausedSubscr[i] ); pEventsStorage->PauseSubscription( vectPausedSubscr[i] ); } */ }
CAutoPtr<CMatroskaNode> CMatroskaNode::GetFirstBlock() { CAutoPtr<CMatroskaNode> pNode = Child(); do { if (pNode->m_id == 0xA0 || pNode->m_id == 0xA3) { return pNode; } } while (pNode->Next()); return CAutoPtr<CMatroskaNode>(); }
void AddValue( KLPAR::Params* pParams, KLPAR::ValuesFactory* pFactory, std::wstring& strName, std::wstring& strVal) { CAutoPtr<KLPAR::StringValue> pValue; pFactory->CreateStringValue(&pValue); pValue->SetValue(strVal.c_str()); pParams->AddValue(strName, pValue); };
void get_saveflag(Params* pParams, bool& bSaveFlag) { CAutoPtr<IntValue> pIntValue; pParams->GetValue(c_szwSyncType, (Value**)&pIntValue); KLPAR_CHKTYPE(pIntValue, INT_T, c_szwSyncType); if(pIntValue->GetValue() != 3) KLSTD_THROW(STDE_CANCELED); CAutoPtr<BoolValue> pSaveFlag; pParams->GetValue(c_szwSyncSaveFlag, (Value**)&pSaveFlag); KLPAR_CHKTYPE(pSaveFlag, BOOL_T, c_szwSyncSaveFlag); bSaveFlag=pSaveFlag->GetValue(); };
static void AddNodes(Params* pParams, ValuesFactory* pFactory, int nLevels, int nVars, int nNodes, long *pSum) { AddVars(pParams, pFactory, nVars, pSum); if(nLevels > 0){ for(int i=0; i < nNodes; ++i){ CAutoPtr<ParamsValue> pParamsValue; pFactory->CreateParamsValue(&pParamsValue); pParams->AddValue(genRandString(8), pParamsValue); if(pSum)++(*pSum); AddNodes(pParamsValue->GetValue(), pFactory, nLevels-1, nVars, nNodes, pSum); }; }; };
static void put_sections(sections_list_t& sections, Params** ppParams, bool bEOF) { KL_TMEASURE_BEGIN(L"put_sections", 4) KLPAR_CreateParams(ppParams); CAutoPtr<ValuesFactory> pFactory; KLPAR_CreateValuesFactory(&pFactory); CAutoPtr<IntValue> pIntValue; KLPAR::CreateValue(2, &pIntValue); CAutoPtr<ArrayValue> pArray; pFactory->CreateArrayValue(&pArray); (*ppParams)->AddValue(c_szwSyncType, pIntValue); (*ppParams)->AddValue(c_szwSyncSections, pArray); { CAutoPtr<BoolValue> pEOF; KLPAR::CreateValue(bEOF, &pEOF); (*ppParams)->AddValue(c_szwSyncEOF, pEOF); }; pArray->SetSize(sections.size()); int i=0; for(sections_list_t::iterator it=sections.begin(); it!=sections.end(); ++it, ++i) { section_data_t& sec=*it; CAutoPtr<Params> pTmpParams; KLPAR_CreateParams(&pTmpParams); { CAutoPtr<ParamsValue> pParamsValue; KLPAR::CreateValue(pTmpParams, &pParamsValue); pArray->SetAt(i, pParamsValue); }; CAutoPtr<StringValue> pProduct, pVersion, pSection; CAutoPtr<IntValue> pAction; CAutoPtr<ParamsValue> pContents; CAutoPtr<Params> pContentsParams; if(sec.pContents) sec.pContents->Clone(&pContentsParams);//@todo really need clone ? KLPAR::CreateValue(sec.wstrProduct.c_str(), &pProduct); KLPAR::CreateValue(sec.wstrVersion.c_str(), &pVersion); KLPAR::CreateValue(sec.wstrSection.c_str(), &pSection); KLPAR::CreateValue((long)sec.nAction, &pAction); KLPAR::CreateValue(pContentsParams, &pContents); ; pTmpParams->AddValue(c_szwSyncProduct, pProduct); pTmpParams->AddValue(c_szwSyncVersion, pVersion); pTmpParams->AddValue(c_szwSyncSection, pSection); pTmpParams->AddValue(c_szwSyncAction, pAction); pTmpParams->AddValue(c_szwSyncContents, pContents); }; KL_TMEASURE_END() };
void CSplashScreen::hide() { if (m_nDelay<=0 || m_startTime.toULong() == 0) return; long nWaitMs = howLongWaitMs(); m_startTime = CTimeInterval(); if ( nWaitMs <= 0 ) return; CAutoPtr<IRhoClassFactory> ptrFactory = createClassFactory(); CAutoPtr<IRhoThreadImpl> ptrThread = ptrFactory->createThreadImpl(); ptrThread->sleep(nWaitMs); }
HRESULT CDVBSub::ParsePage(CGolombBuffer& gb, WORD wSegLength, CAutoPtr<DVB_PAGE>& pPage) { HRESULT hr = S_OK; WORD wEnd = (WORD)gb.GetPos() + wSegLength; int nPos = 0; pPage.Attach (DNew DVB_PAGE()); pPage->PageTimeOut = gb.ReadByte(); pPage->PageVersionNumber = (BYTE)gb.BitRead(4); pPage->PageState = (BYTE)gb.BitRead(2); pPage->RegionCount = 0; gb.BitRead(2); // Reserved while (gb.GetPos() < wEnd) { if (nPos < MAX_REGIONS) { pPage->Regions[nPos].Id = gb.ReadByte(); gb.ReadByte(); // Reserved pPage->Regions[nPos].HorizAddr = gb.ReadShort(); pPage->Regions[nPos].VertAddr = gb.ReadShort(); pPage->RegionCount++; } nPos++; } return S_OK; }
void CreateTestJournal() { CAutoPtr<Journal> pJournal; KLJRNL_CreateJournal( & pJournal, true ); wstring wstrJrnlPath; //KLSTD_GetTempFile( wstrJrnlPath ); wstrJrnlPath = L"c:\\test\\jrnl\\cool.txt"; KLSTD_TRACE1(1, L"Will create test journal at \"%s\".\n", wstrJrnlPath.c_str() ); CreationInfo creationInfo; creationInfo.bLimitPages = false; creationInfo.bBinaryFormat = true; creationInfo.pageLimitType = pltRecCount; creationInfo.nMaxRecordsInPage = 10000; pJournal->Open( wstrJrnlPath, CF_OPEN_ALWAYS, ACCESS_FLAGS( AF_WRITE | AF_READ ), creationInfo ); char * szLongBuf = new char[1024]; Cool2 cool2; { for( int i = 0; i < 1024; i++ ) { #ifdef N_PLAT_NLM szLongBuf[i] = 30 + stlp_std::div( i, 30 ).rem; #else szLongBuf[i] = 30 + div( i, 30 ).rem; #endif } } szLongBuf[1023] = 0; char szBuf[100]; unsigned long dwTickCount = KLSTD::GetSysTickCount(); for( int i = 0; i < 100000; i++ ) { sprintf( szBuf, "%d", i ); memcpy( szLongBuf, szBuf, strlen(szBuf) ); cool2.str = szLongBuf; long nId = pJournal->Add( & cool2 ); pJournal->Flush(); } KLSTD_TRACE1( 1, L"Time with flush: %d msec\n", KLSTD::GetSysTickCount() - dwTickCount ); }
void CBaseSplitterFilter::SortOutputPin() { // Sorting output pin - video at the beginning of the list. CAutoPtrList<CBaseSplitterOutputPin> m_pOutputsVideo; CAutoPtrList<CBaseSplitterOutputPin> m_pOutputsOther; POSITION pos = m_pOutputs.GetHeadPosition(); while (pos) { CAutoPtr<CBaseSplitterOutputPin> pin; pin.Attach(m_pOutputs.GetNext(pos).Detach()); CMediaType mt; if (SUCCEEDED(pin->GetMediaType(0, &mt))) { if (mt.majortype == MEDIATYPE_Video) { m_pOutputsVideo.AddTail(pin); } else { m_pOutputsOther.AddTail(pin); } } } m_pOutputs.RemoveAll(); pos = m_pOutputsVideo.GetHeadPosition(); while (pos) { CAutoPtr<CBaseSplitterOutputPin> pin; pin.Attach(m_pOutputsVideo.GetNext(pos).Detach()); m_pOutputs.AddTail(pin); } pos = m_pOutputsOther.GetHeadPosition(); while (pos) { CAutoPtr<CBaseSplitterOutputPin> pin; pin.Attach(m_pOutputsOther.GetNext(pos).Detach()); m_pOutputs.AddTail(pin); } }
CSimpleType * CElement::AddSimpleType(CSimpleType * p) { CAutoPtr<CSimpleType> spOut; if (p== NULL) { spOut.Attach( new CSimpleType ); p = spOut; } if (p != NULL) { if (m_elements.AddTail(p) != NULL) { spOut.Detach(); return p; } } return NULL; }
TAG_METHOD_IMPL(CSchemaParser, OnElement) { TRACE_PARSE_ENTRY(); CSchema * pCurr = GetSchema(); if (pCurr != NULL) { CAutoPtr<CElement> spElem; spElem.Attach( new CElement ); if (spElem != NULL) { SetXSDElementInfo(spElem, pCurr, GetLocator()); spElem->SetParentSchema(pCurr); CAutoPtr<CElementParser> p( new CElementParser(GetReader(), this, GetLevel(), spElem) ); if (p != NULL) { if (g_ParserList.AddHead(p) != NULL) { if (SUCCEEDED(p.Detach()->GetAttributes(pAttributes))) { if (spElem->GetName().GetLength() != 0) { if (pCurr->AddElement(spElem) != NULL) { spElem.Detach(); return S_OK; } } EmitNamedElementError("element"); } } } } } EmitErrorHr(E_OUTOFMEMORY); return E_FAIL; }
CStreamSwitcherFilter::CStreamSwitcherFilter(LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid) : CBaseFilter(NAME("CStreamSwitcherFilter"), lpunk, &m_csState, clsid) { if(phr) *phr = S_OK; HRESULT hr = S_OK; do { CAutoPtr<CStreamSwitcherInputPin> pInput; CAutoPtr<CStreamSwitcherOutputPin> pOutput; hr = S_OK; pInput.Attach(new CStreamSwitcherInputPin(this, &hr, L"Channel 1")); if(!pInput || FAILED(hr)) break; hr = S_OK; pOutput.Attach(new CStreamSwitcherOutputPin(this, &hr)); if(!pOutput || FAILED(hr)) break; CAutoLock cAutoLock(&m_csPins); m_pInputs.AddHead(m_pInput = pInput.Detach()); m_pOutput = pOutput.Detach(); return; } while(false); if(phr) *phr = E_FAIL; }
ret_ CXMLLoaderActions::LoadEmpty(CProgram &Program, const DOMElement *pElement, const CPDUInfo *pPDU) { #ifdef _DEBUG_ if (!pElement) return (PARAMETER_NULL | PARAMETER_2); #endif // DOMElement *pSub = (DOMElement *)pElement->getFirstChild(); if (!pSub) return XML_LOADER_ERROR; CAutoPtr<CVariable> OV; while (pSub) { ret_ Ret = LoadVariable(Program.Data(), pSub, OV.Ptr(), pPDU); if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret) return Ret; if (SUCCESS == Ret) break; pSub = (DOMElement *)pSub->getNextSibling(); } COptEmpty *pOperator = new COptEmpty(OV.Ptr()); if (false_v == Program.AddOperator(pOperator)) return XML_LOADER_ERROR; return SUCCESS; }
void TestBug() { wstring wstrJrnlPath; wstrJrnlPath = L"c:\\test\\jrnl\\SRhuomilN7nkh30O8SNvs0.jrnl"; CAutoPtr<Journal> pJournal; KLJRNL_CreateJournal( & pJournal, true ); pJournal->Open( wstrJrnlPath, CF_OPEN_EXISTING, ACCESS_FLAGS( AF_WRITE | AF_READ ) ); long nId; string strData; pJournal->ResetIterator(); while( ! pJournal->IsEOF() ) { pJournal->GetCurrent( nId, strData ); pJournal->Next(); } }
void DoTest( bool bBinary ) { KLSTD_TRACE0(1, L"Obtaining journal object...\n" ); CAutoPtr<Journal> pJournal; KLJRNL_CreateJournal( & pJournal, true ); wstring wstrJrnlPath; KLSTD_GetTempFile( wstrJrnlPath ); //wstrJrnlPath = L"c:\\test\\jrnl\\cool.txt"; KLSTD_Unlink( wstrJrnlPath.c_str(), false ); KLSTD_TRACE1(1, L"Will create journal at \"%s\".\n", wstrJrnlPath.c_str() ); CreationInfo creationInfo; creationInfo.bLimitPages = false; creationInfo.bBinaryFormat = bBinary; creationInfo.pageLimitType = pltRecCount; creationInfo.nMaxRecordsInPage = 5; creationInfo.bUseRecNumIndex = true; pJournal->Open( wstrJrnlPath, CF_CREATE_ALWAYS, ACCESS_FLAGS( AF_WRITE | AF_READ ), creationInfo ); CAutoPtr<Params> pParams; KLPAR_CreateParams( & pParams ); ADD_PARAMS_VALUE( pParams, L"param0", StringValue, L"agent" ); ADD_PARAMS_VALUE( pParams, L"param1", StringValue, L"kuku01" ); ADD_PARAMS_VALUE( pParams, L"param2", BoolValue, false ); Cool cool; cool.intVal = 1; cool.charVal = 'c'; cool.wstrVal = L"Hello"; //cool.strVal = "Kuku"; for( int i = 0; i < 22; i++ ) { long nId = pJournal->Add( & cool ); } pJournal->Close(); pJournal->Open( wstrJrnlPath, CF_OPEN_EXISTING, ACCESS_FLAGS( AF_WRITE | AF_READ ), creationInfo ); AVP_longlong llSize = pJournal->GetJournalSize(); KLSTD_TRACE1( 1, L"Journal size: %d bytes\n", long(llSize) ); pJournal->Flush(); KLSTD_TRACE0( 1, L"Getting records - check MoveToRecordN...\n" ); pJournal->DeleteOlderThanID( 3 ); pJournal->Flush(); int nRecCount = pJournal->GetRecordCount(); long nTestCount = 0; pJournal->MoveToRecordN( 5 ); while( ! pJournal->IsEOF() ) { long nId; Cool cool; pJournal->GetCurrent( nId, & cool ); bool bTest = false; if( nId > 11 && nId < 15 ) { cool.strVal = "Hello guys how you doing"; pJournal->Update( & cool ); } KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool.strVal.c_str() ); nTestCount++; pJournal->Next(); } if( nTestCount != 14 ) { KLSTD_TRACE0( 1, L"Error with MoveToRecordN\n" ); KLSTD_THROW(STDE_BADFORMAT); } KLSTD_TRACE0( 1, L"Getting records - check SetIterator...\n" ); pJournal->SetIterator(3); long nId; nTestCount = 0; while( ! pJournal->IsEOF() ) { Cool cool; pJournal->GetCurrent( nId, & cool ); KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool.strVal.c_str() ); pJournal->Next(); nTestCount++; } if( nTestCount != 19 ) { KLSTD_TRACE0( 1, L"Error with SetIterator\n" ); KLSTD_THROW(STDE_BADFORMAT); } KLSTD_TRACE2( 1, L"Journal record count: %d, last id is %d\n", pJournal->GetRecordCount(), nId ); //pJournal->DeleteOlderThanID( 10 ); KLSTD_TRACE1( 1, L"Journal record count: %d\n", pJournal->GetRecordCount() ); pJournal->ResetIterator(); while( ! pJournal->IsEOF() ) { long nId; Cool2 cool2; pJournal->GetCurrent( nId, & cool2 ); KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool2.str.c_str() ); pJournal->Next(); } pair<long, long> range; vector< pair<long, long> > vectRanges; range.first = 2; range.second = 4; vectRanges.push_back( range ); range.first = 21; range.second = 7; vectRanges.push_back( range ); pJournal->DeleteRanges( vectRanges ); pJournal->Flush(); pJournal->DeleteAll(); pJournal->DeleteOlderThanID( 10 ); pJournal->CloseAndRemoveFiles(); }
static void CreateRandomValue(ValuesFactory* pFactory, Value** ppValue, long* pSum) { int x=random(1, 10); switch(x){ case 1: { CAutoPtr<StringValue> pValue; pFactory->CreateStringValue(&pValue); pValue->SetValue(genRandString(random(0, 1)).c_str()); pValue.CopyTo((StringValue**)ppValue); } break; case 2: { CAutoPtr<BoolValue> pValue; pFactory->CreateBoolValue(&pValue); pValue->SetValue(random(0, 1)!=0); pValue.CopyTo((BoolValue**)ppValue); } break; case 3: { CAutoPtr<IntValue> pValue; pFactory->CreateIntValue(&pValue); pValue->SetValue(rand()); pValue.CopyTo((IntValue**)ppValue); } break; case 4: { CAutoPtr<LongValue> pValue; pFactory->CreateLongValue(&pValue); pValue->SetValue(rand()); pValue.CopyTo((LongValue **)ppValue); } break; case 5: { CAutoPtr<DateTimeValue> pValue; pFactory->CreateDateTimeValue(&pValue); if(random(0, 1) == 0) pValue->SetValue(time_t(random(0, SHRT_MAX))); else pValue->SetValue(-1); pValue.CopyTo((DateTimeValue **)ppValue); } break; case 6: { CAutoPtr<DateValue> pValue; pFactory->CreateDateValue(&pValue); pValue->SetValue("01-01-2001"); pValue.CopyTo((DateValue **)ppValue); } break; case 7: { CAutoPtr<BinaryValue> pValue; pFactory->CreateBinaryValue(&pValue); if(random(0, 1) == 0){ const int nSize=random(0, 32); if(nSize) pValue->SetValue(memset(alloca(nSize), 0, nSize), nSize); else pValue->SetValue(NULL, 0); } else{ const int nSize=random(1, 32); void* p=malloc(nSize); pValue->SetValue(memset(p, 0, nSize), nSize, MyFreeBufferCallback, p); }; pValue.CopyTo((BinaryValue **)ppValue); } break; case 8: { CAutoPtr<FloatValue> pValue; pFactory->CreateFloatValue(&pValue); pValue->SetValue((float)random(8191)); pValue.CopyTo((FloatValue **)ppValue); } break; case 9: { CAutoPtr<DoubleValue> pValue; pFactory->CreateDoubleValue(&pValue); pValue->SetValue(random(8191)); pValue.CopyTo((DoubleValue **)ppValue); } break; case 10: { CAutoPtr<ArrayValue> pValue; pFactory->CreateArrayValue(&pValue); const int nSize=random(0, 4); pValue->SetSize(nSize); for(int i=0; i < nSize; ++i) { CAutoPtr<Value> pValue2; CreateRandomValue(pFactory, &pValue2, pSum); pValue->SetAt(i, pValue2); }; pValue.CopyTo((ArrayValue **)ppValue); } break; default: KLSTD_ASSERT(false); }; if(pSum) ++(*pSum); };
void CheckSimpleJournal() { KLSTD_TRACE0(1, L"Obtaining journal object...\n" ); CAutoPtr<Journal> pJournal; KLJRNL_CreateSimpleJournal( & pJournal, true ); wstring wstrJrnlPath; //wstrJrnlPath = L"c:\\test\\jrnl\\cool.txt"; KLSTD_GetTempFile( wstrJrnlPath ); KLSTD_Unlink( wstrJrnlPath.c_str(), false ); KLSTD_TRACE1(1, L"Will create journal at \"%s\".\n", wstrJrnlPath.c_str() ); CreationInfo creationInfo; creationInfo.bLimitPages = false; creationInfo.pageLimitType = pltSize; creationInfo.nMaxRecordsInPage = 5; creationInfo.nMaxPageSize = 1024; Cool2 cool2; pJournal->Open( wstrJrnlPath, CF_OPEN_ALWAYS, ACCESS_FLAGS( AF_READ | AF_WRITE ), creationInfo ); for( int i = 0; i < 20; i++ ) { cool2.intVal = i; pJournal->Add( & cool2 ); } AVP_longlong llSize = pJournal->GetJournalSize(); KLSTD_TRACE1( 1, L"Journal size: %d bytes\n", long(llSize) ); pJournal->Flush(); bool bFoo = false; long nTestCount = 0; nTestCount = 0; pJournal->ResetIterator(); KLSTD_TRACE0( 1, L"Getting records...\n" ); while( ! pJournal->IsEOF() ) { long nId; Cool2 cool2; pJournal->GetCurrent( nId, & cool2 ); bFoo = nId < 5; KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool2.str.c_str() ); if( bFoo ) { pJournal->DeleteCurrent(); } else { pJournal->Next(); } nTestCount++; } if( nTestCount != 20 ) { KLSTD_THROW(STDE_BADFORMAT); } nTestCount = 0; KLSTD_TRACE0( 1, L"Getting records - check MoveToRecordN...\n" ); pJournal->MoveToRecordN( 30 ); while( ! pJournal->IsEOF() ) { long nId; Cool2 cool2; pJournal->GetCurrent( nId, & cool2 ); KLSTD_TRACE2( 1, L"Id: %d, data: %S\n", nId, cool2.str.c_str() ); pJournal->Next(); nTestCount++; } pJournal->Flush(); pJournal->DeleteOlderThanID( 14 ); long nId = 0; nTestCount = 0; pJournal->ResetIterator(); while( ! pJournal->IsEOF() ) { Cool2 cool2; nTestCount++; pJournal->GetCurrent( nId, & cool2 ); pJournal->Next(); } if( ( nId != 20 ) || ( nTestCount != 6 ) ) { KLSTD_THROW(STDE_BADFORMAT); } nTestCount = 0; pJournal->SetIterator(15); while( ! pJournal->IsEOF() ) { Cool2 cool2; nTestCount++; pJournal->GetCurrent( nId, & cool2 ); pJournal->Next(); } if( ( nId != 20 ) || ( nTestCount != 6 ) ) { KLSTD_THROW(STDE_BADFORMAT); } pJournal->Flush(); nTestCount = 0; pJournal->ResetIterator(); while( ! pJournal->IsEOF() ) { Cool2 cool2; pJournal->GetCurrent( nId, & cool2 ); if( nTestCount == 5 ) { cool2.intVal = nTestCount * 100; pJournal->Update( & cool2 ); } pJournal->Next(); nTestCount++; } KLSTD_TRACE1( 1, L"Journal record count: %d\n", pJournal->GetRecordCount() ); pJournal->DeleteAll(); pJournal->DeleteOlderThanID( 10 ); //pair<long, long>() //pJournal pJournal->CloseAndRemoveFiles(); }
void DoTestsWithMyPRES() { CAutoPtr<EventsStorage> pEventsStorage; ComponentId compId( L"Test product", L"Test version", L"Test component", L"Test instance" ); if( true ) { KLPRES_CreateEventsStorageServer( L"Test server", L"Test product", L"Test version", L"c:\\test\\jrnl\\pres.pres", L"c:\\test\\jrnl\\pres" ); KLPRES_CreateEventsStorageProxy( L"Test server", ComponentId(), ComponentId(), & pEventsStorage, true ); } wstring wstrTrServerCompName; int serverUsedPort; wstring trLocalCompName; if( false ) { // получаем транспортное имя компоненты KLTRAP::ConvertComponentIdToTransportName(wstrTrServerCompName, compId); KLTR_GetTransport()->SetTimeouts(300000, 300000, 1000); // добавляем location сервера для входящих соединений ( порт location'а может быть любым ) // используется для сохранения порта KLTR_GetTransport()->AddListenLocation(wstrTrServerCompName.c_str(), L"http://127.0.0.1:17071", serverUsedPort); KLPRES_CreateEventsStorageServer( L"Test server", L"Test product", L"Test version", L"c:\\test\\jrnl\\pres.pres", L"c:\\test\\jrnl\\pres" ); KLPRCI::ComponentId cidLocalComponent( L"KLPRES_TEST_PRODUCT", L"1.0", KLSTD_CreateLocallyUniqueString().c_str(), L"1"); KLTRAP::ConvertComponentIdToTransportName(trLocalCompName, cidLocalComponent); KLTR_GetTransport()->AddClientConnection(trLocalCompName.c_str(), wstrTrServerCompName.c_str(), L"http://127.0.0.1:17071" ); KLPRES_CreateEventsStorageProxy( L"Test server", cidLocalComponent, compId, & pEventsStorage ); } if( true ) { std::wstring sID; SubscriptionInfo si; si.subscriber = compId; si.filter = compId; si.maxEvents = KLSTD_INFINITE; si.eventTypes.push_back( TEST_EVENT_TYPE_1 ); CAutoPtr<Params> parBody; KLPAR_CreateParams(&parBody); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_PATH, StringValue, L""); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_DATE1, DateTimeValue, 0); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_STATUS1, StringValue, L""); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_DATE2, DateTimeValue, 0); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_STATUS2, StringValue, L""); KLPAR_CreateParams(&si.parEventParametersMask); ADD_PARAMS_VALUE(si.parEventParametersMask, EVENT_CLASS_MASK_EVENT_TYPE, IntValue, 0); ADD_PARAMS_VALUE(si.parEventParametersMask, EVENT_CLASS_MASK_EVENT_TIME, DateTimeValue, 0); ADD_PARAMS_VALUE(si.parEventParametersMask, EVENT_CLASS_MASK_EVENT_PARAMS, ParamsValue, parBody); si.isSubscriptionPersist = true; pEventsStorage->StartSubscription(si, sID); si.eventTypes.push_back( TEST_EVENT_TYPE_2 ); pEventsStorage->UpdateSubscription(sID, si); pEventsStorage->PauseSubscription( sID ); pEventsStorage->ResumeSubscription( sID ); KLSTD_Sleep(20000); } if( false ) { pEventsStorage->ResetSubscriptionsIterator( ComponentId() ); } // /* if( false ) { std::wstring sID; int nTotalEventCount = 0; long dwTotalTickCount = KLSTD::GetSysTickCount(); do { CPointer<SubscriptionInfo> pSI; if (! pEventsStorage->GetNextSubscription( & pSI, sID) ) break; printf( "\n...Start to read subscription %S...", sID.c_str() ); unsigned long dwTickCount = KLSTD::GetSysTickCount(); long nEventCount = 0; pEventsStorage->ResetEventsIterator( sID ); bool bNextEventOk = false; do { KLPRCI::ComponentId cidPublisher; std::wstring sEventType; long eventID; CAutoPtr<Params> parEventBody; time_t timeBirth = 0; //TestTickCount ttcGetEvent( "GetEvent", 20 ); bool bEvent = pEventsStorage->GetEvent( cidPublisher, sEventType, & parEventBody, timeBirth, eventID ); if( ! bEvent ) break; bNextEventOk = pEventsStorage->NextEvent(); } while( bNextEventOk ); printf( "\n.....%d events read, tick count is %d", nEventCount, KLSTD::GetSysTickCount() - dwTickCount ); nTotalEventCount += nEventCount; } while(true); printf( "\nTotal: %d events read, tick count is %d\n", nTotalEventCount, KLSTD::GetSysTickCount() - dwTotalTickCount ); } */ pEventsStorage = NULL; KLPRES_DeleteEventsStorageServer( L"Test server" ); }
void ReadTestJournal() { CAutoPtr<Journal> pJournal; KLJRNL_CreateJournal( & pJournal, true ); KLJRNL::CreationInfo creationInfo; creationInfo.bLimitPages = false; creationInfo.pageLimitType = KLJRNL::pltRecCount; creationInfo.nMaxRecordsInPage = 10; creationInfo.bBinaryFormat = true; pJournal->ChangeLimits( L"c:\\test\\jrnl\\slowdata\\events.xml", creationInfo ); return; wstring wstrJrnlPath; //wstrJrnlPath = L"c:\\test\\jrnl\\cool.txt"; wstrJrnlPath = L"C:\\Test\\Jrnl\\pres\\kI0M1LkehpabvX6Yvo_j91.jrnl"; pJournal->Open( wstrJrnlPath, CF_OPEN_ALWAYS, ACCESS_FLAGS( AF_READ ) ); printf( "Will read test journal at \"%ls\".\n", wstrJrnlPath.c_str() ); unsigned long dwTickCount = KLSTD::GetSysTickCount(); long nId = 0, nCount = 0; pJournal->ResetIterator(); string strData; while( ! pJournal->IsEOF() ) { nCount++; pJournal->GetCurrent( nId, strData ); pJournal->Next(); } printf( "Done read test journal, last id is %d, record count is %d, tick count is %d.\n", nId, nCount, KLSTD::GetSysTickCount() - dwTickCount ); /* pJournal->MoveToRecordN( 9999 ); long nId; string strData; pJournal->GetCurrent( nId, strData ); KLSTD_TRACE3(1, L"Done MoveToRecordN, id is %d, record is %hs, tick count is %d.\n", nId, strData.c_str(), KLSTD::GetSysTickCount() - dwTickCount ); */ /* string strData; unsigned long dwTickCount = KLSTD::GetSysTickCount(); long nId; pJournal->SetIterator( 5000 ); unsigned long dwEndTickCount = KLSTD::GetSysTickCount() - dwTickCount; pJournal->GetCurrent( nId, strData ); KLSTD_TRACE3(1, L"Tick count is %d, id is %d, record is %hs.\n", KLSTD::GetSysTickCount() - dwTickCount, nId, strData.c_str() ); */ /* int n20Plus = 0; int n20 = 0; int n0 = 0; for( int i = 0; i < 100000; i++ ) { unsigned long dwTickCount = KLSTD::GetSysTickCount(); long nId; pJournal->SetIterator( i ); unsigned long dwEndTickCount = KLSTD::GetSysTickCount() - dwTickCount; if( dwEndTickCount == 0 ) { n0++; } else if( dwEndTickCount < 20 ) { n20++; } else { n20Plus++; string strData; pJournal->GetCurrent( nId, strData ); KLSTD_TRACE2(1, L"Tick count is %d, id is %d.\n", KLSTD::GetSysTickCount() - dwTickCount, nId ); } } KLSTD_TRACE3(1, L"Done set iterator. n0=%d, n20=%d, n20Plus=%d.\n", n0, n20, n20Plus ); */ /* unsigned long dwTickCount = KLSTD::GetSysTickCount(); long nId = 0, nCount = 0; pJournal->ResetIterator(); Cool2 cool2; while( ! pJournal->IsEOF() ) { nCount++; pJournal->GetCurrent( nId, & cool2 ); pJournal->Next(); } KLSTD_TRACE3(1, L"Done read test journal, last id is %d, record count is %d, tick count is %d.\n", nId, nCount, KLSTD::GetSysTickCount() - dwTickCount ); */ }
void CreateTestPRES() { unsigned long dwTickCount = KLSTD::GetSysTickCount(); KLPRES_CreateEventsStorageServer( L"Test server", L"Test product", L"Test version", L"c:\\test\\jrnl\\pres.pres", L"c:\\test\\jrnl\\pres" ); ComponentId compId( L"Test product", L"Test version", L"Test component", L"Test instance" ); { std::wstring sID; SubscriptionInfo si; si.subscriber = compId; si.filter = compId; si.maxEvents = KLSTD_INFINITE; si.eventTypes.push_back( TEST_EVENT_TYPE_2 ); si.nCloseWriteOpenedJournalTimeout = 10000; si.nStoreEventsAs = SubscriptionInfo::SI_STORE_AS_TEXT; CAutoPtr<Params> parBody; KLPAR_CreateParams(&parBody); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_PATH, StringValue, L""); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_DATE1, DateTimeValue, 0); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_STATUS1, StringValue, L""); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_DATE2, DateTimeValue, 0); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_STATUS2, StringValue, L""); KLPAR_CreateParams(&si.parEventParametersMask); ADD_PARAMS_VALUE(si.parEventParametersMask, EVENT_CLASS_MASK_EVENT_TYPE, StringValue, L""); ADD_PARAMS_VALUE(si.parEventParametersMask, EVENT_CLASS_MASK_EVENT_TIME, DateTimeValue, 0); ADD_PARAMS_VALUE(si.parEventParametersMask, EVENT_CLASS_MASK_EVENT_PARAMS, ParamsValue, parBody); si.isSubscriptionPersist = true; CAutoPtr<EventsStorage> pEventsStorage; KLPRES_CreateEventsStorageProxy( L"Test server", ComponentId(), ComponentId(), & pEventsStorage, true ); pEventsStorage->StartSubscription(si, sID); } printf( "Start publish events...\n" ); { wchar_t szwPath[1024]; for( int i = 0; i < 10000; i++) { CAutoPtr<Params> parBody; KLPAR_CreateParams(&parBody); KLSTD_SWPRINTF( szwPath, sizeof(szwPath), L"E:\\Temp\\%d.exe", i ); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_PATH, StringValue, szwPath); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_DATE1, DateTimeValue, 0); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_STATUS1, StringValue, L"OnDemandScanner_EA_StatusIdOK"); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_DATE2, DateTimeValue, time(0) ); ADD_PARAMS_VALUE(parBody, TST_EVENT_BODY_STATUS2, StringValue, L"OnDemandScanner_EV_ObjectOK"); CAutoPtr<Event> pEvent; KLEV_CreateEvent( & pEvent, compId, TEST_EVENT_TYPE_2, parBody, time(0) ); KLEV_GetEventSource()->PublishEvent( pEvent ); /* if( div( i, 100 ).rem == 0 ) { Sleep( 1000 ); } */ } } KLEV_GetEventSource()->WaitForCleanEventsQueue( L"", true ); printf( "Finished publishing events - %d ms\n", KLSTD::GetSysTickCount() - dwTickCount ); //Sleep( 10000 ); KLPRES_DeleteEventsStorageServer( L"Test server" ); }
void ReadTestPRES() { KLPRES_CreateEventsStorageServer( L"Test server", L"Test product", L"Test version", L"c:\\test\\jrnl\\pres.pres", L"c:\\test\\jrnl\\pres" ); //ComponentId compId( L"Test product", L"5.0.0.0", L"", L"Test instance" ); CAutoPtr<EventsStorage> pEventsStorage; KLPRES_CreateEventsStorageProxy( L"Test server", ComponentId(), ComponentId(), & pEventsStorage, true ); printf( "\nStart to read events..." ); unsigned long dwTotalTickCount = KLSTD::GetSysTickCount(); long nTotalEventCount = 0; pEventsStorage->ResetSubscriptionsIterator( ComponentId() ); std::wstring sID; do { CPointer<SubscriptionInfo> pSI; if (! pEventsStorage->GetNextSubscription( & pSI, sID) ) break; printf( "\n...Start to read subscription %S...", sID.c_str() ); unsigned long dwTickCount = KLSTD::GetSysTickCount(); long nEventCount = 0; pEventsStorage->ResetEventsIterator( sID ); bool bNextEventOk = false; do { KLPRCI::ComponentId cidPublisher; std::wstring sEventType; long eventID; CAutoPtr<Params> parEventBody; time_t timeBirth = 0; //TestTickCount ttcGetEvent( "GetEvent", 20 ); bool bEvent = pEventsStorage->GetEvent( cidPublisher, sEventType, & parEventBody, timeBirth, eventID ); //if( ttcGetEvent.Finish() ) { // printf( " (%ds event)", nEventCount ); } if( ! bEvent ) break; /* CAutoPtr<Params> parParamParam; GET_PARAMS_VALUE(parEventBody, EVENT_BODY_PARAM_PARAM, ParamsValue, PARAMS_T, parParamParam); std::wstring sParamText; GET_PARAMS_VALUE(parParamParam, EVENT_BODY_PARAM_PARAM_TEXT, StringValue, STRING_T, sParamText); int nTest; GET_PARAMS_VALUE(parEventBody, TST_EVENT_BODY_PATH, IntValue, INT_T, nTest); */ wstring wstrPath, wstrStatus1, wstrStatus2; time_t t1, t2; GET_PARAMS_VALUE(parEventBody, TST_EVENT_BODY_PATH, StringValue, STRING_T, wstrPath); GET_PARAMS_VALUE(parEventBody, TST_EVENT_BODY_DATE1, DateTimeValue, DATE_TIME_T, t1); GET_PARAMS_VALUE(parEventBody, TST_EVENT_BODY_STATUS1, StringValue, STRING_T, wstrStatus1); GET_PARAMS_VALUE(parEventBody, TST_EVENT_BODY_DATE2, DateTimeValue, DATE_TIME_T, t2); GET_PARAMS_VALUE(parEventBody, TST_EVENT_BODY_STATUS2, StringValue, STRING_T, wstrStatus2); char * test = ctime(&t2); nEventCount++; //TestTickCount ttcNextEvent( "NextEvent", 20 ); bNextEventOk = pEventsStorage->NextEvent(); //if( ttcNextEvent.Finish() ) { // printf( " (%ds event)", nEventCount ); } } while( bNextEventOk ); printf( "\n.....%d events read, tick count is %d", nEventCount, KLSTD::GetSysTickCount() - dwTickCount ); nTotalEventCount += nEventCount; } while(true); printf( "\nTotal: %d events read, tick count is %d\n", nTotalEventCount, KLSTD::GetSysTickCount() - dwTotalTickCount ); KLPRES_DeleteEventsStorageServer( L"Test server" ); }