libsrc/bert.cxx File Reference

??? More...

#include "udanax.h"

Include dependency graph for bert.cxx:

Include dependency graph

Go to the source code of this file.

Classes

struct  bertentry
struct  conscell

Defines

#define NUMBEROFBERTTABLE   1327

Functions

unsigned int hashoftumbler (Tumbler *tp)
 ???

int checkforopen (Session *sess, Tumbler *tp, int type)
 ???

void logbertmodifiedforcrum (Session *sess, typecuc *crumptr)
 ???

void logbertmodified (Session *sess, Tumbler *tp)
 ???

void incrementopen (Session *sess, Tumbler *tp)
 ???

void addtoopen (Session *sess, Tumbler *tp, int created, int type)
 ???

void deleteversion (Tumbler *tp)
 ???

bool removefromopen (Session *sess, Tumbler *tp)
 ???

void closeberts (Session *sess)
 ???

bool doopen (Session *sess, IStreamAddr *tp, IStreamAddr *newtp, int type, int mode)
 ???

bool doclose (Session *sess, IStreamAddr *tp)
 ???


Variables

const int primes []
conscellberttable [NUMBEROFBERTTABLE]
char * bertTypeNames [] = { "NOBERT", "READBERT", "WRITEBERT" }


Detailed Description

???

(to be defined)

Definition in file bert.cxx.


Define Documentation

#define NUMBEROFBERTTABLE   1327
 

Definition at line 124 of file bert.cxx.

Referenced by closeberts(), and hashoftumbler().


Function Documentation

void addtoopen Session sess,
Tumbler tp,
int  created,
int  type
[static]
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 285 of file bert.cxx.

References assert, BERTCONSCELLTAG, berttable, BERTTAG, bertTypeNames, bertentry::count, bertentry::created, bertentry::documentid, dumptumbler(), eallocwithtag(), hash(), hashoftumbler(), L, bertentry::modified, conscell::next, NULL, bertentry::sess, conscell::stuff, tumblercopy(), and bertentry::type.

Referenced by doopen().

00286                                      : User's session context
00287     Tumbler *tp,
00288     int      created,
00289     int      type)
00290 {
00291 #ifndef DISTRIBUTION
00292     L("addtoopen:  sess = %d  type = %s  created = %d  tp = ", (int) sess, bertTypeNames[type], created);
00293     dumptumbler(tp);
00294     L("\n");
00295 #endif
00296 
00297     int hash = hashoftumbler(tp);
00298 
00299 /* these eallocwithtags changed to malloc by hill zzzz */
00300 
00301     bertentry *ptr;
00302     if ((ptr = (bertentry *) eallocwithtag(sizeof(bertentry), BERTTAG)) == NULL)
00303         assert(0); // out of memory
00304 
00305     tumblercopy(tp, &ptr->documentid);
00306 
00307     ptr->sess       = sess;
00308     ptr->count      = 1;
00309     ptr->created    = created;
00310     ptr->modified   = false;
00311     ptr->type       = type;
00312 
00313     conscell *consp;
00314     if ((consp = (conscell *) eallocwithtag(sizeof(conscell), BERTCONSCELLTAG)) == NULL)
00315         assert(0); // out of memory
00316 
00317     consp->stuff    = ptr;
00318     consp->next     = berttable[hash];
00319     berttable[hash] = consp;
00320 }

int checkforopen Session sess,
Tumbler tp,
int  type
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 176 of file bert.cxx.

References berttable, bertentry::documentid, hashoftumbler(), isthisusersdocument(), conscell::next, NOBERTREQUIRED, READBERT, bertentry::sess, conscell::stuff, tumblereq(), bertentry::type, and WRITEBERT.

Referenced by doopen(), and findorgl().

