C Language Specifics
Objects in TIM API C
The TIM API C is based on an object-type concept. Most TIM API functions will either take or return parameters in shape of the "opaque type" ta_object_t. For example: ta_terminal_create will create a new terminal-instance, which returns a ta_object_t. On the other hand terminal-function calls like ta_terminal_get_terminal_id require the terminal-instance as parameter of type ta_object_t.
Note: This concept introduces a behaviour similar to certain aspects of object-oriented programming to the environment of C. Similarities are as follows:
* For each object-type there are functions similar to getters and setters, in order to access the object-properties.
* The naming of getters and setters is as follows: ta_DATATYPE_get/set_PROPERTY
* e.g.: [ta_terminal_settings_get_terminal_id()](https://six-tim.github.io/timapi/doc/c/doc/terminal__settings_8h.html#a73f2947a07fc9f8cefbfa7a3b0f17dfc)
* For each object-type there are functions similar to methods, performing object-specific tasks.
* e.g.: [ta_terminal_login()](https://six-tim.github.io/timapi/doc/c/doc/terminal_8h.html#a227343e36d8f4956c9342945109b3b26)
* For certain object-types create-functions exist, which are similar to constructors.
* e.g.: [ta_string_create()](https://six-tim.github.io/timapi/doc/c/doc/string_8h.html#a36aa84b85923fa00ff19b9932307b831)
Memory Management in TIM API C
The memory needed for each object will be allocated and freed by the TIM API itself. However, the user is responsible to release retained objects, when no longer needed. Retained objects are:
* Objects returned by the TIM API as retained objects (e.g. [terminal](https://six-tim.github.io/timapi/doc/c/doc/terminal_8h.html)-instance created with [ta_terminal_create](https://six-tim.github.io/timapi/doc/c/doc/terminal_8h.html#ab71047155839a18148d9a41406db42b4), or a [hardware_information_response](https://six-tim.github.io/timapi/doc/c/doc/hardware__information__response_8h.html)-instance returned by [ta_terminal_hardware_information](https://six-tim.github.io/timapi/doc/c/doc/terminal_8h.html#a76fe78ef3297a1c301d03402a183afe2)).
* Objects that the user explicitly retained by calling [ta_object_retain](https://six-tim.github.io/timapi/doc/c/doc/object_8h.html#a9a8917ee724f85a764111fa1c2553f40). Basically each [ta_object_retain](https://six-tim.github.io/timapi/doc/c/doc/object_8h.html#a9a8917ee724f85a764111fa1c2553f40) must be paired with a [ta_object_release](https://six-tim.github.io/timapi/doc/c/doc/object_8h.html#aa9e6e27c12a3c1e61e90080f6d0048c6). The TIM API tells you if returned objects are already retained or not. An object that hasn't been retained, must not be released (would lead to errors)! Objects that are returned as not-retained are to read immediately or to explictely retain with [ta_object_retain](https://six-tim.github.io/timapi/doc/c/doc/object_8h.html#a9a8917ee724f85a764111fa1c2553f40).
(see header-documentation or this doxygen-dok to determine, if objects are retained / not retained. Most IDE support doxygen of header-documentation and will show these information while coding).
Following an example of memory management. Shown by using a list:
/* --- Create list -------------------------------------------------- */
ta_object_t myList = ta_object_invalid;
ta_list_create(&myList);
/* --- Add an integer ----------------------------------------------- */
// Create an object of type integer, since list can only contain
// ta_object_t-instances
ta_object_t myInteger = ta_object_invalid;
ta_integer_create(&myInteger, 1234);
ta_list_add(myList, myInteger);
// Important: User must release the integer-object. Either now or later.
ta_object_release(myInteger);
/* --- Get size of list --------------------------------------------- */
size_t myListSize;
ta_list_get_count(myList, &myListSize);
/* --- Receive first element of list -------------------------------- */
ta_object_t myListElement = ta_object_invalid;
ta_list_get_at(myList, 0, &myListElement);
// do something with element...
// - user is responsible to know how to read /
// process retreived objects from list
// - in our case here its an integer-object
int64_t myIntValue = 0;
ta_integer_get_value(myListElement, &myIntValue);
printf("MyIntValue: %Id\n", myIntValue);
// Important:
// - The list returns list elements as not retained!
// - List element must not be released!
/* --- Release list ------------------------------------------------- */
ta_object_release(myList);
// - At this point, myListElement is no longer (reliably) accessible.
// Since list has been released, all its elements have been released
// as well, if no one else is retaining the list elements.
// - If user still wants to use myListElement, he needs to call
// ta_object_retain(myListElement) right after receiving it from
// the list. In this case, he later needs to release the list
// element with ta_object_release(myListElement).
Data Types in TIM API C
C doesn't provide data types / collections like string, boolean, list, timedate etc. Therefore the TIM API uses and provides a set of basic data types. In various places the TIM API requires or returns these data types.
| Data Type | Description |
|---|---|
| boolean | A Boolean type (true/false) |
| integer | An Integer type (64-bit) |
| list | A list collection. Supports create, add, get, index of, remove and more. |
| map | A map collection. Supports create, set, get, has, remove and more. |
| object | The base object (see [Objects in TIM APIC]). |
| string | A String type. Null-terminated character sequence. |
| timedate | Time-Date type. |