mtpdataproviders/mtppictbridgedp/src/rptp.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 #include <f32file.h>
       
    18 #include "rptp.h"
       
    19 #include "ptpdef.h"
       
    20 
       
    21 
       
    22 //-----------------------------------------------------------------------------
       
    23 // RPtp::RPtp()
       
    24 // C++ Constructor
       
    25 //-----------------------------------------------------------------------------
       
    26 //
       
    27 EXPORT_C RPtp::RPtp()
       
    28     {
       
    29     iConnected=EFalse;
       
    30     }
       
    31 
       
    32 //-----------------------------------------------------------------------------
       
    33 // RPtp::Connect()
       
    34 // Creates session with PtpServer
       
    35 //-----------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C TInt RPtp::Connect()
       
    38     {
       
    39     // We do not attempt to start the server since it is started up only when 
       
    40     // MTP is loaded (at USB cable connection). To be compatible with previous 
       
    41     // version of PTP server we keep track of the connection and try to create it
       
    42     // if it does not yet exist.
       
    43     if(DoConnect() != KErrNone) // we claim that the connection succeeded.
       
    44     	{
       
    45     	//Do nothing.Still return KErrNone to lanuch ImagePrint to prompt users to plug-in USB cable.
       
    46     	}
       
    47     
       
    48     return KErrNone;
       
    49     }
       
    50 
       
    51 //-----------------------------------------------------------------------------
       
    52 // RPtp::DoConnect()
       
    53 //-----------------------------------------------------------------------------
       
    54 //
       
    55 TInt RPtp::DoConnect()
       
    56     {
       
    57     TInt ret=KErrNone;
       
    58     if(EFalse==iConnected)
       
    59         {
       
    60         TVersion version(KPtpServerVersionMajor, KPtpServerVersionMinor, 0);
       
    61         ret=KErrNotReady;
       
    62         ret = CreateSession( KPTPServer, version );
       
    63         if (KErrNone==ret)
       
    64             {
       
    65             iConnected=ETrue;
       
    66             }
       
    67         }
       
    68     return ret; 
       
    69     }
       
    70 
       
    71 //-----------------------------------------------------------------------------
       
    72 // RPtp::CreatePtpStack()
       
    73 // Creates session with PTP Server, creates PTP stack and loads transposrt plugin
       
    74 // Called by PTP Class controller
       
    75 //-----------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C TInt RPtp::CreatePtpStack(const TUid /* aTransport */)
       
    78     {
       
    79     Connect();
       
    80     return KErrNone;
       
    81     }
       
    82     
       
    83 
       
    84 //-----------------------------------------------------------------------------
       
    85 // RPtp::IsDpsPrinter()
       
    86 // Asynchronously request request DPS printer status
       
    87 //-----------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C void RPtp::IsDpsPrinter(TRequestStatus& aStatus)
       
    90     {
       
    91     if(DoConnect()==KErrNone)
       
    92         {
       
    93         SendReceive(EIsDpsPrinter, aStatus);
       
    94         }
       
    95     else
       
    96         {
       
    97         TRequestStatus* statusP=&aStatus;
       
    98         User::RequestComplete(statusP, EPrinterNotAvailable);
       
    99         }
       
   100     }
       
   101 
       
   102 //-----------------------------------------------------------------------------
       
   103 // RPtp::CancelIsDpsPrinter()
       
   104 // Cancel DPS printer status request
       
   105 //-----------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C void RPtp::CancelIsDpsPrinter()
       
   108     {
       
   109     if(DoConnect()==KErrNone)
       
   110         {
       
   111         if(SendReceive(ECancelIsDpsPrinter)==KErrServerTerminated)
       
   112             {
       
   113             iConnected=EFalse;
       
   114             }
       
   115         }
       
   116     }
       
   117     
       
   118 //-----------------------------------------------------------------------------
       
   119 // RPtp::SendObject()
       
   120 // Request send object to Pictbridge Printer host 
       
   121 //-----------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void RPtp::SendObject(const TDesC& aNameAndPath, 
       
   124                                TRequestStatus& aStatus, TBool aTimeout, 
       
   125                                TInt aSize, TBool aAdd)
       
   126     {   
       
   127     if(DoConnect()==KErrNone)
       
   128         {
       
   129         iFile.Copy(aNameAndPath);
       
   130         const TIpcArgs args(&iFile, aAdd, aTimeout, aSize); 
       
   131         SendReceive(ESendObject, args, aStatus);
       
   132         }
       
   133     else
       
   134         {
       
   135         TRequestStatus* statusP=&aStatus;
       
   136         User::RequestComplete(statusP, KErrNotReady);
       
   137         }
       
   138     }
       
   139 
       
   140 //-----------------------------------------------------------------------------
       
   141 // RPtp::CancelSendObject()
       
   142 // Cancel send object request 
       
   143 //-----------------------------------------------------------------------------
       
   144 //
       
   145 EXPORT_C void RPtp::CancelSendObject()
       
   146     {
       
   147     if(DoConnect()==KErrNone)
       
   148         {
       
   149         if(SendReceive(ECancelSendObject)==KErrServerTerminated)
       
   150             {
       
   151             iConnected=EFalse;    
       
   152             }
       
   153         }
       
   154     }
       
   155 
       
   156 //-----------------------------------------------------------------------------
       
   157 // RPtp::GetObjectHandleByName()
       
   158 // Get Object handle by name
       
   159 //-----------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C TInt RPtp::GetObjectHandleByName(const TDesC& aNameAndPath, 
       
   162                                           TUint32& aHandle, 
       
   163                                           TBool /*aAdd*/)
       
   164     {
       
   165     TInt ret=KErrNone;
       
   166     if((ret=DoConnect())==KErrNone)
       
   167         {
       
   168         TPckgBuf<TUint32> pckgHandle(aHandle);
       
   169         const TIpcArgs args(&aNameAndPath, &pckgHandle, EFalse/*aAdd*/);
       
   170         ret = SendReceive(EGetObjectHandleByName, args);
       
   171         if (ret == KErrNone)
       
   172             {
       
   173             aHandle = (TUint32)pckgHandle();
       
   174             if(0 == aHandle)
       
   175                 {
       
   176                 ret = KErrNotFound;
       
   177                 }
       
   178             }
       
   179         else if (ret == KErrServerTerminated)
       
   180             {
       
   181             iConnected=EFalse;    
       
   182             }
       
   183         }
       
   184     return ret;     
       
   185     }
       
   186 
       
   187 //-----------------------------------------------------------------------------
       
   188 // GetNameByObjectHandle()
       
   189 // Get object name and path by object handle 
       
   190 //-----------------------------------------------------------------------------
       
   191 //
       
   192 EXPORT_C TInt RPtp::GetNameByObjectHandle(TDes& aNameAndPath, 
       
   193                                           const TUint32 aHandle)
       
   194     {
       
   195     TInt ret=KErrNone;
       
   196     if((ret=DoConnect())==KErrNone)
       
   197         {   
       
   198         TPckgBuf<TUint32> pckgHandle(aHandle);
       
   199         const TIpcArgs args(&aNameAndPath, &pckgHandle);
       
   200         ret = SendReceive(EGetNameByObjectHandle, args);
       
   201         if (ret==KErrServerTerminated)
       
   202             {
       
   203             iConnected=EFalse;    
       
   204             }
       
   205         }
       
   206     return ret;
       
   207     }
       
   208 
       
   209 //-----------------------------------------------------------------------------
       
   210 // RPtp::ObjectReceivedNotify()
       
   211 // Register for object received notification
       
   212 //-----------------------------------------------------------------------------
       
   213 //
       
   214 EXPORT_C void RPtp::ObjectReceivedNotify( const TDesC& aExt,
       
   215                                           TDes& aNameAndPath,
       
   216                                           TRequestStatus& aStatus,
       
   217                                           TBool aDelete )
       
   218     {
       
   219     if(DoConnect()==KErrNone)
       
   220         {
       
   221         iExt.Copy(aExt);
       
   222         const TIpcArgs args(&iExt, &aNameAndPath, aDelete);
       
   223         SendReceive(EObjectReceivedNotify, args, aStatus);
       
   224         }
       
   225     else
       
   226         {
       
   227         TRequestStatus* statusP=&aStatus;
       
   228         User::RequestComplete(statusP, KErrNotReady);
       
   229         }
       
   230     }
       
   231 
       
   232 //-----------------------------------------------------------------------------
       
   233 // RPtp::CancelObjectReceivedNotify()
       
   234 // Cancel for object received notification
       
   235 //-----------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void RPtp::CancelObjectReceivedNotify()
       
   238     {
       
   239     if(DoConnect()==KErrNone)
       
   240         {
       
   241         if(SendReceive(ECancelObjectReceivedNotify)==KErrServerTerminated)
       
   242             {
       
   243             iConnected=EFalse;    
       
   244             }
       
   245         }
       
   246     }
       
   247 
       
   248 //-----------------------------------------------------------------------------
       
   249 // RPtp::DestroyPtpStatck()
       
   250 // Destroy PTP stack @deprecated, only calls close, use Close() instead
       
   251 //-----------------------------------------------------------------------------
       
   252 //
       
   253 EXPORT_C void RPtp::DestroyPtpStatck()
       
   254     {
       
   255     Close();
       
   256     }
       
   257  
       
   258 //-----------------------------------------------------------------------------
       
   259 // RPtp::Close()
       
   260 // Override RSessionBase::Close();
       
   261 //-----------------------------------------------------------------------------
       
   262 //
       
   263 EXPORT_C void RPtp::Close()
       
   264     {
       
   265     RSessionBase::Close();
       
   266     iConnected=EFalse;
       
   267     }
       
   268 
       
   269 //-----------------------------------------------------------------------------
       
   270 // RPtp::PtpFolder()
       
   271 // returns name and Path of PtpFolder
       
   272 //-----------------------------------------------------------------------------
       
   273 //      
       
   274 EXPORT_C const TDesC& RPtp::PtpFolder()
       
   275     {
       
   276     if(DoConnect()==KErrNone)
       
   277         {
       
   278         const TIpcArgs args(&iFile); 
       
   279         if(SendReceive(EPtpFolder, args)==KErrServerTerminated)
       
   280             {
       
   281             iConnected=EFalse;    
       
   282             }
       
   283         }
       
   284     return iFile;
       
   285     }
       
   286