00177                                      : User's session context
00178     Tumbler *tp,
00179     int      type)
00180 {
00181     int foundnonread = false;
00182 
00183     if (type == NOBERTREQUIRED)
00184         return 1;                      /* Random > 0 */
00185 
00186     conscell *p;
00187     for (p = berttable[hashoftumbler(tp)]; p && p->stuff; p = p->next) {
00188         bertentry *bert = p->stuff;
00189 
00190         if (tumblereq(tp, &bert->documentid)) {
00191             if (sess == bert->sess) {
00192                 switch (bert->type) {
00193                 case READBERT:
00194                     return (type == READBERT) ? READBERT : /* WRITE */ -1;
00195                 case WRITEBERT:
00196                     return WRITEBERT;
00197                 }
00198             } else {
00199                 if (bert->type != READBERT) {
00200                     foundnonread = true;
00201                 }
00202             }
00203         }
00204     }
00205 
00206     if (!foundnonread && (type == READBERT || isthisusersdocument(sess, tp)))
00207         return 0;
00208     else
00209         return -1;
00210 }

void closeberts Session sess  ) 
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 401 of file bert.cxx.

References berttable, bertentry::created, deleteversion(), bertentry::documentid, efree(), L, bertentry::modified, conscell::next, NULL, NUMBEROFBERTTABLE, bertentry::sess, and conscell::stuff.

Referenced by quitxanadu(), and xanadu().

00402                                      : User's session context
00403 {
00404 #ifndef DISTRIBUTION
00405     L("closeberts:  sess = 0x%08lX\n", (int) sess);
00406 #endif
00407 
00408     conscell *oldptr = NULL;
00409     int i;
00410     for (i = 0; i < NUMBEROFBERTTABLE; i++) {
00411         conscell *p;
00412         for (p = berttable[i]; p && p->stuff; p = p->next) {
00413             bertentry *bert = p->stuff;
00414             if (bert->sess == sess) {
00415                 int status = bert->modified && bert->created;
00416                 if (status)
00417                     deleteversion(&bert->documentid);
00418 
00419                 efree((char *)p->stuff);
00420 
00421                 conscell *temp;
00422                 if (oldptr == NULL) {
00423                     temp = berttable[i];
00424                     berttable[i] = berttable[i]->next;
00425                     efree((char *) temp);
00426                     return;
00427                 } else {
00428                     temp = oldptr->next;
00429                     oldptr->next = p->next;
00430                     efree((char *) temp);
00431                     return;
00432                 }
00433             }
00434             oldptr = p;
00435         }
00436     }
00437 }

void deleteversion Tumbler tp  )  [static]
 

???

(to be defined)

Definition at line 330 of file bert.cxx.

References dumptumbler(), and L.

Referenced by closeberts(), and removefromopen().

00332 {
00333 #ifndef DISTRIBUTION
00334     L("deleteversion: tp = ");
00335     dumptumbler(tp);
00336     L("\n");
00337 #endif
00338 }

bool doclose Session sess,
IStreamAddr tp
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 548 of file bert.cxx.

References dumptumbler(), ERR_CLOSE_WO_OPEN, Session::errorcode, L, and removefromopen().

Referenced by docreatenewversion(), and myclose().

00549                                          : User's session context
00550     IStreamAddr *tp)
00551 {
00552 #ifndef DISTRIBUTION
00553     L("doclose: sess = %d  tp = ", (int) sess);
00554     dumptumbler(tp);
00555     L("\n");
00556 #endif
00557 
00558     if (!removefromopen(sess, tp)) {
00559         sess->errorcode = ERR_CLOSE_WO_OPEN; // Attempted close of a document that was never opened
00560         return false;
00561     }
00562 
00563     return true;                       /* for now, so as to not upset front-end */
00564 }

bool doopen Session sess,
IStreamAddr tp,
IStreamAddr newtp,
int  type,
int  mode
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 465 of file bert.cxx.

References Session::account, addtoopen(), assert, BERTMODECOPY, BERTMODECOPYIF, BERTMODEONLY, checkforopen(), docreatenewversion(), ERR_OPEN_COPY, Session::errorcode, incrementopen(), L, NOBERTREQUIRED, tumblercopy(), and WRITEBERT.

