Hi Sasha,

I wrote this patch so I could avoid passing around a pointer to the opensm, 
just to
get access to the log.  Also, it provides a method to get a pointer to the 
opensm
as well, because there are several instances where this is needed for a trivial 
reason,
and many functions include it as one of their arguments.  Since the opensm is a
singleton, it could just be accessed directly by the function when its needed.

Ultimately, this can lead to simplification of header files.

--
Timothy A. Meier
Computer Scientist
ICCD/High Performance Computing
925.422.3341
[EMAIL PROTECTED]
>From ad55cf9e7e812960bb187eee4a329903dabae760 Mon Sep 17 00:00:00 2001
From: Tim Meier <[EMAIL PROTECTED]>
Date: Tue, 4 Mar 2008 17:09:25 -0800
Subject: [PATCH] opensm:  provide methods for getting the OpenSM and Log

This patch provides convenient access to the OpenSM
object and the OSM_Log.  Often methods just need to
log messages, and this allows them to get and use
the log, without involving the entire OpenSM object.

Signed-off-by: Tim Meier <[EMAIL PROTECTED]>
---
 opensm/include/opensm/osm_opensm.h |    7 +++++++
 opensm/opensm/osm_opensm.c         |   31 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/opensm/include/opensm/osm_opensm.h 
b/opensm/include/opensm/osm_opensm.h
index cd1e73b..26294d5 100644
--- a/opensm/include/opensm/osm_opensm.h
+++ b/opensm/include/opensm/osm_opensm.h
@@ -500,6 +500,13 @@ osm_routing_engine_type_t osm_routing_engine_type(IN const 
char *str);
 * SEE ALSO
 *********/
 
+/* accessor functions - helps maintain "opaqueness"
+ *   opensm - the one and only super object
+ *   log    - the opensm log
+ */
+osm_opensm_t * osm_opensm_get_opensm(void);
+osm_log_t * osm_opensm_get_opensm_log(void);
+
 /* dump helpers */
 void osm_dump_mcast_routes(osm_opensm_t * osm);
 void osm_dump_all(osm_opensm_t * osm);
diff --git a/opensm/opensm/osm_opensm.c b/opensm/opensm/osm_opensm.c
index aa7ded3..c3ec259 100644
--- a/opensm/opensm/osm_opensm.c
+++ b/opensm/opensm/osm_opensm.c
@@ -68,6 +68,11 @@ struct routing_engine_module {
        int (*setup) (osm_opensm_t * p_osm);
 };
 
+/*     
+ * A pointer to the OpenSM super object.  See osm_opensm_construct().
+ */
+static osm_opensm_t * p_osm_object = NULL;
+
 extern int osm_ucast_updn_setup(osm_opensm_t * p_osm);
 extern int osm_ucast_file_setup(osm_opensm_t * p_osm);
 extern int osm_ucast_ftree_setup(osm_opensm_t * p_osm);
@@ -170,6 +175,29 @@ static int osm_ucast_null_setup(osm_opensm_t * p_osm)
 
 /**********************************************************************
  **********************************************************************/
+osm_opensm_t * osm_opensm_get_opensm(void)
+{
+       /* an accessor method for the super object;
+        *   preferred over passing pointer around as an argument
+        */
+       CL_ASSERT(p_osm_object);
+       return p_osm_object;
+}
+
+/**********************************************************************
+ **********************************************************************/
+osm_log_t * osm_opensm_get_opensm_log(void)
+{
+       /* an accessor method for the osm log;
+        *   preferred over passing pointer around as an argument
+        */
+       CL_ASSERT(p_osm_object);
+       CL_ASSERT(&p_osm_object->log);
+       return &p_osm_object->log;
+}
+
+/**********************************************************************
+ **********************************************************************/
 void osm_opensm_construct(IN osm_opensm_t * const p_osm)
 {
        memset(p_osm, 0, sizeof(*p_osm));
@@ -180,6 +208,7 @@ void osm_opensm_construct(IN osm_opensm_t * const p_osm)
        osm_mad_pool_construct(&p_osm->mad_pool);
        osm_vl15_construct(&p_osm->vl15);
        osm_log_construct(&p_osm->log);
+       p_osm_object = p_osm;
 }
 
 /**********************************************************************
@@ -245,6 +274,8 @@ void osm_opensm_destroy(IN osm_opensm_t * const p_osm)
        cl_plock_destroy(&p_osm->lock);
 
        osm_log_destroy(&p_osm->log);
+       
+       p_osm_object = NULL;    /* prevent its use via assertions */
 }
 
 /**********************************************************************
-- 
1.5.1

_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to