BRL-CAD
bu_tcl.h
Go to the documentation of this file.
1 /* B U _ T C L . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /** @file bu_tcl.h
22  *
23  */
24 #ifndef BU_TCL_H
25 #define BU_TCL_H
26 
27 #include "common.h"
28 
29 #include "tcl.h" /* Included for Tcl_Interp definition */
30 
31 #include "bu/defines.h"
32 #include "bu/magic.h"
33 #include "bu/list.h"
34 #include "bu/vls.h"
35 
37 
38 /** @addtogroup tcl */
39 /** @{ */
40 
41 /* FIXME Temporary global interp. Remove me. */
42 BU_EXPORT extern Tcl_Interp *brlcad_interp;
43 
44 /**
45  * TBD
46  */
47 struct bu_observer {
48  struct bu_list l;
49  struct bu_vls observer;
50  struct bu_vls cmd;
51 };
52 typedef struct bu_observer bu_observer_t;
53 #define BU_OBSERVER_NULL ((struct bu_observer *)0)
54 
55 /**
56  * asserts the integrity of a non-head node bu_observer struct.
57  */
58 #define BU_CK_OBSERVER(_op) BU_CKMAG(_op, BU_OBSERVER_MAGIC, "bu_observer magic")
59 
60 /**
61  * initializes a bu_observer struct without allocating any memory.
62  */
63 #define BU_OBSERVER_INIT(_op) { \
64  BU_LIST_INIT_MAGIC(&(_op)->l, BU_OBSERVER_MAGIC); \
65  BU_VLS_INIT(&(_op)->observer); \
66  BU_VLS_INIT(&(_op)->cmd); \
67  }
68 
69 /**
70  * macro suitable for declaration statement initialization of a bu_observer
71  * struct. does not allocate memory. not suitable for a head node.
72  */
73 #define BU_OBSERVER_INIT_ZERO { {BU_OBSERVER_MAGIC, BU_LIST_NULL, BU_LIST_NULL}, BU_VLS_INIT_ZERO, BU_VLS_INIT_ZERO }
74 
75 /**
76  * returns truthfully whether a bu_observer has been initialized.
77  */
78 #define BU_OBSERVER_IS_INITIALIZED(_op) (((struct bu_observer *)(_op) != BU_OBSERVER_NULL) && LIKELY((_op)->magic == BU_OBSERVER_MAGIC))
79 
80 /** @file libbu/observer.c
81  *
82  * @brief
83  * Routines for implementing the observer pattern.
84  *
85  */
86 
87 /**
88  * runs a given command, calling the corresponding observer callback
89  * if it matches.
90  */
91 BU_EXPORT extern int bu_observer_cmd(void *clientData, int argc, const char *argv[]);
92 
93 /**
94  * Notify observers.
95  */
96 BU_EXPORT extern void bu_observer_notify(Tcl_Interp *interp, struct bu_observer *headp, char *self);
97 
98 /**
99  * Free observers.
100  */
101 BU_EXPORT extern void bu_observer_free(struct bu_observer *);
102 
103 /** @file libbu/tcl.c
104  *
105  * @brief
106  * Routine(s) to allow TCL calling libbu code.
107  *
108  */
109 /**
110  * Bu_Init
111  *
112  * Allows LIBBU to be dynamically loaded to a vanilla tclsh/wish with
113  * "load /usr/brlcad/lib/libbu.so"
114  *
115  * @param interp - tcl interpreter in which this command was registered.
116  *
117  * @return BRLCAD_OK if successful, otherwise, BRLCAD_ERROR.
118  */
119 BU_EXPORT extern int Bu_Init(void *interp);
120 
121 
122 /** @} */
123 
125 
126 #endif /* BU_TCL_H */
127 
128 /*
129  * Local Variables:
130  * mode: C
131  * tab-width: 8
132  * indent-tabs-mode: t
133  * c-file-style: "stroustrup"
134  * End:
135  * ex: shiftwidth=4 tabstop=8
136  */
int bu_observer_cmd(void *clientData, int argc, const char *argv[])
Definition: list.h:118
ustring interp
struct bu_vls observer
Definition: bu_tcl.h:49
int Bu_Init(void *interp)
Definition: tcl.c:422
Header file for the BRL-CAD common definitions.
struct bu_list l
Definition: bu_tcl.h:48
#define __BEGIN_DECLS
Definition: common.h:73
void bu_observer_free(struct bu_observer *)
Definition: observer.c:162
#define __END_DECLS
Definition: common.h:74
Definition: vls.h:56
struct bu_vls cmd
Definition: bu_tcl.h:50
Tcl_Interp * brlcad_interp
Definition: tcl.c:41
void bu_observer_notify(Tcl_Interp *interp, struct bu_observer *headp, char *self)
Definition: observer.c:140