Xenomai  3.0.2
setup.h
1 /*
2  * Copyright (C) 2015 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _BOILERPLATE_SETUP_H
19 #define _BOILERPLATE_SETUP_H
20 
21 #include <boilerplate/list.h>
22 #include <boilerplate/wrappers.h>
23 #include <string.h>
24 #include <sched.h>
25 
26 struct base_setup_data {
27  cpu_set_t cpu_affinity;
28  int no_mlock;
29  int no_sanity;
30  int verbosity_level;
31  int trace_level;
32  const char *arg0;
33 };
34 
35 struct option;
36 
37 struct setup_descriptor {
38  const char *name;
39  int (*tune)(void);
40  int (*parse_option)(int optnum, const char *optarg);
41  void (*help)(void);
42  int (*init)(void);
43  const struct option *options;
44  struct {
45  int id;
46  int opt_start;
47  int opt_end;
48  struct pvholder next;
49  } __reserved;
50 };
51 
52 /*
53  * We have three pre-defined constructor priorities:
54  *
55  * - One for setup calls (__setup_ctor), which are guaranteed to run
56  * prior to the bootstrap code. You should use setup calls for
57  * implementing initialization hooks which depend on a particular call
58  * order. Each Xenomai interface layer is initialized via a dedicated
59  * setup call.
60  *
61  * - A second priority is assigned to early init calls (__early_ctor),
62  * which are also guaranteed to run prior to the bootstrap
63  * code. Whether such early code runs before OR after any setup code
64  * is __UNSPECIFIED__. By design, such code may not invoke any Xenomai
65  * service, and generally speaking, should have no dependencies on
66  * anything else.
67  *
68  * - The last priority level is used for the bootstrap code
69  * (__bootstrap_ctor), which is guaranteed to run after any
70  * setup/early code, provided such bootstrap code is part of the main
71  * executable.
72  *
73  * The guarantees on the init order don't go beyond what is stated
74  * here, do NOT assume more than this.
75  */
76 #define __setup_ctor __attribute__ ((constructor(200)))
77 #define __early_ctor __attribute__ ((constructor(210)))
78 #define __bootstrap_ctor __attribute__ ((constructor(220)))
79 
80 #define __setup_call(__name, __id) \
81 static __setup_ctor void __declare_ ## __name(void) \
82 { \
83  __register_setup_call(&(__name), __id); \
84 }
85 
86 #define core_setup_call(__name) __setup_call(__name, 0)
87 #define boilerplate_setup_call(__name) __setup_call(__name, 1)
88 #define copperplate_setup_call(__name) __setup_call(__name, 2)
89 #define interface_setup_call(__name) __setup_call(__name, 3)
90 #define post_setup_call(__name) __setup_call(__name, 4)
91 #define user_setup_call(__name) __setup_call(__name, 5)
92 
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
97 void __register_setup_call(struct setup_descriptor *p, int id);
98 
99 extern pid_t __node_id;
100 
101 extern int __config_done;
102 
103 extern struct base_setup_data __base_setup_data;
104 
105 static inline const char *get_program_name(void)
106 {
107  return basename(__base_setup_data.arg0 ?: "program");
108 }
109 
110 void __trace_me(const char *fmt, ...);
111 
112 #define trace_me(__fmt, __args...) \
113  do { \
114  if (__base_setup_data.trace_level > 0) \
115  __trace_me(__fmt, ##__args); \
116  } while (0)
117 
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif /* !_BOILERPLATE_SETUP_H */