videofeeds/server/IptvEpgManager/src/CIptvEpgVodMsqQueue.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2004-2005 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include <s32mem.h>
       
    24 #include "IptvDebug.h"
       
    25 #include "CIptvTimer.h"
       
    26 
       
    27 #include "MIptvVodContentClientObserver.h"
       
    28 #include "IptvClientServerCommon.h"
       
    29 #include "CIptvEpgVodMsqQueue.h"
       
    30 
       
    31 // CONSTANTS
       
    32 const TInt KIptvMaxTries = 600;
       
    33 const TInt KIptvVodMsgQueueTimerInterval = 100000;
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CIptvEpgVodMsqQueue::ConstructL
       
    39 // Symbian 2nd phase constructor can leave.
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 void CIptvEpgVodMsqQueue::ConstructL()
       
    43     {       
       
    44     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::ConstructL");               
       
    45 
       
    46     iTimer = CIptvTimer::NewL(CActive::EPriorityUserInput, *this);    
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // CIptvEpgVodMsqQueue::NewL
       
    51 // Two-phased constructor.
       
    52 // Create instance of concrete interface implementation
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 CIptvEpgVodMsqQueue* CIptvEpgVodMsqQueue::NewL()
       
    56     {
       
    57     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::NewL");  
       
    58 
       
    59     CIptvEpgVodMsqQueue* self = new(ELeave) CIptvEpgVodMsqQueue();
       
    60     CleanupStack::PushL(self);
       
    61 
       
    62     self->ConstructL();
       
    63 
       
    64     CleanupStack::Pop(self);
       
    65     return self;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CIptvEpgVodMsqQueue::~CIptvEpgVodMsqQueue
       
    70 // Destructor
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 CIptvEpgVodMsqQueue::~CIptvEpgVodMsqQueue()
       
    74     {	
       
    75     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::~CIptvEpgVodMsqQueue");            
       
    76 
       
    77     iMsgQueue.Close();
       
    78     CancelRequest();
       
    79 
       
    80     if (iTimer)
       
    81         {
       
    82         iTimer->Cancel();
       
    83         delete iTimer;
       
    84         iTimer = NULL;
       
    85         }            
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CIptvEpgVodMsqQueue::CIptvEpgVodMsqQueue
       
    90 // C++ default constructor
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 CIptvEpgVodMsqQueue::CIptvEpgVodMsqQueue() :
       
    94     iRequestPending( EFalse ),
       
    95     iTimer ( NULL ),
       
    96     iCounter( 0 )
       
    97     {
       
    98     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::CIptvEpgVodMsqQueue");
       
    99     }
       
   100   
       
   101 // ------------------------------------------------------------------
       
   102 // CIptvEpgVodMsqQueue::SendMessageToClientL
       
   103 // ------------------------------------------------------------------
       
   104 //
       
   105 void CIptvEpgVodMsqQueue::SendMessageToClientL(TInt aMsg, TInt aInfo)
       
   106     {
       
   107     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::SendMessageToClientL");
       
   108     
       
   109     if (!iRequestPending)
       
   110         {            
       
   111         TIptvEpgVodMsg msg;        
       
   112         msg.iValue = aMsg;
       
   113         msg.iInfo = aInfo;
       
   114 
       
   115         iMsgQueue.AppendL(msg);
       
   116         SetTimer();
       
   117         }
       
   118     else
       
   119         {
       
   120         TIptvEpgVodMsg msg;        
       
   121         msg.iValue = aMsg;
       
   122         msg.iInfo = aInfo;
       
   123 
       
   124         SendMessageL(msg);
       
   125         }                
       
   126     }
       
   127 
       
   128 // ------------------------------------------------------------------
       
   129 // CIptvEpgVodMsqQueue::SetTimer
       
   130 // ------------------------------------------------------------------
       
   131 //
       
   132 void CIptvEpgVodMsqQueue::SetTimer()
       
   133     {
       
   134     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::SetTimer");    			
       
   135 
       
   136     if (!iTimer->IsActive())        
       
   137         {
       
   138         iTimer->After(KIptvVodMsgQueueTimerInterval);
       
   139         }
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CIptvEpgVodMsqQueue::TimerExpired
       
   144 // 
       
   145 // ---------------------------------------------------------
       
   146 //
       
   147 void CIptvEpgVodMsqQueue::TimerExpired(CIptvTimer* /*aTimer*/)
       
   148     {
       
   149     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::TimerExpired");    			
       
   150 
       
   151     TInt count = iMsgQueue.Count();
       
   152     IPTVLOGSTRING2_LOW_LEVEL("CIptvEpgVodMsqQueue::TimerExpired --- Items in message queue %d", count);
       
   153 
       
   154     if (iRequestPending)
       
   155         {        
       
   156         if (count > 0)
       
   157             {
       
   158             TIptvEpgVodMsg msg = iMsgQueue[0];
       
   159             TRAPD(err, SendMessageL(msg));
       
   160             if (err != KErrNone)
       
   161                 {
       
   162                 IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::TimerExpired SendMessageL failed");    			
       
   163                 }
       
   164 
       
   165             iCounter = 0;
       
   166             iMsgQueue.Remove(0);
       
   167             SetTimer();
       
   168             }
       
   169         }
       
   170     else
       
   171         {
       
   172         if (count > 0)
       
   173             {
       
   174             iCounter++;            
       
   175             if (iCounter > KIptvMaxTries)
       
   176                 {
       
   177                 IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::TimerExpired Clearing message queue!");
       
   178                 iMsgQueue.Reset();
       
   179                 iCounter = 0;
       
   180                 }      
       
   181             else
       
   182                 {
       
   183                 SetTimer();
       
   184                 }      
       
   185             }
       
   186         }           
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CIptvEpgVodMsqQueue::SendMessageL
       
   191 // 
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 void CIptvEpgVodMsqQueue::SendMessageL(TIptvEpgVodMsg& aMsg)
       
   195     {
       
   196     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::SendMessageL");    			
       
   197 
       
   198     if (iRequestPending && !iObserverMessage.IsNull())
       
   199         {
       
   200         TBuf8<KIptvVodObserverRequestSize> data;   
       
   201         RDesWriteStream writeStream;
       
   202         writeStream.Open(data);    
       
   203         CleanupClosePushL( writeStream );    
       
   204         writeStream.WriteUint32L(aMsg.iValue);
       
   205         writeStream.WriteInt32L(aMsg.iInfo);
       
   206         CleanupStack::PopAndDestroy( &writeStream );
       
   207         iObserverMessage.WriteL(0, data, 0);
       
   208         iObserverMessage.Complete(KErrNone);
       
   209         iRequestPending = EFalse;
       
   210         }
       
   211 #ifdef _DEBUG
       
   212     else
       
   213         {
       
   214         IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::SendMessageL() Error! Called when no request or message!");
       
   215         }
       
   216 #endif // _DEBUG
       
   217     }
       
   218 
       
   219 // ------------------------------------------------------------------
       
   220 // CIptvEpgVodMsqQueue::SetRequest
       
   221 // ------------------------------------------------------------------
       
   222 //
       
   223 void CIptvEpgVodMsqQueue::SetRequest(const RMessage2& aMessage)
       
   224     {
       
   225     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::SetRequest");
       
   226 
       
   227     iCounter = 0;
       
   228     iObserverMessage = aMessage;
       
   229     iRequestPending = ETrue;
       
   230 
       
   231     TInt count = iMsgQueue.Count();    
       
   232     if (count >= 1)
       
   233         {
       
   234         if (count == 1)
       
   235             {
       
   236             iTimer->Cancel();
       
   237             }
       
   238 
       
   239         TIptvEpgVodMsg msg = iMsgQueue[0];
       
   240         TRAPD(err, SendMessageL(msg));
       
   241         if (err != KErrNone)
       
   242             {
       
   243             IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::SetRequest SendMessageL failed");    			
       
   244             }
       
   245         iMsgQueue.Remove(0);        
       
   246         }    
       
   247     }
       
   248 
       
   249 // ------------------------------------------------------------------
       
   250 // CIptvEpgVodMsqQueue::CancelRequest
       
   251 // ------------------------------------------------------------------
       
   252 //
       
   253 void CIptvEpgVodMsqQueue::CancelRequest()
       
   254     {
       
   255     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::CancelRequest");
       
   256         
       
   257     if (iRequestPending)
       
   258         {
       
   259         iObserverMessage.Complete(KErrCancel);    
       
   260         iRequestPending = EFalse;
       
   261         }
       
   262     }
       
   263 
       
   264 // ------------------------------------------------------------------
       
   265 // CIptvEpgVodMsqQueue::CancelMsgQueue
       
   266 // ------------------------------------------------------------------
       
   267 //
       
   268 void CIptvEpgVodMsqQueue::CancelMsgQueue()
       
   269     {
       
   270     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgVodMsqQueue::CancelMsgQueue");
       
   271     iMsgQueue.Close();
       
   272     }
       
   273 
       
   274 // End of File