ITK Programmer's Guide


 

Table of contents | Intro | General | TCP Low Level | TCP High Level | UDP | DNS | PPP
Encoding/Decoding | Internet Config | Goodies | Cryptography | Appendix

 

Chapter 10 : Goodies

   

   

Chapter contents:

Timer routines:

Inter Process Communication:

Picture routines:

Miscelaneous routines:


About this chapter...

This chapter describes some "goodies" routines provided with ITK.

These routines are useful to measure time accurately (needed for example for optimising a portion of code), communicate between processes (useful in many server implementations), etc.



About ITK Timer Routine

These routines can be used to accurately measure elapsed time in some critical code portions.
Under MacOS, these routines use the Time Manager to get a high level of accuracy (up to the millisecond).

ITK_TimerStart

Syntax:

timerRef := ITK_TimerStart


Description:

Start a timer and returns a reference to it. These reference will be used when calling ITK_TimerLap and ITK_TimerStop.


Params:

In/Out

Parameter

Type

   

Example or note

<-

timerRef

Longint

Timer reference number

   


Example:

$timer := ITK_TimerStart ...
$elapsedTime := ITK_TimerStop($timer)
Back to top


ITK_TimerLap

Syntax:

lapTime := ITK_TimerLap(timerRef)


Description:

Returns the number of milliseconds since ITK_TimerStart was called without stopping the timer.


Params:

In/Out

Parameter

Type

   

Example or note

->

timerRef

Longint

Timer reference number

As returned by ITK_TimerStart

<-

lapTime

Longint

Elapsed time in milliseconds

   


Example:

$timer := ITK_TimerStart ...
$lapTime1 := ITK_TimerLap($timer)
...
$lapTime2 := ITK_TimerLap($timer)
...
$totalTime := ITK_TimerStop($timer)
Back to top


ITK_TimerStop

Syntax:

totalTime := ITK_TimerStop(timerRef)


Description:

Returns the number of milliseconds since ITK_TimerStart was called and then stops the timer.


Note:

After calling ITK_TimerStop, the Timer Reference number returned by ITK_TimerStart is not valid anymore.


Params:

In/Out

Parameter

Type

   

Example or note

->

timerRef

Longint

Timer reference number

As returned by ITK_TimerStart

<-

totalTime

Longint

Elapsed time in milliseconds

   


Example:

$timer := ITK_TimerStart ...
$totalTime := ITK_TimerStop($timer)
Back to top


About ITK Inter Process Communication (IPC) routines

ITK's IPC routines are useful to exchange data between processes through communications channels. These channels are memory based to provide speed efficient communications.

The number of channels and the number of messages queued in a channel are limited by the available memory.

ITK_NbIPCMsg

Syntax:

nbMsg := ITK_NbIPCMsg(ipcChannel)


Description:

Returns the number of messages currently stored on the specified IPC channel.


Note:

IPC channel number are used to create as many IPC channels as you need.
For example, you can use the Current Process instruction in 4D language to allocate one IPC channel for each 4D process or use any other channel numbering.


Params:

In/Out

Parameter

Type

   

Example or note

->

ipcChannel

Longint

IPC Channel Number

see note above.

<-

nbMsg

Longint

Number of messages stored in this IPC channel.

   


Example:

