crashanalysis/crashanalyser/com.nokia.s60tools.crashanalyser/src/com/nokia/s60tools/crashanalyser/model/CrashFileBundle.java
changeset 4 615035072f7e
parent 0 5ad7ad99af01
equal deleted inserted replaced
3:431bbaccaec8 4:615035072f7e
    16 */
    16 */
    17 
    17 
    18 package com.nokia.s60tools.crashanalyser.model;
    18 package com.nokia.s60tools.crashanalyser.model;
    19 
    19 
    20 import com.nokia.s60tools.crashanalyser.files.*;
    20 import com.nokia.s60tools.crashanalyser.files.*;
       
    21 import com.nokia.s60tools.crashanalyser.files.SummaryFile.ContentType;
    21 import com.nokia.s60tools.crashanalyser.data.*;
    22 import com.nokia.s60tools.crashanalyser.data.*;
       
    23 import com.nokia.s60tools.crashanalyser.containers.Thread;
    22 import java.io.*;
    24 import java.io.*;
       
    25 import java.util.List;
    23 
    26 
    24 /**
    27 /**
    25  * CrashFileBundle class bundles up one folder under Crash Analyser plugin's folder. I.e. one
    28  * CrashFileBundle class bundles up one folder under Crash Analyser plugin's folder. I.e. one
    26  * CrashFileBundle is one row in MainView. A bundle can contain an undecoded MobileCrash file, 
    29  * CrashFileBundle is one row in MainView. A bundle can contain an undecoded MobileCrash file, 
    27  * decoded .crashxml file, partially decoded .crashxml file or an emulator panic xml file. Or a 
    30  * decoded .crashxml file, partially decoded .crashxml file or an emulator panic xml file. Or a 
    33  * 
    36  * 
    34  * Bundle can also be an empty bundle, so that 'No crash files found' row can be shown in MainView.
    37  * Bundle can also be an empty bundle, so that 'No crash files found' row can be shown in MainView.
    35  * 
    38  * 
    36  * Bundle can also be a waiting bundle, so that 'Loading files. Please wait' row can be shown in MainView.
    39  * Bundle can also be a waiting bundle, so that 'Loading files. Please wait' row can be shown in MainView.
    37  *
    40  *
       
    41  * Bundle can also be a thread bundle. That is a row in the MainView 
       
    42  * which has no crash (i.e. a child in the treeview)
    38  */
    43  */
    39 public class CrashFileBundle {
    44 public class CrashFileBundle {
    40 
    45 
    41 	public static final int INDEX_TIME = 0;
    46 	public static final int INDEX_TIME = 0;
    42 	public static final int INDEX_THREAD = 1;
    47 	public static final int INDEX_THREAD = 1;
    77 	
    82 	
    78 	/**
    83 	/**
    79 	 * If true, bundle is an empty or waiting bundle
    84 	 * If true, bundle is an empty or waiting bundle
    80 	 */
    85 	 */
    81 	boolean emptyFile = false;
    86 	boolean emptyFile = false;
       
    87 	
       
    88 	/**
       
    89 	 * If true, bundle is a thread bundle
       
    90 	 */
       
    91 	private boolean threadBundle = false;
       
    92 
    82 	
    93 	
    83 	/**
    94 	/**
    84 	 * Directory from where files in this bundle originally came from.
    95 	 * Directory from where files in this bundle originally came from.
    85 	 * This data is not always present.
    96 	 * This data is not always present.
    86 	 */
    97 	 */
   125 	 * Initialise bundle with already read Summary file
   136 	 * Initialise bundle with already read Summary file
   126 	 * @param file summary file
   137 	 * @param file summary file
   127 	 */
   138 	 */
   128 	public CrashFileBundle(SummaryFile file, String originalDirectory) {
   139 	public CrashFileBundle(SummaryFile file, String originalDirectory) {
   129 		summaryFile = file;
   140 		summaryFile = file;
       
   141 		originatingDirectory = originalDirectory;
       
   142 	}
       
   143 
       
   144 	/**
       
   145 	 * Initialise bundle with already read Crash file
       
   146 	 * @param file crash file
       
   147 	 */
       
   148 	public CrashFileBundle(CrashFile file, String originalDirectory, Thread thread) {
       
   149 		threadBundle = true;
       
   150 		crashxmlFile = (CrashFile) file.clone();
       
   151 		crashxmlFile.setThread(thread);
       
   152 		crashxmlFile.formatDescription();
       
   153 		originatingDirectory = originalDirectory;
       
   154 	}
       
   155 	
       
   156 	/**
       
   157 	 * Initialise bundle with already read Summary file
       
   158 	 * @param file summary file
       
   159 	 */
       
   160 	public CrashFileBundle(SummaryFile file, String originalDirectory, Thread thread) {
       
   161 		threadBundle = true;
       
   162 		summaryFile = (CrashFile) file.clone();
       
   163 		summaryFile.setThread(thread);
       
   164 		summaryFile.formatDescription();
   130 		originatingDirectory = originalDirectory;
   165 		originatingDirectory = originalDirectory;
   131 	}
   166 	}
   132 
   167 
   133 	protected CrashFileBundle(String folder) {
   168 	protected CrashFileBundle(String folder) {
   134 		bundleFolder = FileOperations.addSlashToEnd(folder);
   169 		bundleFolder = FileOperations.addSlashToEnd(folder);
   197 		} else if (summaryFile != null) {
   232 		} else if (summaryFile != null) {
   198 			retval = summaryFile.getFileName();
   233 			retval = summaryFile.getFileName();
   199 		} else if (emulatorPanicFile != null) {
   234 		} else if (emulatorPanicFile != null) {
   200 			retval = "Emulator Panic";
   235 			retval = "Emulator Panic";
   201 		}
   236 		}
       
   237 
   202 		return retval;
   238 		return retval;
   203 	}
   239 	}
   204 	
   240 	
   205 	/**
   241 	/**
   206 	 * Returns the name of .crashxml or .xml file is they exists
   242 	 * Returns the name of .crashxml or .xml file is they exists
   210 		String retval = "";
   246 		String retval = "";
   211 		if (crashxmlFile != null) {
   247 		if (crashxmlFile != null) {
   212 			retval = crashxmlFile.getFileName();
   248 			retval = crashxmlFile.getFileName();
   213 		} else if (summaryFile != null) {
   249 		} else if (summaryFile != null) {
   214 			retval = summaryFile.getFileName();
   250 			retval = summaryFile.getFileName();
   215 		}
   251 		} 
       
   252 
   216 		return retval;
   253 		return retval;
   217 	}
   254 	}
   218 
   255 
   219 	/**
   256 	/**
   220 	 * Returns the panic code of this bundle. Panic code is available 
   257 	 * Returns the panic code of this bundle. Panic code is available 
   231 			retval = crashxmlFile.getPanicCode();
   268 			retval = crashxmlFile.getPanicCode();
   232 		} else if (summaryFile != null) {
   269 		} else if (summaryFile != null) {
   233 			retval = summaryFile.getPanicCode();
   270 			retval = summaryFile.getPanicCode();
   234 		} else if (emulatorPanicFile != null) {
   271 		} else if (emulatorPanicFile != null) {
   235 			retval = emulatorPanicFile.getPanicCode();
   272 			retval = emulatorPanicFile.getPanicCode();
   236 		}
   273 		} else if (threadBundle) {
       
   274 			retval = "";
       
   275 		}
       
   276 			
   237 		
   277 		
   238 		return retval;
   278 		return retval;
   239 	}
   279 	}
   240 
   280 
   241 	/**
   281 	/**
   247 	public String getPanicCategory() {
   287 	public String getPanicCategory() {
   248 		if (emptyFile)
   288 		if (emptyFile)
   249 			return "";
   289 			return "";
   250 		
   290 		
   251 		String retval = "";
   291 		String retval = "";
       
   292 
   252 		if (crashxmlFile != null) {
   293 		if (crashxmlFile != null) {
   253 			retval = crashxmlFile.getPanicCategory();
   294 			retval = crashxmlFile.getPanicCategory();
   254 		} else if (summaryFile != null) {
   295 		} else if (summaryFile != null) {
   255 			retval = summaryFile.getPanicCategory();
   296 			retval = summaryFile.getPanicCategory();
   256 		} else if (emulatorPanicFile != null) {
   297 		} else if (emulatorPanicFile != null) {
   257 			retval = emulatorPanicFile.getPanicCategory();
   298 			retval = emulatorPanicFile.getPanicCategory();
   258 		} else if (undecodedFile != null) {
   299 		} else if (undecodedFile != null) {
   259 			retval = "Unknown";
   300 			retval = "Unknown";
   260 		}
   301 		} 
   261 		
   302 		
   262 		return retval;
   303 		return retval;
   263 	}
   304 	}
   264 	
   305 	
   265 	/**
   306 	/**
   271 	public String getThreadName() {
   312 	public String getThreadName() {
   272 		if (emptyFile)
   313 		if (emptyFile)
   273 			return "";
   314 			return "";
   274 		
   315 		
   275 		String retval = "";
   316 		String retval = "";
   276 		if (crashxmlFile != null) {
   317 		if (threadBundle && crashxmlFile != null) {
       
   318 			retval = crashxmlFile.getThread().getFullName();
       
   319 		} else if (threadBundle && summaryFile != null) {
       
   320 			retval = summaryFile.getThread().getFullName();
       
   321 		}else if (crashxmlFile != null) {
   277 			retval = crashxmlFile.getThreadName();
   322 			retval = crashxmlFile.getThreadName();
   278 		} else if (summaryFile != null) {
   323 		} else if (summaryFile != null) {
   279 			retval = summaryFile.getThreadName();
   324 			retval = summaryFile.getThreadName();
   280 		} else if (emulatorPanicFile != null) {
   325 		} else if (emulatorPanicFile != null) {
   281 			retval = emulatorPanicFile.getThreadName();
   326 			retval = emulatorPanicFile.getThreadName();
   282 		} else if (undecodedFile != null) {
   327 		} else if (undecodedFile != null) {
   283 			retval = "Unknown";
   328 			retval = "Unknown";
   284 		}
   329 		} 
   285 		
   330 
   286 		return retval;
   331 		return retval;
   287 	}
   332 	}
   288 	
   333 
       
   334 	/**
       
   335 	 * Returns the total thread count (all threads in all processes).
       
   336 	 * Thread count is available
       
   337 	 * only if bundle contains decoded files or emulator panic.
       
   338 	 * 
       
   339 	 * @return thread count or -1 if not available
       
   340 	 */
       
   341 	public int getTotalThreadCount() {
       
   342 		if (emptyFile)
       
   343 			return -1;
       
   344 		
       
   345 		if (threadBundle) {
       
   346 			return 1;
       
   347 		}
       
   348 		
       
   349 		int retval = -1;
       
   350 		if (crashxmlFile != null) {
       
   351 			retval = crashxmlFile.getTotalThreadCount();
       
   352 		} else if (summaryFile != null) {
       
   353 			retval = summaryFile.getTotalThreadCount();
       
   354 		} else if (emulatorPanicFile != null) {
       
   355 			retval = emulatorPanicFile.getTotalThreadCount();
       
   356 		} else if (undecodedFile != null) {
       
   357 			retval = -1;
       
   358 		}
       
   359 		
       
   360 		return retval;
       
   361 	}
       
   362 
       
   363 	/**
       
   364 	 * Returns the threads in this crash file (all threads in all processes).
       
   365 	 * 
       
   366 	 * @return thread count or -1 if not available
       
   367 	 */
       
   368 	public List<Thread> getThreads() {
       
   369 		if (emptyFile || threadBundle)
       
   370 			return null;
       
   371 		
       
   372 		if (crashxmlFile != null) {
       
   373 			return crashxmlFile.getThreads();
       
   374 		} else if (summaryFile != null) {
       
   375 			return summaryFile.getThreads();
       
   376 		} else if (emulatorPanicFile != null) {
       
   377 			return emulatorPanicFile.getThreads();
       
   378 		}
       
   379 		return null;
       
   380 	}
       
   381 
   289 	/**
   382 	/**
   290 	 * Returns the time of a crash. Crash time is not always available
   383 	 * Returns the time of a crash. Crash time is not always available
   291 	 * (even in decoded crash files).  If crash time is not available,  
   384 	 * (even in decoded crash files).  If crash time is not available,  
   292 	 * the creation time of the crash file is returned.
   385 	 * the creation time of the crash file is returned.
   293 	 * 
   386 	 * 
   327 			retval = undecodedFile.getCreated();
   420 			retval = undecodedFile.getCreated();
   328 		} else if (emulatorPanicFile != null) {
   421 		} else if (emulatorPanicFile != null) {
   329 			retval = emulatorPanicFile.getTime();
   422 			retval = emulatorPanicFile.getTime();
   330 			if ("".equals(retval))
   423 			if ("".equals(retval))
   331 				retval = emulatorPanicFile.getCreated();
   424 				retval = emulatorPanicFile.getCreated();
   332 		}
   425 		} 
   333 		
   426 
   334 		return retval;
   427 		return retval;
   335 	}
   428 	}
   336 	
   429 	
   337 	/**
   430 	/**
   338 	 * Returns the crash files ROM ID if available.
   431 	 * Returns the crash files ROM ID if available.
   390 			return true;
   483 			return true;
   391 		
   484 		
   392 		return false;
   485 		return false;
   393 	}
   486 	}
   394 	
   487 	
       
   488 	/**
       
   489 	 * Returns whether this bundle is a thread bundle.
       
   490 	 * @return true if this bundle is a thread bundle.
       
   491 	 */
       
   492 	public boolean isThread() {
       
   493 		return threadBundle;
       
   494 	}
       
   495 	
       
   496 
   395 	/**
   497 	/**
   396 	 * Returns whether this bundle contains any files.
   498 	 * Returns whether this bundle contains any files.
   397 	 * @return true if bundle contains files, false if not
   499 	 * @return true if bundle contains files, false if not
   398 	 */
   500 	 */
   399 	public boolean hasFiles() {
   501 	public boolean hasFiles() {
   507 	 * @return file description
   609 	 * @return file description
   508 	 */
   610 	 */
   509 	public String getDescription(boolean full) {
   611 	public String getDescription(boolean full) {
   510 		if (isEmpty())
   612 		if (isEmpty())
   511 			return "";
   613 			return "";
   512 			
   614 		
       
   615 		if ((crashxmlFile != null && crashxmlFile.getContentType() == ContentType.REGMSG) ||
       
   616 			(summaryFile  != null && summaryFile.getContentType()  == ContentType.REGMSG )) {
       
   617 			return HtmlFormatter.formatRegistrationMessage();
       
   618 		} else if ((crashxmlFile != null && crashxmlFile.getContentType() == ContentType.REPORT) ||
       
   619 				   (summaryFile  != null && summaryFile.getContentType()  == ContentType.REPORT )) {
       
   620 			return HtmlFormatter.formatReport();
       
   621 		}
       
   622 		
   513 		if (crashxmlFile != null) {
   623 		if (crashxmlFile != null) {
   514 			if (full)
   624 			if (full)
   515 				return crashxmlFile.getDescription();
   625 				return crashxmlFile.getDescription();
   516 			else
   626 			else
   517 				return crashxmlFile.getShortDescription();
   627 				return crashxmlFile.getShortDescription();