2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.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
8 * http://floralicense.org/license/
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.
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
23 #include "IBoxState.h"
24 #include "IBoxContext.h"
27 #define CHECK_BOX_STATE(currentState, operation) \
30 state = currentState->operation(); \
35 #define SWITCH_BOX_STATE() \
36 state->switchState() \
39 #define CHECK_BOX_STATE(currentState, operation)
40 #define SWITCH_BOX_STATE()
42 class BoxState: public IBoxState {
44 virtual IBoxStatePtr permitShow() { throw this; };
45 virtual IBoxStatePtr permitHide() { throw this; };
46 virtual IBoxStatePtr permitResume() { throw this; };
47 virtual IBoxStatePtr permitPause() { throw this; };
48 virtual IBoxStatePtr permitOpenPd() { throw this; };
49 virtual IBoxStatePtr permitClosePd() { throw this ; };
50 virtual IBoxStatePtr permitShutdown() { throw this; };
51 virtual void switchState();
52 virtual ~BoxState() {};
55 explicit BoxState(IBoxContextPtr context) : m_context(context) {};
56 IBoxContextPtr getContext();
59 void setContext(IBoxContextPtr context);
60 IBoxContextPtr m_context;
63 class BoxInitState: public BoxState {
65 static IBoxStatePtr create(IBoxContextPtr context)
67 return IBoxStatePtr(new BoxInitState(context));
69 virtual IBoxStatePtr permitShow();
70 virtual ~BoxInitState() {};
73 explicit BoxInitState(IBoxContextPtr context) : BoxState(context) {};
76 class BoxShowState: public BoxState {
78 static IBoxStatePtr create(IBoxContextPtr context)
80 return IBoxStatePtr(new BoxShowState(context));
82 virtual IBoxStatePtr permitShow();
83 virtual IBoxStatePtr permitHide();
84 virtual IBoxStatePtr permitOpenPd();
85 virtual IBoxStatePtr permitPause();
86 virtual ~BoxShowState() {};
89 explicit BoxShowState(IBoxContextPtr context) : BoxState(context) {};
92 class BoxHideState: public BoxState {
94 static IBoxStatePtr create(IBoxContextPtr context)
96 return IBoxStatePtr(new BoxHideState(context));
98 virtual IBoxStatePtr permitShutdown();
99 virtual ~BoxHideState() {};
102 explicit BoxHideState(IBoxContextPtr context) : BoxState(context) {};
105 class BoxOpenPdState: public BoxState {
107 static IBoxStatePtr create(IBoxContextPtr context)
109 return IBoxStatePtr(new BoxOpenPdState(context));
111 virtual IBoxStatePtr permitClosePd();
112 virtual ~BoxOpenPdState() {};
115 explicit BoxOpenPdState(IBoxContextPtr context) : BoxState(context) {};
118 class BoxClosePdState: public BoxState {
120 static IBoxStatePtr create(IBoxContextPtr context)
122 return IBoxStatePtr(new BoxClosePdState(context));
124 virtual IBoxStatePtr permitShow();
125 virtual ~BoxClosePdState() {};
128 explicit BoxClosePdState(IBoxContextPtr context) : BoxState(context) {};
131 class BoxPauseState: public BoxState {
133 static IBoxStatePtr create(IBoxContextPtr context)
135 return IBoxStatePtr(new BoxPauseState(context));
137 virtual IBoxStatePtr permitResume();
138 virtual IBoxStatePtr permitHide();
139 virtual ~BoxPauseState() {};
142 explicit BoxPauseState(IBoxContextPtr context) : BoxState(context) {};
145 class BoxResumeState: public BoxState {
147 static IBoxStatePtr create(IBoxContextPtr context)
149 return IBoxStatePtr(new BoxResumeState(context));
151 virtual IBoxStatePtr permitShow();
152 virtual IBoxStatePtr permitHide();
153 virtual ~BoxResumeState() {};
156 explicit BoxResumeState(IBoxContextPtr context) : BoxState(context) {};