Skip to content

Instantly share code, notes, and snippets.

@aparajita

aparajita/A4D_Init.txt

Last active Aug 29, 2015
Embed
What would you like to do?
A4D_Init method
`METHOD: A4D_Init{(inStartWebServer)}
`
`Part of Active4D, the ultimate 4D web environment
`Copyright © Aparajita Fishman, All Rights Reserved
C_BOOLEAN($1;$inStartWebServer)
If (Count parameters=0)
$inStartWebServer:=True
Else
$inStartWebServer:=$1
End if
C_BOOLEAN(◊A4D_ClientIsWebServer)
◊A4D_ClientIsWebServer:=False
C_TEXT(◊A4D_HostType;◊A4D_HostAddr;◊A4D_HostPort)
C_LONGINT($hostAddr)
◊A4D_HostType:="4D"
If (Application type=4D Remote Mode )
$hostAddr:=Get database parameter(Client IP Address to listen )
Else
$hostAddr:=Get database parameter(IP Address to listen )
End if
◊A4D_HostAddr:=String(($hostAddr & 0xFF000000) >> 24)+"."+String(($hostAddr & 0x00FF0000) >> 16)+"."+String(($hostAddr & 0xFF00) >> 8)+"."+String($hostAddr & 0x00FF)
C_TEXT(◊A4D_HostMAC)
◊A4D_HostMAC:=A4D Get MAC address
A4D_InitHook (->◊A4D_ClientIsWebServer)
C_BOOLEAN(◊A4D_IsWebServer;$isWebServer)
◊A4D_IsWebServer:=False
`WEB SEND RAW DATA is broken in various versions of 4D
C_BOOLEAN(◊A4D_CanSendRawData)
C_TEXT($version)
C_LONGINT($versionNumber;$updateNumber;$revisionNumber)
$version:=Application version
$versionNumber:=Num(Substring($version;1;2))
$updateNumber:=Num(Substring($version;3;1))
$revisionNumber:=Num(Substring($version;4;1))
◊A4D_CanSendRawData:=True
Case of
: ($versionNumber=13)
◊A4D_CanSendRawData:=($updateNumber>=2) & ($updateNumber#6)
: ($versionNumber=14)
◊A4D_CanSendRawData:=$revisionNumber>=4
End case
If (Application type=4D Remote Mode )
$isWebServer:=◊A4D_ClientIsWebServer
◊A4D_HostPort:=String(Get database parameter(Client Port ID ))
Else
$isWebServer:=Not(◊A4D_ClientIsWebServer)
◊A4D_HostPort:=String(Get database parameter(Port ID ))
End if
If (◊A4D_HostPort="0")
◊A4D_HostPort:="80"
End if
C_LONGINT($err)
$err:=A4D Init
C_LONGINT(◊A4D_HouseKeeperPID)
If ($isWebServer)
C_LONGINT($housekeeperStack)
$housekeeperStack:=Num(A4D_GetParam ("A4D_Config";"HousekeeperStack";"128"))
◊A4D_HouseKeeperPID:=New Process("A4D_HouseKeeper";$housekeeperStack*1024;"A4D_HouseKeeper";*)
If ($inStartWebServer)
// 4D v11-v12
START WEB SERVER
// 4D v13+
WEB START SERVER
End if
Else
◊A4D_HouseKeeperPID:=0
End if
`Define this last, it is the flag that allows requests to be handled by Active4D.
`By waiting until initialization is done we ensure Active4D is fully initialized
`before it handles requests.
◊A4D_IsWebServer:=$isWebServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment