Revision: 65568
http://sourceforge.net/p/brlcad/code/65568
Author: starseeker
Date: 2015-07-11 00:28:27 +0000 (Sat, 11 Jul 2015)
Log Message:
-----------
Rework bu_observer to use an eval callback function instead of explicitly
requiring Tcl_Eval - abstracts the explicit use of Tcl data types out of
bu_observer, although the command strings are still being constructed as before.
Modified Paths:
--------------
brlcad/trunk/include/bu/bu_tcl.h
brlcad/trunk/include/bu.h
brlcad/trunk/include/rt/wdb.h
brlcad/trunk/misc/doxygen/libbu.dox
brlcad/trunk/src/libbu/observer.c
brlcad/trunk/src/libdm/dm_obj.c
brlcad/trunk/src/libged/view_obj.c
brlcad/trunk/src/mged/wdb_obj.c
Added Paths:
-----------
brlcad/trunk/include/bu/observer.h
Modified: brlcad/trunk/include/bu/bu_tcl.h
===================================================================
--- brlcad/trunk/include/bu/bu_tcl.h 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/include/bu/bu_tcl.h 2015-07-11 00:28:27 UTC (rev 65568)
@@ -43,60 +43,6 @@
BU_EXPORT extern Tcl_Interp *brlcad_interp;
/**
- * TBD
- */
-struct bu_observer {
- struct bu_list l;
- struct bu_vls observer;
- struct bu_vls cmd;
-};
-typedef struct bu_observer bu_observer_t;
-#define BU_OBSERVER_NULL ((struct bu_observer *)0)
-
-/**
- * asserts the integrity of a non-head node bu_observer struct.
- */
-#define BU_CK_OBSERVER(_op) BU_CKMAG(_op, BU_OBSERVER_MAGIC, "bu_observer
magic")
-
-/**
- * initializes a bu_observer struct without allocating any memory.
- */
-#define BU_OBSERVER_INIT(_op) { \
- BU_LIST_INIT_MAGIC(&(_op)->l, BU_OBSERVER_MAGIC); \
- BU_VLS_INIT(&(_op)->observer); \
- BU_VLS_INIT(&(_op)->cmd); \
- }
-
-/**
- * macro suitable for declaration statement initialization of a bu_observer
- * struct. does not allocate memory. not suitable for a head node.
- */
-#define BU_OBSERVER_INIT_ZERO { {BU_OBSERVER_MAGIC, BU_LIST_NULL,
BU_LIST_NULL}, BU_VLS_INIT_ZERO, BU_VLS_INIT_ZERO }
-
-/**
- * returns truthfully whether a bu_observer has been initialized.
- */
-#define BU_OBSERVER_IS_INITIALIZED(_op) (((struct bu_observer *)(_op) !=
BU_OBSERVER_NULL) && LIKELY((_op)->magic == BU_OBSERVER_MAGIC))
-
-/** @brief Routines for implementing the observer pattern. */
-
-/**
- * runs a given command, calling the corresponding observer callback
- * if it matches.
- */
-BU_EXPORT extern int bu_observer_cmd(void *clientData, int argc, const char
*argv[]);
-
-/**
- * Notify observers.
- */
-BU_EXPORT extern void bu_observer_notify(Tcl_Interp *interp, struct
bu_observer *headp, char *self);
-
-/**
- * Free observers.
- */
-BU_EXPORT extern void bu_observer_free(struct bu_observer *);
-
-/**
* Bu_Init
*
* Allows LIBBU to be dynamically loaded to a vanilla tclsh/wish with
Added: brlcad/trunk/include/bu/observer.h
===================================================================
--- brlcad/trunk/include/bu/observer.h (rev 0)
+++ brlcad/trunk/include/bu/observer.h 2015-07-11 00:28:27 UTC (rev 65568)
@@ -0,0 +1,111 @@
+/* B U _ O B S E R V E R . H
+ * BRL-CAD
+ *
+ * Copyright (c) 2004-2014 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#ifndef BU_OBSERVER_H
+#define BU_OBSERVER_H
+
+#include "common.h"
+
+#include "bu/defines.h"
+#include "bu/magic.h"
+#include "bu/list.h"
+#include "bu/vls.h"
+
+__BEGIN_DECLS
+
+/** @addtogroup bu_observer
+ * @brief
+ * libbu observer.
+ */
+/** @{ */
+/** @file bu/observer.h */
+
+/* Generic observer cmd execution function */
+typedef void (bu_observer_eval_t)(void *, const char *);
+
+/**
+ * TBD
+ */
+struct bu_observer {
+ struct bu_list l;
+ struct bu_vls observer;
+ struct bu_vls cmd;
+};
+typedef struct bu_observer bu_observer_t;
+#define BU_OBSERVER_NULL ((struct bu_observer *)0)
+
+/**
+ * asserts the integrity of a non-head node bu_observer struct.
+ */
+#define BU_CK_OBSERVER(_op) BU_CKMAG(_op, BU_OBSERVER_MAGIC, "bu_observer
magic")
+
+/**
+ * initializes a bu_observer struct without allocating any memory.
+ */
+#define BU_OBSERVER_INIT(_op) { \
+ BU_LIST_INIT_MAGIC(&(_op)->l, BU_OBSERVER_MAGIC); \
+ BU_VLS_INIT(&(_op)->observer); \
+ BU_VLS_INIT(&(_op)->cmd); \
+ }
+
+/**
+ * macro suitable for declaration statement initialization of a bu_observer
+ * struct. does not allocate memory. not suitable for a head node.
+ */
+#define BU_OBSERVER_INIT_ZERO { {BU_OBSERVER_MAGIC, BU_LIST_NULL,
BU_LIST_NULL}, BU_VLS_INIT_ZERO, BU_VLS_INIT_ZERO }
+
+/**
+ * returns truthfully whether a bu_observer has been initialized.
+ */
+#define BU_OBSERVER_IS_INITIALIZED(_op) (((struct bu_observer *)(_op) !=
BU_OBSERVER_NULL) && LIKELY((_op)->magic == BU_OBSERVER_MAGIC))
+
+/** @brief Routines for implementing the observer pattern. */
+
+/**
+ * runs a given command, calling the corresponding observer callback
+ * if it matches.
+ */
+BU_EXPORT extern int bu_observer_cmd(void *clientData, int argc, const char
*argv[]);
+
+/**
+ * Notify observers.
+ */
+BU_EXPORT extern void bu_observer_notify(void *context, bu_observer_eval_t
*ofunc, struct bu_observer *headp, char *self);
+
+/**
+ * Free observers.
+ */
+BU_EXPORT extern void bu_observer_free(struct bu_observer *);
+
+/** @} */
+
+__END_DECLS
+
+#endif /* BU_OBSERVER_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/include/bu/observer.h
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/include/bu.h 2015-07-11 00:28:27 UTC (rev 65568)
@@ -78,6 +78,7 @@
#include "./bu/malloc.h"
#include "./bu/mapped_file.h"
#include "./bu/mime.h"
+#include "./bu/observer.h"
#include "./bu/opt.h"
#include "./bu/parallel.h"
#include "./bu/parse.h"
Modified: brlcad/trunk/include/rt/wdb.h
===================================================================
--- brlcad/trunk/include/rt/wdb.h 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/include/rt/wdb.h 2015-07-11 00:28:27 UTC (rev 65568)
@@ -29,7 +29,8 @@
#include "bu/magic.h"
#include "bu/list.h"
#include "bu/vls.h"
-#include "bu/bu_tcl.h" /* for bu_observer and Tcl_Interp */
+#include "bu/bu_tcl.h" /* for Tcl_Interp */
+#include "bu/observer.h"
#include "bn/tol.h"
#include "rt/db_instance.h"
#include "rt/tree.h"
Modified: brlcad/trunk/misc/doxygen/libbu.dox
===================================================================
--- brlcad/trunk/misc/doxygen/libbu.dox 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/misc/doxygen/libbu.dox 2015-07-11 00:28:27 UTC (rev 65568)
@@ -86,11 +86,12 @@
/** @ingroup bu_io */
/** @defgroup bu_log Logging */
/** @ingroup bu_io */
+/** @defgroup bu_observer Observer*/
+/** @ingroup bu_io */
/** @defgroup bu_vfont Vector Fonts */
/** @ingroup bu_io */
/** @defgroup bu_debug Debugging */
-
/* Data Management */
/** @ingroup bu_data */
/** @defgroup bu_conv Data Conversion */
Modified: brlcad/trunk/src/libbu/observer.c
===================================================================
--- brlcad/trunk/src/libbu/observer.c 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/src/libbu/observer.c 2015-07-11 00:28:27 UTC (rev 65568)
@@ -25,7 +25,7 @@
#include "bu/cmd.h"
#include "bu/malloc.h"
#include "bu/str.h"
-#include "bu/bu_tcl.h"
+#include "bu/observer.h"
/**
* Attach observer.
@@ -135,9 +135,8 @@
return BRLCAD_OK;
}
-
void
-bu_observer_notify(Tcl_Interp *interp, struct bu_observer *headp, char *self)
+bu_observer_notify(void *context, bu_observer_eval_t *cmd_eval, struct
bu_observer *headp, char *self)
{
struct bu_observer *op;
struct bu_vls vls = BU_VLS_INIT_ZERO;
@@ -146,18 +145,19 @@
if (bu_vls_strlen(&op->cmd) > 0) {
/* Execute cmd */
bu_vls_strcpy(&vls, bu_vls_addr(&op->cmd));
- Tcl_Eval(interp, bu_vls_addr(&vls));
+ if (cmd_eval)
+ (*cmd_eval)(context, bu_vls_addr(&vls));
} else {
/* Assume that observer is some object that has an update method */
bu_vls_trunc(&vls, 0);
bu_vls_printf(&vls, "%s update %s", bu_vls_addr(&op->observer),
self);
- Tcl_Eval(interp, bu_vls_addr(&vls));
+ if (cmd_eval)
+ (*cmd_eval)(context, bu_vls_addr(&vls));
}
}
bu_vls_free(&vls);
}
-
void
bu_observer_free(struct bu_observer *headp)
{
Modified: brlcad/trunk/src/libdm/dm_obj.c
===================================================================
--- brlcad/trunk/src/libdm/dm_obj.c 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/src/libdm/dm_obj.c 2015-07-11 00:28:27 UTC (rev 65568)
@@ -2672,6 +2672,11 @@
return bu_observer_cmd((ClientData)&dmop->dmo_observers, argc-2, (const
char **)argv+2);
}
+HIDDEN void
+_dm_obj_eval(void *context, const char *cmd) {
+ Tcl_Interp *interp = (Tcl_Interp *)context;
+ Tcl_Eval(interp, cmd);
+}
#ifdef USE_FBSERV
HIDDEN void
@@ -2682,7 +2687,7 @@
if (!dmop)
return;
- bu_observer_notify(dmop->interp, &dmop->dmo_observers,
bu_vls_addr(&dmop->dmo_name));
+ bu_observer_notify((void *)dmop->interp, &(_dm_obj_eval),
&dmop->dmo_observers, bu_vls_addr(&dmop->dmo_name));
}
#endif
Modified: brlcad/trunk/src/libged/view_obj.c
===================================================================
--- brlcad/trunk/src/libged/view_obj.c 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/src/libged/view_obj.c 2015-07-11 00:28:27 UTC (rev 65568)
@@ -62,6 +62,11 @@
BU_PUT(vop, struct view_obj);
}
+HIDDEN void
+_vo_eval(void *context, const char *cmd) {
+ Tcl_Interp *interp = (Tcl_Interp *)context;
+ Tcl_Eval(interp, cmd);
+}
void
vo_update(struct view_obj *vop,
@@ -107,7 +112,7 @@
if (vop->vo_callback)
(*vop->vo_callback)(vop->vo_clientData, vop);
else if (oflag)
- bu_observer_notify(vop->interp, &vop->vo_observers,
bu_vls_addr(&vop->vo_name));
+ bu_observer_notify((void *)vop->interp, &(_vo_eval),
&vop->vo_observers, bu_vls_addr(&vop->vo_name));
}
Modified: brlcad/trunk/src/mged/wdb_obj.c
===================================================================
--- brlcad/trunk/src/mged/wdb_obj.c 2015-07-10 21:47:28 UTC (rev 65567)
+++ brlcad/trunk/src/mged/wdb_obj.c 2015-07-11 00:28:27 UTC (rev 65568)
@@ -2657,6 +2657,11 @@
return TCL_OK;
}
+HIDDEN void
+_wdb_eval(void *context, const char *cmd) {
+ Tcl_Interp *interp = (Tcl_Interp *)context;
+ Tcl_Eval(interp, cmd);
+}
int
wdb_adjust_cmd(struct rt_wdb *wdbp,
@@ -2724,7 +2729,7 @@
}
/* notify observers */
- bu_observer_notify(wdbp->wdb_interp, &wdbp->wdb_observers,
bu_vls_addr(&wdbp->wdb_name));
+ bu_observer_notify((void *)wdbp->wdb_interp, &(_wdb_eval),
&wdbp->wdb_observers, bu_vls_addr(&wdbp->wdb_name));
return status;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits