home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-04 | 5.0 KB | 223 lines | [TEXT/KAHL] |
- /*****
- * CNeoBenchApp.c
- *
- * Application methods for a typical application.
- *
- * Copyright © 1992-1993 NeoLogic Systems. All rights reserved.
- *
- *****/
-
- #include "NeoTypes.h"
- #include <CDesktop.h>
- #include <CList.h>
- #include "CNeoBenchApp.h"
- #include "CNeoBenchDoc.h"
- #include "CFiller.h"
- #include CNeoMetaClassH
- #ifdef qNeoThreads
- #include CNeoThreadNativeH
- #endif
-
- extern OSType gSignature;
-
- int main(void)
- {
- CNeoBenchApp * app;
-
- app = new CNeoBenchApp();
- app->Run();
- app->Exit();
-
- return 0;
- }
-
- /***
- * CNeoBenchApp
- *
- * Initialize the application. Your initialization method should
- * at least call the inherited method. If your application class
- * defines its own instance variables or global variables, this
- * is a good place to initialize them.
- *
- ***/
- CNeoBenchApp::CNeoBenchApp(void)
- : CNeoAppTCL()
- {
- long index;
- long delay = 0;
- TMTask timer;
-
- #if defined(qNeoDebug) && !defined(__MWERKS__)
- gBreakFailure = TRUE;
- #endif
-
- IApplication(kNeoExtraMasters, kNeoRainyDayFund, kNeoCriticalBalance, kNeoToolboxBalance);
-
- (void)new CNeoMetaClass(kFillerID, kNeoPersistID, "\pCFiller", CFiller::New);
-
- // measure Time Manager overhead
- timer.tmAddr = NULL;
- timer.tmCount = 0;
- timer.tmWakeUp = 0;
- timer.tmReserved = 0;
-
- for (index = 0; index < 100; index++) {
- InsTime((QElemPtr)&timer);
- PrimeTime((QElemPtr)&timer, k30MicroMinutes);
- RmvTime((QElemPtr)&timer);
-
- if (timer.tmCount > 0)
- // milliseconds
- delay += -(k30MicroMinutes + timer.tmCount * 1000);
- else
- // negated microseconds
- delay += -(k30MicroMinutes - timer.tmCount);
- }
-
- // compute average overhead
- gLoopOverhead = delay / 100;
- }
-
- /***
- * SetUpFileParameters
- *
- * In this routine, you specify the kinds of files your
- * application opens.
- *
- *
- ***/
-
- void CNeoBenchApp::SetUpFileParameters(void)
-
- {
- inherited::SetUpFileParameters(); /* Be sure to call the default method */
-
- /**
- ** sfNumTypes is the number of file types
- ** your application knows about.
- ** sfFileTypes[] is an array of file types.
- ** You can define up to 4 file types in
- ** sfFileTypes[].
- **
- **/
- sfNumTypes = 1;
- sfFileTypes[0] = kNeoBenchFileType;
-
- /**
- ** Although it's not an instance variable,
- ** this method is a good place to set the
- ** gSignature global variable. Set this global
- ** to your application's signature. You'll use it
- ** to create a file (see CFile::CreateNew()).
- **
- **/
- gSignature = kNeoBenchSig;
- }
-
- /***
- * createDocument
- *
- * The user chose New from the File menu.
- * In this method, you need to create a document and send it
- * a NewFile() message.
- *
- ***/
- CNeoDoc *CNeoBenchApp::createDocument(void)
- {
- CNeoBenchDoc * document = nil;
-
- NEOTRY {
- /*
- * Create your document.
- *
- * The arguments indicate whether the document is...
- * printable (FALSE),
- * a new file (TRUE),
- * remote (FALSE).
- */
- document = new CNeoBenchDoc(kNotPrintable, TRUE, FALSE);
-
- /*
- * Send the document a NewFile() message.
- * The document will open a window, and
- * set up the heart of the application.
- */
- document->NewFile();
- }
- NEOCATCH {
- /*
- * This exception handler gets executed if a failure occurred
- * anywhere within the scope of the TRY block above. Since
- * this indicates that a new doc could not be created, we
- * check if an object had been allocated and if it has, send
- * it a unrefer message. The exception will propagate up to
- * CSwitchboard's exception handler, which handles displaying
- * an error alert.
- */
- if (document) {
- delete document;
- document = nil;
- }
- }
- NEOENDTRY;
-
- return document;
- }
-
- /***
- * OpenDocument
- *
- * The user chose Open… from the File menu.
- * In this method you need to create a document
- * and send it an OpenFile() message.
- *
- * The macSFReply is a good SFReply record that contains
- * the name and vRefNum of the file the user chose to
- * open.
- *
- ***/
-
- void CNeoBenchApp::OpenDocument(SFReply *macSFReply)
- {
- Boolean remote = FALSE;
- long procID;
- FSSpec fsSpec;
- CNeoBenchDoc * document = nil;
-
- NEOTRY
- {
- // Our parent will check to see if this is a document we have already opened.
- // If we find the file already open by the app, then fDocument will refer to it.
- // If the file is opened but not by this app, then the parent will signal a failure.
- inherited::OpenDocument(macSFReply);
- if (fDocument)
- return;
-
- document = new CNeoBenchDoc(TRUE, FALSE, remote);
-
- /**
- ** Send the document an OpenFile() message.
- ** The document will open a window, open
- ** the file specified in the macSFReply record,
- ** and display it in its window.
- **
- **/
- document->OpenFile(macSFReply);
- }
- NEOCATCH
- {
- /*
- * This exception handler gets executed if a failure occurred
- * anywhere within the scope of the TRY block above. Since
- * this indicates that the document could not be opened, we
- * send it a unrefer message. The exception will propagate up to
- * CSwitchboard's exception handler, which handles displaying
- * an error alert.
- */
-
- if (document)
- delete document;
- }
- NEOENDTRY;
- }
-