Debian Codegraph @

src/lib/object_store/ObjectStore.h

raw
1 /*
2 * Copyright (c) 2010 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 ObjectStore.h
29
30 The object store manages the separate tokens that the SoftHSM supports. Each
31 token is organised as a directory containing files that are contain the
32 token's objects. The object store is initialised with a root directory from
33 which it enumerates the tokens.
34 *****************************************************************************/
35
36 #ifndef _SOFTHSM_V2_OBJECTSTORE_H
37 #define _SOFTHSM_V2_OBJECTSTORE_H
38
39 #include "config.h"
40 #include "ByteString.h"
41 #include "ObjectStoreToken.h"
42 #include "MutexFactory.h"
43 #include <string>
44 #include <vector>
45
46 class ObjectStore
47 {
48 public:
49 // Constructor
50 ObjectStore(std::string inStorePath);
51
52 // Destructor
53 virtual ~ObjectStore();
54
55 // Return the number of tokens that is present
56 size_t getTokenCount();
57
58 // Return a pointer to the n-th token (counting starts at 0)
59 ObjectStoreToken* getToken(size_t whichToken);
60
61 // Create a new token
62 ObjectStoreToken* newToken(const ByteString& label);
63
64 // Destroy a token
65 bool destroyToken(ObjectStoreToken* token);
66
67 // Check if the object store is valid
68 bool isValid();
69
70 private:
71 // The tokens
72 std::vector<ObjectStoreToken*> tokens;
73
74 // All tokens
75 std::vector<ObjectStoreToken*> allTokens;
76
77 // The object store root directory
78 std::string storePath;
79
80 // The status
81 bool valid;
82
83 // Object store synchronisation
84 Mutex* storeMutex;
85 };
86
87 #endif // !_SOFTHSM_V2_OBJECTSTORE_H
88