Xenomai  3.0.8
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  int done;
50  } __reserved;
51 };
52 
53 /*
54  * We have three pre-defined constructor priorities:
55  *
56  * - One for setup calls (__setup_ctor), which are guaranteed to run
57  * prior to the bootstrap code. You should use setup calls for
58  * implementing initialization hooks which depend on a particular call
59  * order. Each Xenomai interface layer is initialized via a dedicated
60  * setup call.
61  *
62  * - A second priority is assigned to early init calls (__early_ctor),
63  * which are also guaranteed to run prior to the bootstrap
64  * code. Whether such early code runs before OR after any setup code
65  * is __UNSPECIFIED__. By design, such code may not invoke any Xenomai
66  * service, and generally speaking, should have no dependencies on
67  * anything else.
68  *
69  * - The last priority level is used for the bootstrap code
70  * (__bootstrap_ctor), which is guaranteed to run after any
71  * setup/early code, provided such bootstrap code is part of the main
72  * executable.
73  *
74  * The guarantees on the init order don't go beyond what is stated
75  * here, do NOT assume more than this.
76  */
77 #define __setup_ctor __attribute__ ((constructor(200)))
78 #define __early_ctor __attribute__ ((constructor(210)))
79 #define __bootstrap_ctor __attribute__ ((constructor(220)))
80 
81 #define __setup_call(__name, __id) \
82 static __setup_ctor void __declare_ ## __name(void) \
83 { \
84  __register_setup_call(&(__name), __id); \
85 }
86 
87 #define core_setup_call(__name) __setup_call(__name, 0)
88 #define boilerplate_setup_call(__name) __setup_call(__name, 1)
89 #define copperplate_setup_call(__name) __setup_call(__name, 2)
90 #define interface_setup_call(__name) __setup_call(__name, 3)
91 #define post_setup_call(__name) __setup_call(__name, 4)
92 #define user_setup_call(__name) __setup_call(__name, 5)
93 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 void __register_setup_call(struct setup_descriptor *p, int id);
99 
100 extern pid_t __node_id;
101 
102 extern int __config_done;
103 
104 extern struct base_setup_data __base_setup_data;
105 
106 const char *get_program_name(void);
107 
108 void __trace_me(const char *fmt, ...);
109 
110 #define trace_me(__fmt, __args...) \
111  do { \
112  if (__base_setup_data.trace_level > 0) \
113  __trace_me(__fmt, ##__args); \
114  } while (0)
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif /* !_BOILERPLATE_SETUP_H */