legato.h

Go to the documentation of this file.
1 /**
2  * @page c_APIs C Runtime Library
3  *
4  * This section contains detailed info about Legato's C Language library used for low-level routines like
5  * commonly used data structures and OS services APIs.
6  *
7  * <HR>
8  *
9  * The C APIs' @ref cApiOverview has high-level info.
10  *
11  * <HR>
12  *
13  * @subpage c_le_build_cfg <br>
14  * @subpage c_basics <br>
15  * @subpage c_args <br>
16  * @subpage c_atomFile <br>
17  * @subpage c_dir <br>
18  * @subpage c_doublyLinkedList <br>
19  * @subpage c_memory <br>
20  * @subpage c_eventLoop <br>
21  * @subpage c_fdMonitor <br>
22  * @subpage c_flock <br>
23  * @subpage c_hashmap <br>
24  * @subpage c_hex <br>
25  * @subpage c_json <br>
26  * @subpage c_logging <br>
27  * @subpage c_messaging <br>
28  * @subpage c_mutex <br>
29  * @subpage c_path <br>
30  * @subpage c_pathIter <br>
31  * @subpage c_print <br>
32  * @subpage c_safeRef <br>
33  * @subpage c_semaphore <br>
34  * @subpage c_signals <br>
35  * @subpage c_singlyLinkedList <br>
36  * @subpage c_clock <br>
37  * @subpage c_threading <br>
38  * @subpage c_timer <br>
39  * @subpage c_test <br>
40  * @subpage c_utf8 <br>
41  * @subpage c_tty
42  *
43  * @section cApiOverview Overview
44  * Here is some background info on Legato's C Language APIs.
45  *
46  * @subsection Object-Oriented Design
47  *
48  * The Legato framework is constructed in an object-oriented manner.
49  *
50  * The C programming language was created before object-oriented programming was
51  * popular so it doesn't have native support for OOP features like inheritance, private object
52  * members, member functions, and overloading. But object-oriented designs can still be
53  * implemented in C.
54  *
55  * In the Legato C APIs, classes are hidden behind opaque "reference" data types.
56  * You can get references to objects created behind the scenes in Legato, but
57  * you can never see the structure of those objects. The implementation is hidden from view.
58  * Access to object properties is made available through accessor functions.
59  *
60  * @subsection Opaque Types
61  *
62  * The basic "opaque data type" offered by the C programming language is the "void pointer"
63  * <c>(void *)</c>.
64  * The idea is that a pointer to an object of type @a T can be cast to point to a <c>void</c> type
65  * before being passed outside of the module that implements @a T.
66  *
67  * This makes it impossible for anyone outside of the module that implements @a T to
68  * dereference the pointer or access anything about the implementation of @a T. This way,
69  * the module that implements @a T is free to change the implementation of @a T in any
70  * way needed without worrying about breaking code outside of that module.
71  *
72  * The problem with the void pointer type is that it throws away type information. At compile time,
73  * this makes it impossible to detect that a variable with opaque type @a T
74  * has been passed into a function with some other pointer type @a P.
75  *
76  * To overcome this, Legato uses "incomplete types" to implement its opaque types. For example,
77  * there are declarations similar to the following in Legato C API header files:
78  *
79  * @code
80  * // Declare a reference type for referring to Foo objects.
81  * typedef struct le_foo* le_foo_Ref_t;
82  * @endcode
83  *
84  * But "struct le_foo" would @a not be defined in the API header or @a anywhere outside of the
85  * hypothetical "Foo" API's implementation files. This makes "struct le_foo" an "incomplete type"
86  * for all code outside of the Foo API implementation files. Incomplete types can't be used
87  * because the compiler doesn't have enough information about them to generate any code
88  * that uses them. But @a pointers to incomplete types @a can be passed around because the compiler
89  * always knows the pointer size. The compiler knows that one incomplete type
90  * is @a not necessarily interchangeable with another, and it won't allow a pointer to
91  * an incomplete type to be used where a pointer to another non-void type is expected.
92  *
93  * @subsection Handlers and Event-Driven Programs
94  *
95  * "Handler" is an alias for "callback function". Many APIs in the Legato world
96  * use callback functions to notify their clients of asynchronous events. For example, to
97  * register a function called "SigTermHandler" for notification of receipt of a TERM signal,
98  *
99  * @code
100  *
101  * le_sig_SetEventHandler(SIGTERM, SigTermHandler);
102  *
103  * @endcode
104  *
105  * Instead of using "CallbackFunction", "CallbackFunc", or some abbreviation like "CbFn"
106  * (Cub fun? Cubs fan? What?) that is difficult to read and/or remember, "Handler" is used.
107  *
108  * The term "handler" also fits with the event-driven programming style that is favoured in
109  * the Legato world. These callback functions are essentially event handler functions.
110  * That is, the function is called when an event occurs to "handle" that event.
111  *
112  * <HR>
113  *
114  * Copyright (C) Sierra Wireless Inc. Use of this work is subject to license.
115  */
116 
117 //--------------------------------------------------------------------------------------------------
118 /**
119  * @file legato.h
120  *
121  * This file includes all the commonly-used Legato API header files.
122  * It's provided as a convenience to avoid including
123  * dozens of header files in every source file.
124  *
125  * Copyright (C) Sierra Wireless Inc. Use of this work is subject to license.
126  */
127 //--------------------------------------------------------------------------------------------------
128 
129 #ifndef LEGATO_H_INCLUDE_GUARD
130 #define LEGATO_H_INCLUDE_GUARD
131 
132 #ifndef _GNU_SOURCE
133 #define _GNU_SOURCE
134 #endif
135 
136 #include <stddef.h>
137 #include <unistd.h>
138 #include <time.h>
139 #include <string.h>
140 #include <stdio.h>
141 #include <stdlib.h>
142 #include <stdint.h>
143 #include <time.h>
144 #include <sys/time.h>
145 #include <stdarg.h>
146 #include <syslog.h>
147 #include <pthread.h>
148 #include <limits.h>
149 #include <errno.h>
150 #include <sys/socket.h>
151 #include <sys/un.h>
152 #include <fcntl.h>
153 #include <sys/types.h>
154 #include <sys/syscall.h>
155 #include <signal.h>
156 #include <sys/signalfd.h>
157 #include <sys/wait.h>
158 #include <sys/stat.h>
159 #include <stdbool.h>
160 #include <ctype.h>
161 #include <inttypes.h>
162 #include <dirent.h>
163 #include <sys/reboot.h>
164 #include <sys/timeb.h>
165 #include <sys/mount.h>
166 #include <sys/sysinfo.h>
167 #include <sys/resource.h>
168 #include <mntent.h>
169 #include <grp.h>
170 #include <sys/xattr.h>
171 #include <fts.h>
172 #include <poll.h>
173 #include <sys/epoll.h>
174 #include <sys/prctl.h>
175 #include <sched.h>
176 #include <semaphore.h>
177 #include <math.h>
178 
179 
180 #ifdef __cplusplus
181 extern "C" {
182 #endif
183 
184 #include "le_build_config.h"
185 #include "le_basics.h"
186 #include "le_doublyLinkedList.h"
187 #include "le_singlyLinkedList.h"
188 #include "le_utf8.h"
189 #include "le_log.h"
190 #include "le_mem.h"
191 #include "le_mutex.h"
192 #include "le_clock.h"
193 #include "le_semaphore.h"
194 #include "le_safeRef.h"
195 #include "le_thread.h"
196 #include "le_eventLoop.h"
197 #include "le_fdMonitor.h"
198 #include "le_hashmap.h"
199 #include "le_signals.h"
200 #include "le_args.h"
201 #include "le_timer.h"
202 #include "le_messaging.h"
203 #include "le_test.h"
204 #include "le_path.h"
205 #include "le_pathIter.h"
206 #include "le_hex.h"
207 #include "le_dir.h"
208 #include "le_fileLock.h"
209 #include "le_json.h"
210 #include "le_tty.h"
211 #include "le_atomFile.h"
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 #endif // LEGATO_H_INCLUDE_GUARD