/// Private constructor TPgBlob::TPgBlob(const TStr& _FNm, const TFAccess& _Access, const uint64& CacheSize) { EAssertR(CacheSize >= PG_PAGE_SIZE, "Invalid cache size for TPgBlob."); FNm = _FNm; Access = _Access; switch (Access) { case faCreate: TFile::DelWc(FNm + ".*"); SaveMain(); break; case faRdOnly: case faUpdate: LoadMain(); break; default: FailR("Unsupported TFAccess flag for TPgBlob."); } // init cache LastExtentCnt = PG_EXTENT_PCOUNT; // this means the "last" extent is full, so use new one MxLoadedPages = CacheSize / PG_PAGE_SIZE; LruFirst = LruLast = -1; }
/// Loads all pages into cache - cache must be big enough void TPgBlob::Clr() { Extents.Clr(); LoadedPagesH.Clr(); LoadedPages.Clr(); Fsm.Clr(); Files.Clr(); TFile::DelWc(FNm + ".bin*"); // delete all child files LastExtentCnt = PG_EXTENT_PCOUNT; LruFirst = LruLast = -1; SaveMain(); }
/// Destructor TPgBlob::~TPgBlob() { if (Access != TFAccess::faRdOnly) { for (int i = 0; i < LoadedPages.Len(); i++) { if (ShouldSavePage(i)) { LoadedPage& a = LoadedPages[i]; Files[a.Pt.GetFIx()]->SavePage(a.Pt.GetPg(), GetPageBf(i)); } } SaveMain(); Files.Clr(); } }
/* ARGSUSED */ void SaveSessionCB( Widget w, /* widget id */ caddr_t client_data, /* data from application */ caddr_t call_data ) /* data from widget class */ { char *longpath, *fileName; int fd, numPadsToSave; char *xa_CommandStr[10]; char *tmpStr, bufr[1024]; Editor *pPad; int i; /* Xt may not pass a widget as advertised (??? is this needed? - hp) */ if(!XtIsShell(w)) w = XtParent(w); for(pPad = pPadList, numPadsToSave = 0; pPad != (Editor *)NULL; pPad = pPad->pNextPad) { if(pPad->inUse == True) numPadsToSave++; } if(numPadsToSave < 1) { xa_CommandStr[0] = (char *)NULL; XSetCommand(XtDisplay(w), XtWindow(w), xa_CommandStr, 1); return; } DtSessionSavePath(w, &longpath, &fileName); /* Create the session file */ if ((fd = creat (longpath, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1) { tmpStr = (char *)malloc(strlen(MSG2) + strlen(longpath)+ 1); sprintf(tmpStr, MSG2, longpath); _DtSimpleErrnoError(pPad->progname, DtError, MSG1, tmpStr, NULL); free(tmpStr); XtFree ((char *)longpath); return; } sprintf(bufr, "*pads.numActivePads: %d\n", numPadsToSave); write (fd, bufr, strlen(bufr)); for(pPad = pPadList, i = 0; pPad != (Editor *)NULL; pPad = pPad->pNextPad, i++) { if(pPad->inUse == True) SaveMain(pPad, i, fd); } close(fd); i = 0; xa_CommandStr[i] = pPadList->progname; i++; xa_CommandStr[i] = "-session"; i++; xa_CommandStr[i] = fileName; i++; XSetCommand(XtDisplay(topLevelWithWmCommand), XtWindow(topLevelWithWmCommand), xa_CommandStr, i); XtFree ((char *)fileName); }