mtpdataproviders/mtpimagedp/mediasyncserver/src/cmediasyncserver.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <bautils.h>
       
    23 
       
    24 #include "cmediasyncserver.h"
       
    25 #include "cmediasyncserversession.h"
       
    26 #include "cmediasyncobserver.h"
       
    27 #include "cmediasyncserverdef.h"
       
    28 
       
    29 __FLOG_STMT(_LIT8(KComponent, "MediaSyncServer");)
       
    30 
       
    31 const TInt KMediaSyncFunctionCodeRanges[] = 
       
    32     {    
       
    33     EMediaSyncClientGetGSHHandle,
       
    34     EMediaSyncClientShutdown,
       
    35     EMediaSyncClientNotSupported,
       
    36     };
       
    37 
       
    38 const TUint KMediaSyncFunctionCodeRangeCount = (sizeof(KMediaSyncFunctionCodeRanges) 
       
    39                                             / sizeof(KMediaSyncFunctionCodeRanges[0]));
       
    40 
       
    41 
       
    42 const TUint8 KMediaSyncPolicyElementNetworkAndLocal = 0;
       
    43 const TUint8 KMediaSyncPolicyElementPowerMgmt = 1;
       
    44 
       
    45 const TUint8 KMediaSyncElementsIndex[KMediaSyncFunctionCodeRangeCount] =
       
    46     {
       
    47     KMediaSyncPolicyElementNetworkAndLocal,
       
    48     KMediaSyncPolicyElementPowerMgmt,
       
    49     CPolicyServer::ENotSupported,
       
    50     };
       
    51 
       
    52 const CPolicyServer::TPolicyElement KMediaSyncPolicyElements[] = 
       
    53     { 
       
    54     {_INIT_SECURITY_POLICY_C2(ECapabilityNetworkServices, ECapabilityLocalServices), CPolicyServer::EFailClient},
       
    55     {_INIT_SECURITY_POLICY_C1(ECapabilityPowerMgmt), CPolicyServer::EFailClient},
       
    56     };
       
    57 
       
    58 const CPolicyServer::TPolicy KMediaSyncServerPolicy =
       
    59     {
       
    60     CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
       
    61     KMediaSyncFunctionCodeRangeCount,
       
    62     KMediaSyncFunctionCodeRanges,
       
    63     KMediaSyncElementsIndex,     // what each range is compared to 
       
    64     KMediaSyncPolicyElements     // what policies range is compared to
       
    65     };
       
    66 
       
    67 
       
    68 /**
       
    69 Creates and executes a new CMTPServer instance.
       
    70 @leave One of the system wide error codes, if a processing failure occurs.
       
    71 */
       
    72 void CMediaSyncServer::RunServerL()
       
    73     {           
       
    74     RFs fs;
       
    75     User::LeaveIfError(fs.Connect());
       
    76     CleanupClosePushL(fs);
       
    77     
       
    78     TFileName lockFileName;
       
    79     fs.PrivatePath(lockFileName);
       
    80     TDriveUnit driveNum = RFs::GetSystemDrive();
       
    81     lockFileName.Insert(0, driveNum.Name());
       
    82     lockFileName.Append(KMssLockName);
       
    83     
       
    84     RFile lockFile;
       
    85     CleanupClosePushL(lockFile);
       
    86     TInt ret = KErrNone;
       
    87     if (!BaflUtils::FileExists(fs, lockFileName))
       
    88         {        
       
    89         BaflUtils::EnsurePathExistsL(fs, lockFileName);
       
    90         ret = lockFile.Create(fs, lockFileName, EFileShareExclusive|EFileWrite);
       
    91         }
       
    92     else
       
    93         {
       
    94         ret = lockFile.Open(fs, lockFileName, EFileShareExclusive|EFileWrite);
       
    95         }
       
    96     
       
    97     if (ret == KErrNone)
       
    98         {
       
    99         // Naming the server thread after the server helps to debug panics
       
   100         User::LeaveIfError(User::RenameProcess(KMediaSyncServerName));
       
   101         
       
   102         // Create and install the active scheduler.
       
   103         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
   104         CleanupStack::PushL(scheduler);
       
   105         CActiveScheduler::Install(scheduler);
       
   106         
       
   107         // Create the server and leave it on the cleanup stack.
       
   108         CMediaSyncServer* server = CMediaSyncServer::NewLC(fs);
       
   109         
       
   110         // Initialisation complete, signal the client
       
   111         RProcess::Rendezvous(KErrNone);
       
   112         
       
   113         // Execute the server.
       
   114         CActiveScheduler::Start();
       
   115 
       
   116         // Server shutting down. 
       
   117         CleanupStack::PopAndDestroy(server);
       
   118             
       
   119         CleanupStack::PopAndDestroy(scheduler); // scheduler        
       
   120         }
       
   121     else
       
   122         {
       
   123         RProcess::Rendezvous(KErrNone);
       
   124         }
       
   125     
       
   126     CleanupStack::PopAndDestroy(&lockFile);
       
   127     CleanupStack::PopAndDestroy(&fs);    
       
   128     }
       
   129 
       
   130 CMediaSyncServer* CMediaSyncServer::NewLC(RFs& aFs)
       
   131     {
       
   132     CMediaSyncServer* self = new (ELeave) CMediaSyncServer;
       
   133     CleanupStack::PushL(self);
       
   134     self->ConstructL(aFs);
       
   135     return self;
       
   136     }
       
   137 
       
   138 CMediaSyncServer::CMediaSyncServer() : 
       
   139     CPolicyServer(CActive::EPriorityStandard, KMediaSyncServerPolicy)
       
   140     {   
       
   141     
       
   142     }
       
   143 
       
   144 CMediaSyncServer::~CMediaSyncServer()
       
   145     {
       
   146     __FLOG(_L8("CMediaSyncServer::~CMediaSyncServer - Entry")); 
       
   147     
       
   148     delete iDb;
       
   149     delete iObserver;    
       
   150     
       
   151     __FLOG(_L8("CMediaSyncServer::~CMediaSyncServer - Exit"));
       
   152     __FLOG_CLOSE;
       
   153     }
       
   154 
       
   155 void CMediaSyncServer::ConstructL(RFs& aFs)
       
   156     {  
       
   157     __FLOG_OPEN(KMSSSubsystem, KComponent);
       
   158     __FLOG(_L8("CMediaSyncServer::ConstructL - Entry"));
       
   159     
       
   160     iDb = CMediaSyncDatabase::NewL(aFs);
       
   161     iObserver = CMediaSyncObserver::NewL(iDb);
       
   162     iNeedFullSync = iDb->IsMssDbCorrupt();
       
   163     
       
   164     StartL(KMediaSyncServerName);
       
   165 
       
   166     __FLOG(_L8("CMediaSyncObserver::ConstructL - Exit"));    
       
   167     }
       
   168 
       
   169 CSession2* CMediaSyncServer::NewSessionL(const TVersion&,const RMessage2&) const
       
   170     {
       
   171     __FLOG(_L8("CMediaSyncServer::NewSessionL - Entry"));
       
   172     
       
   173     CMediaSyncServer* ncThis = const_cast<CMediaSyncServer*>(this);
       
   174     
       
   175     __FLOG(_L8("CMediaSyncObserver::NewSessionL - Exit"));    
       
   176     return new(ELeave) CMediaSyncServerSession(ncThis);
       
   177     }
       
   178 
       
   179 CMediaSyncObserver* CMediaSyncServer::MediaSyncObserver() const
       
   180     {
       
   181     return iObserver;
       
   182     }
       
   183 
       
   184 CMediaSyncDatabase* CMediaSyncServer::MediaSyncDatabase() const
       
   185     {
       
   186     return iDb;
       
   187     }
       
   188 
       
   189 TBool CMediaSyncServer::NeedFullSync()
       
   190     {
       
   191     return iNeedFullSync;
       
   192     }
       
   193 
       
   194 void CMediaSyncServer::ClearFullSyncFlag()
       
   195     {
       
   196     __FLOG(_L8("CMediaSyncServer::ClearFullSyncFlag - Entry"));
       
   197     
       
   198     iNeedFullSync = EFalse;
       
   199     iDb->ClearMssDbCorrupt();
       
   200     
       
   201     __FLOG(_L8("CMediaSyncObserver::ClearFullSyncFlag - Exit"));    
       
   202     }