1 /** 2 * Copyright (C) 2011 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.internal.util; 18 19 import android.os.Message; 20 21 /** 22 * {@hide} 23 * 24 * The interface for implementing states in a {@link StateMachine} 25 */ 26 public interface IState { 27 28 /** 29 * Returned by processMessage to indicate the the message was processed. 30 */ 31 static final boolean HANDLED = true; 32 33 /** 34 * Returned by processMessage to indicate the the message was NOT processed. 35 */ 36 static final boolean NOT_HANDLED = false; 37 38 /** 39 * Called when a state is entered. 40 */ enter()41 void enter(); 42 43 /** 44 * Called when a state is exited. 45 */ exit()46 void exit(); 47 48 /** 49 * Called when a message is to be processed by the 50 * state machine. 51 * 52 * This routine is never reentered thus no synchronization 53 * is needed as only one processMessage method will ever be 54 * executing within a state machine at any given time. This 55 * does mean that processing by this routine must be completed 56 * as expeditiously as possible as no subsequent messages will 57 * be processed until this routine returns. 58 * 59 * @param msg to process 60 * @return HANDLED if processing has completed and NOT_HANDLED 61 * if the message wasn't processed. 62 */ processMessage(Message msg)63 boolean processMessage(Message msg); 64 65 /** 66 * Name of State for debugging purposes. 67 * 68 * @return name of state. 69 */ getName()70 String getName(); 71 } 72