usbuis/imageprintui/src/connectionmanager.cpp
changeset 0 1e05558e2206
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2006, 2007 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:  Informs about USB connection 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <pictbridge.h>
       
    20 #include <imageprintui.rsg>
       
    21 
       
    22 #include "connectionmanager.h"
       
    23 #include "imageprintuidebug.h"
       
    24 #include "settingsview.h"
       
    25 #include "notes.h"
       
    26 #include "imageprintuiappui.h"
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CConnectionManager::NewL
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CConnectionManager* CConnectionManager::NewL( CImagePrintUiAppUi* aAppUi, 
       
    37 											  CDpsEngine* aEngine, CNotes* aNotes)
       
    38     {
       
    39     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager:NewL"));
       
    40     CConnectionManager* self 
       
    41         = new (ELeave) CConnectionManager(aAppUi, aEngine, aNotes);
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CConnectionManager::~CConnectionManager
       
    48 // C++ default destructor
       
    49 // -----------------------------------------------------------------------------
       
    50 //    
       
    51 CConnectionManager::~CConnectionManager()
       
    52     {
       
    53     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager: desctructor"));
       
    54     Cancel(); // cancels any existing active object orders for iStatus
       
    55     
       
    56     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager: desctructor complete"));
       
    57     }
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CConnectionManager::CConnectionManager
       
    62 // C++ default constructor can NOT contain any code, that
       
    63 // might leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CConnectionManager::CConnectionManager( CImagePrintUiAppUi* aAppUi, 
       
    67 									    CDpsEngine* aEngine, CNotes* aNotes)
       
    68     : CActive(EPriorityStandard), iAppUi(aAppUi), 
       
    69       iDpsEngine(aEngine), iActiveNote(EFalse),iSetPrintCall(EFalse),
       
    70       iNotes(aNotes), iPreviousStatus(CDpsEngine::ENotConnected)
       
    71     {
       
    72     CActiveScheduler::Add(this);
       
    73     }
       
    74 
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CConnectionManager::RunError
       
    79 // Standard active object error function.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 
       
    83 TInt CConnectionManager::RunError(TInt aError)
       
    84     {
       
    85     FTRACE(FPrint(_L("[IMAGEPRINTUI]\tCConnectionManager::RunError: ERROR %d from RunL."), aError));
       
    86     if ( aError == KErrTimedOut)
       
    87     	{
       
    88     	FLOG(_L("[IMAGEPRINTUI] CConnectionManager: Time out, start listen again"));
       
    89     	StartListening();
       
    90     	}
       
    91     else
       
    92     	{
       
    93     	FLOG(_L("[IMAGEPRINTUI] CConnectionManager RunError close application"));
       
    94         iAppUi->CloseApplication(ETrue);	
       
    95     	}
       
    96     return KErrNone;
       
    97     }
       
    98 // -----------------------------------------------------------------------------
       
    99 // Starts search printer
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CConnectionManager::StartSearchPrinter()
       
   103 	{
       
   104 	FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager: StartSerchPrinter"));
       
   105     iDpsEngine->SetPrintMode(iStatus);
       
   106     iSetPrintCall = ETrue;
       
   107     SetActive(); 
       
   108     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager: StartSerchPrinter complete")); 
       
   109 	}
       
   110 // -----------------------------------------------------------------------------
       
   111 // 
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CConnectionManager::RunL()
       
   115     {
       
   116     FLOG(_L("[IMAGEPRINTUI]>>>CConnectionManager::RunL"));
       
   117     FTRACE(FPrint(_L("[IMAGEPRINTUI] CConnectionManager iStatus  is %d"), iStatus.Int() ));
       
   118     FTRACE(FPrint(_L("[IMAGEPRINTUI] CConnectionManager iPreviousStatus  is %d"), iPreviousStatus ))
       
   119     
       
   120     if ( iStatus.Int() == CDpsEngine::ENotConnected  )
       
   121         {
       
   122         FLOG(_L("[IMAGEPRINTUI]>>>CConnectionManager::ENotConnected "));
       
   123         if(iPreviousStatus == CDpsEngine::EOtherConnected)
       
   124         	{
       
   125         	FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager:: Previous was EOtherConnected, close earlier note")); 
       
   126         	iNotes->StopShowNote(R_NOT_CONNECT_PRINTER);
       
   127         	}
       
   128         iNotes->ShowNoteL(R_CONNECT_USB);
       
   129     	iActiveNote = ETrue; 
       
   130     	iPreviousStatus = CDpsEngine::ENotConnected;
       
   131     	StartListening();	
       
   132     	
       
   133         }
       
   134     else if ( iStatus.Int() == CDpsEngine::EOtherConnected )
       
   135         {
       
   136         FLOG(_L("[IMAGEPRINTUI]>>>CConnectionManager::EOtherConnected "));
       
   137         if(iPreviousStatus == CDpsEngine::ENotConnected)
       
   138         	{
       
   139         	FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager:: Previous was ENotConnected, close earlier note")); 
       
   140         	iNotes->StopShowNote(R_CONNECT_USB);
       
   141         	}
       
   142         iNotes->ShowNoteL(R_NOT_CONNECT_PRINTER);
       
   143         iActiveNote = ETrue; 
       
   144         iPreviousStatus = CDpsEngine::EOtherConnected;
       
   145         StartListening();
       
   146         
       
   147         }
       
   148     else if (iStatus.Int() == CDpsEngine::EPrinterConnected)
       
   149         {
       
   150         FLOG(_L("[IMAGEPRINTUI]>>>CConnectionManager::EPrinterConnected"));
       
   151         iSetPrintCall = EFalse;
       
   152         if(iActiveNote)
       
   153         	{
       
   154         	FLOG(_L("[IMAGEPRINTUI]>>>CConnectionManager::Stop show note"));
       
   155             iNotes->StopShowNote(R_CONNECT_USB);
       
   156             iActiveNote = EFalse; 	
       
   157        		}	
       
   158         iPreviousStatus = CDpsEngine::EPrinterConnected;	
       
   159         StartListening(); 
       
   160         TRAPD(err, iAppUi->CableConnectedL());
       
   161         if(err)
       
   162         	{
       
   163         	// creation of some manager instance was unsuccessfull, close application
       
   164         	iNotes->ShowErrorMsgL(R_ERROR_GENERAL);
       
   165         	iAppUi->CloseApplication(EFalse); 
       
   166         	}
       
   167         }
       
   168     else if ( iStatus.Int() == CDpsEngine::EPrinterDisconnected || 
       
   169               iStatus.Int() == CDpsEngine::EWrongPrintModeConnected )
       
   170         {
       
   171         FLOG(_L("[IMAGEPRINTUI]>>>CConnectionManager::EPrinterDisconnected or EWrongPrintModeConnected"));
       
   172         iAppUi->CloseApplication(ETrue); 
       
   173         }
       
   174 
       
   175     FLOG(_L("[IMAGEPRINTUI]<<<CConnectionManager::RunL complete."));
       
   176     }
       
   177 	
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CConnectionManager::StartListening
       
   182 // Orders notifications and sets the object active.
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CConnectionManager::StartListening()
       
   186     {
       
   187     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager: StartListeningL"));
       
   188     if(IsActive())
       
   189         {
       
   190         return;   
       
   191         }
       
   192     iDpsEngine->ConnectStateNotify( iStatus );
       
   193     SetActive();
       
   194     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager: StartListeningL complete"));
       
   195     }
       
   196 
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CConnectionManager::DoCancel
       
   200 // Standard active object cancellation function.
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CConnectionManager::DoCancel()
       
   204     {
       
   205     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager::DoCancel"));
       
   206     FTRACE(FPrint(_L("[IMAGEPRINTUI]\t tCConnectionManager iDpsEngine  is %x"), iDpsEngine ));
       
   207     if(!iDpsEngine)
       
   208     	{
       
   209     	FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager::DpsEngine allredy destroyed, panic"));
       
   210     	}
       
   211 	else
       
   212 		{
       
   213     iDpsEngine->CancelPrintMode();
       
   214 		}
       
   215     FLOG(_L("[IMAGEPRINTUI]\tCConnectionManager::DoCancel complete"));
       
   216     }
       
   217 
       
   218 
       
   219 
       
   220 // End of file