Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.state.model; | |
13 | ||
14 | import java.util.Stack; | |
15 | ||
16 | import org.eclipse.linuxtools.lttng.state.StateStrings; | |
17 | import org.eclipse.linuxtools.lttng.state.StateStrings.IRQMode; | |
18 | ||
19 | /** | |
20 | * <b><u>LttvIRQState</u></b> | |
21 | * @author alvaro | |
22 | * | |
23 | */ | |
24 | public class LttngIRQState implements Cloneable { | |
25 | // ======================================================================== | |
26 | // Data | |
27 | // ======================================================================= | |
28 | private Stack<StateStrings.IRQMode> mode_stack = new Stack<StateStrings.IRQMode>(); | |
29 | ||
30 | // ======================================================================== | |
31 | // Constructor | |
32 | // ======================================================================= | |
33 | public LttngIRQState() { | |
34 | mode_stack.push(IRQMode.LTTV_IRQ_UNKNOWN); | |
35 | } | |
36 | ||
cc6eec3e | 37 | @Override |
5d10d135 ASL |
38 | @SuppressWarnings("unchecked") |
39 | public LttngIRQState clone() { | |
40 | LttngIRQState newState = null; | |
41 | ||
42 | try { | |
43 | newState = (LttngIRQState)super.clone(); | |
44 | ||
45 | // Clone should work correctly for all stack object that contain basic java object (String, Long, etc...) | |
46 | newState.mode_stack = (Stack<StateStrings.IRQMode>)this.mode_stack.clone(); | |
47 | } | |
48 | catch ( CloneNotSupportedException e ) { | |
9c4eb5f7 | 49 | System.out.println("Cloning failed with : " + e.getMessage() ); //$NON-NLS-1$ |
5d10d135 ASL |
50 | } |
51 | ||
52 | return newState; | |
53 | } | |
54 | ||
55 | // ======================================================================== | |
56 | // Methods | |
57 | // ======================================================================= | |
58 | public void clearIrqStack() { | |
59 | mode_stack.clear(); | |
60 | } | |
61 | ||
62 | public void clearAndSetBaseToIrqStack(StateStrings.IRQMode newState) { | |
63 | mode_stack.clear(); | |
64 | // Ensure that there is always at least 1 item in the stack | |
65 | mode_stack.push(newState); | |
66 | } | |
67 | ||
68 | public void pushToIrqStack(StateStrings.IRQMode newState) { | |
69 | mode_stack.push(newState); | |
70 | } | |
71 | ||
72 | public StateStrings.IRQMode popFromIrqStack() { | |
73 | ||
74 | StateStrings.IRQMode returnedMode = mode_stack.pop(); | |
75 | if (mode_stack.size() < 1) { | |
76 | mode_stack.push(IRQMode.LTTV_IRQ_UNKNOWN); | |
77 | } | |
78 | ||
79 | return returnedMode; | |
80 | } | |
81 | ||
82 | public StateStrings.IRQMode peekFromIrqStack() { | |
83 | return mode_stack.peek(); | |
84 | } | |
85 | } |