While (ITK_NbIPCMsg(1)>0)
` process IPC messages
...
End While
Back to top


ITK_SendIPCMsg

Syntax:

ITK_SendIPCMsg(ipcChannel;message)


Description:

Sends a message on the specified IPC channel.
The message will be stored in the channel message queue.


Note:

IPC channel number are used to create as many IPC channels as you need.
For example, you can use the Current Process instruction in 4D language to allocate one IPC channel for each 4D process or use any other channel numbering.


Params:

In/Out

Parameter

Type

   

Example or note

->

ipcChannel

Longint

IPC Channel Number

see note above.

->

message

Text

Message to send in the above channel

   


Example:

ITK_SendIPCMsg(1;"quit")
Back to top


ITK_RcvIPCMsg

Syntax:

message := ITK_RcvIPCMsg(ipcChannel;option)


Description:

Reads a message from the specified IPC channel. If no message is available, returns an empty string.

The option parameter can be used to keep the message in the IPC channel queue.
In that case, the same message will be returned on the next call to ITK_RcvIPCMsg.


Note:

IPC channel number are used to create as many IPC channels as you need.
For example, you can use the Current Process instruction in 4D language to allocate one IPC channel for each 4D process or use any other channel numbering.


Params:

In/Out

Parameter

Type

   

Example or note

->

ipcChannel

Longint

IPC Channel Number

see note above.

->

option

Longint

   

0 = default behaviour
1 = keep message in channel queue

<-

message

Text

Receive message

will be empty if no message available on the requested IPC channel.


Example:

$msg := ITK_RcvIPCMsg(1;0)
If ($msg = "quit")
  QUIT 4D
End If
Back to top


ITK_ResetIPCMsg

Syntax:

ITK_ResetIPCMsg(ipcChannel)


Description:

Removes all the messages stored on the specified IPC channel.


Note:

IPC channel number are used to create as many IPC channels as you need.
For example, you can use the Current Process instruction in 4D language to allocate one IPC channel for each 4D process or use any other channel numbering.


Params:

In/Out

Parameter

Type

   

Example or note

->

ipcChannel

Longint

IPC Channel Number

see note above.


Example:

ITK_ResetIPCMsg(1)
Back to top


ITK_PictSize

Syntax:

pictSize := ITK_PictSize(pict; top; left; bottom; right; type)


Description:

This routines extracts size informations from a given picture.


Params:

In/Out

Parameter

Type

   

Example or note

->

pict

Picture

   

   

->

top

Longint

Top coordinates of the picture

   

->

left

Longint

Left coordinate of the picture

   

->

bottom

Longint

Bottom coordinate of the picture

   

->

right

Longint

Right coordinate of the picture

   

->

type

Longint

type of picture

0 = Mac style PICT
1 = GIF image
2 = JPEG image

<-

pictSize

Longint

Size (in bytes) of the picture

   


Example:

$size := ITK_PictSize($pict;$top;$left;$bottom;$right;$type)
$height := $bottom-$top
$width := $right-$left
Back to top


ITK_PictSave

Syntax:

error := ITK_PictSave(pict; filePath)


Description:

Saves the content of a picture field or variable into a file.

If the picture is encoded in the GIF format, a standard GIF file will be saved.

If the picture contains a JPEG portion, this portion will be save as a JPEG/JFIF file.

Otherwise, the picture will be saved as a standard Picture (PICT).


Params:

In/Out

Parameter

Type

   

Example or note

->

pict

Picture

   

   

->

filePath

String

File pathname

   

<-

error

Longint

OS error code

   


Example:

$err := ITK_PictSave($pict;"MyHD:MyFolder:MyPict")
Back to top


ITK_PictRead

Syntax:

pict := ITK_PictRead(filePath)


Description:

Reads a picture file (PICT, GIF or JFIF/JPEG) and returns it as a 4D pict.


Params:

In/Out

Parameter

Type

   

Example or note

->

filePath

String

Filepath of the Picture file to read

   

<-

pict

Picture

Picture read from file.

If an error occured, this picture will have its size set to 0.


Example:

$pict := ITK_PictRead("MyHD:MyFolder:MyPict")
$err := ITK_TCPSendPict($stream; $pict)
Back to top


ITK_ICMPEcho

Syntax:

time := ITK_ICMPEcho(IPaddr; timeout; size)


Description:

This routines sends an "ICMP Echo" packet to the remote IP address and measures the time needed for the echo to come back. It is an equivallent to the famous "ping" function.


Params:

In/Out

Parameter

Type

   

Example or note

->

IPaddr

Longint

Remote host IP address

As returned by ITK_Name2Addr.

->

timeout

Longint

Timeout in seconds

   

->

size

Longint

Size of the ICMP Echo packet to send.

0 will use a default size of 64 bytes.

<-

result

Longint

Measured time in milliseconds

Negative values indicate that an error occured.


Example:

$pingtime := ITK_ICMPEcho(ITK_Name2Addr("www.internet-toolkit.com");2000;64)
Back to top


ITK_OpenFile

Syntax:

fileRef := ITK_OpenFile(pathname)


Description:

Opens a file in read-only mode.


Note:

The variable used to store the fileRef value must be types as C_TIME when compiled.


Params:

In/Out

Parameter

Type

   

Example or note

->

pathName

String

Pathname of the file to open.

Under Windows, the full pathname must be passed, ex: "C:\MYSTUFF\MYFILE.TXT".

<-

fileRef

Longint

File reference of the opened file.

Will return 0 if the file could not be opened. The returned value can be used in other 4D file related routines like RECEIVE PACKET, CLOSE DOCUMENT, etc. This value is equivallent to the one returned by Open Document.


Example:

$file := ITK_OpenFile("C:\MyFile.TXT")
If ($file#0)
  RECEIVE PACKET($file;$data;32000)
  ...
  CLOSE DOCUMENT($file)
End If
Back to top

ITK_SetPriority

Syntax:

error := ITK_SetPriority(newPriority)


Description:

Changes 4D's priority level in Windows multitasking.


Note:

This routines currently does nothing under MacOS.


Params:

In/Out

Parameter

Type

   

Example or note

->

newPriority

Longint

Priority level value

4 = Idle
9 = Normal
13 = High
24 = Realtime

<-

error

Longint

Windows error code (0= no error)

   


Example:

$err := ITK_SetPriority(4) ` go in Idle mode
Back to top

ITK_GetPriority

Syntax:

priority := ITK_GetPriority


Description:

Retrieves 4D's priority level in Windows multitasking.


Note:

This routines currently does nothing under MacOS.


Params:

In/Out

Parameter

Type

   

Example or note

<-

priority

Longint

Current Windows priority level

4 = Idle
9 = Normal
13 = High
24 = Realtime


Example:

` Set 4D's at least in "normal" priority
If (ITK_GetPriority<9)
  $err := ITK_SetPriority(9)
End If
Back to top

ITK_Pict2Blob

Syntax:

blob := ITK_Pict2Blob(pict)


Description:

Converts a picture value (variable or field) into a blob.


Note:

The content in not changed by this routine which simply does some typecasting.


Params:

In/Out

Parameter

Type

   

Example or note

->

pict

Picture

picture to convert

   

->

option

Longint

option to indicate if a copy of the blob is requested

0 = a copy of the original pict is returned
1= the original picture is returned and emptied

<-

blob

Blob

typecasted blob

   


Example:

$myBlob := ITK_Pict2Blob($myBlob)
Back to top

ITK_Blob2Pict

Syntax:

pict := ITK_Blob2Pict(blob)


Description:

Converts a blob value (variable or field) into a picture.


Note:

The content in not changed by this routine which simply does some typecasting.


Params:

In/Out

Parameter

Type

   

Example or note

->

blob

Blob

blob to convert

   

->

option

Longint

Option to indicate if a copy of the blob is requested

0 = a copy of the original blob is returned
1 = the original blob is returned and emptied

<-

pict

Picture

typecasted picture

   


Example:

$myBlob := ITK_Pict2Blob($myPict) ` return a copy (uses more memory)
$myBlob := ITK_Pict2Blob($myPict;1) ` "transfers" the pict into a blob, the original pict is emptied
Back to top
CQ/16-Dec-98