mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/pictbridge.cpp
changeset 47 63cf70d3ecd8
parent 28 85e0c0339cc3
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 #include <e32debug.h>
       
    21 #include <dps.rsg>
    20 #include <dps.rsg>
    22 #include <f32file.h>
    21 #include <f32file.h>
    23 #include <barsc.h>
    22 #include <barsc.h>
    24 #include <barsread.h>
    23 #include <barsread.h>
    25 #include <bautils.h>
    24 #include <bautils.h>
    34 #include "dpsusbnotifier.h"
    33 #include "dpsusbnotifier.h"
    35 #include "dpsparam.h"
    34 #include "dpsparam.h"
    36 #include "dpsscriptsender.h"
    35 #include "dpsscriptsender.h"
    37 #include "dpstransaction.h"
    36 #include "dpstransaction.h"
    38 #include "dpsfile.h"
    37 #include "dpsfile.h"
    39 
    38 #include "mtpdebug.h"
    40 #ifdef _DEBUG
    39 #include "OstTraceDefinitions.h"
    41 #	define IF_DEBUG(t) {RDebug::t;}
    40 #ifdef OST_TRACE_COMPILER_IN_USE
    42 #else
    41 #include "pictbridgeTraces.h"
    43 #	define IF_DEBUG(t)
       
    44 #endif
    42 #endif
       
    43 
    45 
    44 
    46 const TInt KResource = 32;
    45 const TInt KResource = 32;
    47 const TInt KDriver = 3;
    46 const TInt KDriver = 3;
    48 // ---------------------------------------------------------------------------
    47 // ---------------------------------------------------------------------------
    49 // 
    48 // 
    50 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    51 //
    50 //
    52 EXPORT_C CDpsEngine* CDpsEngine::GetEngineL()
    51 EXPORT_C CDpsEngine* CDpsEngine::GetEngineL()
    53     {
    52     {
    54     IF_DEBUG(Print(_L("CDpsEngine::GetEngineL")));
    53     OstTraceFunctionEntry0( CDPSENGINE_GETENGINEL_ENTRY );
    55     CDpsEngine* me;
    54     CDpsEngine* me;
    56     me = static_cast<CDpsEngine*>(Dll::Tls());
    55     me = static_cast<CDpsEngine*>(Dll::Tls());
    57     if (!me)
    56     if (!me)
    58         {
    57         {
    59         CDpsEngine* self = new(ELeave) CDpsEngine();
    58         CDpsEngine* self = new(ELeave) CDpsEngine();
    60         
    59         
    61         CleanupStack::PushL(self);
    60         CleanupStack::PushL(self);
    62         self->ConstructL();
    61         self->ConstructL();
    63         CleanupStack::Pop();
    62         CleanupStack::Pop();
    64         User::LeaveIfError(Dll::SetTls(self));
    63         LEAVEIFERROR(Dll::SetTls(self),
       
    64                 OstTrace1( TRACE_ERROR, CDPSENGINE_GETENGINEL, 
       
    65                         "Build singleton failed! error code %d", munged_err));
       
    66                 
       
    67         OstTraceFunctionExit0( CDPSENGINE_GETENGINEL_EXIT );
    65         return self;	
    68         return self;	
    66         }
    69         }
    67     else
    70     else
    68         {
    71         {
       
    72         OstTraceFunctionExit0( DUP1_CDPSENGINE_GETENGINEL_EXIT );
    69         return me;	
    73         return me;	
    70         }			    
    74         }			    
    71     }
    75     }
    72 
    76 
    73 // ---------------------------------------------------------------------------
    77 // ---------------------------------------------------------------------------
    74 // 
    78 // 
    75 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    76 //	
    80 //	
    77 EXPORT_C void CDpsEngine::Delete()
    81 EXPORT_C void CDpsEngine::Delete()
    78     {
    82     {
    79     IF_DEBUG(Print(_L(">>>DpsEngine::Delete")));
    83     OstTraceFunctionEntry0( CDPSENGINE_DELETE_ENTRY );
    80     CDpsEngine *me; me = static_cast<CDpsEngine*>(Dll::Tls());
    84     CDpsEngine *me; me = static_cast<CDpsEngine*>(Dll::Tls());
    81     if (me)
    85     if (me)
    82         {
    86         {
    83         delete me;
    87         delete me;
    84         Dll::SetTls(NULL);
    88         Dll::SetTls(NULL);
    85         }
    89         }
    86     IF_DEBUG(Print(_L("<<<DpsEngine::Delete")));	
    90     OstTraceFunctionExit0( CDPSENGINE_DELETE_EXIT );
    87     }
    91     }
    88 
    92 
    89 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
    90 // 
    94 // 
    91 // ---------------------------------------------------------------------------
    95 // ---------------------------------------------------------------------------
    92 //	
    96 //	
    93 void CDpsEngine::ConstructL()	
    97 void CDpsEngine::ConstructL()	
    94     {
    98     {
    95     IF_DEBUG(Print(_L(">>>CDpsEngine::ConstructL")));
    99     OstTraceFunctionEntry0( CDPSENGINE_CONSTRUCTL_ENTRY );
    96     iDpsParameters = TDpsXmlString::NewL();
   100     iDpsParameters = TDpsXmlString::NewL();
    97     User::LeaveIfError(iPtp.Connect());    
   101     LEAVEIFERROR(iPtp.Connect(),
       
   102             OstTrace1( TRACE_ERROR, CDPSENGINE_CONSTRUCTL, 
       
   103                     "Connect iPtp failed! error code %d", munged_err));
       
   104             
    98     iDpsOperator = CDpsStateMachine::NewL(this);
   105     iDpsOperator = CDpsStateMachine::NewL(this);
    99     iUsbNotifier = CDpsUsbNotifier::NewL(this);
   106     iUsbNotifier = CDpsUsbNotifier::NewL(this);	
   100     IF_DEBUG(Print(_L("<<<DpsEngine::ConstructL")));		
   107     OstTraceFunctionExit0( CDPSENGINE_CONSTRUCTL_EXIT );
   101     }
   108     }
   102 
   109 
   103 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   104 // 
   111 // 
   105 // ---------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   106 //	
   113 //	
   107 CDpsEngine::~CDpsEngine()
   114 CDpsEngine::~CDpsEngine()
   108 	{
   115 	{
   109     IF_DEBUG(Print(_L(">>>~CDpsEngine")));
   116     OstTraceFunctionEntry0( CDPSENGINE_CDPSENGINE_DES_ENTRY );
   110 	
   117 	
   111     delete iDpsOperator;
   118     delete iDpsOperator;
   112     iDpsOperator = NULL;
   119     iDpsOperator = NULL;
   113 	
   120 	
   114     delete iUsbNotifier;
   121     delete iUsbNotifier;
   127         User::RequestComplete(iPrinterConnectRequest, KErrCancel);
   134         User::RequestComplete(iPrinterConnectRequest, KErrCancel);
   128         }	    
   135         }	    
   129     delete iDpsParameters;
   136     delete iDpsParameters;
   130     iDpsParameters = NULL;
   137     iDpsParameters = NULL;
   131     iPtp.Close();
   138     iPtp.Close();
   132     IF_DEBUG(Print(_L("<<<~CDpsEngine")));
   139 	OstTraceFunctionExit0( CDPSENGINE_CDPSENGINE_DES_EXIT );
   133 	}
   140 	}
   134 	
   141 	
   135 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   136 // 
   143 // 
   137 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   138 //
   145 //
   139 EXPORT_C void CDpsEngine::SetPrintMode(TRequestStatus& aStatus)
   146 EXPORT_C void CDpsEngine::SetPrintMode(TRequestStatus& aStatus)
   140     {
   147     {
   141     IF_DEBUG(Print(_L(">>>DpsEngine::SearchPrinter")));
   148     OstTraceFunctionEntry0( CDPSENGINE_SETPRINTMODE_ENTRY );
   142     
   149     
   143     iPrinterConnectRequest = &aStatus;
   150     iPrinterConnectRequest = &aStatus;
   144     *iPrinterConnectRequest = KRequestPending;		
   151     *iPrinterConnectRequest = KRequestPending;		
   145     iUsbNotifier->WaitForPrinterNotify();
   152     iUsbNotifier->WaitForPrinterNotify();
   146     IF_DEBUG(Print(_L("<<<DpsEngine::SearchPrinter")));
   153 	OstTraceFunctionExit0( CDPSENGINE_SETPRINTMODE_EXIT );
   147 	}
   154 	}
   148 
   155 
   149 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------
   150 // 
   157 // 
   151 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   152 //	
   159 //	
   153 EXPORT_C void CDpsEngine::CancelPrintMode()
   160 EXPORT_C void CDpsEngine::CancelPrintMode()
   154     {
   161     {
   155     IF_DEBUG(Print(_L(">>>DpsEngine::CancelSearchPrinter")));
   162     OstTraceFunctionEntry0( CDPSENGINE_CANCELPRINTMODE_ENTRY );
   156     iUsbNotifier->CancelPrinterNotify();				
   163     iUsbNotifier->CancelPrinterNotify();				
   157     IF_DEBUG(Print(_L("<<<DpsEngine::CancelSearchPrinter")));
   164     OstTraceFunctionExit0( CDPSENGINE_CANCELPRINTMODE_EXIT );
   158     }
   165     }
   159 
   166 
   160 // ---------------------------------------------------------------------------
   167 // ---------------------------------------------------------------------------
   161 // 
   168 // 
   162 // ---------------------------------------------------------------------------
   169 // ---------------------------------------------------------------------------
   163 //
   170 //
   164 EXPORT_C void CDpsEngine::ConnectStateNotify(TRequestStatus& aStatus)
   171 EXPORT_C void CDpsEngine::ConnectStateNotify(TRequestStatus& aStatus)
   165     {
   172     {
   166     IF_DEBUG(Print(_L(">>>DpsEngine::ConnectStateNotifyL")));
   173     OstTraceFunctionEntry0( CDPSENGINE_CONNECTSTATENOTIFY_ENTRY );
   167     // SetPrintMode must be finished
   174     // SetPrintMode must be finished
   168     if (!iUsbNotifier->IsSetPrintModeIssued())
   175     if (!iUsbNotifier->IsSetPrintModeIssued())
   169         {
   176         {
   170         TRequestStatus* status = &aStatus;
   177         TRequestStatus* status = &aStatus;
   171         User::RequestComplete(status, KErrNotReady);
   178         User::RequestComplete(status, KErrNotReady);
       
   179         OstTraceFunctionExit0( CDPSENGINE_CONNECTSTATENOTIFY_EXIT );
   172         return;
   180         return;
   173         }
   181         }
   174     
   182     
   175     iPrinterConnectRequest = &aStatus;
   183     iPrinterConnectRequest = &aStatus;
   176     *iPrinterConnectRequest = KRequestPending;		
   184     *iPrinterConnectRequest = KRequestPending;		
   177     iUsbNotifier->ConnectNotify();
   185     iUsbNotifier->ConnectNotify();
   178     IF_DEBUG(Print(_L("<<<DpsEngine::ConnecStatetNotifyL")));
   186     OstTraceFunctionExit0( DUP1_CDPSENGINE_CONNECTSTATENOTIFY_EXIT );
   179     }
   187     }
   180 
   188 
   181 // ---------------------------------------------------------------------------
   189 // ---------------------------------------------------------------------------
   182 // 
   190 // 
   183 // ---------------------------------------------------------------------------
   191 // ---------------------------------------------------------------------------
   184 //	
   192 //	
   185 EXPORT_C void CDpsEngine::DoDpsRequestL(TMDpsOperation* aRequest, 
   193 EXPORT_C void CDpsEngine::DoDpsRequestL(TMDpsOperation* aRequest, 
   186                                        TRequestStatus& aStatus)
   194                                        TRequestStatus& aStatus)
   187     {
   195     {
   188     IF_DEBUG(Print(_L(">>>DpsEngine::DoDpsRequestL")));
   196     OstTraceFunctionEntry0( CDPSENGINE_DODPSREQUESTL_ENTRY );
   189     // the ptp printer must be connected and registered for the dps event
   197     // the ptp printer must be connected and registered for the dps event
   190     if (!iUsbNotifier->IsConfigured() || !iDpsEventRequest)
   198     if (!iUsbNotifier->IsConfigured() || !iDpsEventRequest)
   191         {
   199         {
   192         TRequestStatus* status = &aStatus;
   200         TRequestStatus* status = &aStatus;
   193         User::RequestComplete(status, KErrNotReady);
   201         User::RequestComplete(status, KErrNotReady);
       
   202         OstTraceFunctionExit0( CDPSENGINE_DODPSREQUESTL_EXIT );
   194         return;
   203         return;
   195         }
   204         }
   196         
   205         
   197     // there is a request from the host received and the reply has been
   206     // there is a request from the host received and the reply has been
   198     // sending out, but the host has not received it yet. we can not send
   207     // sending out, but the host has not received it yet. we can not send
   199     // the device request now
   208     // the device request now  
   200     IF_DEBUG(Print(_L("curState is %x, idleState is %x"), 
   209     OstTraceExt2( TRACE_NORMAL, CDPSENGINE_DODPSREQUESTL, 
   201         iDpsOperator->CurState(), iDpsOperator->IdleState()));    
   210             "curState is %x, idleState is %x", (TUint32)iDpsOperator->CurState(), (TUint32)iDpsOperator->IdleState() );
       
   211     
   202     if (iDpsOperator->CurState() != iDpsOperator->IdleState())
   212     if (iDpsOperator->CurState() != iDpsOperator->IdleState())
   203         {
   213         {
   204         TRequestStatus* status = &aStatus;
   214         TRequestStatus* status = &aStatus;
   205         User::RequestComplete(status, KErrInUse);        
   215         User::RequestComplete(status, KErrInUse);        
       
   216         OstTraceFunctionExit0( DUP1_CDPSENGINE_DODPSREQUESTL_EXIT );
   206         return;
   217         return;
   207         }
   218         }
   208     
   219     
   209     iDpsOperator->StartTransactionL(aRequest);
   220     iDpsOperator->StartTransactionL(aRequest);
   210     iDpsOperationRequest = &aStatus;
   221     iDpsOperationRequest = &aStatus;
   211     *iDpsOperationRequest = KRequestPending;    
   222     *iDpsOperationRequest = KRequestPending;            
   212     IF_DEBUG(Print(_L("<<<DpsEngine::DoDpsRequestL")));           
   223 	OstTraceFunctionExit0( DUP2_CDPSENGINE_DODPSREQUESTL_EXIT );
   213 	}
   224 	}
   214 
   225 
   215 // ---------------------------------------------------------------------------
   226 // ---------------------------------------------------------------------------
   216 // 
   227 // 
   217 // ---------------------------------------------------------------------------
   228 // ---------------------------------------------------------------------------
   218 //	
   229 //	
   219 EXPORT_C void CDpsEngine::CancelDpsRequest()
   230 EXPORT_C void CDpsEngine::CancelDpsRequest()
   220     {
   231     {
   221     IF_DEBUG(Print(_L(">>>DpsEngine::CancelDpsOperation")));
   232     OstTraceFunctionEntry0( CDPSENGINE_CANCELDPSREQUEST_ENTRY );
   222     if (iDpsOperationRequest)
   233     if (iDpsOperationRequest)
   223         {
   234         {
   224         iDpsOperator->ScriptSender()->Cancel();
   235         iDpsOperator->ScriptSender()->Cancel();
   225         User::RequestComplete(iDpsOperationRequest, KErrCancel);
   236         User::RequestComplete(iDpsOperationRequest, KErrCancel);
   226         }
   237         }
   227     iDpsOperator->Initialize();
   238     iDpsOperator->Initialize();
   228     IF_DEBUG(Print(_L("<<<DpsEngine::CancelDpsOperation")));
   239     OstTraceFunctionExit0( CDPSENGINE_CANCELDPSREQUEST_EXIT );
   229     }
   240     }
   230  
   241  
   231 // ---------------------------------------------------------------------------
   242 // ---------------------------------------------------------------------------
   232 // 
   243 // 
   233 // ---------------------------------------------------------------------------
   244 // ---------------------------------------------------------------------------
   234 //   
   245 //   
   235 EXPORT_C void CDpsEngine::DpsEventNotify(TDpsEvents& aParam,
   246 EXPORT_C void CDpsEngine::DpsEventNotify(TDpsEvents& aParam,
   236                                          TRequestStatus& aStatus)
   247                                          TRequestStatus& aStatus)
   237     {
   248     {
   238     IF_DEBUG(Print(_L(">>>DpsEngine::DpsEventNotify")));
   249     OstTraceFunctionEntry0( CDPSENGINE_DPSEVENTNOTIFY_ENTRY );
   239     // the PTP printer must be connected and registered for the disconnect
   250     // the PTP printer must be connected and registered for the disconnect
   240     if (!iUsbNotifier->IsConfigured() || !iPrinterConnectRequest)
   251     if (!iUsbNotifier->IsConfigured() || !iPrinterConnectRequest)
   241         {
   252         {
   242         TRequestStatus* status = &aStatus;
   253         TRequestStatus* status = &aStatus;
   243         User::RequestComplete(status, KErrNotReady);
   254         User::RequestComplete(status, KErrNotReady);
       
   255         OstTraceFunctionExit0( CDPSENGINE_DPSEVENTNOTIFY_EXIT );
   244         return;
   256         return;
   245         }
   257         }
   246     
   258     
   247     iOutEvent = &aParam;
   259     iOutEvent = &aParam;
   248     iDpsEventRequest = &aStatus;
   260     iDpsEventRequest = &aStatus;
   249     *iDpsEventRequest = KRequestPending;
   261     *iDpsEventRequest = KRequestPending;
   250     iDpsOperator->ScriptReceiver()->WaitForReceive();
   262     iDpsOperator->ScriptReceiver()->WaitForReceive();
   251     IF_DEBUG(Print(_L("<<<DpsEngine::DpsEventNotify")));
   263     OstTraceFunctionExit0( DUP1_CDPSENGINE_DPSEVENTNOTIFY_EXIT );
   252     }
   264     }
   253  
   265  
   254 // ---------------------------------------------------------------------------
   266 // ---------------------------------------------------------------------------
   255 // 
   267 // 
   256 // ---------------------------------------------------------------------------
   268 // ---------------------------------------------------------------------------
   257 //       
   269 //       
   258 EXPORT_C void CDpsEngine::CancelDpsEventNotify()
   270 EXPORT_C void CDpsEngine::CancelDpsEventNotify()
   259     {
   271     {
   260     IF_DEBUG(Print(_L("DpsEngine::CancelDpsEventNotify")));
   272     OstTraceFunctionEntry0( CDPSENGINE_CANCELDPSEVENTNOTIFY_ENTRY );
   261     if (iDpsEventRequest)
   273     if (iDpsEventRequest)
   262         {
   274         {
   263         User::RequestComplete(iDpsEventRequest, KErrCancel);
   275         User::RequestComplete(iDpsEventRequest, KErrCancel);
   264         iDpsOperator->ScriptReceiver()->Cancel();
   276         iDpsOperator->ScriptReceiver()->Cancel();
   265         }  
   277         }  
       
   278     OstTraceFunctionExit0( CDPSENGINE_CANCELDPSEVENTNOTIFY_EXIT );
   266     }
   279     }
   267 
   280 
   268 // ---------------------------------------------------------------------------
   281 // ---------------------------------------------------------------------------
   269 // 
   282 // 
   270 // ---------------------------------------------------------------------------
   283 // ---------------------------------------------------------------------------
   271 //     
   284 //     
   272 EXPORT_C void CDpsEngine::GetDpsConfigL(TDpsConfigPrintReq& aConfig)
   285 EXPORT_C void CDpsEngine::GetDpsConfigL(TDpsConfigPrintReq& aConfig)
   273     {
   286     {
   274     IF_DEBUG(Print(_L(">>>DpsEngine::GetDpsConfigL")));
   287     OstTraceFunctionEntry0( CDPSENGINE_GETDPSCONFIGL_ENTRY );
   275 
   288 
   276     RFs fs = iDpsOperator->Trader()->FileHandle()->FileSession();
   289     RFs fs = iDpsOperator->Trader()->FileHandle()->FileSession();
   277     RResourceFile resource;
   290     RResourceFile resource;
   278     
   291     
   279     TBuf<KResource> resourceFile(PathInfo::RomRootPath());
   292     TBuf<KResource> resourceFile(PathInfo::RomRootPath());
   280     TBuf<KResource> length(KDpsResource);    
   293     TBuf<KResource> length(KDpsResource);    
   281     resourceFile.SetLength(KDriver + length.Length());
   294     resourceFile.SetLength(KDriver + length.Length());
   282     resourceFile.Replace(KDriver, length.Length(), KDpsResource);
   295     resourceFile.Replace(KDriver, length.Length(), KDpsResource);
   283     IF_DEBUG(Print(_L("file is %S"), &resourceFile));
   296     OstTraceExt1( TRACE_NORMAL, CDPSENGINE_GETDPSCONFIGL, "file is %S", resourceFile );
   284     resource.OpenL(fs, resourceFile);
   297     resource.OpenL(fs, resourceFile);
   285     CleanupClosePushL(resource);
   298     CleanupClosePushL(resource);
   286     resource.ConfirmSignatureL(KDpsResourceVersion);
   299     resource.ConfirmSignatureL(KDpsResourceVersion);
   287     HBufC8* id = resource.AllocReadLC(DPS_CONFIG);
   300     HBufC8* id = resource.AllocReadLC(DPS_CONFIG);
   288     TResourceReader reader;
   301     TResourceReader reader;
   305     aConfig.iProductName.Copy(productString);
   318     aConfig.iProductName.Copy(productString);
   306     TPtrC SerialNo = reader.ReadTPtrC();
   319     TPtrC SerialNo = reader.ReadTPtrC();
   307     aConfig.iSerialNo.Copy(SerialNo);
   320     aConfig.iSerialNo.Copy(SerialNo);
   308     CleanupStack::PopAndDestroy(id); 
   321     CleanupStack::PopAndDestroy(id); 
   309     CleanupStack::PopAndDestroy(&resource);
   322     CleanupStack::PopAndDestroy(&resource);
   310     IF_DEBUG(Print(_L("<<<DpsEngine::GetDpsConfigL")));
   323     OstTraceFunctionExit0( CDPSENGINE_GETDPSCONFIGL_EXIT );
   311     }
   324     }
   312    
   325    
   313 // ---------------------------------------------------------------------------
   326 // ---------------------------------------------------------------------------
   314 // 
   327 // 
   315 // ---------------------------------------------------------------------------
   328 // ---------------------------------------------------------------------------