// The caller must free the returned buffer. The buffer is guaranteed
// to have a zero terminator.
HBufC8* ConvToUtf8ZL(const TDesC& name16)
{
  // Note that there is no non-leaving variant of this function, such
  // that the result has no maximum size.
  // 
  // Do not know what happens if any 0 values appear in "name16"; this
  // is not documented.
  HBufC8* name8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L(name16);

  // Ensure there is a zero terminator. Quite a lot of work to do this
  // efficiently.
  TPtr8 ptr = name8->Des();
  if (ptr.Length() < ptr.MaxLength()) {
    ptr.PtrZ(); // modifies HBufC8 content
  } else {
    HBufC8* bigger8 = name8->ReAlloc(ptr.Length() + 1);
    if (bigger8) {
      name8 = bigger8; // name8 already deleted by ReAlloc
      name8->Des().PtrZ(); // modifies HBufC8 content
    } else {
      delete name8;
      User::Leave(KErrNoMemory);
    }
  }

  return name8;
}
TInt COpenMAXALTestModule::al_SetDataFormat( CStifItemParser& aItem )
    {
    TInt status(KErrNone);
    TInt type;
    TInt contType(0);
    TPtrC mimetype;
    status = aItem.GetNextInt(type);

    switch(type)
        {
        case XA_DATAFORMAT_MIME:
            {
            status = aItem.GetNextString(mimetype);
            if(!status)
                {
                status = aItem.GetNextInt(contType);
                if(!status)
                    {
                    if(m_MimeType)
                        {
                        delete m_MimeType;
                        m_MimeType = NULL;
                        }
                    m_MimeType = HBufC8::NewL(mimetype.Length()+1);
                    TPtr8 desc = m_MimeType->Des();
                    desc.Copy(mimetype);
                    m_Mime.formatType = XA_DATAFORMAT_MIME;
                    m_Mime.mimeType = (XAchar*) desc.PtrZ();
                    m_Mime.containerType = contType;
                    }
                else
                    {
                    status = KErrGeneral;
                    }
                }
            else
                {
                status = KErrGeneral;
                }
            }
            break;
        case XA_DATAFORMAT_PCM:
        case XA_DATAFORMAT_RAWIMAGE:
            break;
        default:
            status = KErrGeneral;
            break;
        }
    return status;
    }
Beispiel #3
0
TInt XAPlaySessionImpl::postConstruct()
{
    TInt retVal;
    XAresult xaRes;
    XAEngineOption engineOption[] = {     (XAuint32) XA_ENGINEOPTION_THREADSAFE,
                                          (XAuint32) XA_BOOLEAN_TRUE
                                    };
    XAEngineItf engineItf;

    mNativeDisplay.locatorType = XA_DATALOCATOR_NATIVEDISPLAY;
    mNativeDisplay.hWindow = NULL;
    mNativeDisplay.hDisplay = NULL;
    mVideoSink.pLocator = (void*)&mNativeDisplay;
    mVideoSink.pFormat = NULL;

    // Create and realize Engine object
    xaRes = xaCreateEngine (&mEOEngine, 1, engineOption, 0, NULL, NULL);
    retVal = mapError(xaRes, ETrue);
    RET_ERR_IF_ERR(retVal);
    xaRes = (*mEOEngine)->Realize(mEOEngine, XA_BOOLEAN_FALSE);
    retVal = mapError(xaRes, ETrue);
    RET_ERR_IF_ERR(retVal);

    // Create and realize Output Mix object to be used by player
    xaRes = (*mEOEngine)->GetInterface(mEOEngine, XA_IID_ENGINE, (void**) &engineItf);
    retVal = mapError(xaRes, ETrue);
    RET_ERR_IF_ERR(retVal);

    TRAP(retVal, mWAVMime = HBufC8::NewL(K8WAVMIMETYPE().Length() + 1));
    RET_ERR_IF_ERR(retVal);
    TPtr8 ptr = mWAVMime->Des();
    ptr = K8WAVMIMETYPE(); // copy uri name into local variable
    ptr.PtrZ(); // append zero terminator to end of URI

#ifdef USE_VIDEOPLAYERUTILITY
    TRAP(retVal, mVideoPlayUtil =
             CVideoPlayerUtility2::NewL( *this,
                                         EMdaPriorityNormal,
                                         EMdaPriorityPreferenceTimeAndQuality)
        );
    mActiveSchedulerWait = new CActiveSchedulerWait;
#endif

    return retVal;
}
TInt COpenMAXALTestModule::al_SetDataLocator( CStifItemParser& aItem )
    {
    TInt status(KErrNone);
    TInt type;

    status = aItem.GetNextInt(type);

    switch(type)
        {
        case XA_DATALOCATOR_URI:
            {
            TPtrC uri;
            if(m_URIName)
                {
                delete m_URIName;
                m_URIName = NULL;
                }
            //status = aItem.SetParsingType(CStifItemParser::EQuoteStyleParsing);
            status = aItem.GetNextString(uri);
            if(!status)
                {
                m_URIName = HBufC8::NewL(uri.Length()+1);
                TPtr8 desc = m_URIName->Des();
                desc.Copy(uri);
                m_Uri.locatorType = XA_DATALOCATOR_URI;
                m_Uri.URI = (XAchar*) desc.PtrZ();
                }
            else
                {
                status = KErrGeneral;
                }
            }
            break;
        case XA_DATALOCATOR_IODEVICE:
            {
            TInt devicetype;
            TUint deviceId;

            status = aItem.GetNextInt(devicetype);
            if(!status)
                {
                status = aItem.GetNextInt(deviceId);
                if(!status)
                    {
                    TInt srcsinktype(0);
                    status = aItem.GetNextInt(srcsinktype);
                    if(!status)
                        {
                        if(srcsinktype == 1)
                            {
                            m_SrcIODevice.deviceID = deviceId;
                            m_SrcIODevice.deviceType = devicetype;
                            m_SrcIODevice.locatorType = XA_DATALOCATOR_IODEVICE;
                            }
                        else
                            {
                            m_SinkIODevice.deviceID = deviceId;
                            m_SinkIODevice.deviceType = devicetype;
                            m_SinkIODevice.locatorType = XA_DATALOCATOR_IODEVICE;
                            }
                        }
                    else
                        {
                        status = KErrGeneral;
                        }
                    }
                else
                    {
                    status = KErrGeneral;
                    }
                }
            else
                {
                status = KErrGeneral;
                }
            }
            break;
        case XA_DATALOCATOR_OUTPUTMIX:
        case XA_DATALOCATOR_NATIVEDISPLAY:
        case XA_DATALOCATOR_ADDRESS:
            break;
        default:
            status = KErrGeneral;
            break;
        }
    return status;
    }