Referenced by docreatenewversion(), and myopen().

00466                                          : User's session context
00467     IStreamAddr *tp,
00468     IStreamAddr *newtp,
00469     int          type,
00470     int          mode)
00471 {
00472     L("Entered doopen()\n");
00473 
00474     if (type == NOBERTREQUIRED)
00475         return true;
00476 
00477     L("type != NOBERTREQUIRED\n");
00478 
00479     if (mode == BERTMODECOPY) {
00480         L("mode == BERTMODECOPY, trying to copy document\n");
00481 
00482         if (docreatenewversion(sess, tp, &sess->account, newtp)) {
00483             addtoopen(sess, newtp, true, type);
00484             return true;
00485         } else {
00486             sess->errorcode = ERR_OPEN_COPY; // Attempt to make a copy to open failed
00487             return false;
00488         }
00489     }
00490 
00491     L("about to call checkforopen()\n");
00492 
00493     int openState = checkforopen(sess, tp, type);
00494 
00495     L("returned from call to checkforopen(), openState = %d\n", openState);
00496 
00497     if (openState == 0) {
00498         L("already open in R/O, just trying to inc open count\n");
00499 
00500         addtoopen(sess, tp, false, type);
00501         tumblercopy(tp, newtp);
00502         return true;
00503     }
00504 
00505     switch (mode) {
00506     case BERTMODECOPYIF:
00507         if (openState == -1) { // Document not already open
00508             if (docreatenewversion(sess, tp, &sess->account, newtp)) {
00509                 addtoopen(sess, newtp, true, type);
00510             } else {
00511                 sess->errorcode = ERR_OPEN_COPY; // Attempt to make a copy to open failed
00512                 return false;
00513             }
00514 
00515         } else if (type != WRITEBERT && openState != WRITEBERT) { // Open another Shared Read-Open Reference
00516             incrementopen(sess, tp);
00517             tumblercopy(tp, newtp);
00518 
00519         } else { // Document is already open, Open a new copy
00520             docreatenewversion(sess, tp, &sess->account, newtp);
00521             addtoopen(sess, newtp, true, type);
00522         }
00523         return true;
00524 
00525     case BERTMODEONLY:
00526         if (openState == -1 || type == WRITEBERT || openState == WRITEBERT) {
00527             return false;
00528         } else {
00529             incrementopen(sess, tp);
00530             tumblercopy(tp, newtp);
00531             return true;
00532         }
00533 
00534     default:
00535         assert(0); // DEFAULT CASE IN DOOPEN
00536         return false;
00537     }
00538 }

unsigned int hashoftumbler Tumbler tp  )  [static]
 

???

(to be defined)

Definition at line 142 of file bert.cxx.

References Tumbler::exp, Tumbler::mantissa, NPLACES, NUMBEROFBERTTABLE, and primes.

Referenced by addtoopen(), checkforopen(), incrementopen(), logbertmodified(), and removefromopen().

00144 {
00145     unsigned int ret = tp->exp;
00146 
00147     for (int i = 0; i < NPLACES; i++)
00148         ret += (unsigned int) tp->mantissa[i] * primes[i];
00149 
00150     return ret % NUMBEROFBERTTABLE;
00151 }

void incrementopen Session sess,
Tumbler tp
[static]
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 259 of file bert.cxx.

References berttable, bertentry::count, bertentry::documentid, dumptumbler(), hashoftumbler(), L, conscell::next, bertentry::sess, conscell::stuff, and tumblereq().

Referenced by doopen().

00260                                      : User's session context
00261     Tumbler *tp)
00262 {
00263 #ifndef DISTRIBUTION
00264     L("incrementopen:  sess = %d  tp = ", (int) sess);
00265     dumptumbler(tp);
00266     L("\n");
00267 #endif
00268 
00269     conscell *p;
00270     for (p = berttable[ hashoftumbler(tp) ]; p && p->stuff; p = p->next) {
00271         bertentry *bert = (bertentry *) p->stuff;
00272         if (bert->sess == sess && tumblereq(tp, &bert->documentid))
00273             bert->count += 1;
00274     }
00275 }

