2 // Tizen Web Device API
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.
18 #include "Application.h"
22 #include <app_service.h>
24 #include "ApplicationControlData.h"
25 #include "ApplicationControl.h"
26 #include "ApplicationManager.h"
29 namespace Application {
31 using namespace WrtDeviceApis;
32 using namespace WrtDeviceApis::Commons;
34 extern "C" int service_create_event(bundle *data, struct service_s **service);
36 Application::Application()
40 Application::~Application()
44 std::string Application::getContextId() const
49 void Application::setContextId(const std::string &id)
54 ApplicationInformationPtr Application::getAppInfo() const
59 void Application::setAppInfo(ApplicationInformationPtr& appInfo)
64 void Application::getRequestedAppControl(const EventApplicationGetRequestedAppControlPtr& event)
72 std::string bundle_str = event->getEncodedBundle();
73 LogDebug("bundle str : " << bundle_str);
75 service_h service = NULL;
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)
82 LogError("Fail to create event");
83 event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
84 bundle_free(request_bundle);
87 bundle_free(request_bundle);
89 ApplicationControlPtr appControl(new ApplicationControl());
90 appControl->setService_h(service);
92 ret = service_get_operation(service, &tmpStr);
93 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
95 LogDebug(" operation : " << tmpStr);
96 appControl->setOperation(tmpStr);
101 ret = service_get_uri(service, &tmpStr);
102 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
104 LogDebug(" uri : " << tmpStr);
105 appControl->setUri(tmpStr);
110 ret = service_get_mime(service, &tmpStr);
111 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
113 LogDebug(" mime : " << tmpStr);
114 appControl->setMime(tmpStr);
119 ret = service_get_category(service, &tmpStr);
120 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
122 LogDebug(" category : " << tmpStr);
123 appControl->setCategory(tmpStr);
128 std::vector<ApplicationControlDataPtr> appControlDataArray;
129 ret = service_foreach_extra_data(service, ApplicationManager::service_extra_data_callback, &appControlDataArray);
130 if (ret != SERVICE_ERROR_NONE)
132 LogError("service_foreach_extra_data fail");
133 event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
137 appControl->setAppControlDataArray(appControlDataArray);
140 RequestedApplicationControlPtr appCtrMgr(new RequestedApplicationControl());
141 appCtrMgr->setAppControl(appControl);
144 ret = service_get_caller(service, &tmpStr);
145 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
147 LogDebug(" caller App Id : " << tmpStr);
148 appCtrMgr->setCallerAppId(tmpStr);
152 LogError("caller id fail");
153 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
155 event->setRequestedAppControl(appCtrMgr);
158 Catch (WrtDeviceApis::Commons::Exception)
160 LogError("Error on getAppControl : " << _rethrown_exception.GetMessage());
161 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);