crashanalysis/crashanalyser/com.nokia.s60tools.crashanalyser/src/com/nokia/s60tools/crashanalyser/model/MobileCrashImporter.java
changeset 0 5ad7ad99af01
equal deleted inserted replaced
-1:000000000000 0:5ad7ad99af01
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.s60tools.crashanalyser.model;
       
    19 
       
    20 import org.eclipse.core.runtime.IProgressMonitor;
       
    21 import org.eclipse.core.runtime.IStatus;
       
    22 import org.eclipse.core.runtime.Status;
       
    23 import org.eclipse.core.runtime.jobs.Job;
       
    24 import com.nokia.s60tools.crashanalyser.corecomponents.interfaces.*;
       
    25 import com.nokia.s60tools.crashanalyser.files.*;
       
    26 import com.nokia.s60tools.crashanalyser.data.*;
       
    27 import com.nokia.s60tools.crashanalyser.ui.views.*;
       
    28 import java.io.*;
       
    29 
       
    30 /**
       
    31  * This class imports a mobilecrash file received via TraceViewer.
       
    32  *
       
    33  */
       
    34 public class MobileCrashImporter extends Job {
       
    35 
       
    36 	String traceDumpFolder = "";
       
    37 	String traceDumpFileName = "";
       
    38 	ErrorLibrary errorLibrary = null;
       
    39 	boolean decodeFile = false;
       
    40 	
       
    41 	/**
       
    42 	 * Constructor
       
    43 	 */
       
    44 	public MobileCrashImporter() {
       
    45 		super("Importing MobileCrash File via Trace Data");
       
    46 	}
       
    47 	
       
    48 	/**
       
    49 	 * Starts import process
       
    50 	 * @param dumpFolder folder where file received via Trace is
       
    51 	 * @param dumpFileName name of the trace file
       
    52 	 * @param library error library
       
    53 	 * @param decode if true, crash file is also decoded, if false, crash file is only imported as undecoded state
       
    54 	 */
       
    55 	public void importFrom(String dumpFolder, String dumpFileName, ErrorLibrary library, boolean decode) {
       
    56 		traceDumpFolder = FileOperations.addSlashToEnd(dumpFolder);
       
    57 		traceDumpFileName = dumpFileName;
       
    58 		decodeFile = decode;
       
    59 		errorLibrary = library;
       
    60 		setPriority(Job.LONG);
       
    61 		setUser(false);
       
    62 		schedule();		
       
    63 	}
       
    64 	
       
    65 	/**
       
    66 	 * Executes CrashAnalyser.exe with correct parameters
       
    67 	 */
       
    68 	void executeCrashAnalyserExe(IProgressMonitor monitor) {
       
    69 		CommandLineManager.executeSummary(traceDumpFolder, 
       
    70 											traceDumpFolder + traceDumpFileName, 
       
    71 											CrashAnalyserFile.SUMMARY_FILE_EXTENSION,
       
    72 											monitor);
       
    73 	}
       
    74 	
       
    75 	@Override
       
    76 	protected IStatus run(IProgressMonitor monitor) {
       
    77 		try {
       
    78 			// if we need to decoded the received crash file
       
    79 			if (decodeFile) {
       
    80 				executeCrashAnalyserExe(monitor);
       
    81 				File summaryFile = new File(traceDumpFolder + 
       
    82 											traceDumpFileName + 
       
    83 											"." + 
       
    84 											CrashAnalyserFile.SUMMARY_FILE_EXTENSION);
       
    85 				SummaryFile sf = SummaryFile.read(summaryFile, errorLibrary);
       
    86 				if (sf == null) {
       
    87 					MainView.showOrRefresh();
       
    88 				} else {
       
    89 					MainView.showOrRefreshAndOpenFile(sf);
       
    90 				}
       
    91 			// we did not need to decode the file, just refresh main view and the undecoded file is shown
       
    92 			} else {
       
    93 				MainView.showOrRefresh();
       
    94 			}
       
    95 			
       
    96 		} catch (Exception e){
       
    97 			e.printStackTrace();
       
    98 		}
       
    99 		
       
   100 		return Status.OK_STATUS;
       
   101 	}
       
   102 }