00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00070 Text localname =
00071 VestaConfig::get_Text("UserInterface", "AppendableRootName") +
00072 "/" + relname;
00073
00074
00075
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
00086
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
00156 return remote_space.open(modelname);
00157 }
00158
00159 ParseImports::ModelSpace::type
00160 ParseImports::OptimizedModelSpace::getType(const Text &name) const
00161 throw ()
00162 {
00163
00164 ParseImports::ModelSpace::type result = ParseImports::LocalModelSpace::getType(name);
00165
00166
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 }