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

TestShortId.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 // TestShortId.C
00021 // Last modified on Tue Aug  3 12:52:14 EDT 2004 by ken@xorian.net
00022 //      modified on Thu Jul 20 14:24:28 PDT 2000 by mann
00023 //
00024 // Simple client to test the ShortId layer of the repository server
00025 //
00026 
00027 #include "Basics.H"
00028 #include "SourceOrDerived.H"
00029 #include "SRPC.H"
00030 #include <stdlib.h>
00031 #include <pthread.h>
00032 #include <errno.h>
00033 
00034 using std::cout;
00035 using std::cin;
00036 using std::endl;
00037 using std::hex;
00038 using std::dec;
00039 using std::ios;
00040 
00041 int main(int argc, char *argv[])
00042 {
00043     for (;;) {
00044         try {
00045             char typein[1024];
00046             char junk;
00047             long ltmp;
00048             int mode_read;
00049             ios::openmode mode_used;
00050             bool leafflag, force;
00051             SourceOrDerived sd;
00052             ShortId sid;
00053             time_t time;
00054 
00055             cout << "(q)uit, (c)reate, (o)pen, (l)eafShortId, (s)hortIdToName,\n"
00056               << " (k)eepDerived, check(p)oint, (g)etWeedingInfo, to(u)ch: ";
00057             cin.get(typein, sizeof(typein));
00058             cin.get(junk);
00059             switch (typein[0]) {
00060             case 'c':
00061                 for (;;) {
00062                     cout << "(l)eaf, (n)onleaf: ";
00063                     cin.get(typein, sizeof(typein));
00064                     cin.get(junk);
00065                     switch (typein[0]) {
00066                     case 'l':
00067                         leafflag = true;
00068                         break;
00069                     case 'n':
00070                         leafflag = false;
00071                         break;
00072                       default:
00073                         continue;
00074                     }
00075                     break;
00076                 }
00077                 cout <<
00078                   "mode (in=1 out=2 ate=4 app=8 trunc=16): ";
00079                 cin >> mode_read;
00080                 cin.get(junk);
00081                 if(mode_read & 1)
00082                   {
00083                     mode_used = ios::in;
00084                     if(mode_read & 2)
00085                       {
00086                         mode_used |= ios::out;
00087                       }
00088                   }
00089                 else if(mode_read & 2)
00090                   {
00091                     mode_used = ios::out;
00092                   }
00093                 if(mode_read & 4)
00094                   mode_used |= ios::ate;
00095                 if(mode_read & 8)
00096                   mode_used |= ios::app;
00097                 if(mode_read & 16)
00098                   mode_used |= ios::trunc;
00099                 cout << hex << sd.create(leafflag, mode_used) << dec << endl;
00100                 if (sd.fail()) {
00101                   int saved_errno = errno;
00102                   cout << "error: " << Basics::errno_Text(saved_errno) << endl;
00103                 }
00104                 sd.close();
00105                 break;
00106             
00107             case 'o':
00108                 cout << "ShortId: ";
00109                 cin >> hex >> ltmp >> dec;
00110                 cout <<
00111                   "mode (in=1 out=2 ate=4 app=8 trunc=16): ";
00112                 cin >> mode_read;
00113                 cin.get(junk);
00114                 if(mode_read & 1)
00115                   {
00116                     mode_used = ios::in;
00117                     if(mode_read & 2)
00118                       {
00119                         mode_used |= ios::out;
00120                       }
00121                   }
00122                 else if(mode_read & 2)
00123                   {
00124                     mode_used = ios::out;
00125                   }
00126                 if(mode_read & 4)
00127                   mode_used |= ios::ate;
00128                 if(mode_read & 8)
00129                   mode_used |= ios::app;
00130                 if(mode_read & 16)
00131                   mode_used |= ios::trunc;
00132                 sd.open((ShortId) ltmp, mode_used);
00133                 if (sd.fail()) {
00134                   cout << "error: " << Basics::errno_Text(errno) << endl;
00135                 }
00136                 sd.close();
00137                 break;
00138 
00139             case 'l':
00140                 cout << "ShortId: ";
00141                 cin >> hex >> ltmp >> dec;
00142                 cin.get(junk);
00143                 if (sd.leafShortId((ShortId) ltmp)) {
00144                     cout << "leaf\n";
00145                 } else {
00146                     cout << "nonleaf\n";
00147                 }
00148                 break;
00149 
00150             case 's':
00151                 cout << "ShortId: ";
00152                 cin >> hex >> ltmp >> dec;
00153                 cin.get(junk);
00154                 cout << sd.shortIdToName((ShortId) ltmp) << endl;
00155                 break;
00156 
00157             case 'q':
00158                 exit(0);
00159 
00160             case 'k':
00161                 cout << "ds (shortId): ";
00162                 cin >> hex >> sid >> dec;
00163                 cout << "dt (time_t): ";
00164                 cin >> time;
00165                 cout << "force (0 or 1): ";
00166                 cin >> force;
00167                 ltmp = SourceOrDerived::keepDerived(sid, time, force);
00168                 if (ltmp == 0)
00169                   cout << "ok" << endl;
00170                 else
00171                   cout << Basics::errno_Text(ltmp) << endl;
00172                 break;
00173 
00174             case 'p':
00175                 SourceOrDerived::checkpoint();
00176                 break;
00177 
00178             case 'g':
00179                 {
00180                     ShortIdsFile ds, ss;
00181                     time_t dt, st;
00182                     bool swip, dip, ddun, cip;
00183                     SourceOrDerived::getWeedingState(ds, dt, ss, st,
00184                                                      swip, dip, ddun, cip);
00185                     cout << "ds = " << hex << ds << dec << ", dt = " << dt 
00186                       << ", ss = " << hex << ss << dec << ", st = " << st
00187                         << endl
00188                           << "sourceWeedInProgress = " << (int)swip
00189                             << ", deletionsInProgress = " << (int)dip
00190                               << ", deletionsDone = " << (int)ddun
00191                                 << ", checkpointInProgress = " << (int)cip
00192                                   << endl;
00193                 }
00194                 break;
00195             case 'u':
00196                 cout << "ShortId: ";
00197                 cin >> hex >> sid >> dec;
00198                 cin.get(junk);
00199                 if (SourceOrDerived::touch(sid)) {
00200                     cout << "ok" << endl;
00201                 } else {
00202                   cout << "error: " << Basics::errno_Text(errno) << endl;
00203                 }
00204                 break;
00205 
00206               default:
00207                 break;
00208             }
00209         } catch (SRPC::failure f) {
00210             cout << "SRPC::failure " << f.msg << endl;
00211             exit(1);
00212         }
00213     }
00214 
00215     //exit(0); // not reached
00216 }

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