1/*
2 * Copyright (C) 2010 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#ifndef A_HIERARCHICAL_STATE_MACHINE_H_
18
19#define A_HIERARCHICAL_STATE_MACHINE_H_
20
21#include <media/stagefright/foundation/AHandler.h>
22
23namespace android {
24
25struct AState : public RefBase {
26    AState(const sp<AState> &parentState = NULL);
27
28    sp<AState> parentState();
29
30protected:
31    virtual ~AState();
32
33    virtual void stateEntered();
34    virtual void stateExited();
35
36    virtual bool onMessageReceived(const sp<AMessage> &msg) = 0;
37
38private:
39    friend struct AHierarchicalStateMachine;
40
41    sp<AState> mParentState;
42
43    DISALLOW_EVIL_CONSTRUCTORS(AState);
44};
45
46struct AHierarchicalStateMachine {
47    AHierarchicalStateMachine();
48
49protected:
50    virtual ~AHierarchicalStateMachine();
51
52    virtual void handleMessage(const sp<AMessage> &msg);
53
54    // Only to be called in response to a message.
55    void changeState(const sp<AState> &state);
56
57private:
58    sp<AState> mState;
59
60    DISALLOW_EVIL_CONSTRUCTORS(AHierarchicalStateMachine);
61};
62
63}  // namespace android
64
65#endif  // A_HIERARCHICAL_STATE_MACHINE_H_
66