<> <> <> <> <<>> DIRECTORY AlpineFTP USING [CreateListener, DestroyListener], AlpineFTPCmds USING [], Commander USING [CommandProc, Handle, Register], CommandTool USING [ArgumentVector, Failed, Parse], Rope; AlpineFTPCmdsImpl: CEDAR MONITOR IMPORTS AlpineFTP, Commander, CommandTool, Rope EXPORTS AlpineFTPCmds = BEGIN ROPE: TYPE = Rope.ROPE; CurrentServerName: ROPE _ NIL; StartAlpineFTPServerCommand: Commander.CommandProc = { <<[cmd: REF CommandObject] RETURNS [result: REF _ NIL, msg: ROPE _ NIL]>> <> <> <> <> <<>> argv: CommandTool.ArgumentVector _ CommandTool.Parse[cmd ! CommandTool.Failed => {msg _ errorMsg; GO TO Usage}]; IF argv.argc # 2 THEN GOTO Usage; [result, msg] _ StartAlpineFTPServer[argv[1]]; EXITS Usage => RETURN[$Failure, "Usage: StartAlpineFTPServer volumeGroupName "]; }; StopAlpineFTPServerCommand: Commander.CommandProc = { <<[cmd: REF CommandObject] RETURNS [result: REF _ NIL, msg: ROPE _ NIL]>> <> <> <> <> <<>> argv: CommandTool.ArgumentVector _ CommandTool.Parse[cmd ! CommandTool.Failed => {msg _ errorMsg; GO TO Usage}]; IF argv.argc # 2 THEN GOTO Usage; [result, msg] _ StopAlpineFTPServer[argv[1]]; EXITS Usage => RETURN[$Failure, "Usage: StopAlpineFTPServer volumeGroupName "]; }; StartAlpineFTPServer: PUBLIC PROC [volGroup: ROPE] RETURNS [result: REF _ NIL, msg: ROPE _ "Alpine FTP Server Started"] ~ { new: BOOL; anotherRunning: BOOL; [new, anotherRunning] _ registerVolGroup[volGroup]; SELECT TRUE FROM new AND ~anotherRunning => AlpineFTP.CreateListener[volumeGroupName: volGroup]; new AND anotherRunning => RETURN[$Failure, "Server for a different volume group already running "]; ~new => RETURN[$Failure, "Server for volume group already running "]; ENDCASE; }; StopAlpineFTPServer: PUBLIC PROC [volGroup: ROPE] RETURNS [result: REF _ NIL, msg: ROPE _ "Alpine FTP Server Stopped"] ~ { IF unregisterVolGroup[volGroup] THEN AlpineFTP.DestroyListener[] ELSE RETURN[$Failure, "Server for volume group not running "]; }; registerVolGroup: ENTRY PROC[volumeGroupName: ROPE] RETURNS [new: BOOL _ TRUE, anotherRunning: BOOL _ FALSE] = { ENABLE UNWIND => NULL; IF CurrentServerName.IsEmpty[] THEN {CurrentServerName _ volumeGroupName; RETURN}; IF CurrentServerName.Equal[volumeGroupName, FALSE] THEN RETURN[FALSE, FALSE] ELSE RETURN[FALSE, TRUE]; }; unregisterVolGroup: ENTRY PROC[volumeGroupName: ROPE] RETURNS [found: BOOL] = { ENABLE UNWIND => NULL; IF CurrentServerName.Equal[volumeGroupName, FALSE] THEN { CurrentServerName _ NIL; RETURN[TRUE]; }; RETURN[FALSE]; }; Init: PROCEDURE = { Commander.Register[ "StartAlpineFTPServer", StartAlpineFTPServerCommand, "StartAlpineFTPServer volumeGroupName -- Start up the Alpine FTP Server for the named volume group"]; Commander.Register[ "StopAlpineFTPServer", StopAlpineFTPServerCommand, "StopAlpineFTPServer volumeGroupName -- Stop up the Alpine FTP Server for the named volume group"]; }; <<>> <> Init[]; END. <<>> <<>> <> <> <> <> <<>>