The license change version 1.0 to version 1.1
[platform/framework/web/web-provider.git] / src / Core / BoxState.h
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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  * @file    BoxState.h
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  */
20 #ifndef BOX_STATE
21 #define BOX_STATE
22
23 #include "IBoxState.h"
24 #include "IBoxContext.h"
25
26 /*
27 #define CHECK_BOX_STATE(currentState, operation)        \
28     IBoxStatePtr state;                                 \
29     try {                                               \
30         state = currentState->operation();              \
31     } catch (...) {                                     \
32         return false;                                   \
33     }                                                   \
34
35 #define SWITCH_BOX_STATE()                              \
36     state->switchState()                                \
37 */
38
39 #define CHECK_BOX_STATE(currentState, operation) 
40 #define SWITCH_BOX_STATE()
41
42 class BoxState: public IBoxState {
43     public:
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() {};
53
54     protected:
55         explicit BoxState(IBoxContextPtr context) : m_context(context) {};
56         IBoxContextPtr getContext();
57
58     private:
59         void setContext(IBoxContextPtr context);
60         IBoxContextPtr m_context;
61 };
62
63 class BoxInitState: public BoxState {
64     public:
65         static IBoxStatePtr create(IBoxContextPtr context) 
66         { 
67             return IBoxStatePtr(new BoxInitState(context)); 
68         };
69         virtual IBoxStatePtr permitShow();
70         virtual ~BoxInitState() {};
71
72     private:
73         explicit BoxInitState(IBoxContextPtr context) : BoxState(context) {};
74 };
75
76 class BoxShowState: public BoxState {
77     public:
78         static IBoxStatePtr create(IBoxContextPtr context) 
79         { 
80             return IBoxStatePtr(new BoxShowState(context)); 
81         };
82         virtual IBoxStatePtr permitShow();
83         virtual IBoxStatePtr permitHide();
84         virtual IBoxStatePtr permitOpenPd();
85         virtual IBoxStatePtr permitPause();
86         virtual ~BoxShowState() {};
87
88     private:
89         explicit BoxShowState(IBoxContextPtr context) : BoxState(context) {};
90 };
91
92 class BoxHideState: public BoxState {
93     public:
94         static IBoxStatePtr create(IBoxContextPtr context) 
95         { 
96             return IBoxStatePtr(new BoxHideState(context)); 
97         };
98         virtual IBoxStatePtr permitShutdown();
99         virtual ~BoxHideState() {};
100
101     private:
102         explicit BoxHideState(IBoxContextPtr context) : BoxState(context) {};
103 };
104
105 class BoxOpenPdState: public BoxState {
106     public:
107         static IBoxStatePtr create(IBoxContextPtr context) 
108         { 
109             return IBoxStatePtr(new BoxOpenPdState(context)); 
110         };
111         virtual IBoxStatePtr permitClosePd();
112         virtual ~BoxOpenPdState() {};
113
114     private:
115         explicit BoxOpenPdState(IBoxContextPtr context) : BoxState(context) {};
116 };
117
118 class BoxClosePdState: public BoxState {
119     public:
120         static IBoxStatePtr create(IBoxContextPtr context) 
121         { 
122             return IBoxStatePtr(new BoxClosePdState(context)); 
123         };
124         virtual IBoxStatePtr permitShow();
125         virtual ~BoxClosePdState() {};
126
127     private:
128         explicit BoxClosePdState(IBoxContextPtr context) : BoxState(context) {};
129 };
130
131 class BoxPauseState: public BoxState {
132     public:
133         static IBoxStatePtr create(IBoxContextPtr context) 
134         { 
135             return IBoxStatePtr(new BoxPauseState(context)); 
136         };
137         virtual IBoxStatePtr permitResume();
138         virtual IBoxStatePtr permitHide();
139         virtual ~BoxPauseState() {};
140
141     private:
142         explicit BoxPauseState(IBoxContextPtr context) : BoxState(context) {};
143 };
144
145 class BoxResumeState: public BoxState {
146     public:
147         static IBoxStatePtr create(IBoxContextPtr context) 
148         { 
149             return IBoxStatePtr(new BoxResumeState(context)); 
150         };
151         virtual IBoxStatePtr permitShow();
152         virtual IBoxStatePtr permitHide();
153         virtual ~BoxResumeState() {};
154
155     private:
156         explicit BoxResumeState(IBoxContextPtr context) : BoxState(context) {};
157 };
158 #endif // BOX_STATE