trace/traceanalyser/com.nokia.s60tools.traceanalyser/src/com/nokia/s60tools/traceanalyser/model/Engine.java
changeset 9 14dc2103a631
equal deleted inserted replaced
8:15296fd0af4a 9:14dc2103a631
       
     1 /*
       
     2 * Copyright (c) 2009 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 
       
    19 package com.nokia.s60tools.traceanalyser.model;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 
       
    23 import org.eclipse.core.runtime.IConfigurationElement;
       
    24 import org.eclipse.core.runtime.IExtension;
       
    25 import org.eclipse.core.runtime.IExtensionPoint;
       
    26 import org.eclipse.core.runtime.IExtensionRegistry;
       
    27 import org.eclipse.core.runtime.Platform;
       
    28 
       
    29 
       
    30 import com.nokia.s60tools.traceanalyser.containers.RuleInformation;
       
    31 import com.nokia.s60tools.traceanalyser.export.ITraceAnalyserRuleType;
       
    32 import com.nokia.s60tools.traceanalyser.export.RuleEvent;
       
    33 import com.nokia.s60tools.traceanalyser.export.TraceAnalyserRule;
       
    34 import com.nokia.s60tools.traceanalyser.interfaces.ITraceAnalyserFileObserver;
       
    35 import com.nokia.s60tools.traceanalyser.plugin.TraceAnalyserPlugin;
       
    36 import com.nokia.s60tools.traceanalyser.ui.views.MainView;
       
    37 
       
    38 /**
       
    39  * class engine.
       
    40  * Engine of Trace Analyser extension.
       
    41  */
       
    42 
       
    43 public class Engine implements ITraceAnalyserFileObserver {
       
    44 	
       
    45 	/* Fail Log Manager */
       
    46 	private FailLogManager failLogManager;
       
    47 	
       
    48 	/* Rule Manager */
       
    49 	private RuleManager ruleManager;	
       
    50 	
       
    51 	/* Trace Listener */
       
    52 	private TraceListener traceListener;
       
    53 	
       
    54 	/* list of rule types */
       
    55 	ArrayList<ITraceAnalyserRuleType> ruleTypes;
       
    56 	
       
    57 	/* Main view */
       
    58 	MainView mainView;
       
    59 	
       
    60 	/**
       
    61 	 * Engine.
       
    62 	 * constructor.
       
    63 	 */
       
    64 	public Engine(){
       
    65 		
       
    66 		// Get rule types
       
    67 		ruleTypes = new ArrayList<ITraceAnalyserRuleType>();
       
    68 		getRuleTypeArray();
       
    69 		
       
    70 		// create fail log manager
       
    71 		failLogManager = new FailLogManager(this);
       
    72 		
       
    73 		// create rule manager
       
    74 		ruleManager = new RuleManager(this, ruleTypes);
       
    75 		
       
    76 		// create trace listener
       
    77 		traceListener = new TraceListener(this);
       
    78 		
       
    79 		// refresh fail log and rule information.
       
    80 		failLogManager.refresh();
       
    81 		ruleManager.refresh();
       
    82 	}
       
    83 
       
    84 	/**
       
    85 	 * setMainView.
       
    86 	 * @param mainView main view.
       
    87 	 */
       
    88 	public void setMainView(MainView mainView){
       
    89 		this.mainView = mainView;
       
    90 	}
       
    91 
       
    92 
       
    93 	/**
       
    94 	 * getRuleArray.
       
    95 	 * Searches for rule type plug-ins and creates rule array from them.
       
    96 	 */
       
    97 	private void getRuleTypeArray(){
       
    98 
       
    99 		final String EXTENSION_TRACE_ANALYSER_RULE = "traceanalyserrule"; //$NON-NLS-1$
       
   100 
       
   101 		try {
       
   102 			IExtensionRegistry er = Platform.getExtensionRegistry();
       
   103 			IExtensionPoint ep = 
       
   104 				er.getExtensionPoint(TraceAnalyserPlugin.PLUGIN_ID, EXTENSION_TRACE_ANALYSER_RULE);
       
   105 			IExtension[] extensions = ep.getExtensions();
       
   106 
       
   107 			// if plug-ins were found.
       
   108 			if (extensions != null && extensions.length > 0) {
       
   109 				
       
   110 				// read all found rules
       
   111 				for (int i = 0; i < extensions.length; i++) {
       
   112 					IConfigurationElement[] ce = extensions[i].getConfigurationElements();
       
   113 					if (ce != null && ce.length > 0) {
       
   114 						try {
       
   115 							ITraceAnalyserRuleType provider = (ITraceAnalyserRuleType)ce[0].createExecutableExtension("class");
       
   116 							if (provider != null) {
       
   117 								ruleTypes.add(provider);
       
   118 							}
       
   119 						} catch (Exception e) {
       
   120 							e.printStackTrace();
       
   121 						}
       
   122 					}
       
   123 				}
       
   124 			}
       
   125 		} catch (Exception e) {
       
   126 			e.printStackTrace();
       
   127 		}
       
   128 	}
       
   129 	
       
   130 	/**
       
   131 	 * getFailLog
       
   132 	 * @return fail log
       
   133 	 */
       
   134 	public RuleEvent[] getFailLog(){
       
   135 		return failLogManager.getTraceAnalyserFailLog();
       
   136 	}
       
   137 	
       
   138 	/**
       
   139 	 * refreshFailLog.
       
   140 	 * Refreshes Fail log
       
   141 	 */
       
   142 	public void refreshFailLog(){
       
   143 		failLogManager.refresh();
       
   144 	}
       
   145 	
       
   146 	/**
       
   147 	 * clearFailLog.
       
   148 	 * Clears fail log.
       
   149 	 */
       
   150 	public void clearFailLog(){
       
   151 		failLogManager.clearLog();
       
   152 	}
       
   153 	
       
   154 	/**
       
   155 	 * addFailLogItem.
       
   156 	 * @param item, new fail log item.
       
   157 	 */
       
   158 	public void addFailLogItem(RuleEvent item){
       
   159 		failLogManager.addItem(item);
       
   160 		if(mainView != null){
       
   161 			mainView.blinkIcon();
       
   162 		}
       
   163 	}
       
   164 
       
   165 	/**
       
   166 	 * stop.
       
   167 	 * Stops Trace Analyser Engine.
       
   168 	 */
       
   169 	public void stop(){
       
   170 		failLogManager.saveLogToFile();
       
   171 		ruleManager.saveData();
       
   172 		traceListener.stopListening();
       
   173 	}
       
   174 
       
   175 	/*
       
   176 	 * (non-Javadoc)
       
   177 	 * @see com.nokia.s60tools.traceanalyser.interfaces.ITraceAnalyserFileObserver#failLogUpdated()
       
   178 	 */
       
   179 	public void failLogUpdated() {
       
   180 		if(mainView != null){
       
   181 			mainView.failLogUpdated();
       
   182 		}
       
   183 	}
       
   184 
       
   185 	/*
       
   186 	 * (non-Javadoc)
       
   187 	 * @see com.nokia.s60tools.traceanalyser.interfaces.ITraceAnalyserFileObserver#rulesUpdated()
       
   188 	 */
       
   189 	public void rulesUpdated() {
       
   190 		TraceAnalyserRule[] rules = ruleManager.getActivatedRules();
       
   191 		traceListener.setRules(rules);
       
   192 		if(mainView != null){
       
   193 			mainView.rulesUpdated();
       
   194 		}
       
   195 	}
       
   196 	
       
   197 	/*
       
   198 	 * (non-Javadoc)
       
   199 	 * @see com.nokia.s60tools.traceanalyser.interfaces.ITraceAnalyserFileObserver#ruleUpdated(java.lang.String)
       
   200 	 */
       
   201 	public void ruleUpdated(String ruleName) {
       
   202 		if(mainView != null){
       
   203 			mainView.ruleUpdated(ruleName);
       
   204 		}
       
   205 	}
       
   206 	
       
   207 	/**
       
   208 	 * refreshRuleList.
       
   209 	 * Refreshes rule list. 
       
   210 	 */
       
   211 	public void refreshRuleList(){
       
   212 		ruleManager.refresh();
       
   213 	}
       
   214 
       
   215 	/**
       
   216 	 * getRuleInformation.
       
   217 	 * @return Trace analyser rules.
       
   218 	 */
       
   219 	public RuleInformation[] getRuleInformation(){
       
   220 		return ruleManager.getRuleInformation();
       
   221 	}
       
   222 
       
   223 	/**
       
   224 	 * getRule.
       
   225 	 * returns one rule.
       
   226 	 * @param ruleName name of the rule that is requested.
       
   227 	 * @return rule
       
   228 	 */
       
   229 	public TraceAnalyserRule getRule(String ruleName){
       
   230 		return ruleManager.getRule(ruleName);
       
   231 	}
       
   232 	
       
   233 	/**
       
   234 	 * getRuleTypes.
       
   235 	 * @return Trace Analyser Rule Types
       
   236 	 */
       
   237 	public ArrayList<ITraceAnalyserRuleType> getRuleTypes() {
       
   238 		return ruleTypes;
       
   239 	}
       
   240 	
       
   241 	/**
       
   242 	 * addRule.
       
   243 	 * @param newRule new Trace Analyser rule
       
   244 	 * @return true if rule was added succesfully.
       
   245 	 */
       
   246 	public boolean addRule(TraceAnalyserRule newRule){
       
   247 		boolean retval = ruleManager.addRule(newRule);
       
   248 		traceListener.setRules(ruleManager.getActivatedRules());
       
   249 		return retval;
       
   250 	}
       
   251 	
       
   252 	
       
   253 	/**
       
   254 	 * getTraceListener.
       
   255 	 * @return trace listener
       
   256 	 */
       
   257 	public TraceListener getTraceListener() {
       
   258 		return traceListener;
       
   259 	}
       
   260 
       
   261 	/**
       
   262 	 * changeRuleaActivation.
       
   263 	 * @param ruleName name of the rule
       
   264 	 */
       
   265 	public void changeRuleaActivation(String ruleName, boolean value){
       
   266 		ruleManager.changeRuleActivation(ruleName, value);
       
   267 		TraceAnalyserRule[] rules = ruleManager.getActivatedRules();
       
   268 		traceListener.setRules(rules);
       
   269 	}
       
   270 	/**
       
   271 	 * removeRule
       
   272 	 * @param ruleName rule that should be removed.
       
   273 	 * @return true if rule was removed successfully.
       
   274 	 */
       
   275 	public boolean removeRule(String ruleName){
       
   276 		return ruleManager.removeRule(ruleName);
       
   277 	}
       
   278 	
       
   279 	/**
       
   280 	 * addRuleEvent.
       
   281 	 * @param ruleName name of rule where event is added.
       
   282 	 * @param event rule that event is added into.
       
   283 	 */
       
   284 	public void addRuleEvent(String ruleName, RuleEvent event){
       
   285 		ruleManager.addHistoryEvent(ruleName, event);
       
   286 	}
       
   287 
       
   288 	/**
       
   289 	 * resets all rules history data.
       
   290 	 */
       
   291 	public void resetHistory(){
       
   292 		ruleManager.clearHistory();
       
   293 	}
       
   294 	
       
   295 	/**
       
   296 	 * resets one rules history.
       
   297 	 * @param ruleName
       
   298 	 */
       
   299 	public void resetOneRulesHistory(String ruleName){
       
   300 		ruleManager.clearOneRulesHistory(ruleName);
       
   301 	}
       
   302 	
       
   303 	/**
       
   304 	 * ruleExists.
       
   305 	 * @param ruleName name of the rule
       
   306 	 * @return true if rule with that name already exists
       
   307 	 */
       
   308 
       
   309 	public boolean ruleExists(String ruleName){
       
   310 		return ruleManager.ruleExists(ruleName);
       
   311 	}
       
   312 	
       
   313 	
       
   314 }