commonservices/commonengine/diskspacereserver/src/shareddataclient.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *     This module offers an interface for applications to access other
       
    16 *     applications' settings which are meant to have shared access.
       
    17 *
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "shareddataclient.h"
       
    24 #include "dosclishareddata.h"
       
    25 #include <s32file.h>
       
    26 #include "tracemacros.h"
       
    27 // CONSTANTS
       
    28 
       
    29 // CLASS DECLARATION
       
    30 
       
    31 class CDosWrapper : public CBase
       
    32     {
       
    33     public:
       
    34         CDosWrapper() {};
       
    35         ~CDosWrapper() {};
       
    36 
       
    37     public: // data
       
    38         RDosServer iDosSession;
       
    39         RDosSharedData iDosSubsession;
       
    40 };
       
    41 
       
    42 
       
    43 // ================= MEMBER FUNCTIONS ==========================================
       
    44 
       
    45 EXPORT_C RSharedDataClient::RSharedDataClient()
       
    46     {
       
    47     iDosWrapper = NULL;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // RSharedDataClient::Connect()
       
    52 // Connects to the  server - default number of message slots = 2
       
    53 // -----------------------------------------------------------------------------
       
    54 
       
    55 EXPORT_C TInt RSharedDataClient::Connect()
       
    56     {
       
    57     COMMONENGINE_RDEBUG(_L("RSharedDataClient::Connect()"));
       
    58     TInt err(KErrNone);
       
    59     
       
    60     if( !iDosWrapper )
       
    61         {
       
    62         iDosWrapper = new CDosWrapper();
       
    63         if ( !iDosWrapper )
       
    64             {
       
    65             COMMONENGINE_RDEBUG(_L("RSharedDataClient::Connect() - Could not create iDosWrapper, return KErrCouldNotConnect"));
       
    66             return KErrCouldNotConnect;
       
    67             }
       
    68         COMMONENGINE_RDEBUG(_L("RSharedDataClient::Connect() - iDosWrapper created"));
       
    69         }
       
    70 
       
    71     err = iDosWrapper->iDosSession.Connect();
       
    72     COMMONENGINE_RDEBUG_INT(_L("RSharedDataClient::Connect() - iDosSession.Connect() returned %d"), err);
       
    73     if ( err != KErrNone )
       
    74         {
       
    75         COMMONENGINE_RDEBUG(_L("RSharedDataClient::Connect() - Could not connect iDosSession, return KErrCouldNotConnect"));
       
    76         return KErrCouldNotConnect;
       
    77         }
       
    78     
       
    79     err = iDosWrapper->iDosSubsession.Open(iDosWrapper->iDosSession);
       
    80     COMMONENGINE_RDEBUG_INT(_L("RSharedDataClient::Connect() - iDosSubSession.Open() returned %d"), err);
       
    81     
       
    82     if ( err != KErrNone )
       
    83         {
       
    84         COMMONENGINE_RDEBUG(_L("RSharedDataClient::Connect() - Could not open iDosSubSession, return KErrCouldNotConnect"));
       
    85         return KErrCouldNotConnect;
       
    86         }
       
    87     
       
    88     COMMONENGINE_RDEBUG(_L("RSharedDataClient::Connect() - return"));
       
    89        
       
    90     return err;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // RSharedDataClient::Close()
       
    95 // Closes a client session.
       
    96 // -----------------------------------------------------------------------------
       
    97 
       
    98 EXPORT_C void RSharedDataClient::Close()
       
    99     {
       
   100     COMMONENGINE_RDEBUG(_L("RSharedDataClient::Close()"));
       
   101     if ( iDosWrapper )
       
   102         {
       
   103         iDosWrapper->iDosSubsession.Close();
       
   104         iDosWrapper->iDosSession.Close();
       
   105         delete iDosWrapper;
       
   106         iDosWrapper = NULL;
       
   107         }
       
   108     COMMONENGINE_RDEBUG(_L("RSharedDataClient::Close() - return"));
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // RSharedDataClient::RequestFreeDiskSpaceLC()
       
   113 // -----------------------------------------------------------------------------
       
   114 
       
   115 EXPORT_C void RSharedDataClient::RequestFreeDiskSpaceLC( const TInt aAmount ) 
       
   116     const
       
   117     {
       
   118     COMMONENGINE_RDEBUG_INT(_L("RSharedDataClient::RequestFreeDiskSpaceLC( %d )"), aAmount);
       
   119     CleanupStack::PushL( 
       
   120         TCleanupItem( CleanupFreeDiskSpaceRequest, 
       
   121                       CONST_CAST( RSharedDataClient*, this ) ) );
       
   122                       
       
   123     COMMONENGINE_RDEBUG_INT(_L("RSharedDataClient::RequestFreeDiskSpaceLC - calling RequestFreeDiskSpace( %d )"), 
       
   124                                 aAmount);
       
   125     RequestFreeDiskSpace( aAmount );
       
   126     COMMONENGINE_RDEBUG(_L("RSharedDataClient::RequestFreeDiskSpaceLC() - return"));
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // RSharedDataClient::RequestFreeDiskSpace()
       
   131 // -----------------------------------------------------------------------------
       
   132 
       
   133 EXPORT_C void RSharedDataClient::RequestFreeDiskSpace( const TInt aAmount ) 
       
   134     const
       
   135     {
       
   136     COMMONENGINE_RDEBUG_INT(_L("RSharedDataClient::RequestFreeDiskSpace( %d )"), aAmount);
       
   137     TInt amount(aAmount);
       
   138     if ( iDosWrapper )
       
   139         {
       
   140         iDosWrapper->iDosSubsession.RequestFreeDiskSpace( amount ); //Use the subsession.
       
   141         COMMONENGINE_RDEBUG(_L("RSharedDataClient::RequestFreeDiskSpace() - return"));
       
   142         }
       
   143     else
       
   144         {
       
   145         COMMON_RDEBUG(_L("RSharedDataClient::RequestFreeDiskSpace() - Not connected to the  server, return!"));
       
   146         }
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // RSharedDataClient::CancelFreeDiskSpaceRequest()
       
   151 // -----------------------------------------------------------------------------
       
   152 
       
   153 EXPORT_C void RSharedDataClient::CancelFreeDiskSpaceRequest() const
       
   154     {
       
   155     COMMONENGINE_RDEBUG(_L("RSharedDataClient::CancelFreeDiskSpaceRequest()"));
       
   156     if ( iDosWrapper )
       
   157         {
       
   158         iDosWrapper->iDosSubsession.RequestFreeDiskSpaceCancel(); //Use the subsession.    
       
   159         COMMONENGINE_RDEBUG(_L("RSharedDataClient::CancelFreeDiskSpaceRequest() - return"));
       
   160         }
       
   161     else
       
   162         {
       
   163         COMMON_RDEBUG(_L("RSharedDataClient::RequestFreeDiskSpace() - Not connected to the  server, return!"));
       
   164         }
       
   165     }
       
   166     
       
   167 // -----------------------------------------------------------------------------
       
   168 // RSharedDataClient::CleanupFreeDiskSpaceRequest()
       
   169 // -----------------------------------------------------------------------------
       
   170 
       
   171 void RSharedDataClient::CleanupFreeDiskSpaceRequest( TAny* aAny )
       
   172     {
       
   173     COMMONENGINE_RDEBUG(_L("RSharedDataClient::CleanupFreeDiskSpaceRequest()"));
       
   174     REINTERPRET_CAST( RSharedDataClient*, aAny )->CancelFreeDiskSpaceRequest();
       
   175     COMMONENGINE_RDEBUG(_L("RSharedDataClient::CleanupFreeDiskSpaceRequest() - return"));
       
   176     }
       
   177 
       
   178 
       
   179 // End of File