cure v0.5.0 Cure

The main Cure module. Provides a few functions to easily start a connection with a C/C++ program, to send messages to the program and to handle the incoming responses.

Summary

Functions

Starts a Cure.Server process that can communicate with a C-program

Sends binary data to the C/C++ program that the server is connected with. The result is sent back to the process that called this function. The third argument indicates how the response should be handled. Possible modes for handling the response are the following

Sends binary data to the C/C++ program that the server is connected with. A callback-function (arity 1) can be added to handle the incoming response of the program. If no callback is added, the response will be sent to the calling process of this function

Sends binary data to the C/C++ program that the server is connected with. The server waits with processing further events until the response for this function is handled

Starts the Cure application, returns the Cure.Supervisor-PID

Stops a server process that is being supervised in the supervision tree

Subscribes the calling process to receive data events from the server process

Adds an extra callback function to the server that is triggered on all incoming data

Unsubscribes the calling process from receiving further data events coming from the server process

Removes a callback that was applied to all incoming data events. NOTE: this has to be the exact same callback function that was registered earlier with subscribe in order for this function to work properly

Functions

load(c_program_name)

Specs

load(String.t) :: {:ok, pid}

Starts a Cure.Server process that can communicate with a C-program.

send_data(server, data, atom)

Sends binary data to the C/C++ program that the server is connected with. The result is sent back to the process that called this function. The third argument indicates how the response should be handled. Possible modes for handling the response are the following:

:once -> Only the first event will be sent back to the calling process. :noreply -> No event will be sent back to the calling process. :permanent -> All following events will be sent back to the calling process. :sync -> the server waits with processing further events until the response is sent back to the calling process (timeout = :infinity unless specified).

(Same effect as calling Cure.Server.send_data directly.)

send_data(server, data, atom, callback)

Specs

send_data(pid, binary, :once | :permanent | :sync, (binary -> any) | timeout) :: :ok
send_data(pid, binary, :once | :noreply | :permanent, :sync) ::
  :ok |
  {:error, term}

Sends binary data to the C/C++ program that the server is connected with. A callback-function (arity 1) can be added to handle the incoming response of the program. If no callback is added, the response will be sent to the calling process of this function.

The third argument indicates how the response should be handled. Possible modes for handling the response are the following:

:once -> callback function is only applied once. :permanent -> callback function is applied to all following events :sync -> the server waits with further events until response is processed (no timeout specified = :infinity).

(Same effect as calling Cure.Server.send_data directly.)

send_data(server, data, atom, callback, timeout)

Specs

send_data(pid, binary, :sync, (binary -> any), timeout) :: :ok

Sends binary data to the C/C++ program that the server is connected with. The server waits with processing further events until the response for this function is handled.

(Same effect as calling Cure.Server.send_data directly.)

start(type, args)

Specs

start(any, any) :: {:ok, pid} | {:error, term}

Starts the Cure application, returns the Cure.Supervisor-PID.

stop(server)

Specs

stop(pid) :: :ok

Stops a server process that is being supervised in the supervision tree.

subscribe(server)

Specs

subscribe(pid) :: :ok

Subscribes the calling process to receive data events from the server process.

subscribe(server, fun)

Specs

subscribe(pid, (binary -> any)) :: :ok

Adds an extra callback function to the server that is triggered on all incoming data.

unsubscribe(server)

Specs

unsubscribe(pid) :: :ok

Unsubscribes the calling process from receiving further data events coming from the server process.

unsubscribe(server, fun)

Specs

unsubscribe(pid, (binary -> any)) :: :ok

Removes a callback that was applied to all incoming data events. NOTE: this has to be the exact same callback function that was registered earlier with subscribe in order for this function to work properly.