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"
30 namespace Application {
32 using namespace WrtDeviceApis;
33 using namespace WrtDeviceApis::Commons;
35 extern "C" int service_create_event(bundle *data, struct service_s **service);
37 Application::Application()
41 Application::~Application()
45 std::string Application::getContextId() const
50 void Application::setContextId(const std::string &id)
55 ApplicationInformationPtr Application::getAppInfo() const
60 void Application::setAppInfo(ApplicationInformationPtr& appInfo)
65 void Application::getRequestedAppControl(const EventApplicationGetRequestedAppControlPtr& event)
73 std::string bundle_str = event->getEncodedBundle();
74 LoggerD("bundle str : " << bundle_str);
76 service_h service = NULL;
79 bundle *request_bundle = bundle_decode((bundle_raw*)bundle_str.c_str(), bundle_str.length());
80 ret = service_create_event(request_bundle, &service);
81 if(ret != SERVICE_ERROR_NONE)
83 LoggerE("Fail to create event");
84 event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
85 bundle_free(request_bundle);
88 bundle_free(request_bundle);
90 ApplicationControlPtr appControl(new ApplicationControl());
91 appControl->setService_h(service);
93 ret = service_get_operation(service, &tmpStr);
94 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
96 LoggerD(" operation : " << tmpStr);
97 appControl->setOperation(tmpStr);
102 ret = service_get_uri(service, &tmpStr);
103 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
105 LoggerD(" uri : " << tmpStr);
106 appControl->setUri(tmpStr);
111 ret = service_get_mime(service, &tmpStr);
112 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
114 LoggerD(" mime : " << tmpStr);
115 appControl->setMime(tmpStr);
120 ret = service_get_category(service, &tmpStr);
121 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
123 LoggerD(" category : " << tmpStr);
124 appControl->setCategory(tmpStr);
129 std::vector<ApplicationControlDataPtr> appControlDataArray;
130 ret = service_foreach_extra_data(service, ApplicationManager::service_extra_data_callback, &appControlDataArray);
131 if (ret != SERVICE_ERROR_NONE)
133 LoggerE("service_foreach_extra_data fail");
134 event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
138 appControl->setAppControlDataArray(appControlDataArray);
141 RequestedApplicationControlPtr appCtrMgr(new RequestedApplicationControl());
142 appCtrMgr->setAppControl(appControl);
145 ret = service_get_caller(service, &tmpStr);
146 if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
148 LoggerD(" caller App Id : " << tmpStr);
149 appCtrMgr->setCallerAppId(tmpStr);
153 LoggerE("caller id fail");
154 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
156 event->setRequestedAppControl(appCtrMgr);
159 Catch (WrtDeviceApis::Commons::Exception)
161 LoggerE("Error on getAppControl : " << _rethrown_exception.GetMessage());
162 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);