Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame^] | 1 | /* |
| 2 | Copyright (c) 2018-2019 Nokia. |
| 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 | #include "private/asyncdummystorage.hpp" |
| 18 | #include <sys/eventfd.h> |
| 19 | #include "private/engine.hpp" |
| 20 | |
| 21 | using namespace shareddatalayer; |
| 22 | |
| 23 | AsyncDummyStorage::AsyncDummyStorage(std::shared_ptr<Engine> engine): |
| 24 | engine(engine) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | int AsyncDummyStorage::fd() const |
| 29 | { |
| 30 | return engine->fd(); |
| 31 | } |
| 32 | |
| 33 | void AsyncDummyStorage::handleEvents() |
| 34 | { |
| 35 | engine->handleEvents(); |
| 36 | } |
| 37 | |
| 38 | void AsyncDummyStorage::postCallback(const Callback& callback) |
| 39 | { |
| 40 | engine->postCallback(callback); |
| 41 | } |
| 42 | |
| 43 | void AsyncDummyStorage::waitReadyAsync(const Namespace&, const ReadyAck& readyAck) |
| 44 | { |
| 45 | postCallback(std::bind(readyAck, std::error_code())); |
| 46 | } |
| 47 | |
| 48 | void AsyncDummyStorage::setAsync(const Namespace&, const DataMap&, const ModifyAck& modifyAck) |
| 49 | { |
| 50 | postCallback(std::bind(modifyAck, std::error_code())); |
| 51 | } |
| 52 | |
| 53 | void AsyncDummyStorage::setIfAsync(const Namespace&, const Key&, const Data&, const Data&, const ModifyIfAck& modifyIfAck) |
| 54 | { |
| 55 | postCallback(std::bind(modifyIfAck, std::error_code(), true)); |
| 56 | } |
| 57 | |
| 58 | void AsyncDummyStorage::setIfNotExistsAsync(const Namespace&, const Key&, const Data&, const ModifyIfAck& modifyIfAck) |
| 59 | { |
| 60 | postCallback(std::bind(modifyIfAck, std::error_code(), true)); |
| 61 | } |
| 62 | |
| 63 | void AsyncDummyStorage::getAsync(const Namespace&, const Keys&, const GetAck& getAck) |
| 64 | { |
| 65 | postCallback(std::bind(getAck, std::error_code(), DataMap())); |
| 66 | } |
| 67 | |
| 68 | void AsyncDummyStorage::removeAsync(const Namespace&, const Keys&, const ModifyAck& modifyAck) |
| 69 | { |
| 70 | postCallback(std::bind(modifyAck, std::error_code())); |
| 71 | } |
| 72 | |
| 73 | void AsyncDummyStorage::removeIfAsync(const Namespace&, const Key&, const Data&, const ModifyIfAck& modifyIfAck) |
| 74 | { |
| 75 | postCallback(std::bind(modifyIfAck, std::error_code(), true)); |
| 76 | } |
| 77 | |
| 78 | void AsyncDummyStorage::findKeysAsync(const Namespace&, const std::string&, const FindKeysAck& findKeysAck) |
| 79 | { |
| 80 | postCallback(std::bind(findKeysAck, std::error_code(), Keys())); |
| 81 | } |
| 82 | |
| 83 | void AsyncDummyStorage::removeAllAsync(const Namespace&, const ModifyAck& modifyAck) |
| 84 | { |
| 85 | postCallback(std::bind(modifyAck, std::error_code())); |
| 86 | } |