mmfenh/enhancedmediaclient/Client/src/Components/ClientFileSource/ClientFileSource.cpp
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Definition of the ClientFileSource class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <MCustomCommand.h>
       
    20 #include <SourceControlObserver.h>
       
    21 #include "ClientFileSource.h"
       
    22 #include "EventNotifier.h"
       
    23 #include "ErrorCode.h"
       
    24 
       
    25 
       
    26 #define RETURN_IF_ERROR(x) if(x != KErrNone) return x
       
    27 
       
    28 using namespace multimedia;
       
    29 
       
    30 CClientFileSource::CClientFileSource()
       
    31 :iMimeType(NULL),
       
    32 iFileName(NULL)
       
    33     {
       
    34     // No Impl
       
    35     }
       
    36 
       
    37 CClientFileSource::~CClientFileSource()
       
    38     {
       
    39     delete iMimeType;
       
    40     delete iFileName;
       
    41     delete iAsyncEventAO;
       
    42     delete iEventNotifier;
       
    43     }
       
    44 
       
    45 TInt CClientFileSource::PostConstructor()
       
    46     {
       
    47     TInt status(KErrNone);
       
    48     TRAP(status, iAsyncEventAO = CAsyncAO::NewL(*this));
       
    49     RETURN_IF_ERROR( status );
       
    50     
       
    51     if ( !iEventNotifier )
       
    52         {
       
    53         TRAP(status, iEventNotifier = CEventNotifier::NewL());
       
    54         }
       
    55 
       
    56     return status;
       
    57     }
       
    58 
       
    59 // From MControl begins
       
    60 TInt CClientFileSource::AddObserver( MControlObserver& aObserver )
       
    61     {
       
    62     return iEventNotifier->AddObserver( aObserver );
       
    63     }
       
    64 
       
    65 TInt CClientFileSource::RemoveObserver( MControlObserver& aObserver )
       
    66     {
       
    67     return iEventNotifier->RemoveObserver( aObserver );
       
    68     }
       
    69 
       
    70 TUid CClientFileSource::Type()
       
    71     {
       
    72     return KFileSourceControl;
       
    73     }
       
    74 
       
    75 TControlType CClientFileSource::ControlType()
       
    76     {
       
    77     return ESourceControl;
       
    78     }
       
    79 // From MControl ends
       
    80 
       
    81 // From MSourceControl begins
       
    82 TInt CClientFileSource::GetSize( TUint& aSize )
       
    83     {
       
    84     TInt status(KErrUnknown);
       
    85     
       
    86     if(iServerSourceExists)
       
    87         {
       
    88         if(!iFileSize)
       
    89             {
       
    90             iEventPckg().iType = EFileSize;
       
    91             iCustomCommand->CustomCommandSync( iSourceHandle, EGetFileSourceEvent, iEventPckg, KNullDesC8, iEventPckg );
       
    92             aSize = iFileSize = iEventPckg().iFileSize;
       
    93             status = KErrNone;
       
    94             }
       
    95         else
       
    96             {
       
    97             aSize = iFileSize;
       
    98             status = KErrNone;    
       
    99             }
       
   100         }
       
   101      else
       
   102         {
       
   103         aSize = 0;
       
   104         status = KErrUnknown;
       
   105         }   
       
   106     
       
   107     return status;
       
   108     }
       
   109 
       
   110 TInt CClientFileSource::GetMimeType( TDes8& aMimeType )
       
   111     {
       
   112     TInt status(KErrUnknown);
       
   113     if ( iMimeType )
       
   114         {
       
   115         aMimeType.Copy(*iMimeType);
       
   116         status = KErrNone;
       
   117         }
       
   118     return status;
       
   119     }
       
   120 
       
   121 TInt CClientFileSource::Close()
       
   122     {
       
   123     delete iMimeType;
       
   124     iMimeType = NULL;
       
   125     delete iFileName;
       
   126     iFileName = NULL;
       
   127     iBitRate = 0;
       
   128     iFileSize = 0;
       
   129     return KErrNone;
       
   130     }
       
   131 
       
   132 // From MSourceControl ends
       
   133 
       
   134 // From MFileSource begins
       
   135 TInt CClientFileSource::Open( TDesC& aFileName, TDesC8& aMimeType  )
       
   136     {
       
   137     TInt status(KErrAlreadyExists);
       
   138     Close();
       
   139     if ( aFileName.Ptr() != NULL )
       
   140         {
       
   141         if(aMimeType.Size())
       
   142             {
       
   143             TRAP( status, iMimeType = aMimeType.AllocL() );
       
   144             RETURN_IF_ERROR( status );
       
   145             }
       
   146         
       
   147         TRAPD(status,iFileName = HBufC::NewL(aFileName.Size()));
       
   148         
       
   149         if(!status)
       
   150             {
       
   151             TPtr des = iFileName->Des();
       
   152             des.Copy(aFileName);
       
   153             }
       
   154         else
       
   155             return status;   
       
   156 
       
   157         }
       
   158     return status;
       
   159     }
       
   160 
       
   161 TInt CClientFileSource::GetBitRate( TUint& aRate )
       
   162     {
       
   163     TInt status(KErrNone);
       
   164     
       
   165     if(iServerSourceExists)
       
   166         {
       
   167         if(!iBitRate)
       
   168             {
       
   169             iEventPckg().iType = EFileBitRateChanged;
       
   170             iCustomCommand->CustomCommandSync( iSourceHandle, EGetFileSourceEvent, iEventPckg, KNullDesC8, iEventPckg );
       
   171             aRate = iBitRate = iEventPckg().iBitRate;
       
   172             status = KErrNone;
       
   173             }
       
   174         else
       
   175             {
       
   176             aRate = iBitRate;
       
   177             status = KErrNone;    
       
   178             }
       
   179         }
       
   180      else
       
   181         {
       
   182         aRate = 0;
       
   183         status = KErrUnknown;
       
   184         }   
       
   185     
       
   186     return status;
       
   187     }
       
   188 
       
   189 TInt CClientFileSource::GetFileName(TPtr& aFileName)
       
   190     {
       
   191     TInt status(KErrNone);
       
   192     aFileName.Set(iFileName->Des());
       
   193     return status;
       
   194     }
       
   195 
       
   196 // From MFileSource ends
       
   197 
       
   198 // From CSourceBase begins
       
   199 void CClientFileSource::ServerSourceCreated( MCustomCommand& aCustomCommand,
       
   200                             TMMFMessageDestination& aSourceHandle )
       
   201     {
       
   202     iServerSourceExists = ETrue;
       
   203     iCustomCommand = &aCustomCommand;
       
   204     iSourceHandle = aSourceHandle;
       
   205 
       
   206     
       
   207 
       
   208     
       
   209     // Subcribe for source event notifications
       
   210     iEventPckg().iType = EFileSourceStateChanged;
       
   211     iAsyncEventAO->SetActive();
       
   212     iCustomCommand->CustomCommandAsync( iSourceHandle,
       
   213                                         EGetFileSourceEvent,
       
   214                                         iEventPckg,
       
   215                                         KNullDesC8,
       
   216                                         iEventPckg,
       
   217                                         iAsyncEventAO->iStatus );
       
   218     }
       
   219 
       
   220 void CClientFileSource::ServerSourceDeleted()
       
   221     {
       
   222     iServerSourceExists = EFalse;
       
   223     iCustomCommand = NULL;
       
   224     }
       
   225 
       
   226 TBool CClientFileSource::IsEncrypted()
       
   227     {
       
   228     return EFalse;
       
   229     }
       
   230 
       
   231 TUid CClientFileSource::GetSourceUid()
       
   232     {
       
   233     return KFileDataSourcePlugin;
       
   234     }
       
   235 
       
   236 TInt CClientFileSource::GetHeaderData( TPtr& /*aPtr*/ )
       
   237     {
       
   238     return KErrNotSupported;
       
   239     }
       
   240 
       
   241 // From CSourceBase ends
       
   242 
       
   243 // From MAsyncAOObserver begins
       
   244 void CClientFileSource::Event( TInt aError )
       
   245     {
       
   246     if ( aError == KErrNone )
       
   247         {
       
   248 #ifdef _DEBUG
       
   249         RDebug::Print(_L("CClientFileSource::Event() Client State[%d] Type[%d]"), iEventPckg().iState, iEventPckg().iType);
       
   250 #endif        
       
   251         switch (iEventPckg().iType)
       
   252             {
       
   253             case EFileBitRateChanged:
       
   254                 DoBitRateChanged(iEventPckg().iBitRate);                
       
   255                 break;
       
   256             case EFileSourceStateChanged:
       
   257                 iState = iEventPckg().iState;
       
   258                 break;
       
   259 
       
   260             default:
       
   261                 break;
       
   262             };
       
   263         }
       
   264 
       
   265     // Subcribe for more source event notifications
       
   266     iEventPckg().iState = iState;
       
   267     
       
   268     if(iServerSourceExists)
       
   269         {
       
   270         iAsyncEventAO->SetActive();
       
   271         iCustomCommand->CustomCommandAsync( iSourceHandle,
       
   272                                             EGetFileSourceEvent,
       
   273                                             iEventPckg,
       
   274                                             KNullDesC8,
       
   275                                             iEventPckg,
       
   276                                             iAsyncEventAO->iStatus );
       
   277         }
       
   278     }
       
   279 
       
   280 // From MAsyncAOObserver ends
       
   281 
       
   282 void CClientFileSource::DoBitRateChanged( TUint aBitRate )
       
   283     {
       
   284     iBitRate = aBitRate;
       
   285     CErrorCode* event1 = new CErrorCode( KErrNone );       
       
   286     iEventNotifier->Event(this,MSourceControlObserver::KBitRateChangedEvent,event1);
       
   287     }
       
   288 
       
   289 // End of file