// ---------------------------------------------------------------------------
// Run state machine for backup. Each file is opened and streamed to the
// BUR engine.
// ---------------------------------------------------------------------------
//
void CAknsSrvActiveBackupDataClient::GetBackupDataSectionL(
    TPtr8& aBuffer, TBool& aFinished)
    {
    AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL" );
    // Make sure that the buffer is empty and starts from the beginning
    aBuffer.SetLength(0);

    // don't assume they set it to false
    aFinished = EFalse;
    // any files to backup
    if( iFileArray.Count() == 0 )
        {
        // nothing to backup - just return the finished flag
        aFinished = ETrue;
        // clear the list and stop.
        iFileArray.Reset();
        AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL no files" );
        return;
        }

    // run the state machine
    while( ETrue )
        {
        switch( iBackupState )
            {
            // open a file for processing
            case EBackupNoFileOpen:
                {
                AKNS_TRACE_DEBUG1("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL state %d", iBackupState );
                if( iFileIndex >= iFileArray.Count() )
                    {
                    // all files have been processed - send the finished flag
                    aFinished = ETrue;
                    // clear the list and stop.
                    iFileArray.Reset();
                    AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL all processed" );
                    return;
                    }

                // open file to send
                TInt rc=iFile.Open( iFsSession,
                                    iFileArray[iFileIndex].FullName(),
                                    ( EFileRead | EFileShareExclusive | EFileStream ) );
                if( rc != KErrNone )
                    {
                    // there's nothing we can do if we can't open the file
                    // so we just skip it
                    AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL skip file" );
                    ++iFileIndex;
                    break;
                    }
                iBackupState = EBackupOpenNothingSent;
                break;
                }
            // nothing sent (so far) for this file - send the header info
            case EBackupOpenNothingSent:
                {
                AKNS_TRACE_DEBUG1("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL state %d", iBackupState );
                TInt fileSize;
                TInt retValue = iFile.Size( fileSize );
                if( retValue != KErrNone || fileSize == 0 )
                    {
                    // empty or unreadable - skip this file
                    iBackupState = EBackupEndOfFile;
                    AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL skip file2" );
                    break;
                    }

                // build the header - this is an instance member because it
                // has to persist over multiple calls to this method
                TPtr headerPtr = iBuffer->Des();

                // get the checksum - only grab last 4 bytes - enough to be satisfied that
                // the backup and restore worked ok
                TUint64 checksum = CheckSumL( iFile ) & 0xffffffff;

                // build the header - note NOT AppendFormat(); wipes out previous content.
                // <no of files><checksum><filesize><filenamelen><filename>
                headerPtr.Format(_L("%8x%8lx%8x%8x"),
                    iFileArray.Count(),
                    checksum,
                    fileSize,
                    iFileArray[iFileIndex].FullName().Length());
                headerPtr.Append( iFileArray[iFileIndex].FullName() );

                // we need it to look like an 8bit buffer
                TPtr8 headerPtr8(
                    (TUint8*)headerPtr.Ptr(),
                    headerPtr.Size(),
                    headerPtr.Size() );

                // Check how much room is left in the buffer.
                // it starts out empty when we get it from the BUE
                TInt available = aBuffer.MaxSize() - aBuffer.Size();

                // Check is there enough room for the whole header.
                TBool enoughRoom = headerPtr8.Size() < available;

                // append the header to the buffer (only till it's full)
                aBuffer.Append(
                    headerPtr8.Ptr(),
                    enoughRoom ? headerPtr8.Size() : available) ;

                // decide what needs to happen next
                // if complete then we need data, otherwise we need to put
                // the rest of the header in the next chunk
                if( enoughRoom )
                    {
                    iBackupState = EBackupOpenAllHeaderSent;
                    }
                else
                    {
                    // we need to keep track of how much of the header has
                    // been sent so that we only send the reminder on the next
                    // iteration
                    iHeaderSent = available;
                    iBackupState = EBackupOpenPartHeaderSent;
                    }

                // if the buffer's full we need to return control to the backup engine
                // Because the finishedFlag is not set, the BUE will process this
                // chunk and then ask for another
                if( aBuffer.Size() == aBuffer.MaxSize() )
                    {
                    return;
                    }
                break;
                }
            // need to send the rest of the header
            case EBackupOpenPartHeaderSent:
                {
                AKNS_TRACE_DEBUG1("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL state %d", iBackupState );
                // get back the header - this is already loaded with the necessary info
                // from the previous state we were in
                TPtr headerPtr = iBuffer->Des();

                // we need it to look like an 8bit buffer
                TPtr8 headerPtr8(
                    (TUint8*)headerPtr.Ptr(),
                    headerPtr.Size(),
                    headerPtr.Size() );

                // Check how many bytes have we yet to send.
                TInt bytesRemaining = headerPtr.Size() - iHeaderSent;

                // Check how much room in the buffer.
                TInt available = aBuffer.MaxSize() - aBuffer.Size();

                // enough, if not send as much as we can
                TBool enoughRoom = bytesRemaining < available;
                aBuffer.Append(
                    headerPtr8.Ptr() + iHeaderSent,
                    enoughRoom ? bytesRemaining : available );

                if( enoughRoom )
                    {
                    iHeaderSent = 0; // ready for next header
                    iBackupState = EBackupOpenAllHeaderSent;
                    }
                else
                    {
                    iHeaderSent += available; // ready to do round again
                    // state remains as EBackupOpenPartHeaderSent
                    }

                // if the buffer's full we need to return control to the backup engine
                // Because the finishedFlag is not set, the BUE will process this
                // chunk and then ask for another
                if( aBuffer.Size() == aBuffer.MaxSize() )
                    {
                    return;
                    }
                break;
                }
            // need to send some data
            case EBackupOpenAllHeaderSent:
                {
                AKNS_TRACE_DEBUG1("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL state %d", iBackupState );
                // how many bytes can we send
                TInt available = aBuffer.MaxSize() - aBuffer.Size();

                // create a buffer for this data (plus one for PtrZ)
                HBufC8* transferBuffer = HBufC8::NewLC( available + 1 );
                TPtr8 bufferToSend = transferBuffer->Des();

                // get the data
                User::LeaveIfError( iFile.Read( bufferToSend, available ) );

                // Check how much did we actually read.
                TInt bytesRead = bufferToSend.Size();

                // EOF
                if( bytesRead == 0 )
                    {
                    CleanupStack::PopAndDestroy( transferBuffer );
                    iBackupState = EBackupEndOfFile;
                    break;
                    }

                // add it to the aBuffer
                aBuffer.Append( bufferToSend.PtrZ(), bytesRead );

                // tidy up
                CleanupStack::PopAndDestroy( transferBuffer );

                // if the buffer's full we need to return control to the backup engine
                if( aBuffer.Size() == aBuffer.MaxSize() )
                    {
                    return;
                    }
                break;
                }
            // At the end of the current file.
            case EBackupEndOfFile:
                {
                AKNS_TRACE_DEBUG1("CAknsSrvActiveBackupDataClient::GetBackupDataSectionL state %d", iBackupState );

                // how many bytes can we send
                if ( aBuffer.Size() != 0 )
                    {
                    TInt available = aBuffer.MaxSize() - aBuffer.Size();
                    // pad the end of the buffer with NULL.
                    HBufC8* transferBuffer = HBufC8::NewLC( available + 1 );
                    TPtr8 bufferToSend = transferBuffer->Des();
                    bufferToSend.FillZ();
                    aBuffer.Append( bufferToSend.PtrZ(), available );
                    CleanupStack::PopAndDestroy( transferBuffer );
                    if( aBuffer.Size() != aBuffer.MaxSize() )
                        {
                        // Sanity check
                        User::Leave( KErrGeneral );
                        }
                    }
                // Close file and move on to next file.
                iFile.Close();
                ++iFileIndex;
                // Start all over again.
                iBackupState = EBackupNoFileOpen;
                break;
                }
            default:
                {
                // not reachable
                return;
                }
            }
        }
    }
