mtpdataproviders/mtppictbridgedp/src/cmtppictbridgeprinter.cpp
changeset 47 63cf70d3ecd8
parent 18 1b39655331a3
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    21 #include "cptpsession.h"
    21 #include "cptpsession.h"
    22 #include "cptpreceivedmsghandler.h"
    22 #include "cptpreceivedmsghandler.h"
    23 #include "cmtppictbridgeprinter.h"
    23 #include "cmtppictbridgeprinter.h"
    24 #include "mtppictbridgedpconst.h"
    24 #include "mtppictbridgedpconst.h"
    25 #include "cmtppictbridgeusbconnection.h"
    25 #include "cmtppictbridgeusbconnection.h"
       
    26 #include "OstTraceDefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "cmtppictbridgeprinterTraces.h"
       
    29 #endif
       
    30 
    26 
    31 
    27 // --------------------------------------------------------------------------
    32 // --------------------------------------------------------------------------
    28 // 
    33 // 
    29 // --------------------------------------------------------------------------
    34 // --------------------------------------------------------------------------
    30 //
    35 //
    41 // 
    46 // 
    42 // --------------------------------------------------------------------------
    47 // --------------------------------------------------------------------------
    43 //
    48 //
    44 void CMTPPictBridgePrinter::ConstructL()
    49 void CMTPPictBridgePrinter::ConstructL()
    45     {
    50     {
    46     __FLOG_OPEN(KMTPSubsystem, KPtpServerLog);
       
    47     iMsgHandlerP = CPtpReceivedMsgHandler::NewL(&iServer);
    51     iMsgHandlerP = CPtpReceivedMsgHandler::NewL(&iServer);
    48     iUsbConnectionP = CMTPPictBridgeUsbConnection::NewL(*this);
    52     iUsbConnectionP = CMTPPictBridgeUsbConnection::NewL(*this);
    49     }
    53     }
    50 
    54 
    51 // --------------------------------------------------------------------------
    55 // --------------------------------------------------------------------------
    62 //
    66 //
    63 CMTPPictBridgePrinter::~CMTPPictBridgePrinter()
    67 CMTPPictBridgePrinter::~CMTPPictBridgePrinter()
    64     {
    68     {
    65     delete iMsgHandlerP;
    69     delete iMsgHandlerP;
    66     delete iUsbConnectionP;
    70     delete iUsbConnectionP;
    67     __FLOG_CLOSE;
       
    68     }
    71     }
    69 
    72 
    70 // --------------------------------------------------------------------------
    73 // --------------------------------------------------------------------------
    71 // 
    74 // 
    72 // --------------------------------------------------------------------------
    75 // --------------------------------------------------------------------------
   101         {
   104         {
   102         iPrinterStatus=ENotPrinter;
   105         iPrinterStatus=ENotPrinter;
   103         }
   106         }
   104     else
   107     else
   105         {
   108         {
   106         __FLOG(_L8("WARNING! CMTPPictBridgePrinter::NoDpsDiscovery trying to say no printer even though already discovered"));
   109         OstTrace0( TRACE_WARNING, CMTPPICTBRIDGEPRINTER_NODPSDISCOVERY, 
       
   110                 "WARNING! trying to say no printer even though already discovered" );
   107         }
   111         }
   108     }
   112     }
   109 
   113 
   110 // --------------------------------------------------------------------------
   114 // --------------------------------------------------------------------------
   111 //
   115 //
   112 // --------------------------------------------------------------------------
   116 // --------------------------------------------------------------------------
   113 //
   117 //
   114 void CMTPPictBridgePrinter::DpsObjectReceived(TUint32 aHandle)
   118 void CMTPPictBridgePrinter::DpsObjectReceived(TUint32 aHandle)
   115     {
   119     {
   116     __FLOG(_L8("CMTPPictBridgePrinter::DpsObjectReceived"));                    
   120     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_DPSOBJECTRECEIVED_ENTRY );                 
   117     if(iPrinterStatus==EConnected) // we only handle the object when we are connected to the printer
   121     if(iPrinterStatus==EConnected) // we only handle the object when we are connected to the printer
   118         {
   122         {
   119         iMsgHandlerP->ObjectReceived(aHandle);
   123         iMsgHandlerP->ObjectReceived(aHandle);
   120         }
   124         }
   121     else
   125     else
   122         {
   126         {
   123         __FLOG(_L8("!!!!WARNING: CMTPPictBridgePrinter::DpsObjectReceived Rx dps file when printer not connected!"));
   127         OstTrace0( TRACE_WARNING, CMTPPICTBRIDGEPRINTER_DPSOBJECTRECEIVED, 
   124         }
   128                 "!!!!WARNING: CMTPPictBridgePrinter::DpsObjectReceived Rx dps file when printer not connected!" );
       
   129         
       
   130         }
       
   131     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_DPSOBJECTRECEIVED_EXIT );
   125     }        
   132     }        
   126 
   133 
   127 // --------------------------------------------------------------------------
   134 // --------------------------------------------------------------------------
   128 // 
   135 // 
   129 // --------------------------------------------------------------------------
   136 // --------------------------------------------------------------------------
   130 //
   137 //
   131 void CMTPPictBridgePrinter::DpsDiscovery(const TFileName& aFileName, MMTPConnection* aConnectionP)
   138 void CMTPPictBridgePrinter::DpsDiscovery(const TFileName& aFileName, MMTPConnection* aConnectionP)
   132     {
   139     {
   133     __FLOG_VA(_L8(">> CMTPPictBridgePrinter::DpsDiscovery"));
   140     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_DPSDISCOVERY_ENTRY );
   134     if ( iPrinterStatus != EConnected )
   141     if ( iPrinterStatus != EConnected )
   135         {
   142         {
   136         if (KErrNotFound!=aFileName.Find(KHostDiscovery))
   143         if (KErrNotFound!=aFileName.Find(KHostDiscovery))
   137             {
   144             {
   138             __FLOG(_L8("***Dps printer Discovered."));
   145             OstTrace0( TRACE_NORMAL, DUP1_CMTPPICTBRIDGEPRINTER_DPSDISCOVERY, "***Dps printer Discovered." );
   139             iPrinterConnectionP=aConnectionP;
   146             iPrinterConnectionP=aConnectionP;
   140             iPrinterStatus=EConnected;
   147             iPrinterStatus=EConnected;
   141             iUsbConnectionP->Listen();
   148             iUsbConnectionP->Listen();
   142             if(iDpsPrinterNotifyCbP)
   149             if(iDpsPrinterNotifyCbP)
   143                 {
   150                 {
   144                 iDpsPrinterNotifyCbP->IsDpsPrinterCompleted(EPrinterAvailable);    
   151                 iDpsPrinterNotifyCbP->IsDpsPrinterCompleted(EPrinterAvailable);    
   145                 }
   152                 }
   146             }
   153             }
   147         }    
   154         }   
   148     __FLOG_VA((_L16("<< CMTPPictBridgePrinter::DpsDiscovery received file %S"), &aFileName)); 
   155     OstTraceExt1( TRACE_NORMAL, CMTPPICTBRIDGEPRINTER_DPSDISCOVERY, "received file %S", aFileName );    
       
   156     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_DPSDISCOVERY_EXIT );
   149     }
   157     }
   150 // --------------------------------------------------------------------------
   158 // --------------------------------------------------------------------------
   151 //
   159 //
   152 // --------------------------------------------------------------------------
   160 // --------------------------------------------------------------------------
   153 //    
   161 //    
   154 void CMTPPictBridgePrinter::DeRegisterDpsPrinterNotify(CPtpSession* /*aSessionP*/ )
   162 void CMTPPictBridgePrinter::DeRegisterDpsPrinterNotify(CPtpSession* /*aSessionP*/ )
   155     {
   163     {
   156     __FLOG(_L8(">>>CMTPPictBridgePrinter::DeRegisterDpsPrinterNotify"));
   164     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_DEREGISTERDPSPRINTERNOTIFY_ENTRY );
   157     iDpsPrinterNotifyCbP=NULL;
   165     iDpsPrinterNotifyCbP=NULL;
   158     __FLOG(_L8("<<<CMTPPictBridgePrinter::DeRegisterDpsPrinterNotify"));
   166     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_DEREGISTERDPSPRINTERNOTIFY_EXIT );
   159     }
   167     }
   160     
   168     
   161 // --------------------------------------------------------------------------
   169 // --------------------------------------------------------------------------
   162 //
   170 //
   163 // --------------------------------------------------------------------------
   171 // --------------------------------------------------------------------------
   164 //
   172 //
   165 void CMTPPictBridgePrinter::RegisterDpsPrinterNotify(CPtpSession* aSessionP)
   173 void CMTPPictBridgePrinter::RegisterDpsPrinterNotify(CPtpSession* aSessionP)
   166     {
   174     {
   167     __FLOG_VA((_L8(">>>CMTPPictBridgePrinter::RegisterDpsPrinterNotify 0x%x (old) 0x%x (new)"), iDpsPrinterNotifyCbP, aSessionP));
   175     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_REGISTERDPSPRINTERNOTIFY_ENTRY );
       
   176     OstTraceExt2( TRACE_NORMAL, CMTPPICTBRIDGEPRINTER_REGISTERDPSPRINTERNOTIFY, 
       
   177             " 0x%x (old) 0x%x (new)", (TUint)iDpsPrinterNotifyCbP, (TUint)aSessionP );
   168     __ASSERT_DEBUG(iDpsPrinterNotifyCbP==NULL, User::Invariant());
   178     __ASSERT_DEBUG(iDpsPrinterNotifyCbP==NULL, User::Invariant());
   169     iDpsPrinterNotifyCbP=aSessionP;
   179     iDpsPrinterNotifyCbP=aSessionP;
   170     __FLOG(_L8("<<<CMTPPictBridgePrinter::RegisterDpsPrinterNotify"));    
   180     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_REGISTERDPSPRINTERNOTIFY_EXIT );
   171     }
   181     }
   172 
   182 
   173     
   183     
   174 // --------------------------------------------------------------------------
   184 // --------------------------------------------------------------------------
   175 // CPtpEventSender::SendL()
   185 // CPtpEventSender::SendL()
   177 // and registers observer for object sent notification 
   187 // and registers observer for object sent notification 
   178 // --------------------------------------------------------------------------
   188 // --------------------------------------------------------------------------
   179 //    
   189 //    
   180 void CMTPPictBridgePrinter::SendDpsFileL(const TDesC& aFile, TBool /*aTimeout*/, TInt /*aSize*/)
   190 void CMTPPictBridgePrinter::SendDpsFileL(const TDesC& aFile, TBool /*aTimeout*/, TInt /*aSize*/)
   181     {
   191     {
   182     __FLOG_VA((_L16(">> CMTPPictBridgePrinter::SendDpsFileL %S"), &aFile));            
   192     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_SENDDPSFILEL_ENTRY );
       
   193     OstTraceExt1( TRACE_NORMAL, CMTPPICTBRIDGEPRINTER_SENDDPSFILEL, "DpsFile %S", aFile );          
   183     
   194     
   184     TUint32 handle(0);  
   195     TUint32 handle(0);  
   185     TRAPD(err, iServer.GetObjectHandleByNameL(aFile, handle));
   196     TRAPD(err, iServer.GetObjectHandleByNameL(aFile, handle));
   186     if(err!=KErrNone || handle==0)
   197     if(err!=KErrNone || handle==0)
   187         {
   198         {
   188         __FLOG_VA((_L8("   Object does not exist, adding it, errorcode = %d"), err));
   199         OstTrace1( TRACE_WARNING, DUP1_CMTPPICTBRIDGEPRINTER_SENDDPSFILEL, 
       
   200                 "   Object does not exist, adding it, errorcode = %d", err);
   189         iServer.AddTemporaryObjectL(aFile, handle);    
   201         iServer.AddTemporaryObjectL(aFile, handle);    
   190         }
   202         }
   191 
   203 
   192     CreateRequestObjectTransfer(handle, iEvent);
   204     CreateRequestObjectTransfer(handle, iEvent);
   193     iServer.SendEventL(iEvent);
   205     iServer.SendEventL(iEvent);
   194     iOutgoingObjectHandle=handle;
   206     iOutgoingObjectHandle=handle;
   195     __FLOG_VA((_L8("<< CMTPPictBridgePrinter::SendDpsFileL handle 0x%x"),iOutgoingObjectHandle));
   207     OstTrace1( TRACE_NORMAL, DUP2_CMTPPICTBRIDGEPRINTER_SENDDPSFILEL, "handle 0x%x", iOutgoingObjectHandle );    
       
   208     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_SENDDPSFILEL_EXIT );
   196     }
   209     }
   197 
   210 
   198 // --------------------------------------------------------------------------
   211 // --------------------------------------------------------------------------
   199 // CPtpServer::CancelSendDpsFile()
   212 // CPtpServer::CancelSendDpsFile()
   200 // Cancels Object sedn and call for deregister object sent notification
   213 // Cancels Object sedn and call for deregister object sent notification
   201 // --------------------------------------------------------------------------
   214 // --------------------------------------------------------------------------
   202 //
   215 //
   203 void CMTPPictBridgePrinter::CancelSendDpsFile()
   216 void CMTPPictBridgePrinter::CancelSendDpsFile()
   204     {
   217     {
   205     __FLOG(_L8(">>>CMTPPictBridgePrinter::CancelSendObject"));    
   218     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_CANCELSENDDPSFILE_ENTRY );  
   206     iOutgoingObjectHandle=0;
   219     iOutgoingObjectHandle=0; 
   207     __FLOG(_L8("<<<CMTPPictBridgePrinter::CancelSendObject"));    
   220     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_CANCELSENDDPSFILE_EXIT );
   208     }
   221     }
   209 
   222 
   210 // --------------------------------------------------------------------------
   223 // --------------------------------------------------------------------------
   211 // --------------------------------------------------------------------------
   224 // --------------------------------------------------------------------------
   212 //
   225 //
   221 // --------------------------------------------------------------------------
   234 // --------------------------------------------------------------------------
   222 //
   235 //
   223 void CMTPPictBridgePrinter::CreateRequestObjectTransfer(TUint32 aHandle, 
   236 void CMTPPictBridgePrinter::CreateRequestObjectTransfer(TUint32 aHandle, 
   224                                                  TMTPTypeEvent& aEvent )
   237                                                  TMTPTypeEvent& aEvent )
   225     {
   238     {
   226     __FLOG_VA((_L8("CMTPPictBridgePrinter::CreateRequestEventTransfer for 0x%x"), aHandle)); 
   239     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_CREATEREQUESTOBJECTTRANSFER_ENTRY );
       
   240     OstTrace1( TRACE_NORMAL, CMTPPICTBRIDGEPRINTER_CREATEREQUESTOBJECTTRANSFER, 
       
   241             " for handle 0x%x", aHandle );
   227 
   242 
   228     aEvent.Reset();
   243     aEvent.Reset();
   229 
   244 
   230     aEvent.SetUint16(TMTPTypeEvent::EEventCode, EMTPEventCodeRequestObjectTransfer);
   245     aEvent.SetUint16(TMTPTypeEvent::EEventCode, EMTPEventCodeRequestObjectTransfer);
   231     aEvent.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll); 
   246     aEvent.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll); 
   232     aEvent.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdLast);
   247     aEvent.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdLast);
   233     
   248     
   234     aEvent.SetUint32(TMTPTypeEvent::EEventParameter1, aHandle);
   249     aEvent.SetUint32(TMTPTypeEvent::EEventParameter1, aHandle);
   235     aEvent.SetUint32(TMTPTypeEvent::EEventParameter2, KPtpNoValue);
   250     aEvent.SetUint32(TMTPTypeEvent::EEventParameter2, KPtpNoValue);
   236     aEvent.SetUint32(TMTPTypeEvent::EEventParameter3, KPtpNoValue);
   251     aEvent.SetUint32(TMTPTypeEvent::EEventParameter3, KPtpNoValue);
       
   252     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_CREATEREQUESTOBJECTTRANSFER_EXIT );
   237     }
   253     }
   238 
   254 
   239 // --------------------------------------------------------------------------
   255 // --------------------------------------------------------------------------
   240 // CPtpServer::ObjectReceived
   256 // CPtpServer::ObjectReceived
   241 // Notifies of object received
   257 // Notifies of object received
   242 // --------------------------------------------------------------------------
   258 // --------------------------------------------------------------------------
   243 //
   259 //
   244 void CMTPPictBridgePrinter::ObjectReceived(TDes& aFile)
   260 void CMTPPictBridgePrinter::ObjectReceived(TDes& aFile)
   245     {
   261     {
   246     __FLOG(_L8("CMTPPictBridgePrinter::ObjectReceived"));                    
   262     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_OBJECTRECEIVED_ENTRY );                  
   247     iObserverP->ReceivedObjectCompleted(aFile);
   263     iObserverP->ReceivedObjectCompleted(aFile);
       
   264     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_OBJECTRECEIVED_EXIT );
   248     }    
   265     }    
   249 
   266 
   250 // --------------------------------------------------------------------------
   267 // --------------------------------------------------------------------------
   251 // --------------------------------------------------------------------------
   268 // --------------------------------------------------------------------------
   252 //
   269 //
   253 void CMTPPictBridgePrinter::DpsFileSent(TInt aError)
   270 void CMTPPictBridgePrinter::DpsFileSent(TInt aError)
   254     {
   271     {
   255     __FLOG_VA((_L8("CMTPPictBridgePrinter::DpsFileSent error %d handle 0x%x"), aError, iOutgoingObjectHandle));
   272     OstTraceFunctionEntry0( CMTPPICTBRIDGEPRINTER_DPSFILESENT_ENTRY );
       
   273     OstTraceExt2( TRACE_NORMAL, CMTPPICTBRIDGEPRINTER_DPSFILESENT, "error %d handle 0x%x", (TInt32)aError, iOutgoingObjectHandle );
       
   274 
   256     if( SendObjectPending() )
   275     if( SendObjectPending() )
   257         {
   276         {
   258         iObserverP->SendObjectCompleted(aError); 
   277         iObserverP->SendObjectCompleted(aError); 
   259         iOutgoingObjectHandle=0;
   278         iOutgoingObjectHandle=0;
   260         }
   279         }
       
   280     OstTraceFunctionExit0( CMTPPICTBRIDGEPRINTER_DPSFILESENT_EXIT );
   261     }
   281     }
   262 
   282 
   263 // --------------------------------------------------------------------------
   283 // --------------------------------------------------------------------------
   264 // --------------------------------------------------------------------------
   284 // --------------------------------------------------------------------------
   265 //    
   285 //