File: ResourceManager.h

package info (click to toggle)
magnus 20060324-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,404 kB
  • ctags: 20,466
  • sloc: cpp: 130,118; ansic: 37,076; tcl: 10,970; perl: 1,109; makefile: 963; sh: 403; yacc: 372; csh: 57; awk: 33; asm: 10
file content (154 lines) | stat: -rw-r--r-- 4,839 bytes parent folder | download | duplicates (3)
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
// Copyright (C) 1995 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.
//
// Contents: Declaration of class ResourceManager
//
// Principal Author: Roger Needham
//
// Status: in progress
//
// Revision History:
//

//@rn Give some thought to access restrictions and efficiency.


#ifndef _RESOURCEMANAGER_H_
#define _RESOURCEMANAGER_H_


#include "ARC.h"
#include "ARCSlotID.h"
#include "OID.h"


//---------------------------------------------------------------------------//
//------------------------- ResourceManager ---------------------------------//
//---------------------------------------------------------------------------//

class ResourceManager
{
public:

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Constructors:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  ResourceManager(OID oid);

  ~ResourceManager( );

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Accessors:                                                          //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  OID getOID( ) const;
  // Since this class is imported by an SMObject, we need to store the
  // OID here, too.

  ARC freeARCs( ) const;
  // Returns the number of liquid, i.e., spendable ARCs available to this.

  bool workingFor(OID oid) const;
  // Returns true if this has 1 or more ARCs from oid.

  bool isNeeded() const;


  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Control:                                                            //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  void freeze( );
  // Says that this may not spend any ARCs, and any ARCs allocated by this
  // are also frozen.

  void liquefy( );
  // Reverses the effect of `freeze' (which need not have been called).

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Transactions:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  void allocate(ResourceManager& recipient, ARC arcs);
  // This wishes to give `arcs' to `recipient', to spend as `recipient'
  // likes.

  void acceptAllocation(OID benefactor,
								ARCSlotID asi,
								ARC arcs,
								bool overrides = false
								);
  // `benefactor' wants to give us `arcs'. We are told to which ARCSlotID
  // of the OID to report spending. When `overrides', we clear any record
  // of allocation from `oid', and substitute this one.

  void usedARCs(ARC arcs);
  // A derivative informs this that is has spent `arcs'.

  void usedOneARC( );
  // Commonly used shortcut.

  void usedMemory(int kilobytes) { }  //@rn Not yet supported.


private:

  bool isLiquid(OID oid) const;
  // We will record in a central location which objects in this class
  // are frozen. This aids in determining whether a Resources record
  // is free for use.

  ResourceManager(const ResourceManager&);
  // Hidden, not to be implemented.

  ResourceManager& operator = (const ResourceManager&);
  // Hidden, not to be implemented.

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Data Members:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  struct Resources
  {
	 Resources(OID oid, ARCSlotID asi, ARC arcs, Resources* n) :
	   benefactor(oid),
		theARCs(arcs),
		theARCSlotID(asi),
		memory(-1),        // No limit
		next(n)
	 { }

	 ~Resources( ) { delete next; }

	 OID benefactor;
	 ARCSlotID theARCSlotID;
	 ARC theARCs;
	 int memory;

	 Resources* next;
  };


  Resources* toUse;
  // These are the Resources gotten from elsewhere.

  Resources* lastDrawnFrom;
  // Pointer into toUse of last Resources drawn from.

  OID theOID;
  // The oid of the ComputationManager for which this manages Resources.

};

#endif