2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FShell_LiveboxContext.cpp
20 * @brief This is the implementation for the _LiveboxContext class.
24 #include <unique_ptr.h>
26 #include "provider_buffer.h"
29 #include <FBaseSysLog.h>
30 #include <FBase_StringConverter.h>
32 #include <FApp_AppControlManager.h>
34 #include "FShell_LiveboxManagerService.h"
35 #include "FShell_LiveboxPopupContext.h"
36 #include "FShell_LiveboxContextBase.h"
37 #include "FShell_LiveboxContext.h"
40 namespace Tizen { namespace Shell { namespace App
43 using namespace Tizen::App;
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
49 const String LIVEBOX_ON_ADD(L"Livebox='event=add'");
50 const String LIVEBOX_ON_REMOVE(L"Livebox='event=remove'");
51 const String LIVEBOX_ON_UPDATE(L"Livebox='event=update'");
52 const String LIVEBOX_ON_RESIZE(L"Livebox='event=resize'");
53 const String LIVEBOX_ON_TOUCH(L"Livebox='event=touch'");
55 const String ARG_KEY_WIDTH = L"_Width";
56 const String ARG_KEY_HEIGHT = L"_Height";
57 const String ARG_KEY_ARGUMENT = L"_Argument";
58 const String ARG_KEY_EVENT_TYPE = L"_EventType";
59 const String ARG_KEY_TIME_STAMP = L"_TimeStamp";
60 const String ARG_KEY_X = L"_X";
61 const String ARG_KEY_Y = L"_Y";
63 const int LIVE_DURATION_MSEC= 30000;//30sec
65 _LiveboxContext::_LiveboxContext(const String& info, const String& providerId, const String& instanceId, int width, int height, int period, int priority)
66 :_LiveboxContextBase(TYPE_LB, info, providerId, instanceId, width, height, priority)
67 ,__pLiveboxPopup(null), __UpdateMillis(period)
69 SysLog(NID_APP, "period(%d)", period);
71 __lifeDurationTimer.Construct(*this);//, true);
72 __lifeDurationTimer.Start(LIVE_DURATION_MSEC);
74 SysLog(NID_APP, "period(%d)", __UpdateMillis);
75 if( __UpdateMillis > 0)
77 __UpdateTimer.Construct(*this);//, false);
78 __UpdateTimer.StartAsRepeatable(__UpdateMillis);
82 _LiveboxContext::~_LiveboxContext()
84 SysLog(NID_APP, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
85 __lifeDurationTimer.Cancel();
86 __UpdateTimer.Cancel();
90 _LiveboxContext::GetLiveboxPopup() const
92 return __pLiveboxPopup;
96 _LiveboxContext::OnAdded(void)
98 SendAddRequest(__width, __height);
102 _LiveboxContext::OnRemoved()
108 _LiveboxContext::OnUpdate(const String& argument)
110 SysLog(NID_APP, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
112 SendUpdateRequest(__width, __height, argument);
116 _LiveboxContext::OnResize(int width, int height)
118 SysLog(NID_APP, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
122 SendResizeRequest(__width, __height);
126 _LiveboxContext::OnForeground()
129 __isForeground = true;
131 __UpdateTimer.Cancel();
132 __UpdateTimer.StartAsRepeatable(__UpdateMillis);
136 _LiveboxContext::OnBackground()
139 __isForeground = false;
140 __UpdateTimer.Cancel();
144 _LiveboxContext::OnPopupCreated(int width, int height)
146 __pLiveboxPopup = new (std::nothrow) _LiveboxPopupContext(__userInfo, __providerId, __instanceId, width, height, __priority);
147 __pLiveboxPopup->SetClientId(__ipcClientId);
148 __pLiveboxPopup->OnPopupCreated(width, height);
150 __lifeDurationTimer.Cancel();
154 _LiveboxContext::OnPopupDestoyed(void)
158 __pLiveboxPopup->OnPopupDestoyed();
159 delete __pLiveboxPopup;
160 __pLiveboxPopup = null;
162 RestartLifeDurationTimer();
166 _LiveboxContext::SendAddRequest(int width, int height)
168 /* std::unique_ptr<ArrayList, AllElementsDeleter> pArgs (new (std::nothrow) ArrayList);
170 pArgs->Add(*new String(__instanceId));
171 pArgs->Add(*new String(__providerId));
172 pArgs->Add(*new String(__info));
173 pArgs->Add(*new String(Integer::ToString(width)));
174 pArgs->Add(*new String(Integer::ToString(height)));*/
176 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
178 pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
179 pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
181 return SendRequestToApp( __appId, LIVEBOX_ON_ADD, pArgs.get());
185 _LiveboxContext::SendUpdateRequest(int width, int height, const String& argument)
187 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
189 pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
190 pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
191 pArgs->Add(new String(ARG_KEY_ARGUMENT), new String(argument));
193 return SendRequestToApp( __appId, LIVEBOX_ON_UPDATE, pArgs.get());
197 _LiveboxContext::SendResizeRequest(int width, int height)
199 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
201 pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
202 pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
204 return SendRequestToApp( __appId, LIVEBOX_ON_RESIZE, pArgs.get());
208 _LiveboxContext::SendRemoveRequest()
210 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
212 return SendRequestToApp( __appId, LIVEBOX_ON_REMOVE, pArgs.get());
216 _LiveboxContext::SendTouchEvent(buffer_event event, double timestamp, double x, double y)
219 if( HasValidClientId() == false )
221 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
223 pArgs->Add(new String(ARG_KEY_EVENT_TYPE), new String(Integer::ToString(event)));
224 pArgs->Add(new String(ARG_KEY_TIME_STAMP), new String(Double::ToString(timestamp)));
225 pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
226 pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
228 return SendRequestToApp( __appId, LIVEBOX_ON_TOUCH, pArgs.get());
232 // SysAssertf( Tizen::App::AppManager::GetInstance()->IsRunning(__appId) == false, "application isn't running");
233 LiveboxManagerService::GetInstance()->SendTouchEvent(__ipcClientId, __instanceId, event, timestamp, x, y);
239 _LiveboxContext::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
241 result r = _LiveboxContextBase::SendRequestToApp(appId, operation, pArgs);
242 RestartLifeDurationTimer();
248 _LiveboxContext::RequestUpdateRemote(int width, int height)
250 /*if( GetLiveboxPopup() != null)
252 SysLog(NID_APP, "LiveboxPopup is appeared, so livebox doesn't need to update");
255 std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
256 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
257 std::unique_ptr<char[]> content_info(_StringConverter::CopyToCharArrayN(__userInfo));
259 int ret = provider_send_updated(packageName.get(), id.get(), width, height, __priority, content_info.get(), null);
260 SysTryReturnResult(NID_APP, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
262 SysLog(NID_APP, "Done");
267 _LiveboxContext::RestartLifeDurationTimer()
269 __lifeDurationTimer.Cancel();
270 __lifeDurationTimer.Start(LIVE_DURATION_MSEC);
271 SysLog(NID_APP, "lifeDuration timer restarted (%d)msec", LIVE_DURATION_MSEC);
275 _LiveboxContext::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
279 if( &timer == &__lifeDurationTimer)
281 SysLog(NID_APP, "lifeDuration timer is expired, so terminating livebox app(%ls)..", __providerId.GetPointer() );
284 AppManager::GetInstance()->TerminateApplication(__appId);
287 else if( &timer == &__UpdateTimer)
289 SysLog(NID_APP, "update timer is expired for livebox app(%ls)..", __providerId.GetPointer() );
295 } } } // Tizen::Shell::App {