GenericObject.hpp 3.19 KB
Newer Older
1
/*
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  CERN
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

19
20
21
22
23
24
25
26
27
28
#pragma once

#include "ObjectOps.hpp"
#include "objectstore/cta.pb.h"

namespace cta {  namespace objectstore {

class GenericObject: public ObjectOps<serializers::GenericObject> {
public:
  GenericObject(const std::string & name, Backend & os):
29
    ObjectOps<serializers::GenericObject>(os, name) {};
30
31
32
33
34
35
    
  class ForbiddenOperation: public cta::exception::Exception {
  public:
    ForbiddenOperation(const std::string & w): cta::exception::Exception(w) {}
  };
    
36
37
  /** Overload of ObjectOps's implementation: this special object tolerates all
   * types of objects */
38
39
  void fetch();
  
40
41
  /** Overload of ObjectOps's implementation: we will leave the payload transparently
   * untouched and only deal with header parameters */
42
43
  void commit();
  
44
  /** Get the object's type (type is forced implicitly in other classes) */
45
46
  serializers::ObjectType type();
  
47
48
  /** Overload of ObjectOps's implementation: this operation is forbidden. Generic
   * Object is only used to manipulate existing objects */
49
50
  void insert();
  
51
52
  /** Overload of ObjectOps's implementation: this operation is forbidden. Generic
   * Object is only used to manipulate existing objects */
53
54
  void initialize();
  
55
56
57
58
  /** This dispatcher function will call the object's garbage collection function.
   * It also handles the passed lock and returns is unlocked.
   * The object is expected to be passed exclusive locked and already fetched.
   * No extra care will be required from the object
59
60
61
   *
   * @param lock reference to the generic object's lock
   * @param presumedOwner address of the agent which pointed to the object
62
   */
63
  void garbageCollect(ScopedExclusiveLock & lock, const std::string &presumedOwner);
64
  
Eric Cano's avatar
Eric Cano committed
65
66
67
68
69
70
71
  /** This dispatcher function will call the object's dump.
   * It also handles the passed lock.
   *
   * @param lock reference to the generic object's lock
   */
  std::string dump(ScopedSharedLock & lock);
  
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  CTA_GENERATE_EXCEPTION_CLASS(UnsupportedType);
  /**
   * This static function is a helper that will garbage collect the object at 
   * the given address
   */
  static void garbageCollect(const std::string & address);
  
  /**
   * This method will extract contents of the generic object's header and
   * transfer them to the header of the destination
   * The source (this) will be emptied.
   * @param destination pointed to the new object's destination
   */
  void transplantHeader(ObjectOpsBase & destination);
  
  /**
   * This method exposes the reference to the object store.
   */
  Backend & objectStore();
91
92
93
94
};

}}