locationmgmt/networkgateway/src/cpsyrequestchannel.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Definition of PSY request channel component functions.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21  @released
       
    22 */
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32debug.h>
       
    26 #include <lbs/lbslocerrors.h>
       
    27 #include "lbsdevloggermacros.h"
       
    28 #include "lbsprocessuiddefs.h"
       
    29 #include "cpsyrequestchannel.h"
       
    30 
       
    31 
       
    32 CPsyRequestChannel::CPsyRequestChannel(MPsyRequestObserver& aObserver) : 
       
    33     CActive(EPriorityStandard),
       
    34     iObserver(aObserver)
       
    35     {
       
    36     }
       
    37     
       
    38 CPsyRequestChannel::~CPsyRequestChannel()
       
    39     {
       
    40     Cancel();
       
    41     iPsyResponseChannel.Close();
       
    42     delete iMsgBuffer;
       
    43     }
       
    44 
       
    45 CPsyRequestChannel* CPsyRequestChannel::NewL(MPsyRequestObserver& aObserver, TUint aChannel)
       
    46     {
       
    47     CPsyRequestChannel* self = new (ELeave) CPsyRequestChannel(aObserver);
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL(aChannel);
       
    50     CleanupStack::Pop(self);
       
    51     return self;
       
    52     }
       
    53     
       
    54 /**
       
    55 Opens the channel specified
       
    56  
       
    57 @param aChannel, Net Internal API channel to use for this object
       
    58 */
       
    59 void CPsyRequestChannel::ConstructL(TUint aChannel)
       
    60     {
       
    61     iPsyResponseChannel.OpenL(static_cast<RLbsNetChannel::TLbsNetChannelId> (aChannel), *this);
       
    62     iMsgBuffer = CRequestMessageBuffer::NewL();
       
    63     CActiveScheduler::Add(this);
       
    64     }
       
    65     
       
    66 /**
       
    67 Handle the ACK from the SendMessage call.
       
    68 */
       
    69 void CPsyRequestChannel::RunL()
       
    70     {
       
    71     LBS_RDEBUG_ARGINT("PSY Req Chan", "LBS", "RunL", iStatus.Int());
       
    72 
       
    73     User::LeaveIfError(iStatus.Int());
       
    74     SendNextBufferedMessage();
       
    75     }
       
    76     
       
    77 void CPsyRequestChannel::DoCancel()
       
    78     {
       
    79     iPsyResponseChannel.CancelSendMessageNotification();
       
    80     }
       
    81     
       
    82 TInt CPsyRequestChannel::RunError(TInt aError)
       
    83     {
       
    84     return aError;
       
    85     }
       
    86 
       
    87 /**
       
    88 Sends a message to a Network PSY from the Network Gateway
       
    89  
       
    90 @param aChannel, Net Internal API channel to use for this object
       
    91 */
       
    92 void CPsyRequestChannel::SendNetworkResponse(const TLbsNetInternalMsgBase& aMessage)
       
    93     {
       
    94     LBSLOG(ELogP1, "CPsyRequestChannel::SendNetworkResponse:");
       
    95     if (!IsActive())
       
    96         {       
       
    97         // Immediately send the new message.
       
    98         SendMessage(aMessage);
       
    99         }
       
   100     else
       
   101         {
       
   102         // Still waiting for acknowledgement that a previous message
       
   103         // was read, so buffer this new message.
       
   104         TInt err = iMsgBuffer->BufferMessage(aMessage);
       
   105         if (err != KErrNone)
       
   106             {
       
   107             LBSLOG(ELogP1, "BUFFERING MESSAGE FAILED!!");
       
   108             }
       
   109         }
       
   110     }
       
   111 
       
   112 
       
   113 void CPsyRequestChannel::SendMessage(const TLbsNetInternalMsgBase& aMessage)
       
   114     {
       
   115     LBSLOG(ELogP1, "CPsyRequestChannel::SendMessage:");
       
   116     LBSLOG2(ELogP2, "Sending message : Type %d", aMessage.Type());
       
   117     
       
   118     iPsyResponseChannel.SendMessage(aMessage, iStatus);
       
   119     SetActive();
       
   120     }
       
   121 
       
   122 
       
   123 void CPsyRequestChannel::SendNextBufferedMessage()
       
   124     {
       
   125     LBSLOG(ELogP1, "CPsyRequestChannel::SendNextBufferedMessage:");
       
   126     
       
   127     const TLbsNetInternalMsgBase* msg = iMsgBuffer->PeekNextMessage();
       
   128     if (msg != NULL)
       
   129         {
       
   130         // Send the oldest buffered message. This will always
       
   131         // be the one at position zero.
       
   132         LBSLOG2(ELogP2, "Sending buffered message. Type: %d", msg->Type());
       
   133         SendMessage(*msg);
       
   134         iMsgBuffer->RemoveMessage(msg);
       
   135         }
       
   136     }
       
   137 
       
   138 
       
   139 /**
       
   140 Passes a message from a Network PSY to the Network Gateway
       
   141  
       
   142 @param aChannel, Net Internal API channel to use for this object
       
   143 */
       
   144 void CPsyRequestChannel::ProcessNetChannelMessage(RLbsNetChannel::TLbsNetChannelId aChannelId, const TLbsNetInternalMsgBase& aMessage)
       
   145     {
       
   146     LBSLOG(ELogP1, "CPsyRequestChannel::ProcessNetChannelMessage");
       
   147     __ASSERT_DEBUG(aChannelId == RLbsNetChannel::EChannelNG2SUPLPSY, User::Panic(KLbsNGFault, ENGUnexpectedNetChannelId));
       
   148     (void) aChannelId;
       
   149     iObserver.ProcessPsyMessage(aMessage);
       
   150     }
       
   151 
       
   152 
       
   153