2 * Copyright (c) 2000 - 2017 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
17 * @file ckm-logic-ext.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #include "ckm-logic-ext.h"
24 #include "db-crypto-ext.h"
28 DB::SqlConnection::Output CKMLogicExt::Execute(uid_t user,
29 const std::string &cmd)
32 * We need to access to DB::Crypto::m_connection to call Execute() on it. We don't want to mess
33 * with DB::Crypto too much so adding a friend and extending public interface was not an option.
34 * That's why we need a derived class DB::CryptoExt. m_userDataMap must be left unchanged after
35 * this operation but DB::Crypto can't be copied. According to C++ standard static casting
36 * DB::Crypto pointer to DB::CryptoExt pointer is UB. Therefore DB::Crypto is temporarily moved
37 * into DB::CryptoExt and moved back to m_userDataMap after the call to Execute().
39 DB::CryptoExt db(std::move(m_userDataMap[user].database));
42 DB::SqlConnection::Output output = db.Execute(cmd);
43 m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
45 } catch (const DB::SqlConnection::Exception::Base &e) {
46 m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
51 DB::RowVector CKMLogicExt::getRows(uid_t user)
53 DB::CryptoExt db(std::move(m_userDataMap[user].database));
56 DB::RowVector output = db.getRows();
57 m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
59 } catch (const DB::SqlConnection::Exception::Base &e) {
60 m_userDataMap[user].database = std::move(*static_cast<DB::Crypto *>(&db));
65 void CKMLogicExt::saveRow(uid_t user, const DB::Row &row)
67 m_userDataMap[user].database.saveRow(row);