package artistmetrics.actions;

import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.debug.core.IExpressionManager;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IProcess;

public class DebugTracker {

	public static IBreakpointManager IBM;
	public static ILaunchManager ILM;
	public static IExpressionManager IEM;
	
	public User user;
/*Constructor*/
	/*
	 * Create a new log to store the debug detail, such as add/remove breakpoint
	 * and start and finish debug event.
	 * Create the IBreakpointManager to get all breakpoint events.
	 * Create ILaunchManager to get all debug launch events. 
	 */
	public DebugTracker(User user)
	{	
		this.user = user;
		IBM = DebugPlugin.getDefault().getBreakpointManager(); 
		IBM.addBreakpointListener(new DebugBreakListener(this,IBM));
		ILM = DebugPlugin.getDefault().getLaunchManager();
		ILM.addLaunchListener(new DebugLaunchListener(this,ILM));
		IEM = DebugPlugin.getDefault().getExpressionManager();
		IEM.addExpressionListener(new DebugExpressionListener(this,IEM));
	}
	/*
	 * Write the event messages to the debugger event log.
	 * Currently it's writing to the log when some states changes. 
	 *
	 *	Maybe it's a good idea to store all the information and write to the log all at once
	 * when user are logging off.... 
	 */
	/*
	 * This is the old method that will get all the proccess for each launch
	 * This method is no longer be call, I just put here just incase need in the
	 * future
	 * 
	 */
	public void printAllLaunch()
	{
		try
		{
			ILaunch[] IL = ILM.getLaunches();
			for(int index = 0; index < IL.length; index++)
			{
				ILaunch ILL = IL[index];
				IProcess[] ip = ILL.getProcesses();
				for(int index1= 0;index1< ip.length; index1++)
				{
					/* got the time when this process end!!!!*/
					System.out.println("process: " + ip[index1].getLabel() );
				}
			}
		}
		catch(Exception e)
		{
			System.out.println("Error!!!!");
			System.out.println("In printAllLaunch: " + e.getMessage());
		}
	}
}
