(FILECREATED " 8-Aug-86 16:21:12" {ROSEBOWL}<FEUERMAN>LISP>NCSERVER>NCMULTIREMOTE.;10 18718  

      changes to:  (FNS NCMultiRemote.DeleteNoteFile)

      previous date: " 6-Aug-86 13:45:54" {ROSEBOWL}<FEUERMAN>LISP>NCSERVER>NCMULTIREMOTE.;9)


(PRETTYCOMPRINT NCMULTIREMOTECOMS)

(RPAQQ NCMULTIREMOTECOMS ((FNS NCMultiRemote.BuildHashArray NCMultiRemote.COLLECTLINKS 
				 NCMultiRemote.CancelCacheSubscription 
				 NCMultiRemote.CheckpointNoteFile NCMultiRemote.CloseNoteFile 
				 NCMultiRemote.CompactNoteFile NCMultiRemote.ConvertNoteFileFormat 
				 NCMultiRemote.CreateNoteFile NCMultiRemote.DeleteNoteFile 
				 NCMultiRemote.GetCardInfo NCMultiRemote.GetCardPart 
				 NCMultiRemote.ListNoteFiles NCMultiRemote.MarkCardDeleted 
				 NCMultiRemote.NewCardUID NCMultiRemote.NoteFileOpenP 
				 NCMultiRemote.ObtainWritePermission NCMultiRemote.OpenNoteFile 
				 NCMultiRemote.PUTLINKS NCMultiRemote.PutCardPart 
				 NCMultiRemote.ReleaseWritePermission NCMultiRemote.RepairNoteFile 
				 NCMultiRemote.TruncateNoteFile)
	(INITVARS (NC.DeviceVectorsHashArray (HASHARRAY 10)))
	(P (PUTHASH (QUOTE REMOTEMULTIUSER)
		    (create NoteFileDevice ListNoteFilesFn ← (FUNCTION NCMultiRemote.ListNoteFiles)
			    CreateNoteFileFn ← (FUNCTION NCMultiRemote.CreateNoteFile)
			    DeleteNoteFileFn ← (FUNCTION NCMultiRemote.DeleteNoteFile)
			    OpenNoteFileFn ← (FUNCTION NCMultiRemote.OpenNoteFile)
			    BuildHashArrayFn ← (FUNCTION NCMultiRemote.BuildHashArray)
			    CloseNoteFileFn ← (FUNCTION NCMultiRemote.CloseNoteFile)
			    NoteFileOpenPFn ← (FUNCTION NCMultiRemote.NoteFileOpenP)
			    CheckpointNoteFileFn ← (FUNCTION NCMultiRemote.CheckpointNoteFile)
			    NewCardUIDFn ← (FUNCTION NCMultiRemote.NewCardUID)
			    MarkCardDeletedFn ← (FUNCTION NCMultiRemote.MarkCardDeleted)
			    GetCardInfoFn ← (FUNCTION NCMultiRemote.GetCardInfo)
			    PutCardPartFn ← (FUNCTION NCMultiRemote.PutCardPart)
			    GetCardPartFn ← (FUNCTION NCMultiRemote.GetCardPart)
			    ObtainWritePermissionFn ← (FUNCTION NCMultiRemote.ObtainWritePermission)
			    ReleaseWritePermissionFn ← (FUNCTION NCMultiRemote.ReleaseWritePermission)
			    CancelCacheSubscriptionFn ← (FUNCTION 
							    NCMultiRemote.CancelCacheSubscription)
			    RepairNoteFileFn ← (FUNCTION NCMultiRemote.RepairNoteFile)
			    CompactNoteFileFn ← (FUNCTION NCMultiRemote.CompactNoteFile)
			    TruncateNoteFileFn ← (FUNCTION NCMultiRemote.TruncateNoteFile)
			    ConvertNoteFileFormatFn ← (FUNCTION NCMultiRemote.ConvertNoteFileFormat))
		    NC.DeviceVectorsHashArray))))
