Update change log and spec for wrt-plugins-tizen_0.4.9
[platform/framework/web/wrt-plugins-tizen.git] / src / Application / Application.cpp
1 //
2 // Tizen Web Device API
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 #include "Application.h"
19
20 #include <bundle.h>
21 #include <app.h>
22 #include <app_service.h>
23
24 #include "ApplicationControlData.h"
25 #include "ApplicationControl.h"
26 #include "ApplicationManager.h"
27
28 namespace DeviceAPI {
29 namespace Application { 
30
31 using namespace WrtDeviceApis;
32 using namespace WrtDeviceApis::Commons;
33
34 extern "C" int service_create_event(bundle *data, struct service_s **service);
35         
36 Application::Application()
37 {
38 }
39
40 Application::~Application()
41 {
42 }
43
44 std::string Application::getContextId() const
45 {
46         return m_contextId;
47 }
48
49 void Application::setContextId(const std::string &id)
50 {
51         m_contextId = id;
52 }
53
54 ApplicationInformationPtr Application::getAppInfo() const
55 {
56         return m_appInfo;
57 }
58
59 void Application::setAppInfo(ApplicationInformationPtr& appInfo)
60 {
61         m_appInfo = appInfo;
62 }
63
64 void Application::getRequestedAppControl(const EventApplicationGetRequestedAppControlPtr& event)
65 {
66         LogDebug("entered");
67
68         Try
69         {
70                 int ret = 0;
71
72                 std::string bundle_str = event->getEncodedBundle();
73                 LogDebug("bundle str : " << bundle_str);
74
75                 service_h service = NULL;
76                 char* tmpStr = NULL;
77
78                 bundle *request_bundle = bundle_decode((bundle_raw*)bundle_str.c_str(), bundle_str.length());
79                 ret = service_create_event(request_bundle, &service);
80                 if(ret != SERVICE_ERROR_NONE)
81                 {
82                         LogError("Fail to create event");
83                         event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
84                         bundle_free(request_bundle);
85                         return;
86                 }
87                 bundle_free(request_bundle);
88
89                 ApplicationControlPtr appControl(new ApplicationControl());
90                 appControl->setService_h(service);
91
92                 ret = service_get_operation(service, &tmpStr);
93                 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
94                 {
95                         LogDebug(" operation : " << tmpStr);
96                         appControl->setOperation(tmpStr);
97                         free(tmpStr);
98                         tmpStr = NULL;
99                 }
100
101                 ret = service_get_uri(service, &tmpStr);
102                 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
103                 {
104                         LogDebug(" uri       : " << tmpStr);
105                         appControl->setUri(tmpStr);
106                         free(tmpStr);
107                         tmpStr = NULL;
108                 }
109
110                 ret = service_get_mime(service, &tmpStr);
111                 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
112                 {
113                         LogDebug(" mime      : " << tmpStr);
114                         appControl->setMime(tmpStr);
115                         free(tmpStr);
116                         tmpStr = NULL;
117                 }
118
119                 ret = service_get_category(service, &tmpStr);
120                 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
121                 {
122                         LogDebug(" category      : " << tmpStr);
123                         appControl->setCategory(tmpStr);
124                         free(tmpStr);
125                         tmpStr = NULL;
126                 }
127
128                 std::vector<ApplicationControlDataPtr> appControlDataArray;
129                 ret = service_foreach_extra_data(service, ApplicationManager::service_extra_data_callback, &appControlDataArray);
130                 if (ret != SERVICE_ERROR_NONE)
131                 {
132                         LogError("service_foreach_extra_data fail");
133                         event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
134                 }
135                 else
136                 {
137                         appControl->setAppControlDataArray(appControlDataArray);
138                 }
139                 
140                 RequestedApplicationControlPtr appCtrMgr(new RequestedApplicationControl());
141                 appCtrMgr->setAppControl(appControl);
142
143                 // add caller id
144                 ret = service_get_caller(service, &tmpStr);
145                 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
146                 {
147                         LogDebug(" caller App Id   : " << tmpStr);
148                         appCtrMgr->setCallerAppId(tmpStr);
149                         free(tmpStr);
150                         tmpStr = NULL;
151                 } else {
152                         LogError("caller id fail");
153                         event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
154                 }
155                 event->setRequestedAppControl(appCtrMgr);               
156                 
157         }
158         Catch (WrtDeviceApis::Commons::Exception)
159         {
160                 LogError("Error on getAppControl : " << _rethrown_exception.GetMessage());
161                 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
162         }
163 }
164
165 }
166 }