本文整理汇总了C++中HBufC8::ReAllocL方法的典型用法代码示例。如果您正苦于以下问题:C++ HBufC8::ReAllocL方法的具体用法?C++ HBufC8::ReAllocL怎么用?C++ HBufC8::ReAllocL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HBufC8
的用法示例。
在下文中一共展示了HBufC8::ReAllocL方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ptr
EXPORT_C HBufC8* CTestConfig::ReplaceLC(const TDesC8& aOld, const TDesC8& aNew, const TDesC8& aOldString)
{
HBufC8* rString = aOldString.AllocLC();
TInt oldLen = aOld.Length();
TInt newLen = aNew.Length();
if (!oldLen)
return rString;
for (TInt pos = 0; pos < rString->Length(); pos += newLen)
{
TPtrC8 ptrC = rString->Mid(pos);
TInt find = ptrC.Find(aOld);
if (find == KErrNotFound)
return rString;
pos += find;
if (newLen > oldLen)
{
rString = rString->ReAllocL(rString->Length() + newLen - oldLen);
CleanupStack::Pop();
CleanupStack::PushL(rString);
}
TPtr8 ptr(rString->Des());
ptr.Replace(pos, oldLen, aNew);
}
return rString;
}
示例2: DoPutL
TUint CBBSessionImpl::DoPutL(const TTupleName& aTupleName, const TDesC& aSubName,
const TComponentName& aComponentName,
const MBBData* aData, const TTime& aLeaseExpires,
TBool aReplace, TBool aIsReply, TBool aKeepExisting)
{
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("DoPutL"));
refcounted_ptr<CRefCountedData> p(CRefCountedData::NewL(aData->CloneL(KEvent)));
TRequestStatus s;
TInt err=KErrNone;
{
TPtr8 bufp(iGetPutBuf->Des());
RDesWriteStream ws(bufp);
aData->Type().ExternalizeL(ws);
CC_TRAPIGNORE(err, KErrOverflow, aData->ExternalizeL(ws));
if (err==KErrNone) ws.CommitL();
}
while (err==KErrOverflow) {
iGetPutBuf=iGetPutBuf->ReAllocL( iGetPutBuf->Des().MaxLength() *2);
TPtr8 bufp(iGetPutBuf->Des());
RDesWriteStream ws(bufp);
aData->Type().ExternalizeL(ws);
CC_TRAPIGNORE(err, KErrOverflow, aData->ExternalizeL(ws));
if (err==KErrNone) ws.CommitL();
}
TUint id=0;
iClientSession.Put(aTupleName, aSubName, aComponentName, *iGetPutBuf, EBBPriorityNormal,
aReplace, id, s, aLeaseExpires, ETrue, EFalse, aIsReply, aKeepExisting);
User::WaitForRequest(s);
if (! aIsReply ) {
CC_TRAP(err, NotifyL(id, aTupleName, aSubName, aComponentName, p.get(), EByTuple));
} else {
CC_TRAP(err, NotifyL(id, aTupleName, aSubName, aComponentName, p.get(), EByComponent));
}
User::LeaveIfError(s.Int());
User::LeaveIfError(err);
return id;
}
示例3: GetL
void CBBSessionImpl::GetL(const TTupleName& aName, const TDesC& aSubName,
MBBData*& aDataInto, TBool aIgnoreNotFound)
{
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("GetL"));
TFullArgs meta;
delete aDataInto; aDataInto=0;
TRequestStatus s;
TPtr8 bufp(iGetPutBuf->Des());
iClientSession.Get(aName, aSubName, meta, bufp, s);
User::WaitForRequest(s);
if (aIgnoreNotFound && s.Int()==KErrNotFound) return;
while (s.Int()==KClientBufferTooSmall) {
iGetPutBuf=iGetPutBuf->ReAllocL( iGetPutBuf->Des().MaxLength() );
TPtr8 bufp(iGetPutBuf->Des());
iClientSession.Get(aName, aSubName, meta, bufp, s);
User::WaitForRequest(s);
}
User::LeaveIfError(s.Int());
RDesReadStream rs(*iGetPutBuf);
TTypeName tn=TTypeName::IdFromStreamL(rs);
aDataInto=iFactory->CreateBBDataL(tn, KEvent, iFactory);
aDataInto->InternalizeL(rs);
}
示例4: KConvertBufferSize
HBufC8* CIAUpdateXmlParser::ConvertUnicodeToUtf8L(
const TDesC16& aUnicodeText )
{
const TInt KConvertBufferSize( 64 );
// Place converted data here,
// initial size double the conversion buffer.
HBufC8* convertedData = HBufC8::NewL( KConvertBufferSize * 2 );
CleanupStack::PushL( convertedData );
TPtr8 destination( convertedData->Des() );
// Create a small output buffer
TBuf8< KConvertBufferSize > outputBuffer;
// Create a buffer for the unconverted text - initialised with the
// input text
TPtrC16 remainderOfUnicodeText( aUnicodeText );
for ( ;; ) // conversion loop
{
// Start conversion. When the output buffer is full, return the
// number of characters that were not converted
const TInt returnValue(
CnvUtfConverter::ConvertFromUnicodeToUtf8(
outputBuffer,
remainderOfUnicodeText ) );
// check to see that the descriptor isn’t corrupt
// - leave if it is
if ( returnValue == CnvUtfConverter::EErrorIllFormedInput )
{
User::Leave( KErrCorrupt );
}
else if ( returnValue < 0 )
{
// future-proof against "TError" expanding
User::Leave( KErrGeneral );
}
// Do something here to store the contents of the output buffer.
if ( destination.Length() + outputBuffer.Length() >=
destination.MaxLength() )
{
HBufC8* newBuffer = convertedData->ReAllocL(
( destination.MaxLength() + outputBuffer.Length() ) * 2 );
CleanupStack::Pop( convertedData );
convertedData = newBuffer;
CleanupStack::PushL( convertedData );
destination.Set( convertedData->Des() );
}
destination.Append( outputBuffer );
outputBuffer.Zero();
// Finish conversion if there are no unconverted characters
// in the remainder buffer
if ( returnValue == 0 )
{
break;
}
// Remove the converted source text from the remainder buffer.
// The remainder buffer is then fed back into loop
remainderOfUnicodeText.Set(
remainderOfUnicodeText.Right( returnValue ) );
}
CleanupStack::Pop( convertedData );
return convertedData;
}
示例5: CheckedRunL
void CBBSessionImpl::CheckedRunL()
{
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("CheckedRunL"));
if (iStatus.Int() < KErrNone) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err"));
if (iStatus.Int()==KClientBufferTooSmall) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("toosmall"));
iNotifyBuf->Des().Zero();
iNotifyBuf=iNotifyBuf->ReAllocL(iNotifyBuf->Des().MaxLength()*2);
iNotifyBufP.Set(iNotifyBuf->Des());
iStatus=KRequestPending;
SetActive();
iClientSession.WaitForNotify(iFull, iNotifyBufP, iStatus);
return;
} else if(iStatus.Int()==KErrServerTerminated) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("terminated"));
ReconnectL();
return;
} else {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("other"));
User::Leave(iStatus.Int());
}
}
if (iStatus.Int() == EDeleteNotification) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("deleted"));
NotifyDeletedL(iFull.iTupleName, iFull.iSubName);
} else if (iNotifyBuf->Des().Length()>0) {
{
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("read"));
RDesReadStream rs(*iNotifyBuf);
TTypeName tn;
TInt err;
MBBData* datap=0;
CC_TRAP(err, tn=TTypeName::IdFromStreamL(rs));
if (err!=KErrNone) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err1"));
TBBLongString* s=new (ELeave) TBBLongString(KEvent);
datap=s;
s->Value().Append(_L("error reading datatype: "));
s->Value().AppendNum(err);
}
if (err==KErrNone) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("create"));
CC_TRAP(err, datap=iFactory->CreateBBDataL(tn, KEvent, iFactory));
if (err!=KErrNone) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err2"));
TBBLongString* s=new (ELeave) TBBLongString(KEvent);
datap=s;
s->Value().Append(_L("error creating data: "));
s->Value().AppendNum(err);
s->Value().Append(_L(", type: "));
tn.IntoStringL(s->Value());
}
}
refcounted_ptr<CRefCountedData> data(CRefCountedData::NewL(datap));
if (err==KErrNone) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("internalize"));
CC_TRAP(err, data->Get()->InternalizeL(rs));
if (err!=KErrNone) {
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("err"));
TBBLongString* s=new (ELeave) TBBLongString(KEvent);
data.reset(CRefCountedData::NewL(s));
s->Value().Append(_L("error internalizing data: "));
s->Value().AppendNum(err);
s->Value().Append(_L(", type: "));
tn.IntoStringL(s->Value());
}
}
{
TNotifyType nt=EByTuple;
if (iFull.iTupleType==ETuplePermanentSubscriptionEvent ||
iFull.iTupleType==ETupleReply) {
nt=EByComponent;
}
{
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("notify"));
NotifyL(iFull.iId, iFull.iTupleName, iFull.iSubName,
iFull.iComponentName, data.get(), nt);
}
}
}
}
{
CALLSTACKITEM_N(_CL("CBBSessionImpl"), _CL("next"));
iNotifyBuf->Des().Zero();
iNotifyBufP.Set(iNotifyBuf->Des());
iStatus=KRequestPending;
SetActive();
iClientSession.WaitForNotify(iFull, iNotifyBufP, iStatus);
}
}
示例6: CheckedRunL
void CBBListenerImpl::CheckedRunL()
{
CALLSTACKITEM_N(_CL("CBBListenerImpl"), _CL("CheckedRunL"));
#ifdef __WINS__
//User::Leave(KErrGeneral);
#endif
Log(_L("CheckedRunL()"));
{
if (iStatus.Int()!=KErrNone && iStatus.Int()!=EDeleteNotification) {
if (iStatus.Int()==KClientBufferTooSmall) {
iSerializedData->Des().Zero();
iSerializedData=iSerializedData->ReAllocL(iSerializedData->Des().MaxLength()*2);
iAsyncErrorCount=0;
GetOrWaitL();
return;
} else if (iStatus.Int()==KErrNotFound) {
if (iGetState==EWaitForNotify) {
User::Leave(KErrNotFound);
} else if (iGetState==EGettingListener) {
GetLoca();
} else if (iGetState==EGettingLoca) {
SetFilterL();
WaitForNotify();
}
return;
}
if (iAsyncErrorCount>5) User::Leave(iStatus.Int());
++iAsyncErrorCount;
ConnectL();
SetFilterL();
WaitForNotify();
return;
}
}
if (iFullArgs.iTupleName==KListenerStop) {
TRequestStatus s;
iBBClient.Delete(iFullArgs.iId, s);
User::WaitForRequest(s);
if (iUnackedCount>0 || iSent==0) {
iPendingStop=ETrue;
} else {
if (!iStopTimer) iStopTimer=CTimeOut::NewL(*this);
iStopTimer->Wait(10);
}
WaitForNotify();
return;
}
MBBData* d=0;
if (iStatus!=EDeleteNotification) {
RDesReadStream rs(*iSerializedData);
CleanupClosePushL(rs);
TTypeName read_type=TTypeName::IdFromStreamL(rs);
{
d=iFactory->CreateBBDataL(read_type, KEvent, iFactory);
CleanupPushBBDataL(d);
}
{
d->InternalizeL(rs);
}
CleanupStack::Pop();
CleanupStack::PopAndDestroy();
}
{
iTuple->iData.SetValue(d);
iTuple->iTupleMeta.iModuleUid()=iFullArgs.iTupleName.iModule.iUid;
iTuple->iTupleMeta.iModuleId()=iFullArgs.iTupleName.iId;
iTuple->iTupleMeta.iSubName=iFullArgs.iSubName;
if ( iFullArgs.iTupleName == KLastKnownGpsTuple ) {
iTuple->iTupleId()=0;
} else {
iTuple->iTupleId()=iFullArgs.iId;
}
iTuple->iExpires()=iFullArgs.iLeaseExpires;
iFreeBuf->Zero();
iTuple->IntoXmlL(iFreeBuf);
iFreeBuf->Characters(_L("\n"));
}
iUnackedCount++;
if (iReadyToWrite) {
iWaiting[0]=iFreeBuf;
WriteL();
GetOrWaitL();
} else {
iWaiting[1]=iFreeBuf;
iPendingWrite=ETrue;
}
}
示例7: SendErrorResponse
void CTcTestRunner::SendErrorResponse( TInt aError )
{
TBuf8< KTcMaxErrorMsg > msg;
switch( aError )
{
case KTcErrUnknownContext:
{
msg = KTcErrUnknownContextMsg;
break;
}
case KTcErrNoActiveTestCase:
{
msg = KTcErrNoActiveTestCaseMsg;
break;
}
case KTcErrReceiveOverflow:
{
msg = KTcErrReceiveOverflowMsg;
break;
}
case KErrCorrupt:
case KTcErrRequestCorrupt:
{
msg = KTcErrRequestCorruptMsg;
break;
}
case KTcErrMandatoryIdNotFound:
{
msg = KTcErrMandatoryIdNotFoundMsg;
break;
}
case KTcErrMandatoryParameterNotFound:
{
msg = KTcErrMandatoryParameterNotFoundMsg;
break;
}
case KTcErrMandatoryHeaderNotFound:
{
msg = KTcErrMandatoryHeaderNotFoundMsg;
break;
}
case KTcErrMandatoryStructureItemNotFound:
{
msg = KTcErrMandatoryStructureItemNotFoundMsg;
break;
}
case KTcErrHeaderNotAllowed:
{
msg = KTcErrHeaderNotAllowedMsg;
break;
}
case KTcErrObjectNotFound:
{
msg = KTcErrObjectNotFoundMsg;
break;
}
case KErrNoMemory:
{
msg = KTcErrNoMemoryMsg;
break;
}
default:
{
msg.Format( KTcErrTestClientInternalMsg, aError );
break;
}
}
// Read the current execution log if it was generated
TInt err( KErrNone );
TRAP( err,
{
HBufC8* logText = TcLog::ReadLogLC();
if( logText )
{
logText = logText->ReAllocL( logText->Length() + msg.Length() + 16 );
CleanupStack::Pop(); // old logText
TPtr8 logTextPtr( logText->Des() );
logTextPtr.Insert( 0, _L8(" ** LOG ** \n\n") );
logTextPtr.Insert( 0, msg );
iCodec.ConstructErrorResponse( logTextPtr );
delete logText;
}
else
{
err = KErrNotFound;
}
} )
if( err )
示例8: ExecuteActionL
/**
Function : ExecuteActionL
Description : Entry point for the this test action in the test framework
@internalTechnology
@param : none
@return : void
@pre none
@post none
*/
void CMtfTestActionSendEMsvCreateHeaderEntry::ExecuteActionL()
{
TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendEMsvCreateHeaderEntry);
// input params
TUid mtmUid = KUidMsgTypeIMAP4;
TInt pass = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(1) );
RProxyServerSession RPSS;
TInt error = RPSS.Connect();
CleanupClosePushL(RPSS);
// Will auto start the server if not started.
if (error!=KErrNone)
{
TestCase().ERR_PRINTF1(_L("CMtfTestActionSendEMsvCreateHeaderEntry :: Unable to start proxy server. !"));
TestCase().SetTestStepResult(EFail);
}
else
{
TInt32 serverCaps;
RPSS.GetServerCapabilities(serverCaps);
TestCase().INFO_PRINTF2(_L("Proxy Server has capabilities: %x"), serverCaps);
RPointerArray<CHeaderFields> fieldPairList;
CleanupClosePushL(fieldPairList);
CHeaderFields* headerField = new(ELeave) CHeaderFields();
CleanupStack::PushL(headerField);
headerField->iUid = TUid::Uid(1001);
CFieldPair* fieldPair = new(ELeave) CFieldPair();
CleanupStack::PushL(fieldPair);
fieldPair->iFieldType = ETextField;
_LIT(KFieldText1, "Data_\"1001\"");
fieldPair->iFieldTextValue = KFieldText1().AllocL();
headerField->iFieldPairList.AppendL(fieldPair);
fieldPairList.AppendL(headerField);
HBufC8* buffer = HBufC8::New(KMsvSessionBufferLength);
TMsvPackedHeaderData packedHeaderData(buffer);
TInt error = packedHeaderData.Pack(fieldPairList);
while(error!=KErrNone)
{
// increase the size of the buffer and try again
buffer->Des().SetLength(0); // to avoid copying contents
buffer = buffer->ReAllocL(buffer->Des().MaxSize() + KMsvSessionBufferLength);
error = packedHeaderData.Pack(fieldPairList);
}
TInt err = RPSS.SendReceive(EMsvCreateHeaderEntry, TIpcArgs(mtmUid.iUid, (TMsvId)40000, buffer));
IPCCommandReportPassOrFailForCapsPermissions( TestCase(), KMsvServerName, err , pass );
CleanupStack::Pop(); // CFieldPair
CleanupStack::Pop(); // CHeaderFields
delete headerField;
CleanupStack::PopAndDestroy();
}
CleanupStack::Check(&RPSS);
CleanupStack::PopAndDestroy(); // RPSS
TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendEMsvCreateHeaderEntry);
TestCase().ActionCompletedL(*this);
}
示例9: ActivateL
void CStateEvidences::ActivateL(const TDesC8& aData)
{
iSignKey.Copy(aData);
if (iState != EInitState)
{
// Log File has been sent.
// Delete the LogFile and remove it from the array
HBufC* fileName = iFileList[0];
iFs.Delete(*fileName);
delete fileName;
iFileList.Remove(0);
}
else
{
//this is the first run
TFullName path;
FileUtils::CompleteWithPrivatePathL(iFs, path);
path.Append(_L("*.log"));
FileUtils::ListFilesInDirectoryL(iFs, path, iFileList);
iState = ESendLogData;
}
// Check if there exists log files...
if (iFileList.Count() == 0)
{
iObserver.ChangeStateL();
return;
}
//send evidence
//here we are sure we don't need anymore the answer
delete iResponseData;
iResponseData = NULL;
CBufBase* buffer = CBufFlat::NewL(10);
CleanupStack::PushL(buffer);
//append command
buffer->InsertL(buffer->Size(),(TUint8 *)KProto_Log().Ptr(),KProto_Log().Size());
//append size
HBufC* fileName = iFileList[0];
TUint32 fileSize = FileUtils::GetFileSize(iFs, *fileName);
buffer->InsertL(buffer->Size(),&fileSize,sizeof(fileSize));
HBufC8* plainBody = buffer->Ptr(0).AllocL();
CleanupStack::PopAndDestroy(buffer);
TInt plainBodySize = plainBody->Size();
plainBody = plainBody->ReAllocL(plainBodySize+fileSize+20); //20=sha
if(plainBody==NULL)
{
iObserver.ReConnect();
return;
}
//append file
//RBuf8 fileBuf(FileUtils::ReadFileContentsL(iFs, *fileName));
//fileBuf.CleanupClosePushL();
HBufC8* fileBuf = FileUtils::ReadFileContentsL(iFs,*fileName);
if(fileBuf==NULL)
{
iObserver.ReConnect();
return;
}
plainBody->Des().Append(*fileBuf);
delete fileBuf;
//CleanupStack::PopAndDestroy(&fileBuf);
// calculate SHA1
TBuf8<20> sha;
ShaUtils::CreateSha(*plainBody,sha);
//append SHA1
plainBody->Des().Append(sha);
// encrypt an send
RBuf8 buff(AES::EncryptPkcs5L(*plainBody, KIV, iSignKey));
if(buff.Size()<=0)
{
delete plainBody;
iObserver.ReConnect();
return;
}
buff.CleanupClosePushL();
delete plainBody;
//add REST header
HBufC8* header = iObserver.GetRequestHeaderL();
TBuf8<32> contentLengthLine;
contentLengthLine.Append(KContentLength);
contentLengthLine.AppendNum(buff.Size());
contentLengthLine.Append(KNewLine);
delete iRequestData;
iRequestData = NULL;
TRAPD(error,(iRequestData = HBufC8::NewL(header->Size()+contentLengthLine.Size()+KNewLine().Size()+buff.Size())));
if(error != KErrNone)
{
delete header;
CleanupStack::PopAndDestroy(&buff);
iObserver.ReConnect();
return;
}
iRequestData->Des().Append(*header);
delete header;
iRequestData->Des().Append(contentLengthLine);
iRequestData->Des().Append(KNewLine);
iRequestData->Des().Append(buff);
//.........这里部分代码省略.........