update for beta universally
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Account / AccountManagerController.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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. 
15  */
16
17
18 /*
19  * @file                AccountManagerController.cpp
20  * @author      Jihwa Park (jh7979.park@samsung.com)
21  * @author      Sangtai Kim
22  * @version     0.1
23  * @brief
24  */
25
26 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
27 #include "AccountManagerController.h"
28 #include "JSAccountService.h"
29 #include "AccountConverter.h"
30
31 using namespace TizenApis::Api::Account;
32 using namespace WrtDeviceApis::Commons;
33 using namespace WrtDeviceApis::CommonsJavaScript;
34
35 namespace TizenApis {
36 namespace Tizen1_0 {
37 namespace Account{
38         
39 AccountManagerController::AccountManagerController(JSContextRef context,
40         IAccountManagerPtr accountManager) :
41     GetAccountServicesEventAnswerReceiver(ThreadEnum::NULL_THREAD),
42     AccountManagerPrivObject(context, accountManager)
43 {
44     LogDebug("entered");
45 }
46
47 AccountManagerController::~AccountManagerController()
48 {
49     LogDebug("entered");
50 }
51
52 void AccountManagerController::OnAnswerReceived(
53         const IEventGetAccountServicesPtr &event)
54 {
55     LogDebug("entered");
56     JSCallbackManagerPtr cbm =
57         DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
58     if (!cbm) {
59         LogError("no callback manager");
60         return;
61     }
62     Try
63     {
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);
71             return;
72         }
73     }
74     Catch(Exception)
75     {
76         LogError("error during processing answer");
77     }
78     JSValueRef errorObject = JSDOMExceptionFactory::UnknownException.make(
79             cbm->getContext());
80     cbm->callOnError(errorObject);
81 }
82
83
84 }
85 }
86 }