2 * Copyright (c) 2014-2015 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 src/storage/InMemoryStorageBackend.h
18 * @author Aleksander Zdyb <a.zdyb@samsung.com>
20 * @brief Headers for InMemoryStorageBackend
23 #ifndef SRC_STORAGE_INMEMORYSTORAGEBACKEND_H_
24 #define SRC_STORAGE_INMEMORYSTORAGEBACKEND_H_
30 #include <types/pointers.h>
31 #include <types/PolicyBucket.h>
32 #include <types/PolicyBucketId.h>
33 #include <types/PolicyKey.h>
34 #include <types/PolicyResult.h>
36 #include <storage/BucketDeserializer.h>
37 #include <storage/Buckets.h>
38 #include <storage/Integrity.h>
39 #include <storage/StorageBackend.h>
40 #include <storage/StorageSerializer.h>
44 class InMemoryStorageBackend : public StorageBackend {
46 InMemoryStorageBackend() = delete;
47 InMemoryStorageBackend(const std::string &path);
48 virtual ~InMemoryStorageBackend() {};
50 virtual void load(void);
51 virtual void save(void);
53 virtual PolicyBucket searchDefaultBucket(const PolicyKey &key);
54 virtual PolicyBucket searchBucket(const PolicyBucketId &bucketId, const PolicyKey &key);
55 virtual void insertPolicy(const PolicyBucketId &bucketId, PolicyPtr policy);
56 virtual void createBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy);
57 virtual void updateBucket(const PolicyBucketId &bucketId, const PolicyResult &defaultPolicy);
58 virtual void deleteBucket(const PolicyBucketId &bucketId);
59 virtual bool hasBucket(const PolicyBucketId &bucketId);
60 virtual void deletePolicy(const PolicyBucketId &bucketId, const PolicyKey &key);
61 virtual void deleteLinking(const PolicyBucketId &bucketId);
62 virtual PolicyBucket::Policies listPolicies(const PolicyBucketId &bucketId,
63 const PolicyKey &filter) const;
64 virtual void erasePolicies(const PolicyBucketId &bucketId, bool recursive,
65 const PolicyKey &filter);
68 void openFileStream(std::shared_ptr<std::ifstream> stream, const std::string &filename);
69 std::shared_ptr<BucketDeserializer> bucketStreamOpener(const PolicyBucketId &bucketId,
70 const std::string &fileNameSuffix);
72 virtual void openDumpFileStream(std::shared_ptr<std::ofstream> stream,
73 const std::string &filename);
74 std::shared_ptr<StorageSerializer<std::ofstream> > bucketDumpStreamOpener(
75 const PolicyBucketId &bucketId);
77 virtual void postLoadCleanup(bool isBackupValid);
82 Integrity m_integrity;
83 static const std::string m_indexFilename;
84 static const std::string m_backupFilenameSuffix;
85 static const std::string m_bucketFilenamePrefix;
88 virtual Buckets &buckets(void) {
91 virtual const Buckets &buckets(void) const {
96 } /* namespace Cynara */
98 #endif /* SRC_STORAGE_INMEMORYSTORAGEBACKEND_H_ */