javacommons/fileutils/src/driveutilities.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  DriveUtilities - platform independent
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #if defined(__SYMBIAN32__) && defined(__WINSCW__)
       
    20 #include <e32std.h>
       
    21 #include <e32def.h>
       
    22 #include <e32cmn.h>
       
    23 #include <pls.h>
       
    24 #endif
       
    25 
       
    26 #include "logger.h"
       
    27 
       
    28 #include "driveobserverclient.h"
       
    29 #include "driveobserverserver.h"
       
    30 
       
    31 #include "driveutilities.h"
       
    32 
       
    33 namespace java
       
    34 {
       
    35 namespace fileutils
       
    36 {
       
    37 
       
    38 // Empty declaration for a pure virtual destructor
       
    39 DriveObserverServerInterface::~DriveObserverServerInterface()
       
    40 {}
       
    41 
       
    42 
       
    43 OS_EXPORT void DriveUtilities::getAccesibleDrives(driveInfos& aDriveInfos)
       
    44 {
       
    45     JELOG2(EJavaFile);
       
    46 
       
    47     getAllDrives(aDriveInfos);
       
    48 
       
    49     for (driveInfos::iterator iter = aDriveInfos.begin() ; iter != aDriveInfos.end() ;)
       
    50     {
       
    51         if (iter->iIsPresent)
       
    52         {
       
    53             iter++;
       
    54         }
       
    55         else
       
    56         {
       
    57             iter = aDriveInfos.erase(iter);
       
    58         }
       
    59     }
       
    60 }
       
    61 
       
    62 #if defined(__SYMBIAN32__) && defined(__WINSCW__)
       
    63 DriveObserverClient* getObserverInstance()
       
    64 {
       
    65     // Access the PLS of this process
       
    66     DriveObserverClient* instance  = Pls<DriveObserverClient>(TUid::Uid(0x20022FB6));
       
    67     return instance;
       
    68 }
       
    69 void deleteObserverInstance()
       
    70 {
       
    71 
       
    72 }
       
    73 
       
    74 #else
       
    75 static DriveObserverClient* sDOinstance = 0;
       
    76 DriveObserverClient* getObserverInstance()
       
    77 {
       
    78     if (sDOinstance == 0)
       
    79     {
       
    80         sDOinstance = new DriveObserverClient();
       
    81     }
       
    82     return sDOinstance;
       
    83 }
       
    84 void deleteObserverInstance()
       
    85 {
       
    86     if (sDOinstance)
       
    87     {
       
    88         delete sDOinstance;
       
    89         sDOinstance = 0;
       
    90     }
       
    91 }
       
    92 #endif
       
    93 
       
    94 OS_EXPORT void DriveUtilities::registerListener(DriveListenerInterface* aListener,
       
    95         const int& aServerCommsAddress)
       
    96 {
       
    97     getObserverInstance()->registerListener(aListener, aServerCommsAddress);
       
    98 }
       
    99 
       
   100 OS_EXPORT void DriveUtilities::unregisterListener(DriveListenerInterface* aListener,
       
   101         const int& aServerCommsAddress)
       
   102 {
       
   103     if (0 == getObserverInstance()->unregisterListener(aListener,
       
   104             aServerCommsAddress))
       
   105     {
       
   106         deleteObserverInstance();
       
   107     }
       
   108 }
       
   109 
       
   110 OS_EXPORT DriveObserverServerInterface* DriveUtilities::getDriveObserverServer()
       
   111 {
       
   112     JELOG2(EJavaFile);
       
   113 
       
   114     return new DriveObserverServer();
       
   115 }
       
   116 
       
   117 } // end of namespace fileutils
       
   118 } // end of namespace java