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