1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.state
.model
;
14 import java
.util
.Stack
;
16 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.BdevMode
;
20 * <b><u>LttvBdevState</u></b>
24 public class LttngBdevState
implements Cloneable
{
25 // ========================================================================
27 // =======================================================================
28 private Stack
<BdevMode
> mode_stack
= new Stack
<BdevMode
>() ;
31 // ========================================================================
33 // =======================================================================
34 public LttngBdevState() {
35 mode_stack
.push(BdevMode
.LTTV_BDEV_UNKNOWN
);
38 // ========================================================================
40 // =======================================================================
41 public void clearBdevStack() {
45 public void clearAndSetBaseToBdevStack(BdevMode newState
) {
47 // Ensure that there is always at least 1 item in the stack
48 mode_stack
.push(newState
);
51 public void pushToBdevStack(BdevMode newState
) {
52 mode_stack
.push(newState
);
55 public BdevMode
popFromBdevStack() {
57 BdevMode returnedMode
= mode_stack
.pop();
59 if (mode_stack
.size() < 1) {
60 TraceDebug
.debug("Removing last item from mode stack is not allowed! (popFromModeStack)"); //$NON-NLS-1$
61 mode_stack
.push(BdevMode
.LTTV_BDEV_UNKNOWN
);
67 public BdevMode
peekFromBdevStack() {
68 return mode_stack
.peek();
73 @SuppressWarnings("unchecked")
74 public LttngBdevState
clone() {
75 LttngBdevState newState
= null;
78 newState
= (LttngBdevState
)super.clone();
79 // Clone should work correctly for all stack object that contain basic java object (String, Long, etc...)
80 newState
.mode_stack
= (Stack
<BdevMode
>)this.mode_stack
.clone();
82 catch ( CloneNotSupportedException e
) {
83 System
.out
.println("Cloning failed with : " + e
.getMessage() ); //$NON-NLS-1$