(DEFINEQ

(NCMultiRemote.BuildHashArray
  [LAMBDA (NoteFile PromptWindow)                            (* Feuerman "30-Jul-86 09:55")

          (* * This is the remote multi client build hash array function.)



          (* * kef 7/22/86: Initialize the various Loc fields to -1 rather than leaving them to be 0.0 The reason is that 0 
	  is used later on to determine something, so we don't want to trigger that situation.)


    (PROG ((UIDS (NCCLIENT.LISTUIDS (fetch (NoteFile UID) of NoteFile)))
	     CardTotal)
	    (SETQ CardTotal (LENGTH UIDS))
	    [replace (NoteFile HashArray) of NoteFile with (NC.CreateUIDHashArray
								   (FIX (TIMES 1.5 (LENGTH
										     UIDS]

          (* * Now, fill in hash array with card objects)


	    (for UID in UIDS as CardCount from 1
	       do (AND PromptWindow (EQ (IMOD CardCount 100)
					      1)
			   (NC.PrintMsg PromptWindow T "Building hash array." (CHARACTER 13)
					  "Processing number " CardCount " of " CardTotal "."
					  (CHARACTER 13)))
		    (NC.InstallCardInNoteFile (create Card
							  NoteFile ← NoteFile
							  UID ← UID
							  Status ←[CDR
							    (FASSOC (QUOTE STATUS)
								      (NCCLIENT.GETCARDINFO
									(fetch (NoteFile UID)
									   of NoteFile)
									UID
									(QUOTE STATUS]
							  IndexLoc ← -1
							  MainLoc ← -1
							  LinksLoc ← -1
							  PropListLoc ← -1
							  TitleLoc ← -1)
						NoteFile))
	    (RETURN NoteFile])

(NCMultiRemote.COLLECTLINKS
  [LAMBDA (Card Stream)                                      (* Feuerman "22-Jul-86 09:52")

          (* * This is the unfortunate kludge which needs to take care of collecting all of the links together as TOLINKS, 
	  FROMLINKS, and then GLOBALTOLINKS, in that order, and then dumping them onto the stream.)


    (DECLARE (GLOBALVARS NC.LinksIdentifier))            (* First, we can collect the TOLINKS straight onto the
							     Stream that was passed in.)
    (NCCLIENT.GETCARDPART (fetch (NoteFile UID) of (fetch (Card NoteFile) of Card))
			    (fetch (Card UID) of Card)
			    (QUOTE TOLINKS)
			    Stream)

          (* Next, for each of FROMLINKS and GLOBALTOLINKS, collect them into the CollectionStream, strip out the card part 
	  header, and then read the rest into Stream.)


    (bind CollectionStream for LinkSpecies in (QUOTE (FROMLINKS GLOBALTOLINKS))
       do (SETQ CollectionStream (OPENSTREAM (QUOTE {NODIRCORE})
						   (QUOTE BOTH)))
	    (NCCLIENT.GETCARDPART (fetch (NoteFile UID) of (fetch (Card NoteFile)
								    of Card))
				    (fetch (Card UID) of Card)
				    LinkSpecies CollectionStream)
	    (SETFILEPTR CollectionStream 0)
	    (NC.ReadCardPartHeader Card NC.LinksIdentifier CollectionStream)
	    (COPYBYTES CollectionStream Stream))
    Stream])

(NCMultiRemote.CancelCacheSubscription
  [LAMBDA (Card CardPartName)                                (* Feuerman "21-Jul-86 14:28")
    (NCCLIENT.CANCELCARDPARTSUBSCRIPTION (fetch (NoteFile UID) of (fetch (Card NoteFile)
									   of Card))
					   (fetch (Card UID) of Card)
					   CardPartName])

(NCMultiRemote.CheckpointNoteFile
  [LAMBDA (NoteFile)                                         (* Feuerman "23-Jul-86 16:30")

          (* * This is sort of a degenerate function, since the NC.SaveDirtyCards called by NC.CheckpointNoteFile was 
	  sufficient for us. So this just returns NoteFile.)


    NoteFile])

(NCMultiRemote.CloseNoteFile
  [LAMBDA (NoteFile)                                         (* Feuerman "23-Jul-86 16:33")

          (* * Cancels the NoteFile subscription on NoteFile)


    (COND
      ((CAR (ERSETQ (NCCLIENT.CANCELNOTEFILESUBSCRIPTION NoteFile)))
	NoteFile)
      (T (QUOTE NotClosed])

(NCMultiRemote.CompactNoteFile
  [LAMBDA (ARG1 ARG2 ARG3)
    (ERROR "Not implemented yet:  " (QUOTE NCMultiRemote.CompactNoteFile])

(NCMultiRemote.ConvertNoteFileFormat
  [LAMBDA (ARG1 ARG2 ARG3)
    (ERROR "Not implemented yet:  " (QUOTE NCMultiRemote.ConvertNoteFileFormat])

(NCMultiRemote.CreateNoteFile
  [LAMBDA (ARG1 ARG2 ARG3)
    (ERROR "Not implemented yet:  " (QUOTE NCMultiRemote.CreateNoteFile])

(NCMultiRemote.DeleteNoteFile
  [LAMBDA (NOTEFILENAME)                                     (* Feuerman " 8-Aug-86 14:27")
    (NCCLIENT.DELETENOTEFILE NOTEFILENAME])

(NCMultiRemote.GetCardInfo
  [LAMBDA (Card Aspects)                                     (* Feuerman "30-Jul-86 08:55")
    (NCCLIENT.GETCARDINFO (fetch (NoteFile UID) of (fetch (Card NoteFile) of Card))
			    (fetch (Card UID) of Card)
			    Aspects])

(NCMultiRemote.GetCardPart
  [LAMBDA (Card CardPartName WhenFlg)                        (* Feuerman "21-Jul-86 14:14")

          (* * The GetCardPartFn for remote users. Creates a stream, fills it with the card part's contents, and then stuffs 
	  that stream into the NoteFile data structure.)


    (COND
      ((EQ WhenFlg (QUOTE BEFORE))
	(PROG [(STREAM (OPENSTREAM (QUOTE {NODIRCORE})
				       (QUOTE BOTH]
	        (SELECTQ CardPartName
			   ((TITLE SUBSTANCE PROPLIST)
			     (NCCLIENT.GETCARDPART (fetch (NoteFile UID)
							of (fetch (Card NoteFile) of Card))
						     (fetch (Card UID) of Card)
						     CardPartName STREAM))
			   (TYPE (NCCLIENT.GETCARDPART (fetch (NoteFile UID)
							    of (fetch (Card NoteFile)
								    of Card))
							 (fetch (Card UID) of Card)
							 (QUOTE SUBSTANCE)
							 STREAM))
			   (LINKS (NCMultiRemote.COLLECTLINKS Card STREAM))
			   (SHOULDNT (CONCAT "Unrecognized card part:  " CardPartName)))
	        (SETFILEPTR STREAM 0)
	        (RETURN (replace (NoteFile Stream) of (fetch (Card NoteFile) of Card)
			     with STREAM])

(NCMultiRemote.ListNoteFiles
  [LAMBDA (ARG1 ARG2 ARG3)
    (ERROR "Not implemented yet:  " (QUOTE NCMultiRemote.ListNoteFiles])

(NCMultiRemote.MarkCardDeleted
  [LAMBDA (Card)                                             (* Feuerman "28-Jul-86 16:53")

          (* * Tells the Server to mark this card deleted.)


    (NCCLIENT.DELETECARD (fetch (NoteFile UID) of (fetch (Card NoteFile) of Card))
			   (fetch (Card UID) of Card))
    (NC.SetStatus Card (QUOTE DELETED])

(NCMultiRemote.NewCardUID
  [LAMBDA (Card Type)                                        (* Feuerman " 1-Aug-86 14:04")

          (* * Merely retrieves the new UID for the Card from the Server, and installs that into the Card.)



          (* * kef 8/1/86: Added Type argument so that the server can tell others if they want it.)


    (PROG ((UID (NCCLIENT.CREATECARD (fetch (NoteFile UID) of (fetch (Card NoteFile)
									 of Card))
					 Type)))
	    (COND
	      ((type? UID UID)
		(replace (Card UID) of Card with UID)

          (* * Now put -1's in the various Loc positions to indicate to various functions that this is a remote card, updates
	  to which should happen right away.)


		(NC.SetLinksLoc Card -1)
		(NC.SetTitleLoc Card -1)
		(NC.SetMainLoc Card -1)
		(NC.SetPropListLoc Card -1)

          (* * Now set up the write locks on all of the card parts, since the server did that for us automatically)


		(for CardPart in (QUOTE (SUBSTANCE TOLINKS FROMLINKS TITLE PROPLIST 
							 GLOBALTOLINKS))
		   do (NC.SetWriteLock Card CardPart))
		(RETURN Card))
	      (T                                             (* what is returned is some error indicator 
							     hopefully.)
		 (RETURN UID])

(NCMultiRemote.NoteFileOpenP
  [LAMBDA (NoteFile)                                         (* Feuerman "21-Jul-86 10:43")

          (* * This is hereby defined true for the remote multi user case if the client is listed as a subscriber to the 
	  NoteFile.)


    (DECLARE: (GLOBALVARS \MY.NSADDRESS))
    (AND (find Address in (NCCLIENT.LISTCLIENTS (fetch (NoteFile UID) of NoteFile))
	      suchthat (NCCLIENT.NSEQUAL Address \MY.NSADDRESS))
	   NoteFile])

(NCMultiRemote.ObtainWritePermission
  [LAMBDA (Card CardPartName)                                (* Feuerman "30-Jul-86 15:57")
    (COND
      ((NC.OwnWriteLockP Card CardPartName)
	(NC.SetWriteLock Card CardPartName)
	T)
      (T (AND (NCCLIENT.OBTAINWRITELOCK (fetch (NoteFile UID) of (fetch (Card NoteFile)
									    of Card))
					    (fetch (Card UID) of Card)
					    CardPartName)
		(NC.SetWriteLock Card CardPartName])

(NCMultiRemote.OpenNoteFile
  [LAMBDA (NoteFile)                                         (* Feuerman "30-Jul-86 09:04")

          (* * Calls the OpenNoteFile function for remote multi-use NoteFiles.)



          (* * kef 7/21/86: Uses the ListNoteFiles routine to get a version number for the filename. Should probably be 
	  replaced eventually by a "real" method for determining the version number.)



          (* * kef 7/21/86: Sets freely the variables bound in NC.OpenNoteFile called Don'tGetSpecialCardsFlg so that the top
	  level file boxes are not cached.)


    [replace (NoteFile FullFileName) of NoteFile with (for FileName
							       in (NCCLIENT.LISTNOTEFILES
								      (ffetch (NoteFile 
										     FullFileName)
									 of NoteFile))
							       largest (FILENAMEFIELD
									   FileName
									   (QUOTE VERSION]
    (NC.SetMonitor NoteFile (CREATE.MONITORLOCK (ffetch (NoteFile FullFileName) of NoteFile)))
    (SETQ Don'tGetSpecialCardsFlg T)
    (NCCLIENT.SUBSCRIBETONOTEFILE (ffetch (NoteFile FullFileName) of NoteFile])

(NCMultiRemote.PUTLINKS
  [LAMBDA (Card SOURCESTREAM)                                (* Feuerman "22-Jul-86 08:59")

          (* * This function handles the fact that LINKS are lumped together by the current NoteFile format, but are treated 
	  seperately by the Server. Basically, the links are seperated into the three links species TOLINKS, FROMLINKS and 
	  GLOBALTOLINKS, and then sent off to the server.)


    (PROG [(CardPartHeaderStream (OPENSTREAM (QUOTE {NODIRCORE})
						 (QUOTE BOTH]
	    (NCCLIENT.COPYCARDPARTHEADER SOURCESTREAM CardPartHeaderStream)

          (* * Now, CardPartHeaderStream contains only the card part header. We'll use that in constructing our three 
	  different Links streams.)


	    (bind LinksStream for LinkSpecies in (QUOTE (TOLINKS FROMLINKS GLOBALTOLINKS))
	       do (SETQ LinksStream (OPENSTREAM (QUOTE {NODIRCORE})
						      (QUOTE BOTH)))

          (* * Put the card part header into the LinksStream)


		    (SETFILEPTR CardPartHeaderStream 0)
		    (COPYBYTES CardPartHeaderStream LinksStream) 

          (* * Now, the file pointer on SOURCESTREAM is already pointing to the next list of Links, be we on TOLINKS 
	  FROMLINKS or GLOBALTOLINKS. Copy those guys into the LinksStream.)


		    (NC.WriteListOfLinks LinksStream (NC.ReadListOfLinks SOURCESTREAM)) 

          (* * And finally, send out this set of Links to the server, making sure first to set the file pointer on the Links 
	  stream to the beginning.)


		    (SETFILEPTR LinksStream 0)
		    (NCCLIENT.PUTCARDPART (fetch (NoteFile UID) of (fetch (Card NoteFile)
									    of Card))
					    (fetch (Card UID) of Card)
					    LinkSpecies LinksStream])

(NCMultiRemote.PutCardPart
  [LAMBDA (Card CardPartName WhenFlg)                        (* Feuerman "28-Jul-86 11:28")

          (* * The multi client remote put card part function.)



          (* * The free variable PutSuccessfulLoc is bound in the calling function, either NC.PutTitle or NC.PutLinks, etc. 
	  If NIL, then the Put wasn't successful, so report the error. If non-NIL, then it should be the position in the file
	  where we put the card part, so now we can set the appropriate card part loc slot to be that number.)


    (SELECTQ WhenFlg
	       [BEFORE (replace (NoteFile Stream) of (fetch (Card NoteFile) of Card)
			  with (OPENSTREAM (QUOTE {NODIRCORE})
					       (QUOTE BOTH]
	       [AFTER (AND PutSuccessfulLoc (SETFILEPTR (fetch (NoteFile Stream)
							       of (fetch (Card NoteFile)
								       of Card))
							    0)
			     (SELECTQ CardPartName
					[(TITLE SUBSTANCE PROPLIST FROMLINKS REGION)
					  (NCCLIENT.PUTCARDPART (fetch (NoteFile UID)
								     of (fetch (Card NoteFile)
									     of Card))
								  (fetch (Card UID) of Card)
								  CardPartName
								  (fetch (NoteFile Stream)
								     of (fetch (Card NoteFile)
									     of Card]
					[LINKS (NCMultiRemote.PUTLINKS Card
									 (fetch (NoteFile Stream)
									    of (fetch
										   (Card NoteFile)
										    of Card]
					(SHOULDNT (CONCAT "Bad card part name:  " CardPartName]
	       (SHOULDNT (CONCAT "Don't understand WhenFlg argument:  " WhenFlg])

(NCMultiRemote.ReleaseWritePermission
  [LAMBDA (Card CardPartName)                                (* Feuerman "30-Jul-86 15:42")

          (* * kef 7/29/86: Added Releaser argument to compare in case someone specified that only one function would be 
	  allowed to actually release the write lock.)


    (NC.UnSetWriteLock Card CardPartName)
    (OR (NC.OwnWriteLockP Card CardPartName)
	  (NCCLIENT.RELEASEWRITELOCK (fetch (NoteFile UID) of (fetch (Card NoteFile)
								       of Card))
				       (fetch (Card UID) of Card)
				       CardPartName])

(NCMultiRemote.RepairNoteFile
  [LAMBDA (ARG1 ARG2 ARG3)
    (ERROR "Not implemented yet:  " (QUOTE NCMultiRemote.RepairNoteFile])

(NCMultiRemote.TruncateNoteFile
  [LAMBDA (ARG1 ARG2 ARG3)
    (ERROR "Not implemented yet:  " (QUOTE NCMultiRemote.TruncateNoteFile])
)

(RPAQ? NC.DeviceVectorsHashArray (HASHARRAY 10))
(PUTHASH (QUOTE REMOTEMULTIUSER)
	 (create NoteFileDevice ListNoteFilesFn ← (FUNCTION NCMultiRemote.ListNoteFiles)
		 CreateNoteFileFn ← (FUNCTION NCMultiRemote.CreateNoteFile)
		 DeleteNoteFileFn ← (FUNCTION NCMultiRemote.DeleteNoteFile)
		 OpenNoteFileFn ← (FUNCTION NCMultiRemote.OpenNoteFile)
		 BuildHashArrayFn ← (FUNCTION NCMultiRemote.BuildHashArray)
		 CloseNoteFileFn ← (FUNCTION NCMultiRemote.CloseNoteFile)
		 NoteFileOpenPFn ← (FUNCTION NCMultiRemote.NoteFileOpenP)
		 CheckpointNoteFileFn ← (FUNCTION NCMultiRemote.CheckpointNoteFile)
		 NewCardUIDFn ← (FUNCTION NCMultiRemote.NewCardUID)
		 MarkCardDeletedFn ← (FUNCTION NCMultiRemote.MarkCardDeleted)
		 GetCardInfoFn ← (FUNCTION NCMultiRemote.GetCardInfo)
		 PutCardPartFn ← (FUNCTION NCMultiRemote.PutCardPart)
		 GetCardPartFn ← (FUNCTION NCMultiRemote.GetCardPart)
		 ObtainWritePermissionFn ← (FUNCTION NCMultiRemote.ObtainWritePermission)
		 ReleaseWritePermissionFn ← (FUNCTION NCMultiRemote.ReleaseWritePermission)
		 CancelCacheSubscriptionFn ← (FUNCTION NCMultiRemote.CancelCacheSubscription)
		 RepairNoteFileFn ← (FUNCTION NCMultiRemote.RepairNoteFile)
		 CompactNoteFileFn ← (FUNCTION NCMultiRemote.CompactNoteFile)
		 TruncateNoteFileFn ← (FUNCTION NCMultiRemote.TruncateNoteFile)
		 ConvertNoteFileFormatFn ← (FUNCTION NCMultiRemote.ConvertNoteFileFormat))
	 NC.DeviceVectorsHashArray)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2566 17275 (NCMultiRemote.BuildHashArray 2576 . 4172) (NCMultiRemote.COLLECTLINKS 4174
 . 5650) (NCMultiRemote.CancelCacheSubscription 5652 . 5987) (NCMultiRemote.CheckpointNoteFile 5989 . 
6321) (NCMultiRemote.CloseNoteFile 6323 . 6658) (NCMultiRemote.CompactNoteFile 6660 . 6804) (
NCMultiRemote.ConvertNoteFileFormat 6806 . 6962) (NCMultiRemote.CreateNoteFile 6964 . 7106) (
NCMultiRemote.DeleteNoteFile 7108 . 7285) (NCMultiRemote.GetCardInfo 7287 . 7576) (
NCMultiRemote.GetCardPart 7578 . 8819) (NCMultiRemote.ListNoteFiles 8821 . 8961) (
NCMultiRemote.MarkCardDeleted 8963 . 9353) (NCMultiRemote.NewCardUID 9355 . 10694) (
NCMultiRemote.NoteFileOpenP 10696 . 11210) (NCMultiRemote.ObtainWritePermission 11212 . 11700) (
NCMultiRemote.OpenNoteFile 11702 . 12870) (NCMultiRemote.PUTLINKS 12872 . 14704) (
NCMultiRemote.PutCardPart 14706 . 16367) (NCMultiRemote.ReleaseWritePermission 16369 . 16981) (
NCMultiRemote.RepairNoteFile 16983 . 17125) (NCMultiRemote.TruncateNoteFile 17127 . 17273)))))
STOP