mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsscriptsender.cpp
author hgs
Thu, 04 Nov 2010 15:31:42 +0800
changeset 60 841f70763fbe
parent 49 c20dd21d1eb4
permissions -rw-r--r--
201044_04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     1
/*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     2
* Copyright (c) 2006, 2007 Nokia Corporation and/or its subsidiary(-ies).
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     3
* All rights reserved.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     8
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     9
* Initial Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    11
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    12
* Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    13
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    14
* Description:  This class implements the dps script sending function. 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    15
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    16
*/
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    17
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    18
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    19
#include <f32file.h>
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    20
#include "dpsscriptsender.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    21
#include "dpsstatemachine.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    22
#include "pictbridge.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    23
#include "dpstransaction.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    24
#include "dpsfile.h"
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    25
#include "OstTraceDefinitions.h"
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    26
#ifdef OST_TRACE_COMPILER_IN_USE
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    27
#include "dpsscriptsenderTraces.h"
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    28
#endif
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    30
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    31
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    32
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    33
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    34
CDpsScriptSender* CDpsScriptSender::NewL(CDpsStateMachine* aOperator)
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    35
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    36
    CDpsScriptSender* self = new(ELeave) CDpsScriptSender(aOperator);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    37
    return self;	
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    38
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    39
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    40
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    41
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    42
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    43
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    44
CDpsScriptSender::CDpsScriptSender(CDpsStateMachine* aOperator) : 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    45
    CActive(EPriorityNormal), iOperator(aOperator), 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    46
    iReply(EFalse) 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    47
    {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    48
    OstTraceFunctionEntry0( CDPSSCRIPTSENDER_CDPSSCRIPTSENDER_CONS_ENTRY );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    49
    CActiveScheduler::Add(this);  
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    50
    OstTraceFunctionExit0( CDPSSCRIPTSENDER_CDPSSCRIPTSENDER_CONS_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    51
    }  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    52
  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    53
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    54
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    55
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    56
//	
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    57
CDpsScriptSender::~CDpsScriptSender()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    58
    {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    59
    OstTraceFunctionEntry0( DUP1_CDPSSCRIPTSENDER_CDPSSCRIPTSENDER_DES_ENTRY );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    60
    Cancel();
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    61
    OstTraceFunctionExit0( DUP1_CDPSSCRIPTSENDER_CDPSSCRIPTSENDER_DES_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    62
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    63
 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    64
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    65
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    66
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    67
//  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    68
TInt CDpsScriptSender::SendScript(TBool aReply)
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    69
    {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    70
    OstTraceFunctionEntry0( CDPSSCRIPTSENDER_SENDSCRIPT_ENTRY ); 
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    71
    if (!IsActive())
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    72
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    73
        iReply = aReply;  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    74
        TFileName file(iOperator->DpsEngine()->DpsFolder());
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    75
        RFile script;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    76
        if (aReply)
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    77
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    78
            file.Append(KDpsDeviceResponseFileName);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    79
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    80
        else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    81
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    82
            file.Append(KDpsDeviceRequestFileName);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    83
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    84
        TInt err = script.Open(iOperator->Trader()->
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    85
            FileHandle()->FileSession(), file, EFileRead);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    86
        if (err != KErrNone)
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    87
            {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
    88
            OstTraceFunctionExit0( CDPSSCRIPTSENDER_SENDSCRIPT_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    89
            return err;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    90
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    91
        TInt size;    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    92
        script.Size(size);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    93
        script.Close();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    94
        if (aReply)
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    95
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    96
            iOperator->DpsEngine()->
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    97
                Ptp().SendObject(file, iStatus, EFalse, size);       
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    98
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    99
        else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   100
            {            
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   101
            iOperator->DpsEngine()->
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   102
                Ptp().SendObject(file, iStatus, ETrue, size);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   103
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   104
        SetActive();    
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   105
	    OstTraceFunctionExit0( DUP1_CDPSSCRIPTSENDER_SENDSCRIPT_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   106
	    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   107
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   108
    else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   109
        {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   110
        OstTraceFunctionExit0( DUP2_CDPSSCRIPTSENDER_SENDSCRIPT_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   111
        return KErrInUse;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   112
        }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   113
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   114
 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   115
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   116
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   117
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   118
//
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   119
void CDpsScriptSender::RunL()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   120
    {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   121
    OstTraceFunctionEntry0( CDPSSCRIPTSENDER_RUNL_ENTRY );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   122
    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   123
    if (KErrNone == iStatus.Int())
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   124
        {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   125
        // the device request is sent
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   126
        if (!iReply)
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   127
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   128
            iOperator->ScriptSentNotifyL(EFalse);      
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   129
            }    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   130
        // the device response is sent    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   131
        else 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   132
            {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   133
            iOperator->ScriptSentNotifyL(ETrue);      
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   134
            }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   135
        }                
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   136
    else
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   137
    	{
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   138
        OstTrace1( TRACE_ERROR, CDPSSCRIPTSENDER_RUNL, "the iStatus is wrong %d!!!", iStatus.Int() );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   139
        iOperator->Error(iStatus.Int());
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   140
    	}
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   141
    OstTraceFunctionExit0( CDPSSCRIPTSENDER_RUNL_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   142
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   143
  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   144
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   145
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   146
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   147
//  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   148
void CDpsScriptSender::DoCancel()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   149
    {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   150
    OstTraceFunctionEntry0( CDPSSCRIPTSENDER_DOCANCEL_ENTRY );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   151
    iOperator->DpsEngine()->Ptp().CancelSendObject();
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   152
    OstTraceFunctionExit0( CDPSSCRIPTSENDER_DOCANCEL_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   153
    }
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   154
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   155
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   156
// 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   157
// ---------------------------------------------------------------------------
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   158
//	
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   159
TInt CDpsScriptSender::RunError(TInt aError)	
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   160
    {
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   161
    OstTraceFunctionEntry0( CDPSSCRIPTSENDER_RUNERROR_ENTRY );
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   162
    OstTraceDef1( OST_TRACE_CATEGORY_PRODUCTION, TRACE_IMPORTANT, CDPSSCRIPTSENDER_RUNERROR, 
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   163
            "error code %d", aError);
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   164
    Cancel();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   165
    iOperator->Error(aError);
49
c20dd21d1eb4 201035_05
hgs
parents: 29
diff changeset
   166
    OstTraceFunctionExit0( CDPSSCRIPTSENDER_RUNERROR_EXIT );
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   167
    return KErrNone;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   168
    }