3dc67583782fa991a0bcbe0d35438fc1d65dcc4b
[framework/osp/appwidget-service.git] / inc / FShell_AppWidgetContext.h
1 //
2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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 /**
18  * @file        FShell_AppWidgetContext.h
19  * @brief       This is the header file for the _AppWidgetContext class.
20  *
21  * This header file contains the declarations of the _AppWidgetContext class.
22  */
23
24 #ifndef _FSHELL_INTERNAL_APPWIDGET_CONTEXT_H_
25 #define _FSHELL_INTERNAL_APPWIDGET_CONTEXT_H_
26
27 #include <provider_buffer.h>
28 #include <FAppTypes.h>
29 #include <FBaseRtTimer.h>
30 #include <FBaseColArrayListT.h>
31 #include "FShell_AppWidgetRemoteBuffer.h"
32
33 namespace Tizen { namespace Base  { namespace Collection
34 {
35 class HashMap;
36 }}}
37
38 namespace Tizen { namespace Shell  { namespace App
39 {
40
41 extern const wchar_t ARG_KEY_INSTANCE_ID[];
42 extern const wchar_t ARG_KEY_PROVIDER_NAME[];
43 extern const wchar_t ARG_KEY_USER_INFO[];
44 extern const wchar_t ARG_KEY_X[];
45 extern const wchar_t ARG_KEY_Y[];
46 extern const wchar_t ARG_KEY_WIDTH[];
47 extern const wchar_t ARG_KEY_HEIGHT[];
48 extern const wchar_t ARG_KEY_POPUP_WIDTH[];
49 extern const wchar_t ARG_KEY_POPUP_HEIGHT[];
50 extern const wchar_t ARG_KEY_ARGUMENT[];
51 extern const wchar_t ARG_KEY_EVENT_TYPE[];
52 extern const wchar_t ARG_KEY_TIME_STAMP[];
53
54 extern const int UPDATE_PERIOD_MSEC_MIN;
55 class _AppWidgetContext;
56 class _AppWidgetPopupContext;
57
58 enum _ConnectionState
59 {
60         CONNECTION_STATE_NONE = 0,
61         CONNECTION_STATE_CONNECTING,
62         CONNECTION_STATE_CONNECTED,
63         CONNECTION_STATE_DISCONNECTED
64 };
65
66 ////////////////////////////////////////////////
67 // _AppContext
68 ////////////////////////////////////////////////
69 class _AppContext
70         :public Tizen::Base::Object
71 {
72
73 public:
74         _AppContext(void);
75         ~_AppContext(void);
76
77         _ConnectionState GetConnectionState(void) const;
78         void SetConnectionState(_ConnectionState state);
79         int GetClientId(void) const;
80         void SetClientId(int clientId);
81         void SetWaitingStatus(bool status);
82         bool GetWaitingStatus(void) const;
83
84 private:
85         bool __isWaitingResult;
86         int __ipcClientId;
87         _ConnectionState __connectionState;
88         Tizen::Base::Collection::ArrayListT<_AppWidgetContext*> __appWidetContextList;
89 };
90
91 ////////////////////////////////////////////////
92 // _AppWidgetContext
93 ////////////////////////////////////////////////
94 class _AppWidgetContext
95         : public Tizen::Base::Runtime::ITimerEventListener
96         , public _IAppWidgetRemoteBufferEventListener
97         , public Tizen::Base::Object
98 {
99 public:
100         _AppWidgetContext(_AppContext* pAppContext, const Tizen::Base::String& userInfo, const Tizen::Base::String& appId, const Tizen::Base::String& instanceId, int width, int height, int period, int priority);
101         virtual ~_AppWidgetContext(void);
102
103         // handle dynamic box
104         void OnAdded(void);
105         void OnUpdate(const Tizen::Base::String& argument);
106         void OnResize(int width, int height);
107         result OnRemoved(void);
108         virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y);
109
110         // dynamic box state
111         void OnForeground(void);
112         void OnBackground(void);
113
114         // handle request from dynamic box
115         int AcquireRemoteBuffer(int w, int h) const;
116         result SyncRemoteBuffer(int width, int height);
117         result SendAccessStatus(int accessStatus) const;
118
119         // handle drop view
120         void OnPopupCreated(double x, double y, int width, int height);
121         void OnPopupDestoyed(void);
122         _AppWidgetPopupContext* GetAppWidgetPopup(void) const;
123         result SendPopupRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs) const;
124         Tizen::Base::Collection::HashMap* CreateRequestArgsN(void) const;
125
126         _AppContext* GetAppContext(void) const;
127         void OnDisconnected(void);
128         result SendPendingEvent(void);
129
130         Tizen::Base::String GetAppId(void) const;
131         Tizen::Base::String GetProviderName(void) const;
132         Tizen::Base::String GetUserInfo(void) const;
133         Tizen::Base::String GetProviderId(void) const;
134         Tizen::Base::String GetInstanceId(void) const;
135         int GetWidth(void) const;
136         int GetHeight(void) const;
137         int GetPriority(void) const;
138
139 //      void SetUserInfo(const Tizen::Base::String& userInfo);
140 //      void SetProviderId(const Tizen::Base::String& providerId);
141 //      void SetInstanceId(const Tizen::Base::String& instanceId);
142 //      void SetPriority(int priority);
143
144 private:
145         result SendAddRequest(int width, int height);
146         result SendUpdateRequest(int width, int height, const Tizen::Base::String& argument);
147         result SendResizeRequest(int width, int height);
148         result SendRemoveRequest(void);
149         void SendPendingTouchEvent(void);
150         result RequestUpdate(const Tizen::Base::String& argument);
151         result SendRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs);
152
153         virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
154
155         void SetForeground(bool forground);
156         void SetWidth(int width);
157         void SetHeight(int height);
158         int GetPeriod(void) const;
159
160         int GetClientId(void) const;
161         bool IsForeground(void) const;
162         long long GetLastUpdatedTime(void) const;
163
164 private:
165         struct PendingTouchEvent
166         {
167                 PendingTouchEvent(int eventType, double timeStamp, double       x, double       y)
168                  : eventType(eventType), timeStamp(timeStamp), x(x), y(y) {  }
169
170                 int eventType;
171                 double  timeStamp;
172                 double  x;
173                 double  y;
174         };
175
176         struct PendingEvent
177         {
178                 PendingEvent(const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pHashMap)
179                  : operation(operation), pArg(pHashMap) {  }
180
181                 Tizen::Base::String operation;
182                 Tizen::Base::Collection::HashMap* pArg;
183         };
184
185         mutable bool __isRemoteBufferProxyCreated;
186         bool __hasPendingRequest;
187         bool __isForeground;
188         int __width;
189         int __height;
190         int __priority;
191         int __ipcClientId;
192         int __updateMillis;
193         long long __lastUpdatedTime;
194
195         Tizen::Base::String __userInfo;
196         Tizen::Base::String __providerId;
197         Tizen::Base::String __instanceId;
198         Tizen::Base::String __appId;
199         Tizen::Base::String __providerName;
200         Tizen::Base::String __pendingArgument;
201         Tizen::Base::Runtime::Timer __updateTimer;
202
203         _AppContext* __pAppContext;
204         _AppWidgetPopupContext* __pAppWidgetPopup;
205         _AppWidgetRemoteBuffer* __pAppWidgetRemoteBuffer;
206
207         Tizen::Base::Collection::ArrayListT<PendingTouchEvent*>* __pPendingTouchEventList;
208         Tizen::Base::Collection::ArrayListT<PendingEvent*>* __pPendingEventList;
209
210 };      // class _AppWidgetContext
211
212 }}} // Tizen::Shell::App
213
214 #endif // _FSHELL_INTERNAL_APPWIDGET_CONTEXT_H_