diff options
Diffstat (limited to 'mobile_src/Application/Application.cpp')
-rw-r--r-- | mobile_src/Application/Application.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/mobile_src/Application/Application.cpp b/mobile_src/Application/Application.cpp new file mode 100644 index 0000000..4c9f479 --- /dev/null +++ b/mobile_src/Application/Application.cpp @@ -0,0 +1,159 @@ +// +// Tizen Web Device API +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "Application.h" + +#include <bundle.h> +#include <app.h> +#include <app_service.h> + +#include "ApplicationControlData.h" +#include "ApplicationControl.h" +#include "ApplicationManager.h" +#include <Logger.h> + +namespace DeviceAPI { +namespace Application { + +using namespace WrtDeviceApis; +using namespace WrtDeviceApis::Commons; + +extern "C" int service_create_event(bundle *data, struct service_s **service); + +Application::Application() +{ +} + +Application::~Application() +{ +} + +std::string Application::getContextId() const +{ + return m_contextId; +} + +void Application::setContextId(const std::string &id) +{ + m_contextId = id; +} + +ApplicationInformationPtr Application::getAppInfo() const +{ + return m_appInfo; +} + +void Application::setAppInfo(ApplicationInformationPtr& appInfo) +{ + m_appInfo = appInfo; +} + +void Application::getRequestedAppControl(const EventApplicationGetRequestedAppControlPtr& event) +{ + Try + { + int ret = 0; + + std::string bundle_str = event->getEncodedBundle(); + + service_h service = NULL; + char* tmpStr = NULL; + + bundle *request_bundle = bundle_decode((bundle_raw*)bundle_str.c_str(), bundle_str.length()); + ret = service_create_event(request_bundle, &service); + if(ret != SERVICE_ERROR_NONE) + { + LoggerE("Fail to create event"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + bundle_free(request_bundle); + return; + } + bundle_free(request_bundle); + + ApplicationControlPtr appControl(new ApplicationControl()); + appControl->setService_h(service); + + ret = service_get_operation(service, &tmpStr); + if(ret == SERVICE_ERROR_NONE && tmpStr != NULL) + { + appControl->setOperation(tmpStr); + free(tmpStr); + tmpStr = NULL; + } + + ret = service_get_uri(service, &tmpStr); + if(ret == SERVICE_ERROR_NONE && tmpStr != NULL) + { + appControl->setUri(tmpStr); + free(tmpStr); + tmpStr = NULL; + } + + ret = service_get_mime(service, &tmpStr); + if(ret == SERVICE_ERROR_NONE && tmpStr != NULL) + { + appControl->setMime(tmpStr); + free(tmpStr); + tmpStr = NULL; + } + + ret = service_get_category(service, &tmpStr); + if(ret == SERVICE_ERROR_NONE && tmpStr != NULL) + { + appControl->setCategory(tmpStr); + free(tmpStr); + tmpStr = NULL; + } + + std::vector<ApplicationControlDataPtr> appControlDataArray; + ret = service_foreach_extra_data(service, ApplicationManager::service_extra_data_callback, &appControlDataArray); + if (ret != SERVICE_ERROR_NONE) + { + LoggerE("service_foreach_extra_data fail"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + } + else + { + appControl->setAppControlDataArray(appControlDataArray); + } + + RequestedApplicationControlPtr appCtrMgr(new RequestedApplicationControl()); + appCtrMgr->setAppControl(appControl); + + // add caller id + ret = service_get_caller(service, &tmpStr); + if(ret == SERVICE_ERROR_NONE && tmpStr != NULL) + { + appCtrMgr->setCallerAppId(tmpStr); + free(tmpStr); + tmpStr = NULL; + } else { + LoggerE("fail to get caller application ID"); + event->setExceptionCode(Commons::ExceptionCodes::PlatformException); + } + event->setRequestedAppControl(appCtrMgr); + + } + Catch (WrtDeviceApis::Commons::Exception) + { + LoggerE("Error on getAppControl : " << _rethrown_exception.GetMessage()); + event->setExceptionCode(Commons::ExceptionCodes::PlatformException); + } +} + +} +} |