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.
19 * @file AccountManagerController.cpp
20 * @author Jihwa Park (jh7979.park@samsung.com)
26 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
27 #include "AccountManagerController.h"
28 #include "JSAccountService.h"
29 #include "AccountConverter.h"
31 using namespace TizenApis::Api::Account;
32 using namespace WrtDeviceApis::Commons;
33 using namespace WrtDeviceApis::CommonsJavaScript;
39 AccountManagerController::AccountManagerController(JSContextRef context,
40 IAccountManagerPtr accountManager) :
41 GetAccountServicesEventAnswerReceiver(ThreadEnum::NULL_THREAD),
42 AccountManagerPrivObject(context, accountManager)
47 AccountManagerController::~AccountManagerController()
52 void AccountManagerController::OnAnswerReceived(
53 const IEventGetAccountServicesPtr &event)
56 JSCallbackManagerPtr cbm =
57 DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
59 LogError("no callback manager");
64 if (event->getResult()) {
65 AccountConverterFactory::ConverterType converter =
66 AccountConverterFactory::getConverter(cbm->getContext());
67 const std::vector<IAccountServicePtr> &results = event->getAccountServices();
68 LogDebug("found accounts: " << results.size());
69 JSValueRef result = converter->toJSValueRef(results);
70 cbm->callOnSuccess(result);
76 LogError("error during processing answer");
78 JSValueRef errorObject = JSDOMExceptionFactory::UnknownException.make(
80 cbm->callOnError(errorObject);