refactoring (now _AppContext manages list of _AppWidgetContext, IpcConnection state...
[framework/osp/appwidget-service.git] / src / FShell_AppWidgetPopupContext.cpp
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_AppWidgetPopupContext.cpp
19  * @brief       This is the implementation for the _AppWidgetPopupContext class.
20  */
21
22 #include <stdlib.h>
23 #include <unique_ptr.h>
24 #include <provider.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseInteger.h>
27 #include <FBaseDouble.h>
28 #include <FBaseColHashMap.h>
29 #include <FBaseColAllElementsDeleter.h>
30 #include <FBase_StringConverter.h>
31 #include <FApp_AppControlManager.h>
32 #include "FShell_AppWidgetManagerService.h"
33 #include "FShell_AppWidgetContext.h"
34 #include "FShell_AppWidgetPopupContext.h"
35 #include "FShell_AppWidgetContextHelper.h"
36 #include "FShell_AppWidgetRemoteBuffer.h"
37
38 namespace Tizen { namespace Shell  { namespace App
39 {
40
41 using namespace std;
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Collection;
44
45 const wchar_t APPWIDGET_POPUP_ON_CREATE[] = L"http://tizen.org/appcontrol/appwidgetpopup/create";
46 const wchar_t APPWIDGET_POPUP_ON_DESTROY[] = L"http://tizen.org/appcontrol/appwidgetpopup/destroy";
47 const wchar_t APPWIDGET_POPUP_ON_TOUCH[] = L"http://tizen.org/appcontrol/appwidgetpopup/touch";
48
49 _AppWidgetPopupContext::_AppWidgetPopupContext(const _AppWidgetContext* pParent)
50         : __pParent(pParent)
51 {
52         __pAppWidgetRemoteBuffer = new (nothrow) _AppWidgetRemoteBuffer(__pParent->GetProviderId(), __pParent->GetInstanceId(), TYPE_PD, this);
53         SysTryReturnVoidResult(NID_SHELL, __pAppWidgetRemoteBuffer, E_OUT_OF_MEMORY, "");
54
55         SysLog(NID_SHELL, "The drop view for %ls is constructed.", (__pParent->GetInstanceId()).GetPointer());
56 }
57
58 _AppWidgetPopupContext::~_AppWidgetPopupContext(void)
59 {
60         OnPopupDestoyed();
61         delete __pAppWidgetRemoteBuffer;
62
63         SysLog(NID_SHELL, "The drop view for %ls destructed.", (__pParent->GetInstanceId()).GetPointer());
64 }
65
66 void
67 _AppWidgetPopupContext::OnPopupCreated(double x, double y, int width, int height)
68 {
69         SysLog(NID_SHELL, "width(%d), height(%d)", width, height);
70         SendPopupCreateRequest(x, y, width, height);
71 }
72
73 void
74 _AppWidgetPopupContext::OnPopupDestoyed(void)
75 {
76         SysLog(NID_SHELL, "");
77         SendPopupDestroyRequest();
78 }
79
80 result
81 _AppWidgetPopupContext::SendPopupCreateRequest(double x, double y, int width, int height)
82 {
83         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (__pParent->CreateRequestArgsN() );
84
85         pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
86         pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
87         pArgs->Add(new String(ARG_KEY_POPUP_WIDTH), new String(Integer::ToString(width)));
88         pArgs->Add(new String(ARG_KEY_POPUP_HEIGHT), new String(Integer::ToString(height)));
89
90         return _AppWidgetRequestHelper::SendAppControlRequest(__pParent->GetAppId(), APPWIDGET_POPUP_ON_CREATE, pArgs.get());
91 }
92
93 result
94 _AppWidgetPopupContext::SendPopupDestroyRequest(void)
95 {
96         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (__pParent->CreateRequestArgsN() );
97
98         return _AppWidgetRequestHelper::SendAppControlRequest(__pParent->GetAppId(), APPWIDGET_POPUP_ON_DESTROY, pArgs.get());
99 }
100
101 void
102 _AppWidgetPopupContext::OnTouchEventReceived(buffer_event event, double timestamp, double x, double y)
103 {
104         SysLog(NID_SHELL, "");
105         AppWidgetManagerService::GetInstance()->SendTouchEventForPD(__pParent->GetAppContext()->GetClientId(), __pParent->GetInstanceId(), event, timestamp, x, y);
106 }
107
108 result
109 _AppWidgetPopupContext::SyncRemoteBuffer(void)
110 {
111         std::unique_ptr<char[]> providerId(_StringConverter::CopyToCharArrayN(__pParent->GetProviderId()));
112         std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__pParent->GetInstanceId()));
113
114         int ret = provider_send_desc_updated(providerId.get(), id.get(), null);
115         SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
116
117         SysLog(NID_SHELL, "Done");
118         return E_SUCCESS;
119 }
120
121 /*int
122 _AppWidgetPopupContext::GetClientId(void) const
123 {
124         return __pParent->GetAppContext()->GetClientId();
125 }*/
126
127 int
128 _AppWidgetPopupContext::AcquireRemoteBuffer(int w, int h) const
129 {
130         return __pAppWidgetRemoteBuffer->Acquire(w, h);
131 }
132
133 }}} // Tizen::Shell::App