2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <Commons/Exception.h>
19 #include <Tizen/Common/JSTizenExceptionFactory.h>
20 #include <Tizen/Common/JSTizenException.h>
21 #include <JavaScriptCore/JavaScript.h>
22 #include <CommonsJavaScript/JSCallbackManager.h>
23 #include <CommonsJavaScript/Converter.h>
24 #include "JSApplicationInformation.h"
25 #include "JSApplicationEvent.h"
26 #include "ApplicationListener.h"
30 namespace Application {
33 using namespace TizenApis::Commons;
34 using namespace TizenApis::Api::Application;
35 using namespace WrtDeviceApis;
36 using namespace WrtDeviceApis::Commons;
37 using namespace WrtDeviceApis::CommonsJavaScript;
39 ApplicationListener& ApplicationListener::getInstance()
41 static ApplicationListener instance;
45 ApplicationListener::ApplicationListener() :
46 WrtDeviceApis::Commons::EventListener<EventInstalledApplicationChanged>(WrtDeviceApis::Commons::ThreadEnum::NULL_THREAD)
50 void ApplicationListener::onAnswerReceived(const EventInstalledApplicationChangedPtr& event)
52 JSCallbackManagerPtr callbackManager = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
53 JSContextRef context = callbackManager->getContext();
54 Converter converter(context);
56 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
60 JSValueRef result = JSApplicationEvent::createJSObject(context, event->getEventCode(), event->getApplicationInformation());
61 callbackManager->callOnSuccess(result);
63 Catch(WrtDeviceApis::Commons::Exception)
65 LogError("error during function executing");
69 LogDebug("Operation failed. Exception code: " << event->getExceptionCode());
70 JSValueRef errorObject = NULL;
72 WrtDeviceApis::Commons::ExceptionCodes::Enumeration exception = event->getExceptionCode();
75 errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error");
78 callbackManager->callOnError(errorObject);