mtpdataproviders/mtppictbridgedp/src/cptpreceivedmsghandler.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 <e32base.h>
       
    19 #include <mtp/mtpprotocolconstants.h>
       
    20 
       
    21 #include "mtppictbridgedpconst.h"
       
    22 #include "cptpreceivedmsghandler.h"
       
    23 #include "cmtppictbridgeprinter.h"
       
    24 #include "cptpserver.h"
       
    25 #include "ptpdef.h"
       
    26 
       
    27 // --------------------------------------------------------------------------
       
    28 // CPtpReceivedMsgHandler::NewL()
       
    29 // 
       
    30 // --------------------------------------------------------------------------
       
    31 //
       
    32 CPtpReceivedMsgHandler* CPtpReceivedMsgHandler::NewL(CPtpServer* aServerP)
       
    33     {
       
    34     CPtpReceivedMsgHandler* self = new (ELeave) CPtpReceivedMsgHandler(aServerP);
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop(self); 
       
    38     return self;
       
    39     }
       
    40     
       
    41 
       
    42 // --------------------------------------------------------------------------
       
    43 // CPtpReceivedMsgHandler::CPtpReceivedMsgHandler()
       
    44 // 
       
    45 // --------------------------------------------------------------------------
       
    46 //
       
    47 CPtpReceivedMsgHandler::CPtpReceivedMsgHandler(CPtpServer* aServerP) : iServerP(aServerP)
       
    48     {
       
    49     Initialize();
       
    50     }
       
    51     
       
    52 // --------------------------------------------------------------------------
       
    53 // CPtpReceivedMsgHandler::ConstructL()
       
    54 // 
       
    55 // --------------------------------------------------------------------------
       
    56 //    
       
    57 void CPtpReceivedMsgHandler::ConstructL()
       
    58     {
       
    59     __FLOG_OPEN(KMTPSubsystem, KPtpServerLog);
       
    60     }
       
    61     
       
    62 // --------------------------------------------------------------------------
       
    63 // CPtpReceivedMsgHandler::~CPtpReceivedMsgHandler()
       
    64 // C++ destructor.
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 CPtpReceivedMsgHandler::~CPtpReceivedMsgHandler()
       
    68     {
       
    69     __FLOG(_L8("CPtpReceivedMsgHandler::~"));
       
    70     iReceiveQ.Close();
       
    71     __FLOG_CLOSE;
       
    72     }
       
    73     
       
    74 // --------------------------------------------------------------------------
       
    75 // CPtpReceivedMsgHandler::Initialize()
       
    76 // 
       
    77 // --------------------------------------------------------------------------
       
    78 //    
       
    79 void CPtpReceivedMsgHandler::Initialize()
       
    80     {
       
    81     iReceiveHandle = 0;
       
    82     iExtension.Zero();
       
    83     iTransactionID = 0;
       
    84     iReceiveQ.Reset();
       
    85     }
       
    86     
       
    87  
       
    88 // --------------------------------------------------------------------------
       
    89 // CPtpReceivedMsgHandler::RegisterReceiveObjectNotify()
       
    90 // 
       
    91 // --------------------------------------------------------------------------
       
    92 //
       
    93 void CPtpReceivedMsgHandler::RegisterReceiveObjectNotify(const TDesC& aExtension)
       
    94     {
       
    95     __FLOG(_L8(">>>PtpMsgHandler::RegisterReceiveObjectNotify"));
       
    96     iExtension.Copy(aExtension);
       
    97     __FLOG_VA((_L8("***the Receiving Que msg count: %d"), iReceiveQ.Count()));
       
    98     for ( TUint index = 0; index < iReceiveQ.Count(); ++index )
       
    99         {
       
   100         if ( ObjectReceived( iReceiveQ[index] ) )
       
   101             {
       
   102             iReceiveQ.Remove(index);
       
   103             break;
       
   104             }
       
   105         }
       
   106     __FLOG_VA((_L8("***the Receiving Que msg count:%d"), iReceiveQ.Count()));
       
   107     __FLOG(_L8("<<<PtpMsgHandler::RegisterReceiveObjectNotify"));    
       
   108     }
       
   109        
       
   110 // --------------------------------------------------------------------------
       
   111 // 
       
   112 // --------------------------------------------------------------------------
       
   113 //
       
   114 TBool CPtpReceivedMsgHandler::ObjectReceived(TUint32 aHandle)
       
   115     {
       
   116     __FLOG_VA((_L8(">>>CPtpReceivedMsgHandler::ObjectReceived 0x%x"), aHandle));    
       
   117     TBuf<KFileNameAndPathLength> file;
       
   118     TInt err=KErrNone;
       
   119     TRAP( err, iServerP->GetObjectNameByHandleL(file, aHandle));
       
   120     __FLOG_VA((_L16("---after GetObjectNameByHandleL err(%d) file is %S"), err, &file));    
       
   121     if (err == KErrNone)
       
   122         {
       
   123         TFileName fileName; 
       
   124         TBuf<KFileExtLength> extension;
       
   125         TParse p;
       
   126         err = p.Set(file,NULL,NULL);
       
   127         __FLOG_VA((_L8("---after Set err(%d)"), err));            
       
   128         if (err == KErrNone)
       
   129             {
       
   130             fileName = p.FullName();
       
   131         
       
   132             extension = p.Ext();
       
   133             __FLOG_VA((_L16("---after parse file is %S ext is %S comparing it to %S"), &fileName, &extension, &iExtension));
       
   134             if (!iExtension.CompareF(extension))
       
   135                 {
       
   136                 iServerP->Printer()->ObjectReceived(fileName);
       
   137                 // deregister notification
       
   138                 DeRegisterReceiveObjectNotify();
       
   139                 return ETrue; 
       
   140                 }
       
   141             else
       
   142                 {
       
   143                 // we keep the coming file in a "queue" so that later 
       
   144                 // registry for this file will be informed
       
   145 
       
   146                 if(KErrNotFound == iReceiveQ.Find(aHandle))
       
   147                     {
       
   148                     iReceiveQ.Append(aHandle);
       
   149                     }
       
   150 
       
   151                 __FLOG_VA((_L8("*** Que length is %d err is %d"), iReceiveQ.Count(), err));
       
   152                 }
       
   153             }   
       
   154         }
       
   155         
       
   156     __FLOG_VA((_L8("<<<CPtpReceivedMsgHandler::ObjectReceived %d"), err));
       
   157     return EFalse;
       
   158     }
       
   159 
       
   160     
       
   161 // --------------------------------------------------------------------------
       
   162 // CPtpReceivedMsgHandler::DeRegisterReceiveObjectNotify()
       
   163 // Deregisters observer for Object receive notification
       
   164 // --------------------------------------------------------------------------
       
   165 //    
       
   166 void CPtpReceivedMsgHandler::DeRegisterReceiveObjectNotify()       
       
   167     {
       
   168     __FLOG(_L8("CPtpReceivedMsgHandler::DeRegisterReceivObjectNotify"));        
       
   169     iExtension.Zero();
       
   170     iReceiveHandle = 0;
       
   171     }