/usr/include/xmltooling/util/StorageService.h is in libxmltooling-dev 1.5.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | /**
* Licensed to the University Corporation for Advanced Internet
* Development, Inc. (UCAID) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
/**
* @file xmltooling/util/StorageService.h
*
* Generic data storage interface.
*/
#if !defined(__xmltooling_storage_h__) && !defined(XMLTOOLING_LITE)
#define __xmltooling_storage_h__
#include <xmltooling/base.h>
#include <ctime>
namespace xmltooling {
/**
* Generic data storage facility for use by services that require
* some degree of persistence. Implementations will vary in how much
* persistence they can supply.
*
* <p>Storage is divided into "contexts" identified by a string label.
* Keys need to be unique only within a given context, so multiple
* components can share a single storage service safely as long as they
* use different labels.
*
* <p>The allowable sizes for contexts, keys, and short values can vary
* and be reported by the implementation to callers, but MUST be at least
* 255 bytes.
*/
class XMLTOOL_API StorageService
{
MAKE_NONCOPYABLE(StorageService);
public:
virtual ~StorageService();
class XMLTOOL_API Capabilities {
MAKE_NONCOPYABLE(Capabilities);
unsigned int m_contextSize, m_keySize, m_stringSize;
public:
/**
* Constructor.
*
* @param contextSize max size of context labels in characters
* @param keysize max size of keys in characters
* @param stringSize max size of string values in characters
*/
Capabilities(unsigned int contextSize, unsigned int keySize, unsigned int stringSize);
~Capabilities();
/**
* Returns max size of context labels in characters
* @return max size of context labels in characters
*/
unsigned int getContextSize() const;
/**
* Returns max size of keys in characters
* @return max size of keys in characters
*/
unsigned int getKeySize() const;
/**
* Returns max size of string values in characters
* @return max size of string values in characters
*/
unsigned int getStringSize() const;
};
/**
* Returns the capabilities of the underlying service.
* <p>If implementations support only the 255 character minimum, the default
* implementation of this method will suffice.
*
* @return a reference to an interface to access the service's capabilities
*/
virtual const Capabilities& getCapabilities() const;
/**
* Creates a new "short" record in the storage service.
*
* @param context a storage context label
* @param key null-terminated unique key
* @param value null-terminated value
* @param expiration an expiration timestamp, after which the record can be purged
* @return true iff record was inserted, false iff a duplicate was found
*
* @throws IOException raised if fatal errors occur in the insertion process
*/
virtual bool createString(const char* context, const char* key, const char* value, time_t expiration)=0;
/**
* Returns an existing "short" record from the storage service.
*
* <p>The version parameter can be set for "If-Modified-Since" semantics.
*
* @param context a storage context label
* @param key null-terminated unique key
* @param pvalue location in which to return the record value
* @param pexpiration location in which to return the expiration timestamp
* @param version if > 0, only copy back data if newer than supplied version
* @return the version of the record read back, or 0 if no record exists
*
* @throws IOException raised if errors occur in the read process
*/
virtual int readString(
const char* context, const char* key, std::string* pvalue=nullptr, time_t* pexpiration=nullptr, int version=0
)=0;
/**
* Updates an existing "short" record in the storage service.
*
* @param context a storage context label
* @param key null-terminated unique key
* @param value null-terminated value to store, or nullptr to leave alone
* @param expiration a new expiration timestamp, or 0 to leave alone
* @param version if > 0, only update if the current version matches this value
* @return the version of the record after update, 0 if no record exists, or -1 if the version
* parameter is non-zero and does not match the current version before update (so the caller is out of sync)
*
* @throws IOException raised if errors occur in the update process
*/
virtual int updateString(
const char* context, const char* key, const char* value=nullptr, time_t expiration=0, int version=0
)=0;
/**
* Deletes an existing "short" record from the storage service.
*
* @param context a storage context label
* @param key null-terminated unique key
* @return true iff the record existed and was deleted
*
* @throws IOException raised if errors occur in the deletion process
*/
virtual bool deleteString(const char* context, const char* key)=0;
/**
* Creates a new "long" record in the storage service.
*
* @param context a storage context label
* @param key null-terminated unique key
* @param value null-terminated value of arbitrary length
* @param expiration an expiration timestamp, after which the record can be purged
* @return true iff record was inserted, false iff a duplicate was found
*
* @throws IOException raised if errors occur in the insertion process
*/
virtual bool createText(const char* context, const char* key, const char* value, time_t expiration)=0;
/**
* Returns an existing "long" record from the storage service.
*
* <p>The version parameter can be set for "If-Modified-Since" semantics.
*
* @param context a storage context label
* @param key null-terminated unique key
* @param pvalue location in which to return the record value
* @param pexpiration location in which to return the expiration timestamp
* @param version if > 0, only copy back data if newer than supplied version
* @return the version of the record read back, or 0 if no record exists
*
* @throws IOException raised if errors occur in the read process
*/
virtual int readText(
const char* context, const char* key, std::string* pvalue=nullptr, time_t* pexpiration=nullptr, int version=0
)=0;
/**
* Updates an existing "long" record in the storage service.
*
* @param context a storage context label
* @param key null-terminated unique key
* @param value null-terminated value of arbitrary length to store, or nullptr to leave alone
* @param expiration a new expiration timestamp, or 0 to leave alone
* @param version if > 0, only update if the current version matches this value
* @return the version of the record after update, 0 if no record exists, or -1 if the version
* parameter is non-zero and does not match the current version before update (so the caller is out of sync)
*
* @throws IOException raised if errors occur in the update process
*/
virtual int updateText(
const char* context, const char* key, const char* value=nullptr, time_t expiration=0, int version=0
)=0;
/**
* Deletes an existing "long" record from the storage service.
*
* @param context a storage context label
* @param key null-terminated unique key
* @return true iff the record existed and was deleted
*
* @throws IOException raised if errors occur in the deletion process
*/
virtual bool deleteText(const char* context, const char* key)=0;
/**
* Manually trigger a cleanup of expired records.
* The method <strong>MAY</strong> return without guaranteeing that
* cleanup has already occurred.
*
* @param context a storage context label
*/
virtual void reap(const char* context)=0;
/**
* Updates the expiration time of all records in the context.
*
* @param context a storage context label
* @param expiration a new expiration timestamp
*/
virtual void updateContext(const char* context, time_t expiration)=0;
/**
* Forcibly removes all records in a given context along with any
* associated resources devoted to maintaining the context.
*
* @param context a storage context label
*/
virtual void deleteContext(const char* context)=0;
protected:
StorageService();
};
/**
* Registers StorageService classes into the runtime.
*/
void XMLTOOL_API registerStorageServices();
/** StorageService based on in-memory caching. */
#define MEMORY_STORAGE_SERVICE "Memory"
};
#endif /* __xmltooling_storage_h__ */
|