2 * Copyright (c) 2016 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 * @author Kyungwook Tak (k.tak@samsung.com)
22 #include "client/utils.h"
26 #include "common/audit/logger.h"
27 #include "common/exception.h"
28 #include <csr-error.h>
30 __attribute__((constructor))
31 static void init_lib(void)
33 Csr::Audit::Logger::setTag("CSR_CLIENT");
39 int exceptionGuard(const std::function<int()> &func)
43 } catch (const Exception &e) {
44 ERROR("Exception caught. code: " << e.error() << " message: " << e.what());
46 } catch (const std::invalid_argument &e) {
47 ERROR("invalid argument: " << e.what());
48 return CSR_ERROR_INVALID_PARAMETER;
49 } catch (const std::bad_alloc &e) {
50 ERROR("memory allocation failed: " << e.what());
51 return CSR_ERROR_OUT_OF_MEMORY;
52 } catch (const std::exception &e) {
53 ERROR("std exception: " << e.what());
54 return CSR_ERROR_SYSTEM;
56 ERROR("Unknown exception occured!");
57 return CSR_ERROR_SYSTEM;
61 void exceptionGuardAsync(const Callback &callbacks, void *userdata,
62 const std::function<void()> &func)
66 callbacks.onCompleted(userdata);
67 } catch (const Exception &e) {
68 if (e.error() == -999) {
69 INFO("Async operation cancel exception!");
70 callbacks.onCancelled(userdata);
72 ERROR("Exception caught. code: " << e.error() << " message: " << e.what());
73 callbacks.onError(e.error(), userdata);
75 } catch (const std::invalid_argument &e) {
76 ERROR("invalid argument: " << e.what());
77 callbacks.onError(CSR_ERROR_INVALID_PARAMETER, userdata);
78 } catch (const std::bad_alloc &e) {
79 ERROR("memory allocation failed: " << e.what());
80 callbacks.onError(CSR_ERROR_OUT_OF_MEMORY, userdata);
81 } catch (const std::exception &e) {
82 ERROR("std exception: " << e.what());
83 callbacks.onError(CSR_ERROR_SYSTEM, userdata);
85 ERROR("Unknown exception occured!");
86 callbacks.onError(CSR_ERROR_SYSTEM, userdata);