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 "ApplicationConverter.h"
25 #include "JSApplicationInformation.h"
26 #include "JSApplicationEvent.h"
27 #include "ApplicationListener.h"
28 #include "API/Application/ApplicationInformation.h"
29 #include "ApplicationInformationEventPrivateData.h"
34 namespace Application {
37 using namespace TizenApis::Commons;
38 using namespace TizenApis::Api::Application;
39 using namespace WrtDeviceApis;
40 using namespace WrtDeviceApis::Commons;
41 using namespace WrtDeviceApis::CommonsJavaScript;
43 ApplicationListener& ApplicationListener::getInstance()
45 static ApplicationListener instance;
49 ApplicationListener::ApplicationListener() :
50 WrtDeviceApis::Commons::EventListener<EventInstalledApplicationChanged>(WrtDeviceApis::Commons::ThreadEnum::NULL_THREAD)
54 void ApplicationListener::onAnswerReceived(const EventInstalledApplicationChangedPtr& event)
56 LogError(">>> onAnswerReceived for EventInstalledApplicationChanged");
57 ApplicationInformationEventPrivateDataPtr priveData = DPL::DynamicPointerCast<ApplicationInformationEventPrivateData>(event->getPrivateData());
59 if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None)
63 ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(priveData->getOnInstalled()->getContext());
64 // TODO: why send event code to string. enum value is enough!!
65 if (event->getEventCode() == APPLICATON_EVENT_CODE_INSTALLED)
67 LogError(">>> installed event is come");
68 JSValueRef result = converter->toJSValueRef(event->getApplicationInformation());
69 priveData->getOnInstalled()->callOnSuccess(result);
71 else if (event->getEventCode() == APPLICATON_EVENT_CODE_UPDATED)
73 LogError(">>> updated event is come");
74 JSValueRef result = converter->toJSValueRef(event->getApplicationInformation());
75 priveData->getOnUpdated()->callOnSuccess(result);
77 else if (event->getEventCode() == APPLICATON_EVENT_CODE_UNINSTALLED)
79 LogError(">>> uninstalled event is come");
80 JSValueRef result = converter->toJSValueRef(event->getApplicationInformation()->getAppId());
81 priveData->getOnUninstalled()->callOnSuccess(result);
84 Catch (WrtDeviceApis::Commons::Exception)
86 LogError("error during function executing");
91 LogDebug("Operation failed. Exception code: " << event->getExceptionCode());
92 JSValueRef errorObject = NULL;
94 WrtDeviceApis::Commons::ExceptionCodes::Enumeration exception = event->getExceptionCode();
97 errorObject = JSTizenExceptionFactory::makeErrorObject(priveData->getOnInstalled()->getContext(),JSTizenException::UNKNOWN_ERROR,"unknown error");
100 priveData->getOnInstalled()->callOnError(errorObject);