Backend.hpp 2.33 KB
Newer Older
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
#pragma once

#include <string>

namespace cta { namespace objectstore {
  
/**
 * Interface to the backend stores that we can use.
 */

class Backend {
public:
  virtual ~Backend() {}
  /**
   * Create an object (and possibly the necessary locking structures)
   * @param name name of the object
   * @param content the object's content
   */
  virtual void create(std::string name, std::string content) = 0;
  
  /**
   * Overwrite an existing object atomically
   * @param name name of the object
   * @param content new content of the object
   */
  virtual void atomicOverwrite(std::string name, std::string content) = 0;
  
  /**
   * Read the content of an object
   * @param name name of the object
   * @return the content of the object, as a string.
   */
  virtual std::string read(std::string name) = 0;
  
  /**
   * Delete an object (and possibly its locking structure)
   * @param name name of the object
   */
  virtual void remove(std::string name) = 0;
  
  /**
   * Tests the existence of the object
   * @param name 
   * @return true if the object is found
   */
  virtual bool exists(std::string name) = 0;  
  
  /**
   * RAII class holding locks
   */
  class ScopedLock {
  public:
    /**
     * Explicitely releases the lock
     */
    virtual void release() = 0;
    
    /**
     * Destructor (implicitly releases the lock).
     */
    virtual ~ScopedLock() {}
  };
  
  /**
   * Locks the object shared
   * @param name name of the object
   * @return pointer to a newly created scoped lock object (for RAII)
   */
  virtual ScopedLock * lockShared(std::string name) = 0;
  
  /**
   * Locks the object exclusively
   * @param name name of the object
   * @return pointer to a newly created scoped lock object (for RAII)
   */
  virtual ScopedLock * lockExclusive(std::string name) = 0;

  /**
   * Base class for the representation of the parameters of the BackendStore.
   */
  class Parameters {
  public:
    /**
     * Turns parameter class into string representation
     * @return the string representation
     */
    virtual std::string toStr() = 0;
    
    /**
     * Virtual destructor 
     */
    virtual ~Parameters() {}
  };
  
  /**
   * Returns a type specific representation of the parameters
   * @return pointer to the newly created representation.
   */
  virtual Parameters * getParams() = 0;
};

}} // end of cta::objectstore