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

ShortIdBlock.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 //
00020 // ShortIdBlock.C
00021 // Last modified on Fri Apr 22 12:32:16 EDT 2005 by ken@xorian.net  
00022 //      modified on Fri Jul 27 18:24:29 PDT 2001 by mann  
00023 //      modified on Tue May  4 10:50:07 PDT 1999 by heydon
00024 //
00025 // Implementation for ShortIdBlock.H
00026 // 
00027 
00028 #include "ShortIdBlock.H"
00029 #include "VestaConfig.H"
00030 #include "Basics.H"
00031 #include <stdio.h>
00032 
00033 using std::cerr;
00034 using std::endl;
00035 
00036 static Text sid_dir;
00037 static int sid_dir_len;
00038 static pthread_once_t once = PTHREAD_ONCE_INIT;
00039 
00040 extern "C"
00041 {
00042   static void
00043   ShortIdBlockInit()
00044   {
00045     try {
00046         bool ok = VestaConfig::get("Repository", "sid_dir", sid_dir);
00047         if (!ok) sid_dir = "";
00048         sid_dir_len = sid_dir.Length();
00049     } catch (VestaConfig::failure f) {
00050         cerr << "VestaConfig::failure " << f.msg << endl;
00051         throw; // likely to be uncaught and fatal
00052     }
00053   }
00054 }
00055 
00056 // This method is local
00057 ShortId ShortIdBlock::assignNextAvail() throw ()
00058 {
00059     for (;;) {
00060         if (next >= start + size) {
00061             return NullShortId;
00062         } else if (!assigned(next)) {
00063             set(next);
00064             return next++;
00065         } else {
00066             next++;
00067         }
00068     }
00069 }
00070 
00071 char* ShortIdBlock::shortIdToName(ShortId sid, const char* prepend) throw ()
00072 {
00073     // The encoding of ShortId as filename is hard-coded here,
00074     // relative to the current process working directory.  See also
00075     // DeleteAllShortIdsBut in ShortIdImpl.C, and note that
00076     // ShortIdBlock::size must be equal to the range of the last
00077     // pathname component (i.e., 0x100 if the last component is sid &
00078     // 0xff).
00079     //
00080     pthread_once(&once, ShortIdBlockInit);
00081     char* retval = NEW_PTRFREE_ARRAY(char, sid_dir_len + strlen(prepend) + 11);
00082     sprintf(retval, "%s%s%03x%c%03x%c%02x",
00083             prepend, sid_dir.cchars(),
00084             (sid >> 20) & 0xfff, PathnameSep,
00085             (sid >> 8) & 0xfff,  PathnameSep,
00086             sid & 0xff);
00087     return retval;
00088 }

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