presencefwsimpleadpt/src/simplepluginwinfo.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     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:    SIMPLE Protocol implementation for Presence Framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 
       
    23 #include <ximpdatasubscriptionstate.h>
       
    24 #include <ximpobjectfactory.h>
       
    25 
       
    26 #include <simplefactory.h>
       
    27 #include <msimplewinfowatcher.h>
       
    28 
       
    29 #include "simpleplugincommon.h"
       
    30 #include "simplepluginwinfo.h"
       
    31 #include "simpleplugindebugutils.h"
       
    32 
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CSimplePluginWinfo::CSimplePluginWinfo()
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CSimplePluginWinfo::CSimplePluginWinfo(
       
    41     MSimplePluginConnectionObs& aObs,
       
    42     MSimpleConnection& aConn )
       
    43   : iConnObs(aObs), iConnection(aConn), iSubscribed(0), iWinfoCompleted(EFalse)
       
    44     {
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CSimplePluginWinfo::ConstructL()
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CSimplePluginWinfo::ConstructL( )
       
    52     {
       
    53     iWinfoWatcher = TSimpleFactory::NewWinfoWatcherL( iConnection, *this );
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CSimplePluginWinfo::NewL()
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CSimplePluginWinfo* CSimplePluginWinfo::NewL(
       
    61     MSimplePluginConnectionObs& aObs,
       
    62     MSimpleConnection& aConn )
       
    63     {
       
    64     CSimplePluginWinfo* self =
       
    65         new( ELeave ) CSimplePluginWinfo( aObs, aConn );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL(  );
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CSimplePluginWinfo::~CSimplePluginWinfo()
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CSimplePluginWinfo::~CSimplePluginWinfo()
       
    77     {
       
    78     if ( iWinfoWatcher )
       
    79         {
       
    80         iWinfoWatcher->Close();
       
    81         }
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CSimplePluginWinfo::SetHost()
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CSimplePluginWinfo::SetHost(
       
    89     MXIMPProtocolConnectionHost* aHost )
       
    90     {
       
    91     iHost = aHost;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CSimplePluginWinfo::SubscribeWinfoListL()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CSimplePluginWinfo::SubscribeWinfoListL( TXIMPRequestId aReqId )
       
    99     {
       
   100     iWinfoCompleted = EFalse;
       
   101     iSubscribed++;
       
   102     if ( iSubscribed == 1 )
       
   103         {
       
   104 #ifdef _DEBUG
       
   105     PluginLogger::Log(_L("PluginWinfo: -> SubscribeWatcherListL") );
       
   106 #endif
       
   107         iSimpleId = iWinfoWatcher->SubscribeWatcherListL( NULL );
       
   108         iSubscribed = ETrue;
       
   109         iPrFwId = aReqId;
       
   110         }
       
   111     else
       
   112         {
       
   113         iSimpleId = 0;
       
   114         iPrFwId = aReqId;
       
   115         WinfoReqCompleteL( iSimpleId, KErrNone );
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CSimplePluginWinfo::UnsubscribeWinfoListL()
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CSimplePluginWinfo::UnsubscribeWinfoListL( TXIMPRequestId aReqId )
       
   124     {
       
   125     iWinfoCompleted = EFalse;
       
   126     TInt orig = iSubscribed;
       
   127     iSubscribed--;
       
   128     if ( iSubscribed < 0 )
       
   129         {
       
   130         iSubscribed = 0;
       
   131         }
       
   132 
       
   133     if ( !iSubscribed && orig )
       
   134         {
       
   135 #ifdef _DEBUG
       
   136     PluginLogger::Log(_L("PluginWinfo: -> UnsubscribeL") );
       
   137 #endif
       
   138         iSubscribed++;
       
   139         iSimpleId = iWinfoWatcher->UnsubscribeL();
       
   140         iSubscribed--;
       
   141         iPrFwId = aReqId;
       
   142         }
       
   143     else
       
   144         {
       
   145         iSimpleId = 0;
       
   146         iPrFwId = aReqId;
       
   147         WinfoReqCompleteL( iSimpleId, KErrNone );
       
   148         }
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CSimplePluginWinfo::WinfoReqCompleteL()
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CSimplePluginWinfo::WinfoReqCompleteL( TInt /*aOpId*/, TInt aStatus )
       
   156     {
       
   157 #ifdef _DEBUG
       
   158     PluginLogger::Log(_L("PluginWinfo: WinfoReqCompleteL status=%d"), aStatus );
       
   159 #endif
       
   160 
       
   161     if ( !iWinfoCompleted  )
       
   162         {
       
   163         iWinfoCompleted = ETrue;
       
   164         iSimpleId = 0;
       
   165         iConnObs.CompleteWinfoReq( iPrFwId, aStatus );
       
   166         // Do not wait MXIMPProtocolConnectionHostObserver callback, this
       
   167         // class is ready to serve the next request now.
       
   168         iPrFwId = TXIMPRequestId();
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CSimplePluginWinfo::WinfoTerminatedL()
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CSimplePluginWinfo::WinfoTerminatedL(
       
   177     TInt aOpId, TInt aReason )
       
   178     {
       
   179 #ifdef _DEBUG
       
   180     PluginLogger::Log(_L("PluginWinfo: WinfoTerminatedL opid=%d"), aOpId );
       
   181 #endif
       
   182 
       
   183     if ( iSimpleId == aOpId )
       
   184         {
       
   185         iSimpleId = 0;
       
   186         iConnObs.WinfoTerminatedL( aReason );
       
   187         }
       
   188  }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CSimplePluginWinfo::WinfoNotificationL()
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CSimplePluginWinfo::WinfoNotificationL(
       
   195     MSimpleWinfo& aWinfo )
       
   196     {
       
   197 #ifdef _DEBUG
       
   198     PluginLogger::Log(_L("PluginWinfo: WinfoNotificationL starts"));
       
   199 #endif
       
   200 
       
   201     WinfoReqCompleteL( iSimpleId, KErrNone );
       
   202     iConnObs.WinfoNotification( aWinfo );
       
   203 
       
   204 #ifdef _DEBUG
       
   205     PluginLogger::Log(_L("PluginWinfo: WinfoNotificationL ends"));
       
   206 #endif
       
   207     }
       
   208 
       
   209 
       
   210 // End of file
       
   211