Beispiel #6
0
SYSCALL(MAHandle, maOpenStore(const char* name, int flags))
{
    const char* path;
    int len;
#ifdef _WIN32_WCE
    char temp[256];
    TCHAR wtemp[256];
    getWorkingDirectory(temp, 256);
    strcat(temp, "\\");
    strcat(temp, STORE_PATH);
    convertAsciiToUnicode(wtemp, 256, temp);
    CreateDirectory(wtemp, NULL);
#elif defined(SYMBIAN)
    MyRFs myrfs;
    myrfs.Connect();
#ifdef DEBUGGING_MODE
    int res =
#endif
        FSS.MkDir(KMAStorePath16);
    LOGD("MkDir %i\n", res);
#elif defined(__IPHONE__)
#else
    _mkdir(STORE_PATH);
#endif	//_WIN32_WCE

#ifdef SYMBIAN
    TPtrC8 nameDesC(CBP name);
    TCleaner<HBufC8> hbuf(HBufC8::NewLC(KMAStorePath8().Length() + nameDesC.Length() + 1));
    TPtr8 des = hbuf->Des();
    des.Append(KMAStorePath8);
    des.Append(nameDesC);
    path = CCP des.PtrZ();
    len = des.Length();
#elif defined(__IPHONE__)
    std::string newPath = getWriteablePath(STORE_PATH);
    std::string newFile =  newPath + "/" + std::string(name);
    path = newFile.c_str();
    len = newFile.length();
    _mkdir(newPath.c_str());
#else
    std::string newPath = STORE_PATH + std::string(name);
    path = newPath.c_str();
    len = newPath.length();
#endif

    FileStream readFile(path);
    if(!readFile.isOpen())
    {
        if(flags & MAS_CREATE_IF_NECESSARY)
        {
            WriteFileStream writeFile(path);
            if(!writeFile.isOpen())
                return STERR_GENERIC;
        }
        else
        {
            return STERR_NONEXISTENT;
        }
    }

    SYSCALL_THIS->gStores.insert(SYSCALL_THIS->gStoreNextId, path, len);
    return SYSCALL_THIS->gStoreNextId++;
}