COMPILE FUNCTION Comm_Dialog_IDXSVR( Instruction, Parm1 )

/*
	Commuter Module for Index Server (IDXSVR) Dialog Window
	
	J.C. Henry, Inc. - John C. Henry
	
 */

DECLARE SUBROUTINE Center_Window,StatusLine,Set_Property,End_Dialog, Send_Event, Set_Status, Adios
DECLARE SUBROUTINE ErrMsg, Send_Message, obj_Tables, Post_Event, Set_Bgnd_IX_Time, Set_IDXSvr, ShowWindow
DECLARE FUNCTION Get_Property, Get_Status,Dialog_Box, FindWindow

EQU CRLF$ TO \0D0A\

EQU TRUE$ TO 1
EQU FALSE$ TO 2

$INSERT ENVIRON_CONSTANTS

ErrTitle = 'Error in Comm_Dialog_IDXSVR routine'
ErrorMsg = ''


Instructions  = 'Create'
Instructions := @FM:'Timer'
Instructions := @FM:'StartStop'
Instructions := @FM:'Close'

RetVal = ''

LOCATE Instruction IN Instructions USING @FM SETTING Pos THEN
	ON Pos GOSUB Create,Timer,StartStop,Close
END

RETURN RetVal


* * * * * * *
Create:
* * * * * * *

*Center_Window(@WINDOW)

StatusLine(@WINDOW)

Set_Status(0)

otParms = 'SYSOBJ':@RM:'INDEX_SERVER'
obj_Tables('LockRec',otParms)	;* Places lock on fictional record

IF Get_Status(errCode) THEN
	ErrorMsg = ErrTitle:@SVM:'Another index server is already running.'
	ErrMsg(ErrorMsg)
	Post_Event(@WINDOW,'CLOSE')
	RETURN
END

Set_Property(@WINDOW,'@LOCKED',1)				;* Set ad-hoc property '@LOCKED' to true
*Set_Property(@WINDOW,'TIMER','5000':@FM:'0')	;* Set timer event to 5000 msecs (5 seconds) to check for shutdown time.

* Code added 6/9/2004 to show engine window when running on a runtime JCH

OpenEngineHandle = FindWindow("AREV":\00\,0)
ShowWindow(OpenEngineHandle,1)



* No return on create -> automatically starts index server

* * * * * * *
StartStop:
* * * * * * *

StartStop = Get_Property(@WINDOW:'.START_STOP_BUTTON','TEXT')

IF StartStop = 'Stop Index Server' THEN

	* Index server is running
	
	Set_IDXSvr(0)			;* Turn off index server
	Set_Bgnd_IX_Time(0)		;* Turn off background indexing by setting interval to zero
	Set_Property(@WINDOW:'.START_STOP_BUTTON','TEXT', 'Start Index Server')
	Set_Property(@WINDOW:'.CLOSE_BUTTON','ENABLED',1)
	
END ELSE

	IndexInterval = Get_Property(@WINDOW:'.INTERVAL','TEXT')

	IF IndexInterval = '' THEN
		* bad value entered or null
		IndexInterval = 10
		Set_Property(@WINDOW:'.INTERVAL','INVAL',IndexInterval)
	END

	Set_Bgnd_IX_Time(IndexInterval)		;* Set background index inteval to IndexInterval (Seconds)
	Set_Property(@WINDOW:'.START_STOP_BUTTON','TEXT', 'Stop Index Server')
	Set_IDXSvr(1)						;* Start the index server process
	Set_Property(@WINDOW:'.CLOSE_BUTTON','ENABLED',0)
	
END


RETURN


* * * * * * *
Close:
* * * * * * *

otParms = 'SYSOBJ':@RM:'INDEX_SERVER'

obj_Tables('LockRec',otParms)	;* Places lock on fictional record

IF Get_Status(errCode) THEN
	Set_Status(0)
	obj_Tables('UnlockRec',otParms)	;* Removes lock on fictional record
	
END

Set_Property('SYSTEM','IDLEPROC','ADIOS')
*Adios()			;* Utility('SYSTEM','DESTROY')	in a wrapper

RETURN


* * * * * * *
Timer:
* * * * * * *

ShutDownTime = Get_Property(@WINDOW:'.SHUTDOWN_TIME','INVALUE')

Set_Property(@WINDOW:'.COUNTDOWN','INVALUE',ShutDownTime - TIME())

IF TIME() > ShutDownTime THEN 

	Set_IDXSvr(0)			;* Turn off index server
	Set_Bgnd_IX_Time(0)		;* Turn off background indexing by setting interval to zero
	Set_Property('SYSTEM','IDLEPROC','ADIOS')
	
END


RETURN


