videofeeds/clientapi/src/CIptvClientBase.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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 the License "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:    Base class for iptv engine client classes.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #include "MIptvStreamObject.h"
       
    21 #include "IptvDebug.h"
       
    22 
       
    23 #include "CIptvClientBase.h"
       
    24 #include "CIptvMyVideosGlobalFileId.h"
       
    25 
       
    26 const TInt KTUint16SizeInBytes( 2 );
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CIptvClientBase::CIptvClientBase()
       
    36 : CActive( EPriorityStandard )
       
    37     {
       
    38     }
       
    39 
       
    40 // Destructor
       
    41 CIptvClientBase::~CIptvClientBase()
       
    42     {
       
    43     IPTVLOGSTRING_LOW_LEVEL("CIptvClientBase::~CIptvClientBase()");
       
    44 
       
    45     iSession.Close();
       
    46     Cancel();
       
    47     IPTVLOGSTRING_LOW_LEVEL("CIptvClientBase::~CIptvClientBase() exit");
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CIptvClientBase::RunL
       
    52 // Two-phased constructor.
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CIptvClientBase::RunL()
       
    56     {
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CIptvClientBase::DoCancel
       
    61 // Two-phased constructor.
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CIptvClientBase::DoCancel()
       
    65     {
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CIptvClientBase::SendRequestL
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 TInt CIptvClientBase::SendRequestL(
       
    73     TUint16 aMsgId,
       
    74     MIptvStreamObject& aReqStreamObject,
       
    75     MIptvStreamObject& aRespStreamObject,
       
    76     TInt aIpcMsgSize )
       
    77     {
       
    78     IPTVLOGSTRING_LOW_LEVEL("CIptvClientBase::SendRequestL()");
       
    79 
       
    80     TInt size;
       
    81     HBufC8* ipcMsgInHeap = NULL;
       
    82     const TInt KMaxInStack = 100;
       
    83     TUint8 ipcMsgInStack[KMaxInStack];
       
    84     TPtr8 ipcMsgPtr((TUint8 *)0, 0, 0);
       
    85 
       
    86     if(aIpcMsgSize == 0)
       
    87         {
       
    88         size = aReqStreamObject.CountExternalizeSize();
       
    89         }
       
    90     else
       
    91         {
       
    92         size = aIpcMsgSize;
       
    93         }
       
    94 
       
    95     if(size < KMaxInStack)
       
    96         {
       
    97         IPTVLOGSTRING2_LOW_LEVEL(
       
    98             "CIptvClientBase:: size < %d -> using stack object",
       
    99             KMaxInStack);
       
   100         ipcMsgPtr.Set(
       
   101             ipcMsgInStack,
       
   102             0 /* length */,
       
   103             KMaxInStack /* max length */ );
       
   104         }
       
   105     else
       
   106         {
       
   107         IPTVLOGSTRING2_LOW_LEVEL(
       
   108             "CIptvClientBase:: size >= %d -> using heap object",
       
   109             KMaxInStack);
       
   110 
       
   111         ipcMsgInHeap = HBufC8::NewL(size);
       
   112         CleanupStack::PushL(ipcMsgInHeap); //1->
       
   113         ipcMsgPtr.Set(ipcMsgInHeap->Des());
       
   114         }
       
   115 
       
   116     RDesWriteStream writeStream;
       
   117     CleanupClosePushL( writeStream );
       
   118     //initialize stream object to use ipc msg as a data buffer
       
   119     writeStream.Open(ipcMsgPtr);
       
   120     aReqStreamObject.ExternalizeL(writeStream); //write object to the stream
       
   121     CleanupStack::PopAndDestroy( &writeStream );
       
   122 
       
   123     TInt result = iSession.SendRequest(aMsgId, ipcMsgPtr);
       
   124 
       
   125     if(result == KErrNone)
       
   126         {
       
   127         RDesReadStream readStream;
       
   128         readStream.Open(ipcMsgPtr);
       
   129         CleanupClosePushL( readStream );
       
   130         aRespStreamObject.InternalizeL(readStream); //read object from stream
       
   131         CleanupStack::PopAndDestroy( &readStream );
       
   132         }
       
   133     else
       
   134         {
       
   135         IPTVLOGSTRING2_LOW_LEVEL(
       
   136             "CIptvClientBase:: error in SendRequest: %d",
       
   137             result);
       
   138         }
       
   139 
       
   140     if(ipcMsgInHeap)
       
   141         {
       
   142         CleanupStack::PopAndDestroy(ipcMsgInHeap); //<-1
       
   143         }
       
   144 
       
   145     IPTVLOGSTRING_LOW_LEVEL("CIptvClientBase::SendRequestL() exit");
       
   146     return result;
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CIptvClientBase::SendRequestL
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 TInt CIptvClientBase::SendRequestL(
       
   154     TUint16 aMsgId,
       
   155     MIptvStreamObject& aRespStreamObject,
       
   156     TInt aIpcMsgSize )
       
   157     {
       
   158     TInt result;
       
   159     const TInt KMaxSizeInStack = 100;
       
   160 
       
   161     if(aIpcMsgSize < KMaxSizeInStack)
       
   162         {
       
   163         //use ipc msg from stack
       
   164         IPTVLOGSTRING2_LOW_LEVEL(
       
   165             "CIptvClientBase:: size < %d -> using stack object",
       
   166             KMaxSizeInStack);
       
   167         TBuf8<KMaxSizeInStack> ipcMsgInStack;
       
   168 
       
   169         result = iSession.SendRequest(aMsgId, ipcMsgInStack);
       
   170 
       
   171         if(result == KErrNone)
       
   172             {
       
   173             RDesReadStream readStream;
       
   174             readStream.Open(ipcMsgInStack);
       
   175             CleanupClosePushL( readStream );
       
   176             aRespStreamObject.InternalizeL(readStream); //read object from the stream
       
   177             CleanupStack::PopAndDestroy( &readStream );
       
   178             }
       
   179         }
       
   180     else
       
   181         {
       
   182         //allocate a new IPC message from heap
       
   183         IPTVLOGSTRING2_LOW_LEVEL(
       
   184             "CIptvClientBase:: size >= %d -> using heap object",
       
   185             KMaxSizeInStack );
       
   186 
       
   187         HBufC8* ipcMsgInHeap = HBufC8::NewL(aIpcMsgSize);
       
   188         CleanupStack::PushL(ipcMsgInHeap); // 1->
       
   189         TPtr8 ipcMsgPtr(ipcMsgInHeap->Des());
       
   190 
       
   191         result = iSession.SendRequest(aMsgId, ipcMsgPtr);
       
   192 
       
   193         if(result == KErrNone)
       
   194             {
       
   195             RDesReadStream readStream;
       
   196             readStream.Open(ipcMsgPtr);
       
   197             CleanupClosePushL( readStream );
       
   198             aRespStreamObject.InternalizeL(readStream); //read object from the stream
       
   199             CleanupStack::PopAndDestroy( &readStream );
       
   200             }
       
   201         CleanupStack::PopAndDestroy(ipcMsgInHeap); // <-1
       
   202         }
       
   203 
       
   204     return result;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CIptvClientBase::SendRequestL
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 TInt CIptvClientBase::SendRequestL(
       
   212     TUint16 aMsgId,
       
   213     MIptvStreamObject& aReqStreamObject )
       
   214     {
       
   215     HBufC8* ipcMsg = HBufC8::NewL( aReqStreamObject.CountExternalizeSize() );
       
   216     CleanupStack::PushL(ipcMsg); // 1->
       
   217 
       
   218     TPtr8 ipcMsgPtr(ipcMsg->Des());
       
   219     ipcMsgPtr.Zero();
       
   220 
       
   221     RDesWriteStream writeStream;
       
   222     writeStream.Open(ipcMsgPtr);
       
   223     CleanupClosePushL( writeStream );
       
   224     aReqStreamObject.ExternalizeL(writeStream); //write object to the stream
       
   225     CleanupStack::PopAndDestroy( &writeStream );
       
   226 
       
   227     TInt err = iSession.SendRequest(aMsgId, ipcMsgPtr);
       
   228     CleanupStack::PopAndDestroy(ipcMsg); // <-1
       
   229     return err;
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // CIptvMyVideosClient::SendRequestL
       
   234 // ---------------------------------------------------------------------------
       
   235 //
       
   236 TInt CIptvClientBase::SendRequestL(
       
   237     TInt aMessage,
       
   238     const TDesC& aMsg )
       
   239     {
       
   240     IPTVLOGSTRING_LOW_LEVEL(
       
   241         "My Videos Mgr ## CIptvMyVideosClient::SendRequestL" );
       
   242 
       
   243     TUint32 dataSize(
       
   244         KTUint16SizeInBytes + aMsg.Size() );
       
   245 
       
   246     HBufC8* ipcMsg = HBufC8::NewL( dataSize );
       
   247     CleanupStack::PushL( ipcMsg ); // 1->
       
   248 
       
   249     TPtr8 ipcMsgPtr( ipcMsg->Des() );
       
   250     ipcMsgPtr.Zero();
       
   251 
       
   252     RDesWriteStream stream;
       
   253     stream.Open( ipcMsgPtr );
       
   254     CleanupClosePushL( stream );
       
   255     CIptvUtil::WriteDesToStreamL( aMsg, stream );
       
   256     CleanupStack::PopAndDestroy( &stream );
       
   257 
       
   258     TRequestStatus status;
       
   259     iSession.SendRequest( aMessage, ipcMsgPtr, status );
       
   260     User::WaitForRequest( status );
       
   261 
       
   262     CleanupStack::PopAndDestroy( ipcMsg ); // <-1
       
   263 
       
   264     return status.Int();
       
   265     }