# Defining events and reasons

For each asynchronous function defined in the API, define a set of one or more events for subsequent return to the client application. These events typically denote the results of asynchronous API functions invoked by the client application, but they can also represent unsolicited events that were generated by the managed resource.

Each event structure has a value field that can contain additional information or classification for the event. By convention, the value field of a DONE event contains either a reason for completion or an error code. See Error codes and Events for details.

Set up your service so that it uses existing Natural Access event and reason codes whenever possible. Natural Access events are defined in ctadef.h. Natural Access errors and reason codes are defined in ctaerr.h.

tik service

Based upon the event analysis (described in Understanding the managed resource), the following event codes and associated reasons are defined:

- TIKEVN_TIMER_TICK

Event generated by the tik service and sent back to the client for all tick strings.

- TIKEVN_TIMER_DONE

Event generated by the tik service and sent back to the client to indicate that all tick strings were sent to the client. Can have the following reason codes:

- CTA_REASON_FINISHED - Indicates that the tik service has successfully generated all requested tick strings at the requested frequency.

- TIK_REASON_UNKNOWN_SERVER_REASON - indicates an unexpected error has occurred at the tik service.

- TIK_REASON_TIMER_STOPPED - Indicates tikStopTimer was successful.

- TIK_REASON_INVALID_CHANNEL

Reason code for CTAEVN_DISP_OPEN_SERVICE_DONE. Indicates a failure in initializing communication with the tik service.

- TIK_REASON_CHANNEL_ACTIVE

Reason code for CTAEVN_DISP_OPEN_SERVICE_DONE. Indicates that the requested channel is occupied.