/* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef A_HIERARCHICAL_STATE_MACHINE_H_ #define A_HIERARCHICAL_STATE_MACHINE_H_ #include namespace android { struct AState : public RefBase { AState(const sp &parentState = NULL); sp parentState(); protected: virtual ~AState(); virtual void stateEntered(); virtual void stateExited(); virtual bool onMessageReceived(const sp &msg) = 0; private: friend struct AHierarchicalStateMachine; sp mParentState; DISALLOW_EVIL_CONSTRUCTORS(AState); }; struct AHierarchicalStateMachine { AHierarchicalStateMachine(); protected: virtual ~AHierarchicalStateMachine(); virtual void handleMessage(const sp &msg); // Only to be called in response to a message. void changeState(const sp &state); private: sp mState; DISALLOW_EVIL_CONSTRUCTORS(AHierarchicalStateMachine); }; } // namespace android #endif // A_HIERARCHICAL_STATE_MACHINE_H_