home *** CD-ROM | disk | FTP | other *** search
- //
- // MiscLogFile.h -- a generic class to simplify keeping an atomic lock file
- // Written by Don Yacktman Copyright (c) 1993 by Don Yacktman.
- // Version 1.0. All rights reserved.
- // This notice may not be removed from this source code.
- //
- // This object is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- #import <appkit/appkit.h>
-
- @interface MiscLogFile:Object <NXTransport>
- {
- id lockFile, fileName, lastLine;
- int repeats;
- BOOL fileOpen, special; // special == YES if using stdout or stderr
- FILE *file; // only valid if fileOpen == YES
- }
-
- - init;
- - fileName;
-
- // Changing the name of the file will close the current log, if open,
- // and stop using a lock file (see below). Pass in a MiscString for
- // the file name.
- - setFileName:aString;
-
- // If you pass in a MiscLockFile, then the log file will be locked
- // by using the MiscLockFile you passed in. If more than one process
- // can affect a log file, then you should make sure that all those
- // processes use a lock file! If you don't set up a lock file,
- // then by default none will be used.
- - setLockFile:newLockFile;
-
- // Use this method to add an arbitrary string to the log file --
- // it opens and closes the file automatically, obtaining locks if needed.
- // This is better than sitting for a long time holding locks.
- // returns YES is successful, NO otherwise.
- - (BOOL)addLineToLogFile:aString;
-
- // These are for use when you have multiple things to add and you wish to
- // keep the file open until you are done writing all of it. Function is
- // rather obvious. Return YES if successful, no otherwise.
- - (BOOL)openFile; // always opened for APPENDING. Created if non-existent.
- - (BOOL)appendToLogFile:aString andFlush:(BOOL)flushFlag;
- - (BOOL)closeFile;
-
- // -openFile and -closeFile have no effect if you use these:
- - usestdout;
- - usestderr;
-
- // These are pretty obvious. A copy will not be an opened file nor will it
- // have a lock, regardless of the state of the receiver of the -copy.
- - copy;
- - read:(NXTypedStream *)stream;
- - write:(NXTypedStream *)stream;
-
- // Use these if you must...
- - (FILE *)file;
- - (BOOL)fileIsOpen;
- - (BOOL)special;
- - lockFile;
-
- // Handles closing files and removing locks if necessary.
- - free;
-
- @end
-