Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

RemoteModelSpace.C

Go to the documentation of this file.
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 #include <ReposUI.H>
00023 #include "RemoteModelSpace.H"
00024 
00025 char
00026 ParseImports::RemoteModelSpace::getC() 
00027   throw (ParseImports::Error, FS::EndOfFile, SRPC::failure)
00028 {
00029     if (putback != -1) {
00030         char tmp = putback;
00031         putback = -1;
00032         return tmp;
00033     }
00034     while (bufidx >= inbuf) {
00035         if (goteof) {
00036             throw FS::EndOfFile();
00037         }
00038         inbuf = RMS_BLOCKSIZE;
00039         VestaSource::errorCode err = file->read(buf, &inbuf, offset, who);
00040         if (err != VestaSource::ok) {
00041             throw ParseImports::Error(ReposUI::errorCodeText(err));
00042         }
00043         bufidx = 0;
00044         offset += inbuf;
00045         goteof = (inbuf == 0);
00046     }
00047     return buf[bufidx++];
00048 }
00049 
00050 ParseImports::ModelSpace*
00051 ParseImports::RemoteModelSpace::open(const Text &modelname) const
00052   throw (ParseImports::Error, FS::Failure, SRPC::failure)
00053 {
00054   // The model name relative to the repostiory root.
00055   Text relname;
00056   try
00057   {
00058     relname = ReposUI::stripSpecificRoot(modelname.cchars(), ReposUI::VESTA);
00059   }
00060   catch(ReposUI::failure f)
00061   {
00062     throw ParseImports::Error(f.msg);
00063   }
00064   catch(VestaConfig::failure f)
00065   {
00066     throw ParseImports::Error(f.msg);
00067   }
00068 
00069   // The path this model would have in the locally-mounted repository
00070   Text localname =
00071     VestaConfig::get_Text("UserInterface", "AppendableRootName") +
00072     "/" + relname;
00073 
00074   // If it exists locally, we assume that the replication invariant
00075   // holds and thus that it is identical to the remote copy.
00076   if(FS::Exists(localname))
00077     {
00078       try
00079         {
00080           ParseImports::ModelSpace* local =
00081             NEW_CONSTR(OptimizedModelSpace, (localname, *this));
00082 
00083           return local;
00084         }
00085       // In the even of any failure with trying to open it locally, we
00086       // fall back on reading it from the remote repository.
00087       catch(...)
00088         {
00089         }
00090     }
00091 
00092   RemoteModelSpace* ret = NEW_CONSTR(RemoteModelSpace, (root, who));
00093 
00094     VestaSource::errorCode err =
00095       root->lookupPathname(relname.cchars(), ret->file, who);
00096     if (err != VestaSource::ok) {
00097         throw ParseImports::Error(ReposUI::errorCodeText(err) + ", " +
00098                                   relname);
00099     }
00100     if (ret->file->type != VestaSource::immutableFile &&
00101         ret->file->type != VestaSource::mutableFile) {
00102         delete ret->file;
00103         throw ParseImports::Error("Not a file, " + relname);
00104     }   
00105     return ret;
00106 }
00107 
00108 ParseImports::ModelSpace::type
00109 ParseImports::RemoteModelSpace::getType(const Text &name) const 
00110   throw (SRPC::failure)
00111 {
00112     Text relname;
00113     try 
00114     {
00115       relname = ReposUI::stripSpecificRoot(name.cchars(), ReposUI::VESTA);
00116     }
00117     catch(ReposUI::failure f)
00118     {
00119       throw ParseImports::Error(f.msg);
00120     }
00121     catch(VestaConfig::failure f)
00122     {
00123       throw ParseImports::Error(f.msg);
00124     }
00125 
00126     ParseImports::ModelSpace::type ret = ParseImports::ModelSpace::none;
00127 
00128     VestaSource* vs;
00129     VestaSource::errorCode err =
00130       root->lookupPathname(relname.cchars(), vs, who);
00131     if (err != VestaSource::ok) {
00132         return ret;
00133     }
00134     switch (vs->type) {
00135     case VestaSource::immutableFile:
00136     case VestaSource::mutableFile:
00137       ret = ParseImports::ModelSpace::file;
00138       break;
00139     case VestaSource::immutableDirectory:
00140     case VestaSource::appendableDirectory:
00141     case VestaSource::mutableDirectory:
00142       ret = ParseImports::ModelSpace::directory;
00143       break;
00144     default:
00145       break;
00146     }
00147     delete vs;
00148     return ret;
00149 }
00150 
00151 ParseImports::ModelSpace*
00152 ParseImports::OptimizedModelSpace::open(const Text &modelname) const
00153     throw(ParseImports::Error, FS::Failure)
00154 {
00155   // Always call the RemoteModelSpace for open, as it will do the right thing
00156   return remote_space.open(modelname);
00157 }
00158 
00159 ParseImports::ModelSpace::type
00160 ParseImports::OptimizedModelSpace::getType(const Text &name) const
00161   throw ()
00162 {
00163   // Try to get the type of this object using the local filesystem first.
00164   ParseImports::ModelSpace::type result = ParseImports::LocalModelSpace::getType(name);
00165 
00166   // If we can't find it here, ask the source repository
00167   if(result == ParseImports::ModelSpace::none)
00168     {
00169       result = remote_space.getType(name);
00170     }
00171 
00172   return result;
00173 }
00174 
00175 ParseImports::OptimizedModelSpace::OptimizedModelSpace
00176 (const Text &modelname,
00177  const RemoteModelSpace &remote)
00178   throw(FS::Failure)
00179   : ParseImports::LocalModelSpace(modelname),
00180     remote_space(remote)
00181 {
00182 }

Generated on Mon May 8 00:48:58 2006 for Vesta by  doxygen 1.4.2