1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera.captureintent.stateful;
18 
19 import javax.annotation.Nonnull;
20 
21 /**
22  * Defines a state machine interface that any implementation of this interface
23  * is able to transition among different {@link State} and process various
24  * {@link Event}.
25  */
26 public interface StateMachine {
27     /**
28      * Obtains the current state.
29      *
30      * @return A {@link State} object that represents the current state.
31      */
getCurrentState()32     public State getCurrentState();
33 
34     /**
35      * Sets the initial state of the state machine.
36      *
37      * @param initialState An initial {@link State}.
38      * @return True if the operation is succeeded.
39      */
setInitialState(@onnull State initialState)40     public boolean setInitialState(@Nonnull State initialState);
41 
42     /**
43      * Process a specified {@link Event} and potentially change the current
44      * state.
45      *
46      * This method is thread-safe so it could be called on different threads.
47      * Only one event could be processed at a time.
48      *
49      * @param event An {@link Event} to be processed.
50      */
processEvent(Event event)51     public void processEvent(Event event);
52 }
53