void logbertmodified Session sess,
Tumbler tp
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 235 of file bert.cxx.

References berttable, bertentry::documentid, hashoftumbler(), bertentry::modified, conscell::next, bertentry::sess, conscell::stuff, and tumblereq().

Referenced by deletevspanpm(), insertpm(), and rearrangepm().

00236                                      : User's session context
00237     Tumbler *tp)
00238 {
00239     /* L("logbertmodified sess= %d bert= ", (int) sess);dumptumbler(tp); L("\n"); */
00240 
00241     conscell *p;
00242     for (p = berttable[ hashoftumbler(tp) ]; p && p->stuff; p = p->next) {
00243         bertentry *bert = (bertentry *) p->stuff;
00244         if (bert->sess == sess && tumblereq(tp, &bert->documentid)) {
00245             bert->modified = true;
00246             return;
00247         }
00248     }
00249 }

void logbertmodifiedforcrum Session sess,
typecuc crumptr
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 220 of file bert.cxx.

00221                                      : User's session context
00222     typecuc *crumptr)
00223 {
00224 /* logbertmodified(xxx); */
00225 }

bool removefromopen Session sess,
Tumbler tp
[static]
 

???

(to be defined)

Parameters:
sess  Input: User's session context

Definition at line 348 of file bert.cxx.

References berttable, bertentry::count, bertentry::created, deleteversion(), bertentry::documentid, dumptumbler(), efree(), hash(), hashoftumbler(), L, bertentry::modified, conscell::next, NULL, bertentry::sess, conscell::stuff, and tumblereq().

Referenced by doclose().

00349                                      : User's session context
00350     Tumbler *tp)
00351 {
00352 #ifndef DISTRIBUTION
00353     L("removefromopen:  sess = %d  tp = ", (int) sess);
00354     dumptumbler(tp);
00355     L("\n");
00356 #endif
00357 
00358     int hash = hashoftumbler(tp);
00359     conscell *oldptr = NULL;
00360 
00361     conscell *p;
00362     for (p = berttable[hash]; p && p->stuff; p = p->next) {
00363         bertentry *bert = p->stuff;
00364         if (bert->sess == sess && tumblereq(tp, &bert->documentid)) {
00365             if (--bert->count)
00366                 return true;
00367 
00368             /* status = bert->modified && bert->created ; */
00369             int status = bert->created && !bert->modified;
00370             if (status)
00371                 deleteversion(tp);
00372 
00373             efree((char *) p->stuff);
00374 
00375             conscell *temp;
00376             if (oldptr == NULL) {
00377                 temp = berttable[hash];
00378                 berttable[hash] = berttable[hash]->next;
00379                 efree((char *)temp);
00380                 return true;
00381             } else {
00382                 temp = oldptr->next;
00383                 oldptr->next = p->next;
00384                 efree((char *)temp);
00385                 return true;
00386             }
00387         }
00388         oldptr = p;
00389     }
00390     return false;
00391 }


Variable Documentation

conscell* berttable[NUMBEROFBERTTABLE] [static]
 

Definition at line 126 of file bert.cxx.

Referenced by addtoopen(), checkforopen(), closeberts(), incrementopen(), logbertmodified(), and removefromopen().

char* bertTypeNames[] = { "NOBERT", "READBERT", "WRITEBERT" } [static]
 

Definition at line 130 of file bert.cxx.

Referenced by addtoopen().

const int primes[] [static]
 

Initial value:

 {
      3,   7,  11,  17,  37,  41,  59,  71,  97,  103,
    113, 131, 151, 137, 277, 421, 433, 567, 643,  743
}

Definition at line 119 of file bert.cxx.

Referenced by hashoftumbler().


Generated on Sun Aug 21 04:18:24 2005 for Udanax-Green by doxygen1.3.4