X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-xmltooling.git;a=blobdiff_plain;f=xmltooling%2Futil%2FStorageService.h;h=7a2a707cce6b4841c6f9c1a41596f2cef86b0a89;hp=905884ba3ec7e864e30a16e668d1e26d8aceec93;hb=1634821217afa6ee6751d075afdf23a53f9b73c8;hpb=8c28c26a2cb6adf1e2f56af534b5157a9ec605e0 diff --git a/xmltooling/util/StorageService.h b/xmltooling/util/StorageService.h index 905884b..7a2a707 100644 --- a/xmltooling/util/StorageService.h +++ b/xmltooling/util/StorageService.h @@ -35,26 +35,51 @@ namespace xmltooling { class XMLTOOL_API StorageService { MAKE_NONCOPYABLE(StorageService); - protected: - StorageService() {} - public: virtual ~StorageService() {} /** + * A "context" for accessing a StorageService instance. + * Handles are created and freed using the StorageService interface, + * and can be kept for the life of the service, and shared by multiple + * threads. + */ + class XMLTOOL_API StorageHandle { + MAKE_NONCOPYABLE(StorageHandle); + friend class XMLTOOL_API StorageService; + public: + virtual ~StorageHandle() {} + protected: + StorageHandle(StorageService* storage) : m_storage(storage) {} + StorageService* m_storage; + }; + + + /** + * Returns a new handle for the storage service. + * The caller MUST delete the handle + * before freeing the StorageService itself. + * + * @return a new handle + */ + virtual StorageHandle* createHandle()=0; + + /** * Creates a new "short" record in the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @param value null-terminated value of up to 255 bytes to store * @param expiration an expiration timestamp, after which the record can be purged * * @throws IOException raised if errors occur in the insertion process */ - virtual void createString(const char* key, const char* value, time_t expiration)=0; + virtual void createString(StorageHandle* handle, const char* key, const char* value, time_t expiration)=0; /** * Returns an existing "short" record from the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @param value location in which to return the record value * @param modifiedSince the record should not be returned if unmodified since this time, @@ -63,11 +88,12 @@ namespace xmltooling { * * @throws IOException raised if errors occur in the read process */ - virtual bool readString(const char* key, std::string& value, time_t modifiedSince=0)=0; + virtual bool readString(StorageHandle* handle, const char* key, std::string& value, time_t modifiedSince=0)=0; /** * Updates an existing "short" record in the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @param value null-terminated value of up to 255 bytes to store, or NULL to leave alone * @param expiration a new expiration timestamp, or 0 to leave alone @@ -75,32 +101,35 @@ namespace xmltooling { * * @throws IOException raised if errors occur in the update process */ - virtual bool updateString(const char* key, const char* value=NULL, time_t expiration=0)=0; + virtual bool updateString(StorageHandle* handle, const char* key, const char* value=NULL, time_t expiration=0)=0; /** * Deletes an existing "short" record from the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @return true iff the record existed and was deleted * * @throws IOException raised if errors occur in the deletion process */ - virtual bool deleteString(const char* key)=0; + virtual bool deleteString(StorageHandle* handle, const char* key)=0; /** * Creates a new "long" record in the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @param value null-terminated value of arbitrary length * @param expiration an expiration timestamp, after which the record can be purged * * @throws IOException raised if errors occur in the insertion process */ - virtual void createText(const char* key, const char* value, time_t expiration)=0; + virtual void createText(StorageHandle* handle, const char* key, const char* value, time_t expiration)=0; /** * Returns an existing "long" record from the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @param value location in which to return the record value * @param modifiedSince the record should not be returned if unmodified since this time, @@ -109,11 +138,12 @@ namespace xmltooling { * * @throws IOException raised if errors occur in the read process */ - virtual bool readText(const char* key, std::string& value, time_t modifiedSince=0)=0; + virtual bool readText(StorageHandle* handle, const char* key, std::string& value, time_t modifiedSince=0)=0; /** * Updates an existing "long" record in the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @param value null-terminated value of arbitrary length to store, or NULL to leave alone * @param expiration a new expiration timestamp, or 0 to leave alone @@ -121,24 +151,34 @@ namespace xmltooling { * * @throws IOException raised if errors occur in the update process */ - virtual bool updateText(const char* key, const char* value=NULL, time_t expiration=0)=0; + virtual bool updateText(StorageHandle* handle, const char* key, const char* value=NULL, time_t expiration=0)=0; /** * Deletes an existing "long" record from the storage service. * + * @param handle a valid storage handle * @param key null-terminated unique key of up to 255 bytes * @return true iff the record existed and was deleted * * @throws IOException raised if errors occur in the deletion process */ - virtual bool deleteText(const char* key)=0; + virtual bool deleteText(StorageHandle* handle, const char* key)=0; /** * Manually trigger a cleanup of expired records. * The method MAY return without guaranteeing that * cleanup has already occurred. + * + * @param handle a valid storage handle */ - virtual void reap()=0; + virtual void reap(StorageHandle* handle)=0; + + protected: + StorageService() {} + + virtual bool isValid(StorageHandle* handle) { + return this == (handle ? handle->m_storage : NULL); + } }; /**