sync with master
[platform/framework/native/appwidget-service.git] / src / FShell_AppWidgetPopupContext.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FShell_AppWidgetPopupContext.cpp
20  * @brief       This is the implementation for the _AppWidgetPopupContext class.
21  */
22
23 #include <stdlib.h>
24 #include <unique_ptr.h>
25
26 #include "provider_buffer.h"
27
28 #include <FBase.h>
29 #include <FBaseSysLog.h>
30 #include <FBase_StringConverter.h>
31
32 #include <FApp_AppControlManager.h>
33
34 #include "FShell_AppWidgetManagerService.h"
35 #include "FShell_AppWidgetPopupContext.h"
36
37 namespace Tizen { namespace Shell  { namespace App
38 {
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42
43
44 const char APPWIDGET_POPUP_ON_CREATE[] = "http://tizen.org/appcontrol/appwidgetpopup/create";
45 const char APPWIDGET_POPUP_ON_DESTROY[] = "http://tizen.org/appcontrol/appwidgetpopup/destroy";
46 const char APPWIDGET_POPUP_ON_TOUCH[] = "http://tizen.org/appcontrol/appwidgetpopup/touch";
47
48 const String ARG_KEY_X = L"_X";
49 const String ARG_KEY_Y = L"_Y";
50 const String ARG_KEY_WIDTH = L"_Width";
51 const String ARG_KEY_HEIGHT = L"_Height";
52
53
54 _AppWidgetPopupContext::_AppWidgetPopupContext(const String& info, const String& appId, const String& instanceId, int width, int height, int priority)
55 :_AppWidgetContextBase(TYPE_PD, info, appId, instanceId, width, height, priority)
56 {
57         SysLog(NID_APP, "appId(%ls), instanceId(%ls), width(%d), height(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
58 }
59
60 _AppWidgetPopupContext::~_AppWidgetPopupContext()
61 {
62         SysLog(NID_APP, "appId(%ls), instanceId(%ls), width(%d), height(%d))", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
63         ReleaseSharedMem();
64 }
65
66
67 void
68 _AppWidgetPopupContext::OnPopupCreated(double x, double y, int width, int height)
69 {
70         SysLog(NID_APP, "width(%d), height(%d)", width, height);
71         SendPopupCreateRequest(x, y, width, height);
72 }
73
74 void
75 _AppWidgetPopupContext::OnPopupDestoyed()
76 {
77         SysLog(NID_APP, "");
78         SendPopupDestroyRequest();
79 }
80
81 result
82 _AppWidgetPopupContext::SendPopupCreateRequest(double x, double y, int width, int height)
83 {
84         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
85
86         pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
87         pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
88         pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
89         pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
90
91         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_CREATE, pArgs.get());
92 }
93
94 result
95 _AppWidgetPopupContext::SendPopupDestroyRequest()
96 {
97         std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
98
99         return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_DESTROY, pArgs.get());
100 }
101
102 result
103 _AppWidgetPopupContext::SendTouchEvent(buffer_event event, double timestamp, double x, double y)
104 {
105         SysLog(NID_APP, "");
106         /*if( HasValidClientId() == false )
107         {
108                 std::unique_ptr<ArrayList, AllElementsDeleter> pArgs (new (std::nothrow) ArrayList);
109                 pArgs->Construct();
110                 pArgs->Add(*new String(__instanceId));
111                 pArgs->Add(*new String(__info));
112                 pArgs->Add(*new String(Integer::ToString(event)));
113                 pArgs->Add(*new String(Double::ToString(timestamp)));
114                 pArgs->Add(*new String(Double::ToString(x)));
115                 pArgs->Add(*new String(Double::ToString(y)));
116
117                 return SendRequestToApp( __appId, APPWIDGET_POPUP_ON_TOUCH, pArgs.get());
118         }
119         else*/
120         {
121 //              SysAssertf( Tizen::App::AppManager::GetInstance()->IsRunning(__appId) == false, "application isn't running");
122                 AppWidgetManagerService::GetInstance()->SendTouchEventForPD(__ipcClientId, __instanceId, event, timestamp, x, y);
123         }
124         return E_SUCCESS;
125 }
126
127 result
128 _AppWidgetPopupContext::RequestUpdateRemote()
129 {
130         std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
131         std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
132
133         int ret = provider_send_desc_updated(packageName.get(), id.get(), null);
134         SysTryReturnResult(NID_APP, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
135
136         SysLog(NID_APP, "Done");
137         return E_SUCCESS;
138 }
139
140 } } } // Tizen::Shell::App {
141