Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/SessionManager/include/ResourceManager.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: ResourceManager.h,v 1.3 1996/07/30 20:00:27 bormotov Exp $
00003  */
00004  
00005 // Copyright (C) 1995 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 //
00008 // Contents: Declaration of class ResourceManager
00009 //
00010 // Principal Author: Roger Needham
00011 //
00012 // Status: in progress
00013 //
00014 // Revision History:
00015 //
00016 
00017 //@rn Give some thought to access restrictions and efficiency.
00018 
00019 
00020 #ifndef _RESOURCEMANAGER_H_
00021 #define _RESOURCEMANAGER_H_
00022 
00023 
00024 #include "ARC.h"
00025 #include "ARCSlotID.h"
00026 #include "OID.h"
00027 
00028 
00029 //---------------------------------------------------------------------------//
00030 //------------------------- ResourceManager ---------------------------------//
00031 //---------------------------------------------------------------------------//
00032 
00033 class ResourceManager
00034 {
00035 public:
00036 
00037   /////////////////////////////////////////////////////////////////////////
00038   //                                                                     //
00039   // Constructors:                                                       //
00040   //                                                                     //
00041   /////////////////////////////////////////////////////////////////////////
00042 
00043   ResourceManager(OID oid);
00044 
00045   ~ResourceManager( );
00046 
00047   /////////////////////////////////////////////////////////////////////////
00048   //                                                                     //
00049   // Accessors:                                                          //
00050   //                                                                     //
00051   /////////////////////////////////////////////////////////////////////////
00052 
00053   OID getOID( ) const;
00054   // Since this class is imported by an SMObject, we need to store the
00055   // OID here, too.
00056 
00057   ARC freeARCs( ) const;
00058   // Returns the number of liquid, i.e., spendable ARCs available to this.
00059 
00060   bool workingFor(OID oid) const;
00061   // Returns true if this has 1 or more ARCs from oid.
00062 
00063   bool isNeeded() const;
00064 
00065 
00066   /////////////////////////////////////////////////////////////////////////
00067   //                                                                     //
00068   // Control:                                                            //
00069   //                                                                     //
00070   /////////////////////////////////////////////////////////////////////////
00071 
00072   void freeze( );
00073   // Says that this may not spend any ARCs, and any ARCs allocated by this
00074   // are also frozen.
00075 
00076   void liquefy( );
00077   // Reverses the effect of `freeze' (which need not have been called).
00078 
00079   /////////////////////////////////////////////////////////////////////////
00080   //                                                                     //
00081   // Transactions:                                                       //
00082   //                                                                     //
00083   /////////////////////////////////////////////////////////////////////////
00084 
00085   void allocate(ResourceManager& recipient, ARC arcs);
00086   // This wishes to give `arcs' to `recipient', to spend as `recipient'
00087   // likes.
00088 
00089   void acceptAllocation(OID benefactor,
00090                                                                 ARCSlotID asi,
00091                                                                 ARC arcs,
00092                                                                 bool overrides = false
00093                                                                 );
00094   // `benefactor' wants to give us `arcs'. We are told to which ARCSlotID
00095   // of the OID to report spending. When `overrides', we clear any record
00096   // of allocation from `oid', and substitute this one.
00097 
00098   void usedARCs(ARC arcs);
00099   // A derivative informs this that is has spent `arcs'.
00100 
00101   void usedOneARC( );
00102   // Commonly used shortcut.
00103 
00104   void usedMemory(int kilobytes) { }  //@rn Not yet supported.
00105 
00106 
00107 private:
00108 
00109   bool isLiquid(OID oid) const;
00110   // We will record in a central location which objects in this class
00111   // are frozen. This aids in determining whether a Resources record
00112   // is free for use.
00113 
00114   ResourceManager(const ResourceManager&);
00115   // Hidden, not to be implemented.
00116 
00117   ResourceManager& operator = (const ResourceManager&);
00118   // Hidden, not to be implemented.
00119 
00120   /////////////////////////////////////////////////////////////////////////
00121   //                                                                     //
00122   // Data Members:                                                       //
00123   //                                                                     //
00124   /////////////////////////////////////////////////////////////////////////
00125 
00126   struct Resources
00127   {
00128          Resources(OID oid, ARCSlotID asi, ARC arcs, Resources* n) :
00129            benefactor(oid),
00130                 theARCs(arcs),
00131                 theARCSlotID(asi),
00132                 memory(-1),        // No limit
00133                 next(n)
00134          { }
00135 
00136          ~Resources( ) { delete next; }
00137 
00138          OID benefactor;
00139          ARCSlotID theARCSlotID;
00140          ARC theARCs;
00141          int memory;
00142 
00143          Resources* next;
00144   };
00145 
00146 
00147   Resources* toUse;
00148   // These are the Resources gotten from elsewhere.
00149 
00150   Resources* lastDrawnFrom;
00151   // Pointer into toUse of last Resources drawn from.
00152 
00153   OID theOID;
00154   // The oid of the ComputationManager for which this manages Resources.
00155 
00156 };
00157 
00158 #endif

Generated at Tue Jun 19 09:49:38 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001