00001 // Copyright (C) 2001, Compaq Computer Corporation 00002 // 00003 // This file is part of Vesta. 00004 // 00005 // Vesta is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // Vesta is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with Vesta; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 // RemoteModelSpace.H -- Sub-classes of ParseImports::ModelSpace for 00020 // reading the imports of models in remote repositories 00021 00022 #ifndef _REMOTE_MODEL_SPACE_H 00023 #define _REMOTE_MODEL_SPACE_H 00024 00025 #include <VestaSource.H> 00026 #include "ParseImports.H" 00027 00028 // Size of the model to read from the remote server 00029 #define RMS_BLOCKSIZE 8192 00030 00031 namespace ParseImports { 00032 00033 // Subclass to support ParseImports reading models directly from the 00034 // VestaSource interface. This is needed to support the general case 00035 // where the source repository may not be local or may not be mounted 00036 // locally as /vesta. 00037 // 00038 class RemoteModelSpace : public ModelSpace { 00039 public: 00040 char getC() throw (Error, FS::EndOfFile, SRPC::failure); 00041 void ungetC(char c) throw () { assert(putback == -1); putback = c; }; 00042 long tell() throw () { return offset - inbuf + bufidx; }; 00043 RemoteModelSpace(VestaSource* root, AccessControl::Identity who) { 00044 this->root = root; 00045 this->who = who; 00046 this->file = NULL; 00047 this->putback = -1; 00048 this->bufidx = 0; 00049 this->inbuf = 0; 00050 this->offset = 0; 00051 this->goteof = false; 00052 }; 00053 ModelSpace* open(const Text &modelname) const 00054 throw(Error, FS::Failure, SRPC::failure); 00055 ModelSpace::type getType(const Text &name) 00056 const throw (SRPC::failure); 00057 ~RemoteModelSpace() { if (file) delete file; }; 00058 private: 00059 VestaSource* root; 00060 AccessControl::Identity who; 00061 VestaSource* file; 00062 int putback; 00063 int bufidx; 00064 int inbuf; 00065 unsigned long offset; 00066 bool goteof; 00067 char buf[RMS_BLOCKSIZE]; 00068 }; 00069 00070 // Use the local filesystem for reading a model already replicated 00071 // locally, but fall back on calling the remote repository for 00072 // anything not replicated locally. 00073 00074 class OptimizedModelSpace : public LocalModelSpace 00075 { 00076 private: 00077 const RemoteModelSpace &remote_space; 00078 public: 00079 ModelSpace* open(const Text &modelname) const 00080 throw(Error, FS::Failure); 00081 ModelSpace::type getType(const Text &name) const throw (); 00082 OptimizedModelSpace(const Text &modelname, 00083 const RemoteModelSpace &remote) throw(FS::Failure); 00084 }; 00085 } 00086 00087 #endif